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 com.stevesoft.pat.Regex;
41 import fr.orsay.lri.varna.models.rna.RNA;
45 * Implements the SequenceI interface for a char[] based sequence object.
50 public class Sequence extends ASequence implements SequenceI
52 private static final Regex limitrx = new Regex(
53 "[/][0-9]{1,}[-][0-9]{1,}$");
55 private static final Regex endrx = new Regex("[0-9]{1,}$");
57 SequenceI datasetSequence;
61 private char[] sequence;
69 Vector<PDBEntry> pdbIds;
78 * This annotation is displayed below the alignment but the positions are tied
79 * to the residues of this sequence
81 * TODO: change to List<>
83 Vector<AlignmentAnnotation> annotation;
86 * The index of the sequence in a MSA
90 /** array of sequence features - may not be null for a valid sequence object */
91 public SequenceFeature[] sequenceFeatures;
93 private SequenceFeatures sequenceFeatureStore;
96 * Creates a new Sequence object.
101 * string to form a possibly gapped sequence out of
103 * first position of non-gap residue in the sequence
105 * last position of ungapped residues (nearly always only used for
108 public Sequence(String name, String sequence, int start, int end)
110 initSeqAndName(name, sequence.toCharArray(), start, end);
113 public Sequence(String name, char[] sequence, int start, int end)
115 initSeqAndName(name, sequence, start, end);
119 * Stage 1 constructor - assign name, sequence, and set start and end fields.
120 * start and end are updated values from name2 if it ends with /start-end
127 protected void initSeqAndName(String name2, char[] sequence2, int start2,
131 this.sequence = sequence2;
134 sequenceFeatureStore = new SequenceFeatures();
144 .println("POSSIBLE IMPLEMENTATION ERROR: null sequence name passed to constructor.");
147 // Does sequence have the /start-end signature?
148 if (limitrx.search(name))
150 name = limitrx.left();
151 endrx.search(limitrx.stringMatched());
152 setStart(Integer.parseInt(limitrx.stringMatched().substring(1,
153 endrx.matchedFrom() - 1)));
154 setEnd(Integer.parseInt(endrx.stringMatched()));
158 void checkValidRange()
161 // http://issues.jalview.org/browse/JAL-774?focusedCommentId=11239&page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel#comment-11239
164 for (int j = 0; j < sequence.length; j++)
166 if (!jalview.util.Comparison.isGap(sequence[j]))
185 * Creates a new Sequence object.
192 public Sequence(String name, String sequence)
194 this(name, sequence, 1, -1);
198 * Creates a new Sequence object with new AlignmentAnnotations but inherits
199 * any existing dataset sequence reference. If non exists, everything is
203 * if seq is a dataset sequence, behaves like a plain old copy
206 public Sequence(SequenceI seq)
208 this(seq, seq.getAnnotation());
212 * Create a new sequence object with new features, DBRefEntries, and PDBIds
213 * but inherits any existing dataset sequence reference, and duplicate of any
214 * annotation that is present in the given annotation array.
217 * the sequence to be copied
218 * @param alAnnotation
219 * an array of annotation including some associated with seq
221 public Sequence(SequenceI seq, AlignmentAnnotation[] alAnnotation)
223 initSeqFrom(seq, alAnnotation);
228 * does the heavy lifting when cloning a dataset sequence, or coping data from
229 * dataset to a new derived sequence.
232 * - source of attributes.
233 * @param alAnnotation
234 * - alignment annotation present on seq that should be copied onto
237 protected void initSeqFrom(SequenceI seq,
238 AlignmentAnnotation[] alAnnotation)
240 char[] oseq = seq.getSequence();
241 initSeqAndName(seq.getName(), Arrays.copyOf(oseq, oseq.length),
242 seq.getStart(), seq.getEnd());
244 description = seq.getDescription();
245 if (seq != datasetSequence)
247 setDatasetSequence(seq.getDatasetSequence());
251 * only copy DBRefs and seqfeatures if we really are a dataset sequence
253 if (datasetSequence == null)
255 if (seq.getDBRefs() != null)
257 DBRefEntry[] dbr = seq.getDBRefs();
258 for (int i = 0; i < dbr.length; i++)
260 addDBRef(new DBRefEntry(dbr[i]));
263 if (seq.getSequenceFeatures() != null)
265 SequenceFeature[] sf = seq.getSequenceFeatures();
266 for (int i = 0; i < sf.length; i++)
268 addSequenceFeature(new SequenceFeature(sf[i]));
273 if (seq.getAnnotation() != null)
275 AlignmentAnnotation[] sqann = seq.getAnnotation();
276 for (int i = 0; i < sqann.length; i++)
278 if (sqann[i] == null)
282 boolean found = (alAnnotation == null);
285 for (int apos = 0; !found && apos < alAnnotation.length; apos++)
287 found = (alAnnotation[apos] == sqann[i]);
292 // only copy the given annotation
293 AlignmentAnnotation newann = new AlignmentAnnotation(sqann[i]);
294 addAlignmentAnnotation(newann);
298 if (seq.getAllPDBEntries() != null)
300 Vector<PDBEntry> ids = seq.getAllPDBEntries();
301 for (PDBEntry pdb : ids)
303 this.addPDBId(new PDBEntry(pdb));
309 public void setSequenceFeatures(SequenceFeature[] features)
311 if (datasetSequence == null)
313 sequenceFeatures = features;
317 if (datasetSequence.getSequenceFeatures() != features
318 && datasetSequence.getSequenceFeatures() != null
319 && datasetSequence.getSequenceFeatures().length > 0)
322 "Warning: JAL-2046 side effect ? Possible implementation error: overwriting dataset sequence features by setting sequence features on alignment")
325 datasetSequence.setSequenceFeatures(features);
330 public synchronized boolean addSequenceFeature(SequenceFeature sf)
332 if (sf.getType() == null)
334 System.err.println("SequenceFeature type may not be null: "
339 if (sequenceFeatures == null && datasetSequence != null)
341 return datasetSequence.addSequenceFeature(sf);
343 if (sequenceFeatures == null)
345 sequenceFeatures = new SequenceFeature[0];
348 for (int i = 0; i < sequenceFeatures.length; i++)
350 if (sequenceFeatures[i].equals(sf))
356 SequenceFeature[] temp = new SequenceFeature[sequenceFeatures.length + 1];
357 System.arraycopy(sequenceFeatures, 0, temp, 0, sequenceFeatures.length);
358 temp[sequenceFeatures.length] = sf;
360 sequenceFeatures = temp;
362 sequenceFeatureStore.add(sf);
367 public void deleteFeature(SequenceFeature sf)
369 if (sequenceFeatures == null)
371 if (datasetSequence != null)
373 datasetSequence.deleteFeature(sf);
381 sequenceFeatureStore.delete(sf);
384 * old way - to be removed
387 for (index = 0; index < sequenceFeatures.length; index++)
389 if (sequenceFeatures[index].equals(sf))
395 if (index == sequenceFeatures.length)
400 int sfLength = sequenceFeatures.length;
403 sequenceFeatures = null;
407 SequenceFeature[] temp = new SequenceFeature[sfLength - 1];
408 System.arraycopy(sequenceFeatures, 0, temp, 0, index);
410 if (index < sfLength)
412 System.arraycopy(sequenceFeatures, index + 1, temp, index,
413 sequenceFeatures.length - index - 1);
416 sequenceFeatures = temp;
421 * Returns the sequence features (if any), looking first on the sequence, then
422 * on its dataset sequence, and so on until a non-null value is found (or
423 * none). This supports retrieval of sequence features stored on the sequence
424 * (as in the applet) or on the dataset sequence (as in the Desktop version).
429 public SequenceFeature[] getSequenceFeatures()
431 SequenceFeature[] features = sequenceFeatures;
433 SequenceI seq = this;
434 int count = 0; // failsafe against loop in sequence.datasetsequence...
435 while (features == null && seq.getDatasetSequence() != null
438 seq = seq.getDatasetSequence();
439 features = ((Sequence) seq).sequenceFeatures;
445 public SequenceFeaturesI getFeatures()
447 return datasetSequence != null ? datasetSequence.getFeatures()
448 : sequenceFeatureStore;
452 public boolean addPDBId(PDBEntry entry)
456 pdbIds = new Vector<PDBEntry>();
461 for (PDBEntry pdbe : pdbIds)
463 if (pdbe.updateFrom(entry))
468 pdbIds.addElement(entry);
479 public void setPDBId(Vector<PDBEntry> id)
487 * @return DOCUMENT ME!
490 public Vector<PDBEntry> getAllPDBEntries()
492 return pdbIds == null ? new Vector<PDBEntry>() : pdbIds;
498 * @return DOCUMENT ME!
501 public String getDisplayId(boolean jvsuffix)
503 StringBuffer result = new StringBuffer(name);
506 result.append("/" + start + "-" + end);
509 return result.toString();
519 public void setName(String name)
528 * @return DOCUMENT ME!
531 public String getName()
543 public void setStart(int start)
551 * @return DOCUMENT ME!
554 public int getStart()
566 public void setEnd(int end)
574 * @return DOCUMENT ME!
585 * @return DOCUMENT ME!
588 public int getLength()
590 return this.sequence.length;
600 public void setSequence(String seq)
602 this.sequence = seq.toCharArray();
607 public String getSequenceAsString()
609 return new String(sequence);
613 public String getSequenceAsString(int start, int end)
615 return new String(getSequence(start, end));
619 public char[] getSequence()
627 * @see jalview.datamodel.SequenceI#getSequence(int, int)
630 public char[] getSequence(int start, int end)
636 // JBPNote - left to user to pad the result here (TODO:Decide on this
638 if (start >= sequence.length)
643 if (end >= sequence.length)
645 end = sequence.length;
648 char[] reply = new char[end - start];
649 System.arraycopy(sequence, start, reply, 0, end - start);
655 public SequenceI getSubSequence(int start, int end)
661 char[] seq = getSequence(start, end);
666 int nstart = findPosition(start);
667 int nend = findPosition(end) - 1;
668 // JBPNote - this is an incomplete copy.
669 SequenceI nseq = new Sequence(this.getName(), seq, nstart, nend);
670 nseq.setDescription(description);
671 if (datasetSequence != null)
673 nseq.setDatasetSequence(datasetSequence);
677 nseq.setDatasetSequence(this);
683 * Returns the character of the aligned sequence at the given position (base
684 * zero), or space if the position is not within the sequence's bounds
689 public char getCharAt(int i)
691 if (i >= 0 && i < sequence.length)
708 public void setDescription(String desc)
710 this.description = desc;
716 * @return DOCUMENT ME!
719 public String getDescription()
721 return this.description;
727 * @see jalview.datamodel.SequenceI#findIndex(int)
730 public int findIndex(int pos)
732 // returns the alignment position for a residue
735 // Rely on end being at least as long as the length of the sequence.
736 while ((i < sequence.length) && (j <= end) && (j <= pos))
738 if (!jalview.util.Comparison.isGap(sequence[i]))
746 if ((j == end) && (j < pos))
757 public int findPosition(int i)
761 int seqlen = sequence.length;
762 while ((j < i) && (j < seqlen))
764 if (!jalview.util.Comparison.isGap(sequence[j]))
776 * Returns an int array where indices correspond to each residue in the
777 * sequence and the element value gives its position in the alignment
779 * @return int[SequenceI.getEnd()-SequenceI.getStart()+1] or null if no
780 * residues in SequenceI object
783 public int[] gapMap()
785 String seq = jalview.analysis.AlignSeq.extractGaps(
786 jalview.util.Comparison.GapChars, new String(sequence));
787 int[] map = new int[seq.length()];
791 while (j < sequence.length)
793 if (!jalview.util.Comparison.isGap(sequence[j]))
805 public int[] findPositionMap()
807 int map[] = new int[sequence.length];
810 int seqlen = sequence.length;
814 if (!jalview.util.Comparison.isGap(sequence[j]))
825 public List<int[]> getInsertions()
827 ArrayList<int[]> map = new ArrayList<int[]>();
828 int lastj = -1, j = 0;
830 int seqlen = sequence.length;
833 if (jalview.util.Comparison.isGap(sequence[j]))
844 map.add(new int[] { lastj, j - 1 });
852 map.add(new int[] { lastj, j - 1 });
859 public void deleteChars(int i, int j)
861 int newstart = start, newend = end;
862 if (i >= sequence.length || i < 0)
867 char[] tmp = StringUtils.deleteChars(sequence, i, j);
868 boolean createNewDs = false;
869 // TODO: take a (second look) at the dataset creation validation method for
870 // the very large sequence case
871 int eindex = -1, sindex = -1;
872 boolean ecalc = false, scalc = false;
873 for (int s = i; s < j; s++)
875 if (jalview.schemes.ResidueProperties.aaIndex[sequence[s]] != 23)
885 sindex = findIndex(start) - 1;
890 // delete characters including start of sequence
891 newstart = findPosition(j);
892 break; // don't need to search for any more residue characters.
896 // delete characters after start.
899 eindex = findIndex(end) - 1;
904 // delete characters at end of sequence
905 newend = findPosition(i - 1);
906 break; // don't need to search for any more residue characters.
911 newend--; // decrease end position by one for the deleted residue
912 // and search further
918 // deletion occured in the middle of the sequence
919 if (createNewDs && this.datasetSequence != null)
921 // construct a new sequence
922 Sequence ds = new Sequence(datasetSequence);
923 // TODO: remove any non-inheritable properties ?
924 // TODO: create a sequence mapping (since there is a relation here ?)
925 ds.deleteChars(i, j);
926 datasetSequence = ds;
934 public void insertCharAt(int i, int length, char c)
936 char[] tmp = new char[sequence.length + length];
938 if (i >= sequence.length)
940 System.arraycopy(sequence, 0, tmp, 0, sequence.length);
945 System.arraycopy(sequence, 0, tmp, 0, i);
955 if (i < sequence.length)
957 System.arraycopy(sequence, i, tmp, index, sequence.length - i);
964 public void insertCharAt(int i, char c)
966 insertCharAt(i, 1, c);
970 public String getVamsasId()
976 public void setVamsasId(String id)
982 public void setDBRefs(DBRefEntry[] dbref)
984 if (dbrefs == null && datasetSequence != null
985 && this != datasetSequence)
987 datasetSequence.setDBRefs(dbref);
993 DBRefUtils.ensurePrimaries(this);
998 public DBRefEntry[] getDBRefs()
1000 if (dbrefs == null && datasetSequence != null
1001 && this != datasetSequence)
1003 return datasetSequence.getDBRefs();
1009 public void addDBRef(DBRefEntry entry)
1011 if (datasetSequence != null)
1013 datasetSequence.addDBRef(entry);
1019 dbrefs = new DBRefEntry[0];
1022 for (DBRefEntryI dbr : dbrefs)
1024 if (dbr.updateFrom(entry))
1027 * found a dbref that either matched, or could be
1028 * updated from, the new entry - no need to add it
1035 * extend the array to make room for one more
1037 // TODO use an ArrayList instead
1038 int j = dbrefs.length;
1039 DBRefEntry[] temp = new DBRefEntry[j + 1];
1040 System.arraycopy(dbrefs, 0, temp, 0, j);
1041 temp[temp.length - 1] = entry;
1045 DBRefUtils.ensurePrimaries(this);
1049 public void setDatasetSequence(SequenceI seq)
1053 throw new IllegalArgumentException(
1054 "Implementation Error: self reference passed to SequenceI.setDatasetSequence");
1056 if (seq != null && seq.getDatasetSequence() != null)
1058 throw new IllegalArgumentException(
1059 "Implementation error: cascading dataset sequences are not allowed.");
1061 datasetSequence = seq;
1065 public SequenceI getDatasetSequence()
1067 return datasetSequence;
1071 public AlignmentAnnotation[] getAnnotation()
1073 return annotation == null ? null : annotation
1074 .toArray(new AlignmentAnnotation[annotation.size()]);
1078 public boolean hasAnnotation(AlignmentAnnotation ann)
1080 return annotation == null ? false : annotation.contains(ann);
1084 public void addAlignmentAnnotation(AlignmentAnnotation annotation)
1086 if (this.annotation == null)
1088 this.annotation = new Vector<AlignmentAnnotation>();
1090 if (!this.annotation.contains(annotation))
1092 this.annotation.addElement(annotation);
1094 annotation.setSequenceRef(this);
1098 public void removeAlignmentAnnotation(AlignmentAnnotation annotation)
1100 if (this.annotation != null)
1102 this.annotation.removeElement(annotation);
1103 if (this.annotation.size() == 0)
1105 this.annotation = null;
1111 * test if this is a valid candidate for another sequence's dataset sequence.
1114 private boolean isValidDatasetSequence()
1116 if (datasetSequence != null)
1120 for (int i = 0; i < sequence.length; i++)
1122 if (jalview.util.Comparison.isGap(sequence[i]))
1131 public SequenceI deriveSequence()
1133 Sequence seq = null;
1134 if (datasetSequence == null)
1136 if (isValidDatasetSequence())
1138 // Use this as dataset sequence
1139 seq = new Sequence(getName(), "", 1, -1);
1140 seq.setDatasetSequence(this);
1141 seq.initSeqFrom(this, getAnnotation());
1146 // Create a new, valid dataset sequence
1147 createDatasetSequence();
1150 return new Sequence(this);
1153 private boolean _isNa;
1155 private long _seqhash = 0;
1158 * Answers false if the sequence is more than 85% nucleotide (ACGTU), else
1162 public boolean isProtein()
1164 if (datasetSequence != null)
1166 return datasetSequence.isProtein();
1168 if (_seqhash != sequence.hashCode())
1170 _seqhash = sequence.hashCode();
1171 _isNa = Comparison.isNucleotide(this);
1179 * @see jalview.datamodel.SequenceI#createDatasetSequence()
1182 public SequenceI createDatasetSequence()
1184 if (datasetSequence == null)
1186 Sequence dsseq = new Sequence(getName(), AlignSeq.extractGaps(
1187 jalview.util.Comparison.GapChars, getSequenceAsString()),
1188 getStart(), getEnd());
1190 datasetSequence = dsseq;
1192 dsseq.setDescription(description);
1193 // move features and database references onto dataset sequence
1194 dsseq.sequenceFeatures = sequenceFeatures;
1195 sequenceFeatures = null;
1196 dsseq.sequenceFeatureStore = sequenceFeatureStore;
1197 sequenceFeatureStore = null;
1198 dsseq.dbrefs = dbrefs;
1200 // TODO: search and replace any references to this sequence with
1201 // references to the dataset sequence in Mappings on dbref
1202 dsseq.pdbIds = pdbIds;
1204 datasetSequence.updatePDBIds();
1205 if (annotation != null)
1207 // annotation is cloned rather than moved, to preserve what's currently
1209 for (AlignmentAnnotation aa : annotation)
1211 AlignmentAnnotation _aa = new AlignmentAnnotation(aa);
1212 _aa.sequenceRef = datasetSequence;
1213 _aa.adjustForAlignment(); // uses annotation's own record of
1214 // sequence-column mapping
1215 datasetSequence.addAlignmentAnnotation(_aa);
1219 return datasetSequence;
1226 * jalview.datamodel.SequenceI#setAlignmentAnnotation(AlignmmentAnnotation[]
1230 public void setAlignmentAnnotation(AlignmentAnnotation[] annotations)
1232 if (annotation != null)
1234 annotation.removeAllElements();
1236 if (annotations != null)
1238 for (int i = 0; i < annotations.length; i++)
1240 if (annotations[i] != null)
1242 addAlignmentAnnotation(annotations[i]);
1249 public AlignmentAnnotation[] getAnnotation(String label)
1251 if (annotation == null || annotation.size() == 0)
1256 Vector<AlignmentAnnotation> subset = new Vector<AlignmentAnnotation>();
1257 Enumeration<AlignmentAnnotation> e = annotation.elements();
1258 while (e.hasMoreElements())
1260 AlignmentAnnotation ann = e.nextElement();
1261 if (ann.label != null && ann.label.equals(label))
1263 subset.addElement(ann);
1266 if (subset.size() == 0)
1270 AlignmentAnnotation[] anns = new AlignmentAnnotation[subset.size()];
1272 e = subset.elements();
1273 while (e.hasMoreElements())
1275 anns[i++] = e.nextElement();
1277 subset.removeAllElements();
1282 public boolean updatePDBIds()
1284 if (datasetSequence != null)
1286 // TODO: could merge DBRefs
1287 return datasetSequence.updatePDBIds();
1289 if (dbrefs == null || dbrefs.length == 0)
1293 boolean added = false;
1294 for (DBRefEntry dbr : dbrefs)
1296 if (DBRefSource.PDB.equals(dbr.getSource()))
1299 * 'Add' any PDB dbrefs as a PDBEntry - add is only performed if the
1300 * PDB id is not already present in a 'matching' PDBEntry
1301 * Constructor parses out a chain code if appended to the accession id
1302 * (a fudge used to 'store' the chain code in the DBRef)
1304 PDBEntry pdbe = new PDBEntry(dbr);
1305 added |= addPDBId(pdbe);
1312 public void transferAnnotation(SequenceI entry, Mapping mp)
1314 if (datasetSequence != null)
1316 datasetSequence.transferAnnotation(entry, mp);
1319 if (entry.getDatasetSequence() != null)
1321 transferAnnotation(entry.getDatasetSequence(), mp);
1324 // transfer any new features from entry onto sequence
1325 if (entry.getSequenceFeatures() != null)
1328 SequenceFeature[] sfs = entry.getSequenceFeatures();
1329 for (int si = 0; si < sfs.length; si++)
1331 SequenceFeature sf[] = (mp != null) ? mp.locateFeature(sfs[si])
1332 : new SequenceFeature[] { new SequenceFeature(sfs[si]) };
1333 if (sf != null && sf.length > 0)
1335 for (int sfi = 0; sfi < sf.length; sfi++)
1337 addSequenceFeature(sf[sfi]);
1343 // transfer PDB entries
1344 if (entry.getAllPDBEntries() != null)
1346 Enumeration<PDBEntry> e = entry.getAllPDBEntries().elements();
1347 while (e.hasMoreElements())
1349 PDBEntry pdb = e.nextElement();
1353 // transfer database references
1354 DBRefEntry[] entryRefs = entry.getDBRefs();
1355 if (entryRefs != null)
1357 for (int r = 0; r < entryRefs.length; r++)
1359 DBRefEntry newref = new DBRefEntry(entryRefs[r]);
1360 if (newref.getMap() != null && mp != null)
1362 // remap ref using our local mapping
1364 // we also assume all version string setting is done by dbSourceProxy
1366 * if (!newref.getSource().equalsIgnoreCase(dbSource)) {
1367 * newref.setSource(dbSource); }
1375 * @return The index (zero-based) on this sequence in the MSA. It returns
1376 * {@code -1} if this information is not available.
1379 public int getIndex()
1385 * Defines the position of this sequence in the MSA. Use the value {@code -1}
1386 * if this information is undefined.
1389 * position for this sequence. This value is zero-based (zero for
1390 * this first sequence)
1393 public void setIndex(int value)
1399 public void setRNA(RNA r)
1411 public List<AlignmentAnnotation> getAlignmentAnnotations(String calcId,
1414 List<AlignmentAnnotation> result = new ArrayList<AlignmentAnnotation>();
1415 if (this.annotation != null)
1417 for (AlignmentAnnotation ann : annotation)
1419 if (ann.calcId != null && ann.calcId.equals(calcId)
1420 && ann.label != null && ann.label.equals(label))
1430 public String toString()
1432 return getDisplayId(false);
1436 public PDBEntry getPDBEntry(String pdbIdStr)
1438 if (getDatasetSequence() != null)
1440 return getDatasetSequence().getPDBEntry(pdbIdStr);
1446 List<PDBEntry> entries = getAllPDBEntries();
1447 for (PDBEntry entry : entries)
1449 if (entry.getId().equalsIgnoreCase(pdbIdStr))
1458 public List<DBRefEntry> getPrimaryDBRefs()
1460 if (datasetSequence != null)
1462 return datasetSequence.getPrimaryDBRefs();
1464 if (dbrefs == null || dbrefs.length == 0)
1466 return Collections.emptyList();
1468 synchronized (dbrefs)
1470 List<DBRefEntry> primaries = new ArrayList<DBRefEntry>();
1471 DBRefEntry[] tmp = new DBRefEntry[1];
1472 for (DBRefEntry ref : dbrefs)
1474 if (!ref.isPrimaryCandidate())
1480 MapList mp = ref.getMap().getMap();
1481 if (mp.getFromLowest() > start || mp.getFromHighest() < end)
1483 // map only involves a subsequence, so cannot be primary
1487 // whilst it looks like it is a primary ref, we also sanity check type
1488 if (DBRefUtils.getCanonicalName(DBRefSource.PDB).equals(
1489 DBRefUtils.getCanonicalName(ref.getSource())))
1491 // PDB dbrefs imply there should be a PDBEntry associated
1492 // TODO: tighten PDB dbrefs
1493 // formally imply Jalview has actually downloaded and
1494 // parsed the pdb file. That means there should be a cached file
1495 // handle on the PDBEntry, and a real mapping between sequence and
1496 // extracted sequence from PDB file
1497 PDBEntry pdbentry = getPDBEntry(ref.getAccessionId());
1498 if (pdbentry != null && pdbentry.getFile() != null)
1504 // check standard protein or dna sources
1506 DBRefEntry[] res = DBRefUtils.selectDbRefs(!isProtein(), tmp);
1507 if (res != null && res[0] == tmp[0])
1521 public List<SequenceFeature> findFeatures(int from, int to,
1524 if (datasetSequence != null)
1526 return datasetSequence.findFeatures(from, to, types);
1528 return sequenceFeatureStore.findFeatures(from, to, types);