2 * Jalview - A Sequence Alignment Editor and Viewer ($$Version-Rel$$)
3 * Copyright (C) $$Year-Rel$$ The Jalview Authors
5 * This file is part of Jalview.
7 * Jalview is free software: you can redistribute it and/or
8 * modify it under the terms of the GNU General Public License
9 * as published by the Free Software Foundation, either version 3
10 * of the License, or (at your option) any later version.
12 * Jalview is distributed in the hope that it will be useful, but
13 * WITHOUT ANY WARRANTY; without even the implied warranty
14 * of MERCHANTABILITY or FITNESS FOR A PARTICULAR
15 * PURPOSE. See the GNU General Public License for more details.
17 * You should have received a copy of the GNU General Public License
18 * along with Jalview. If not, see <http://www.gnu.org/licenses/>.
19 * The Jalview Authors are detailed in the 'AUTHORS' file.
21 package jalview.datamodel;
23 import jalview.analysis.AlignSeq;
24 import jalview.api.DBRefEntryI;
25 import jalview.datamodel.features.SequenceFeatures;
26 import jalview.datamodel.features.SequenceFeaturesI;
27 import jalview.util.Comparison;
28 import jalview.util.DBRefUtils;
29 import jalview.util.MapList;
30 import jalview.util.StringUtils;
32 import java.util.ArrayList;
33 import java.util.Arrays;
34 import java.util.Collections;
35 import java.util.Enumeration;
36 import java.util.List;
37 import java.util.Vector;
39 import fr.orsay.lri.varna.models.rna.RNA;
43 * Implements the SequenceI interface for a char[] based sequence object.
48 public class Sequence extends ASequence implements SequenceI
50 SequenceI datasetSequence;
54 private char[] sequence;
62 Vector<PDBEntry> pdbIds;
71 * This annotation is displayed below the alignment but the positions are tied
72 * to the residues of this sequence
74 * TODO: change to List<>
76 Vector<AlignmentAnnotation> annotation;
79 * The index of the sequence in a MSA
83 /** array of sequence features - may not be null for a valid sequence object */
84 public SequenceFeature[] sequenceFeatures;
86 private SequenceFeatures sequenceFeatureStore;
89 * Creates a new Sequence object.
94 * string to form a possibly gapped sequence out of
96 * first position of non-gap residue in the sequence
98 * last position of ungapped residues (nearly always only used for
101 public Sequence(String name, String sequence, int start, int end)
103 initSeqAndName(name, sequence.toCharArray(), start, end);
106 public Sequence(String name, char[] sequence, int start, int end)
108 initSeqAndName(name, sequence, start, end);
112 * Stage 1 constructor - assign name, sequence, and set start and end fields.
113 * start and end are updated values from name2 if it ends with /start-end
120 protected void initSeqAndName(String name2, char[] sequence2, int start2,
124 this.sequence = sequence2;
127 sequenceFeatureStore = new SequenceFeatures();
132 com.stevesoft.pat.Regex limitrx = new com.stevesoft.pat.Regex(
133 "[/][0-9]{1,}[-][0-9]{1,}$");
135 com.stevesoft.pat.Regex endrx = new com.stevesoft.pat.Regex("[0-9]{1,}$");
142 .println("POSSIBLE IMPLEMENTATION ERROR: null sequence name passed to constructor.");
145 // Does sequence have the /start-end signature?
146 if (limitrx.search(name))
148 name = limitrx.left();
149 endrx.search(limitrx.stringMatched());
150 setStart(Integer.parseInt(limitrx.stringMatched().substring(1,
151 endrx.matchedFrom() - 1)));
152 setEnd(Integer.parseInt(endrx.stringMatched()));
156 void checkValidRange()
159 // http://issues.jalview.org/browse/JAL-774?focusedCommentId=11239&page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel#comment-11239
162 for (int j = 0; j < sequence.length; j++)
164 if (!jalview.util.Comparison.isGap(sequence[j]))
183 * Creates a new Sequence object.
190 public Sequence(String name, String sequence)
192 this(name, sequence, 1, -1);
196 * Creates a new Sequence object with new AlignmentAnnotations but inherits
197 * any existing dataset sequence reference. If non exists, everything is
201 * if seq is a dataset sequence, behaves like a plain old copy
204 public Sequence(SequenceI seq)
206 this(seq, seq.getAnnotation());
210 * Create a new sequence object with new features, DBRefEntries, and PDBIds
211 * but inherits any existing dataset sequence reference, and duplicate of any
212 * annotation that is present in the given annotation array.
215 * the sequence to be copied
216 * @param alAnnotation
217 * an array of annotation including some associated with seq
219 public Sequence(SequenceI seq, AlignmentAnnotation[] alAnnotation)
221 initSeqFrom(seq, alAnnotation);
226 * does the heavy lifting when cloning a dataset sequence, or coping data from
227 * dataset to a new derived sequence.
230 * - source of attributes.
231 * @param alAnnotation
232 * - alignment annotation present on seq that should be copied onto
235 protected void initSeqFrom(SequenceI seq,
236 AlignmentAnnotation[] alAnnotation)
239 char[] oseq = seq.getSequence();
240 initSeqAndName(seq.getName(), Arrays.copyOf(oseq, oseq.length),
241 seq.getStart(), seq.getEnd());
243 description = seq.getDescription();
244 if (seq != datasetSequence)
246 setDatasetSequence(seq.getDatasetSequence());
248 if (datasetSequence == null && seq.getDBRefs() != null)
250 // only copy DBRefs and seqfeatures if we really are a dataset sequence
251 DBRefEntry[] dbr = seq.getDBRefs();
252 for (int i = 0; i < dbr.length; i++)
254 addDBRef(new DBRefEntry(dbr[i]));
256 if (seq.getSequenceFeatures() != null)
258 SequenceFeature[] sf = seq.getSequenceFeatures();
259 for (int i = 0; i < sf.length; i++)
261 addSequenceFeature(new SequenceFeature(sf[i]));
265 if (seq.getAnnotation() != null)
267 AlignmentAnnotation[] sqann = seq.getAnnotation();
268 for (int i = 0; i < sqann.length; i++)
270 if (sqann[i] == null)
274 boolean found = (alAnnotation == null);
277 for (int apos = 0; !found && apos < alAnnotation.length; apos++)
279 found = (alAnnotation[apos] == sqann[i]);
284 // only copy the given annotation
285 AlignmentAnnotation newann = new AlignmentAnnotation(sqann[i]);
286 addAlignmentAnnotation(newann);
290 if (seq.getAllPDBEntries() != null)
292 Vector<PDBEntry> ids = seq.getAllPDBEntries();
293 for (PDBEntry pdb : ids)
295 this.addPDBId(new PDBEntry(pdb));
301 public void setSequenceFeatures(SequenceFeature[] features)
303 if (datasetSequence == null)
305 sequenceFeatures = features;
309 if (datasetSequence.getSequenceFeatures() != features
310 && datasetSequence.getSequenceFeatures() != null
311 && datasetSequence.getSequenceFeatures().length > 0)
314 "Warning: JAL-2046 side effect ? Possible implementation error: overwriting dataset sequence features by setting sequence features on alignment")
317 datasetSequence.setSequenceFeatures(features);
322 public synchronized boolean addSequenceFeature(SequenceFeature sf)
324 if (sf.getType() == null)
326 System.err.println("SequenceFeature type may not be null: "
331 if (sequenceFeatures == null && datasetSequence != null)
333 return datasetSequence.addSequenceFeature(sf);
335 if (sequenceFeatures == null)
337 sequenceFeatures = new SequenceFeature[0];
340 for (int i = 0; i < sequenceFeatures.length; i++)
342 if (sequenceFeatures[i].equals(sf))
348 SequenceFeature[] temp = new SequenceFeature[sequenceFeatures.length + 1];
349 System.arraycopy(sequenceFeatures, 0, temp, 0, sequenceFeatures.length);
350 temp[sequenceFeatures.length] = sf;
352 sequenceFeatures = temp;
354 sequenceFeatureStore.add(sf);
359 public void deleteFeature(SequenceFeature sf)
361 if (sequenceFeatures == null)
363 if (datasetSequence != null)
365 datasetSequence.deleteFeature(sf);
373 sequenceFeatureStore.delete(sf);
376 * old way - to be removed
379 for (index = 0; index < sequenceFeatures.length; index++)
381 if (sequenceFeatures[index].equals(sf))
387 if (index == sequenceFeatures.length)
392 int sfLength = sequenceFeatures.length;
395 sequenceFeatures = null;
399 SequenceFeature[] temp = new SequenceFeature[sfLength - 1];
400 System.arraycopy(sequenceFeatures, 0, temp, 0, index);
402 if (index < sfLength)
404 System.arraycopy(sequenceFeatures, index + 1, temp, index,
405 sequenceFeatures.length - index - 1);
408 sequenceFeatures = temp;
413 * Returns the sequence features (if any), looking first on the sequence, then
414 * on its dataset sequence, and so on until a non-null value is found (or
415 * none). This supports retrieval of sequence features stored on the sequence
416 * (as in the applet) or on the dataset sequence (as in the Desktop version).
421 public SequenceFeature[] getSequenceFeatures()
423 SequenceFeature[] features = sequenceFeatures;
425 SequenceI seq = this;
426 int count = 0; // failsafe against loop in sequence.datasetsequence...
427 while (features == null && seq.getDatasetSequence() != null
430 seq = seq.getDatasetSequence();
431 features = ((Sequence) seq).sequenceFeatures;
437 public SequenceFeaturesI getFeatures()
439 return datasetSequence != null ? datasetSequence.getFeatures()
440 : sequenceFeatureStore;
444 public boolean addPDBId(PDBEntry entry)
448 pdbIds = new Vector<PDBEntry>();
453 for (PDBEntry pdbe : pdbIds)
455 if (pdbe.updateFrom(entry))
460 pdbIds.addElement(entry);
471 public void setPDBId(Vector<PDBEntry> id)
479 * @return DOCUMENT ME!
482 public Vector<PDBEntry> getAllPDBEntries()
484 return pdbIds == null ? new Vector<PDBEntry>() : pdbIds;
490 * @return DOCUMENT ME!
493 public String getDisplayId(boolean jvsuffix)
495 StringBuffer result = new StringBuffer(name);
498 result.append("/" + start + "-" + end);
501 return result.toString();
511 public void setName(String name)
520 * @return DOCUMENT ME!
523 public String getName()
535 public void setStart(int start)
543 * @return DOCUMENT ME!
546 public int getStart()
558 public void setEnd(int end)
566 * @return DOCUMENT ME!
577 * @return DOCUMENT ME!
580 public int getLength()
582 return this.sequence.length;
592 public void setSequence(String seq)
594 this.sequence = seq.toCharArray();
599 public String getSequenceAsString()
601 return new String(sequence);
605 public String getSequenceAsString(int start, int end)
607 return new String(getSequence(start, end));
611 public char[] getSequence()
619 * @see jalview.datamodel.SequenceI#getSequence(int, int)
622 public char[] getSequence(int start, int end)
628 // JBPNote - left to user to pad the result here (TODO:Decide on this
630 if (start >= sequence.length)
635 if (end >= sequence.length)
637 end = sequence.length;
640 char[] reply = new char[end - start];
641 System.arraycopy(sequence, start, reply, 0, end - start);
647 public SequenceI getSubSequence(int start, int end)
653 char[] seq = getSequence(start, end);
658 int nstart = findPosition(start);
659 int nend = findPosition(end) - 1;
660 // JBPNote - this is an incomplete copy.
661 SequenceI nseq = new Sequence(this.getName(), seq, nstart, nend);
662 nseq.setDescription(description);
663 if (datasetSequence != null)
665 nseq.setDatasetSequence(datasetSequence);
669 nseq.setDatasetSequence(this);
675 * Returns the character of the aligned sequence at the given position (base
676 * zero), or space if the position is not within the sequence's bounds
681 public char getCharAt(int i)
683 if (i >= 0 && i < sequence.length)
700 public void setDescription(String desc)
702 this.description = desc;
708 * @return DOCUMENT ME!
711 public String getDescription()
713 return this.description;
719 * @see jalview.datamodel.SequenceI#findIndex(int)
722 public int findIndex(int pos)
724 // returns the alignment position for a residue
727 // Rely on end being at least as long as the length of the sequence.
728 while ((i < sequence.length) && (j <= end) && (j <= pos))
730 if (!jalview.util.Comparison.isGap(sequence[i]))
738 if ((j == end) && (j < pos))
749 public int findPosition(int i)
753 int seqlen = sequence.length;
754 while ((j < i) && (j < seqlen))
756 if (!jalview.util.Comparison.isGap(sequence[j]))
768 * Returns an int array where indices correspond to each residue in the
769 * sequence and the element value gives its position in the alignment
771 * @return int[SequenceI.getEnd()-SequenceI.getStart()+1] or null if no
772 * residues in SequenceI object
775 public int[] gapMap()
777 String seq = jalview.analysis.AlignSeq.extractGaps(
778 jalview.util.Comparison.GapChars, new String(sequence));
779 int[] map = new int[seq.length()];
783 while (j < sequence.length)
785 if (!jalview.util.Comparison.isGap(sequence[j]))
797 public int[] findPositionMap()
799 int map[] = new int[sequence.length];
802 int seqlen = sequence.length;
806 if (!jalview.util.Comparison.isGap(sequence[j]))
817 public List<int[]> getInsertions()
819 ArrayList<int[]> map = new ArrayList<int[]>();
820 int lastj = -1, j = 0;
822 int seqlen = sequence.length;
825 if (jalview.util.Comparison.isGap(sequence[j]))
836 map.add(new int[] { lastj, j - 1 });
844 map.add(new int[] { lastj, j - 1 });
851 public void deleteChars(int i, int j)
853 int newstart = start, newend = end;
854 if (i >= sequence.length || i < 0)
859 char[] tmp = StringUtils.deleteChars(sequence, i, j);
860 boolean createNewDs = false;
861 // TODO: take a (second look) at the dataset creation validation method for
862 // the very large sequence case
863 int eindex = -1, sindex = -1;
864 boolean ecalc = false, scalc = false;
865 for (int s = i; s < j; s++)
867 if (jalview.schemes.ResidueProperties.aaIndex[sequence[s]] != 23)
877 sindex = findIndex(start) - 1;
882 // delete characters including start of sequence
883 newstart = findPosition(j);
884 break; // don't need to search for any more residue characters.
888 // delete characters after start.
891 eindex = findIndex(end) - 1;
896 // delete characters at end of sequence
897 newend = findPosition(i - 1);
898 break; // don't need to search for any more residue characters.
903 newend--; // decrease end position by one for the deleted residue
904 // and search further
910 // deletion occured in the middle of the sequence
911 if (createNewDs && this.datasetSequence != null)
913 // construct a new sequence
914 Sequence ds = new Sequence(datasetSequence);
915 // TODO: remove any non-inheritable properties ?
916 // TODO: create a sequence mapping (since there is a relation here ?)
917 ds.deleteChars(i, j);
918 datasetSequence = ds;
926 public void insertCharAt(int i, int length, char c)
928 char[] tmp = new char[sequence.length + length];
930 if (i >= sequence.length)
932 System.arraycopy(sequence, 0, tmp, 0, sequence.length);
937 System.arraycopy(sequence, 0, tmp, 0, i);
947 if (i < sequence.length)
949 System.arraycopy(sequence, i, tmp, index, sequence.length - i);
956 public void insertCharAt(int i, char c)
958 insertCharAt(i, 1, c);
962 public String getVamsasId()
968 public void setVamsasId(String id)
974 public void setDBRefs(DBRefEntry[] dbref)
976 if (dbrefs == null && datasetSequence != null
977 && this != datasetSequence)
979 datasetSequence.setDBRefs(dbref);
985 DBRefUtils.ensurePrimaries(this);
990 public DBRefEntry[] getDBRefs()
992 if (dbrefs == null && datasetSequence != null
993 && this != datasetSequence)
995 return datasetSequence.getDBRefs();
1001 public void addDBRef(DBRefEntry entry)
1003 if (datasetSequence != null)
1005 datasetSequence.addDBRef(entry);
1011 dbrefs = new DBRefEntry[0];
1014 for (DBRefEntryI dbr : dbrefs)
1016 if (dbr.updateFrom(entry))
1019 * found a dbref that either matched, or could be
1020 * updated from, the new entry - no need to add it
1027 * extend the array to make room for one more
1029 // TODO use an ArrayList instead
1030 int j = dbrefs.length;
1031 DBRefEntry[] temp = new DBRefEntry[j + 1];
1032 System.arraycopy(dbrefs, 0, temp, 0, j);
1033 temp[temp.length - 1] = entry;
1037 DBRefUtils.ensurePrimaries(this);
1041 public void setDatasetSequence(SequenceI seq)
1045 throw new IllegalArgumentException(
1046 "Implementation Error: self reference passed to SequenceI.setDatasetSequence");
1048 if (seq != null && seq.getDatasetSequence() != null)
1050 throw new IllegalArgumentException(
1051 "Implementation error: cascading dataset sequences are not allowed.");
1053 datasetSequence = seq;
1057 public SequenceI getDatasetSequence()
1059 return datasetSequence;
1063 public AlignmentAnnotation[] getAnnotation()
1065 return annotation == null ? null : annotation
1066 .toArray(new AlignmentAnnotation[annotation.size()]);
1070 public boolean hasAnnotation(AlignmentAnnotation ann)
1072 return annotation == null ? false : annotation.contains(ann);
1076 public void addAlignmentAnnotation(AlignmentAnnotation annotation)
1078 if (this.annotation == null)
1080 this.annotation = new Vector<AlignmentAnnotation>();
1082 if (!this.annotation.contains(annotation))
1084 this.annotation.addElement(annotation);
1086 annotation.setSequenceRef(this);
1090 public void removeAlignmentAnnotation(AlignmentAnnotation annotation)
1092 if (this.annotation != null)
1094 this.annotation.removeElement(annotation);
1095 if (this.annotation.size() == 0)
1097 this.annotation = null;
1103 * test if this is a valid candidate for another sequence's dataset sequence.
1106 private boolean isValidDatasetSequence()
1108 if (datasetSequence != null)
1112 for (int i = 0; i < sequence.length; i++)
1114 if (jalview.util.Comparison.isGap(sequence[i]))
1123 public SequenceI deriveSequence()
1125 Sequence seq = null;
1126 if (datasetSequence == null)
1128 if (isValidDatasetSequence())
1130 // Use this as dataset sequence
1131 seq = new Sequence(getName(), "", 1, -1);
1132 seq.setDatasetSequence(this);
1133 seq.initSeqFrom(this, getAnnotation());
1138 // Create a new, valid dataset sequence
1139 createDatasetSequence();
1142 return new Sequence(this);
1145 private boolean _isNa;
1147 private long _seqhash = 0;
1150 * Answers false if the sequence is more than 85% nucleotide (ACGTU), else
1154 public boolean isProtein()
1156 if (datasetSequence != null)
1158 return datasetSequence.isProtein();
1160 if (_seqhash != sequence.hashCode())
1162 _seqhash = sequence.hashCode();
1163 _isNa = Comparison.isNucleotide(this);
1171 * @see jalview.datamodel.SequenceI#createDatasetSequence()
1174 public SequenceI createDatasetSequence()
1176 if (datasetSequence == null)
1178 Sequence dsseq = new Sequence(getName(), AlignSeq.extractGaps(
1179 jalview.util.Comparison.GapChars, getSequenceAsString()),
1180 getStart(), getEnd());
1182 datasetSequence = dsseq;
1184 dsseq.setDescription(description);
1185 // move features and database references onto dataset sequence
1186 dsseq.sequenceFeatures = sequenceFeatures;
1187 sequenceFeatures = null;
1188 dsseq.sequenceFeatureStore = sequenceFeatureStore;
1189 sequenceFeatureStore = null;
1190 dsseq.dbrefs = dbrefs;
1192 // TODO: search and replace any references to this sequence with
1193 // references to the dataset sequence in Mappings on dbref
1194 dsseq.pdbIds = pdbIds;
1196 datasetSequence.updatePDBIds();
1197 if (annotation != null)
1199 // annotation is cloned rather than moved, to preserve what's currently
1201 for (AlignmentAnnotation aa : annotation)
1203 AlignmentAnnotation _aa = new AlignmentAnnotation(aa);
1204 _aa.sequenceRef = datasetSequence;
1205 _aa.adjustForAlignment(); // uses annotation's own record of
1206 // sequence-column mapping
1207 datasetSequence.addAlignmentAnnotation(_aa);
1211 return datasetSequence;
1218 * jalview.datamodel.SequenceI#setAlignmentAnnotation(AlignmmentAnnotation[]
1222 public void setAlignmentAnnotation(AlignmentAnnotation[] annotations)
1224 if (annotation != null)
1226 annotation.removeAllElements();
1228 if (annotations != null)
1230 for (int i = 0; i < annotations.length; i++)
1232 if (annotations[i] != null)
1234 addAlignmentAnnotation(annotations[i]);
1241 public AlignmentAnnotation[] getAnnotation(String label)
1243 if (annotation == null || annotation.size() == 0)
1248 Vector subset = new Vector();
1249 Enumeration e = annotation.elements();
1250 while (e.hasMoreElements())
1252 AlignmentAnnotation ann = (AlignmentAnnotation) e.nextElement();
1253 if (ann.label != null && ann.label.equals(label))
1255 subset.addElement(ann);
1258 if (subset.size() == 0)
1262 AlignmentAnnotation[] anns = new AlignmentAnnotation[subset.size()];
1264 e = subset.elements();
1265 while (e.hasMoreElements())
1267 anns[i++] = (AlignmentAnnotation) e.nextElement();
1269 subset.removeAllElements();
1274 public boolean updatePDBIds()
1276 if (datasetSequence != null)
1278 // TODO: could merge DBRefs
1279 return datasetSequence.updatePDBIds();
1281 if (dbrefs == null || dbrefs.length == 0)
1285 boolean added = false;
1286 for (DBRefEntry dbr : dbrefs)
1288 if (DBRefSource.PDB.equals(dbr.getSource()))
1291 * 'Add' any PDB dbrefs as a PDBEntry - add is only performed if the
1292 * PDB id is not already present in a 'matching' PDBEntry
1293 * Constructor parses out a chain code if appended to the accession id
1294 * (a fudge used to 'store' the chain code in the DBRef)
1296 PDBEntry pdbe = new PDBEntry(dbr);
1297 added |= addPDBId(pdbe);
1304 public void transferAnnotation(SequenceI entry, Mapping mp)
1306 if (datasetSequence != null)
1308 datasetSequence.transferAnnotation(entry, mp);
1311 if (entry.getDatasetSequence() != null)
1313 transferAnnotation(entry.getDatasetSequence(), mp);
1316 // transfer any new features from entry onto sequence
1317 if (entry.getSequenceFeatures() != null)
1320 SequenceFeature[] sfs = entry.getSequenceFeatures();
1321 for (int si = 0; si < sfs.length; si++)
1323 SequenceFeature sf[] = (mp != null) ? mp.locateFeature(sfs[si])
1324 : new SequenceFeature[] { new SequenceFeature(sfs[si]) };
1325 if (sf != null && sf.length > 0)
1327 for (int sfi = 0; sfi < sf.length; sfi++)
1329 addSequenceFeature(sf[sfi]);
1335 // transfer PDB entries
1336 if (entry.getAllPDBEntries() != null)
1338 Enumeration e = entry.getAllPDBEntries().elements();
1339 while (e.hasMoreElements())
1341 PDBEntry pdb = (PDBEntry) e.nextElement();
1345 // transfer database references
1346 DBRefEntry[] entryRefs = entry.getDBRefs();
1347 if (entryRefs != null)
1349 for (int r = 0; r < entryRefs.length; r++)
1351 DBRefEntry newref = new DBRefEntry(entryRefs[r]);
1352 if (newref.getMap() != null && mp != null)
1354 // remap ref using our local mapping
1356 // we also assume all version string setting is done by dbSourceProxy
1358 * if (!newref.getSource().equalsIgnoreCase(dbSource)) {
1359 * newref.setSource(dbSource); }
1367 * @return The index (zero-based) on this sequence in the MSA. It returns
1368 * {@code -1} if this information is not available.
1371 public int getIndex()
1377 * Defines the position of this sequence in the MSA. Use the value {@code -1}
1378 * if this information is undefined.
1381 * position for this sequence. This value is zero-based (zero for
1382 * this first sequence)
1385 public void setIndex(int value)
1391 public void setRNA(RNA r)
1403 public List<AlignmentAnnotation> getAlignmentAnnotations(String calcId,
1406 List<AlignmentAnnotation> result = new ArrayList<AlignmentAnnotation>();
1407 if (this.annotation != null)
1409 for (AlignmentAnnotation ann : annotation)
1411 if (ann.calcId != null && ann.calcId.equals(calcId)
1412 && ann.label != null && ann.label.equals(label))
1422 public String toString()
1424 return getDisplayId(false);
1428 public PDBEntry getPDBEntry(String pdbIdStr)
1430 if (getDatasetSequence() != null)
1432 return getDatasetSequence().getPDBEntry(pdbIdStr);
1438 List<PDBEntry> entries = getAllPDBEntries();
1439 for (PDBEntry entry : entries)
1441 if (entry.getId().equalsIgnoreCase(pdbIdStr))
1450 public List<DBRefEntry> getPrimaryDBRefs()
1452 if (datasetSequence != null)
1454 return datasetSequence.getPrimaryDBRefs();
1456 if (dbrefs == null || dbrefs.length == 0)
1458 return Collections.emptyList();
1460 synchronized (dbrefs)
1462 List<DBRefEntry> primaries = new ArrayList<DBRefEntry>();
1463 DBRefEntry[] tmp = new DBRefEntry[1];
1464 for (DBRefEntry ref : dbrefs)
1466 if (!ref.isPrimaryCandidate())
1472 MapList mp = ref.getMap().getMap();
1473 if (mp.getFromLowest() > start || mp.getFromHighest() < end)
1475 // map only involves a subsequence, so cannot be primary
1479 // whilst it looks like it is a primary ref, we also sanity check type
1480 if (DBRefUtils.getCanonicalName(DBRefSource.PDB).equals(
1481 DBRefUtils.getCanonicalName(ref.getSource())))
1483 // PDB dbrefs imply there should be a PDBEntry associated
1484 // TODO: tighten PDB dbrefs
1485 // formally imply Jalview has actually downloaded and
1486 // parsed the pdb file. That means there should be a cached file
1487 // handle on the PDBEntry, and a real mapping between sequence and
1488 // extracted sequence from PDB file
1489 PDBEntry pdbentry = getPDBEntry(ref.getAccessionId());
1490 if (pdbentry != null && pdbentry.getFile() != null)
1496 // check standard protein or dna sources
1498 DBRefEntry[] res = DBRefUtils.selectDbRefs(!isProtein(), tmp);
1499 if (res != null && res[0] == tmp[0])
1513 public List<SequenceFeature> findFeatures(int from, int to,
1516 if (datasetSequence != null)
1518 return datasetSequence.findFeatures(from, to, types);
1520 return sequenceFeatureStore.findFeatures(from, to, types);