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 (sequenceFeatures == null && datasetSequence != null)
326 return datasetSequence.addSequenceFeature(sf);
328 if (sequenceFeatures == null)
330 sequenceFeatures = new SequenceFeature[0];
333 for (int i = 0; i < sequenceFeatures.length; i++)
335 if (sequenceFeatures[i].equals(sf))
341 SequenceFeature[] temp = new SequenceFeature[sequenceFeatures.length + 1];
342 System.arraycopy(sequenceFeatures, 0, temp, 0, sequenceFeatures.length);
343 temp[sequenceFeatures.length] = sf;
345 sequenceFeatures = temp;
347 sequenceFeatureStore.add(sf);
352 public void deleteFeature(SequenceFeature sf)
354 if (sequenceFeatures == null)
356 if (datasetSequence != null)
358 datasetSequence.deleteFeature(sf);
366 sequenceFeatureStore.delete(sf);
369 * old way - to be removed
372 for (index = 0; index < sequenceFeatures.length; index++)
374 if (sequenceFeatures[index].equals(sf))
380 if (index == sequenceFeatures.length)
385 int sfLength = sequenceFeatures.length;
388 sequenceFeatures = null;
392 SequenceFeature[] temp = new SequenceFeature[sfLength - 1];
393 System.arraycopy(sequenceFeatures, 0, temp, 0, index);
395 if (index < sfLength)
397 System.arraycopy(sequenceFeatures, index + 1, temp, index,
398 sequenceFeatures.length - index - 1);
401 sequenceFeatures = temp;
406 * Returns the sequence features (if any), looking first on the sequence, then
407 * on its dataset sequence, and so on until a non-null value is found (or
408 * none). This supports retrieval of sequence features stored on the sequence
409 * (as in the applet) or on the dataset sequence (as in the Desktop version).
414 public SequenceFeature[] getSequenceFeatures()
416 SequenceFeature[] features = sequenceFeatures;
418 SequenceI seq = this;
419 int count = 0; // failsafe against loop in sequence.datasetsequence...
420 while (features == null && seq.getDatasetSequence() != null
423 seq = seq.getDatasetSequence();
424 features = ((Sequence) seq).sequenceFeatures;
430 public SequenceFeaturesI getFeatures()
432 return sequenceFeatureStore;
436 public boolean addPDBId(PDBEntry entry)
440 pdbIds = new Vector<PDBEntry>();
445 for (PDBEntry pdbe : pdbIds)
447 if (pdbe.updateFrom(entry))
452 pdbIds.addElement(entry);
463 public void setPDBId(Vector<PDBEntry> id)
471 * @return DOCUMENT ME!
474 public Vector<PDBEntry> getAllPDBEntries()
476 return pdbIds == null ? new Vector<PDBEntry>() : pdbIds;
482 * @return DOCUMENT ME!
485 public String getDisplayId(boolean jvsuffix)
487 StringBuffer result = new StringBuffer(name);
490 result.append("/" + start + "-" + end);
493 return result.toString();
503 public void setName(String name)
512 * @return DOCUMENT ME!
515 public String getName()
527 public void setStart(int start)
535 * @return DOCUMENT ME!
538 public int getStart()
550 public void setEnd(int end)
558 * @return DOCUMENT ME!
569 * @return DOCUMENT ME!
572 public int getLength()
574 return this.sequence.length;
584 public void setSequence(String seq)
586 this.sequence = seq.toCharArray();
591 public String getSequenceAsString()
593 return new String(sequence);
597 public String getSequenceAsString(int start, int end)
599 return new String(getSequence(start, end));
603 public char[] getSequence()
611 * @see jalview.datamodel.SequenceI#getSequence(int, int)
614 public char[] getSequence(int start, int end)
620 // JBPNote - left to user to pad the result here (TODO:Decide on this
622 if (start >= sequence.length)
627 if (end >= sequence.length)
629 end = sequence.length;
632 char[] reply = new char[end - start];
633 System.arraycopy(sequence, start, reply, 0, end - start);
639 public SequenceI getSubSequence(int start, int end)
645 char[] seq = getSequence(start, end);
650 int nstart = findPosition(start);
651 int nend = findPosition(end) - 1;
652 // JBPNote - this is an incomplete copy.
653 SequenceI nseq = new Sequence(this.getName(), seq, nstart, nend);
654 nseq.setDescription(description);
655 if (datasetSequence != null)
657 nseq.setDatasetSequence(datasetSequence);
661 nseq.setDatasetSequence(this);
667 * Returns the character of the aligned sequence at the given position (base
668 * zero), or space if the position is not within the sequence's bounds
673 public char getCharAt(int i)
675 if (i >= 0 && i < sequence.length)
692 public void setDescription(String desc)
694 this.description = desc;
700 * @return DOCUMENT ME!
703 public String getDescription()
705 return this.description;
711 * @see jalview.datamodel.SequenceI#findIndex(int)
714 public int findIndex(int pos)
716 // returns the alignment position for a residue
719 // Rely on end being at least as long as the length of the sequence.
720 while ((i < sequence.length) && (j <= end) && (j <= pos))
722 if (!jalview.util.Comparison.isGap(sequence[i]))
730 if ((j == end) && (j < pos))
741 public int findPosition(int i)
745 int seqlen = sequence.length;
746 while ((j < i) && (j < seqlen))
748 if (!jalview.util.Comparison.isGap(sequence[j]))
760 * Returns an int array where indices correspond to each residue in the
761 * sequence and the element value gives its position in the alignment
763 * @return int[SequenceI.getEnd()-SequenceI.getStart()+1] or null if no
764 * residues in SequenceI object
767 public int[] gapMap()
769 String seq = jalview.analysis.AlignSeq.extractGaps(
770 jalview.util.Comparison.GapChars, new String(sequence));
771 int[] map = new int[seq.length()];
775 while (j < sequence.length)
777 if (!jalview.util.Comparison.isGap(sequence[j]))
789 public int[] findPositionMap()
791 int map[] = new int[sequence.length];
794 int seqlen = sequence.length;
798 if (!jalview.util.Comparison.isGap(sequence[j]))
809 public List<int[]> getInsertions()
811 ArrayList<int[]> map = new ArrayList<int[]>();
812 int lastj = -1, j = 0;
814 int seqlen = sequence.length;
817 if (jalview.util.Comparison.isGap(sequence[j]))
828 map.add(new int[] { lastj, j - 1 });
836 map.add(new int[] { lastj, j - 1 });
843 public void deleteChars(int i, int j)
845 int newstart = start, newend = end;
846 if (i >= sequence.length || i < 0)
851 char[] tmp = StringUtils.deleteChars(sequence, i, j);
852 boolean createNewDs = false;
853 // TODO: take a (second look) at the dataset creation validation method for
854 // the very large sequence case
855 int eindex = -1, sindex = -1;
856 boolean ecalc = false, scalc = false;
857 for (int s = i; s < j; s++)
859 if (jalview.schemes.ResidueProperties.aaIndex[sequence[s]] != 23)
869 sindex = findIndex(start) - 1;
874 // delete characters including start of sequence
875 newstart = findPosition(j);
876 break; // don't need to search for any more residue characters.
880 // delete characters after start.
883 eindex = findIndex(end) - 1;
888 // delete characters at end of sequence
889 newend = findPosition(i - 1);
890 break; // don't need to search for any more residue characters.
895 newend--; // decrease end position by one for the deleted residue
896 // and search further
902 // deletion occured in the middle of the sequence
903 if (createNewDs && this.datasetSequence != null)
905 // construct a new sequence
906 Sequence ds = new Sequence(datasetSequence);
907 // TODO: remove any non-inheritable properties ?
908 // TODO: create a sequence mapping (since there is a relation here ?)
909 ds.deleteChars(i, j);
910 datasetSequence = ds;
918 public void insertCharAt(int i, int length, char c)
920 char[] tmp = new char[sequence.length + length];
922 if (i >= sequence.length)
924 System.arraycopy(sequence, 0, tmp, 0, sequence.length);
929 System.arraycopy(sequence, 0, tmp, 0, i);
939 if (i < sequence.length)
941 System.arraycopy(sequence, i, tmp, index, sequence.length - i);
948 public void insertCharAt(int i, char c)
950 insertCharAt(i, 1, c);
954 public String getVamsasId()
960 public void setVamsasId(String id)
966 public void setDBRefs(DBRefEntry[] dbref)
968 if (dbrefs == null && datasetSequence != null
969 && this != datasetSequence)
971 datasetSequence.setDBRefs(dbref);
977 DBRefUtils.ensurePrimaries(this);
982 public DBRefEntry[] getDBRefs()
984 if (dbrefs == null && datasetSequence != null
985 && this != datasetSequence)
987 return datasetSequence.getDBRefs();
993 public void addDBRef(DBRefEntry entry)
995 if (datasetSequence != null)
997 datasetSequence.addDBRef(entry);
1003 dbrefs = new DBRefEntry[0];
1006 for (DBRefEntryI dbr : dbrefs)
1008 if (dbr.updateFrom(entry))
1011 * found a dbref that either matched, or could be
1012 * updated from, the new entry - no need to add it
1019 * extend the array to make room for one more
1021 // TODO use an ArrayList instead
1022 int j = dbrefs.length;
1023 DBRefEntry[] temp = new DBRefEntry[j + 1];
1024 System.arraycopy(dbrefs, 0, temp, 0, j);
1025 temp[temp.length - 1] = entry;
1029 DBRefUtils.ensurePrimaries(this);
1033 public void setDatasetSequence(SequenceI seq)
1037 throw new IllegalArgumentException(
1038 "Implementation Error: self reference passed to SequenceI.setDatasetSequence");
1040 if (seq != null && seq.getDatasetSequence() != null)
1042 throw new IllegalArgumentException(
1043 "Implementation error: cascading dataset sequences are not allowed.");
1045 datasetSequence = seq;
1049 public SequenceI getDatasetSequence()
1051 return datasetSequence;
1055 public AlignmentAnnotation[] getAnnotation()
1057 return annotation == null ? null : annotation
1058 .toArray(new AlignmentAnnotation[annotation.size()]);
1062 public boolean hasAnnotation(AlignmentAnnotation ann)
1064 return annotation == null ? false : annotation.contains(ann);
1068 public void addAlignmentAnnotation(AlignmentAnnotation annotation)
1070 if (this.annotation == null)
1072 this.annotation = new Vector<AlignmentAnnotation>();
1074 if (!this.annotation.contains(annotation))
1076 this.annotation.addElement(annotation);
1078 annotation.setSequenceRef(this);
1082 public void removeAlignmentAnnotation(AlignmentAnnotation annotation)
1084 if (this.annotation != null)
1086 this.annotation.removeElement(annotation);
1087 if (this.annotation.size() == 0)
1089 this.annotation = null;
1095 * test if this is a valid candidate for another sequence's dataset sequence.
1098 private boolean isValidDatasetSequence()
1100 if (datasetSequence != null)
1104 for (int i = 0; i < sequence.length; i++)
1106 if (jalview.util.Comparison.isGap(sequence[i]))
1115 public SequenceI deriveSequence()
1117 Sequence seq = null;
1118 if (datasetSequence == null)
1120 if (isValidDatasetSequence())
1122 // Use this as dataset sequence
1123 seq = new Sequence(getName(), "", 1, -1);
1124 seq.setDatasetSequence(this);
1125 seq.initSeqFrom(this, getAnnotation());
1130 // Create a new, valid dataset sequence
1131 createDatasetSequence();
1134 return new Sequence(this);
1137 private boolean _isNa;
1139 private long _seqhash = 0;
1142 * Answers false if the sequence is more than 85% nucleotide (ACGTU), else
1146 public boolean isProtein()
1148 if (datasetSequence != null)
1150 return datasetSequence.isProtein();
1152 if (_seqhash != sequence.hashCode())
1154 _seqhash = sequence.hashCode();
1155 _isNa = Comparison.isNucleotide(this);
1163 * @see jalview.datamodel.SequenceI#createDatasetSequence()
1166 public SequenceI createDatasetSequence()
1168 if (datasetSequence == null)
1170 Sequence dsseq = new Sequence(getName(), AlignSeq.extractGaps(
1171 jalview.util.Comparison.GapChars, getSequenceAsString()),
1172 getStart(), getEnd());
1174 datasetSequence = dsseq;
1176 dsseq.setDescription(description);
1177 // move features and database references onto dataset sequence
1178 dsseq.sequenceFeatures = sequenceFeatures;
1179 sequenceFeatures = null;
1180 dsseq.dbrefs = dbrefs;
1182 // TODO: search and replace any references to this sequence with
1183 // references to the dataset sequence in Mappings on dbref
1184 dsseq.pdbIds = pdbIds;
1186 datasetSequence.updatePDBIds();
1187 if (annotation != null)
1189 // annotation is cloned rather than moved, to preserve what's currently
1191 for (AlignmentAnnotation aa : annotation)
1193 AlignmentAnnotation _aa = new AlignmentAnnotation(aa);
1194 _aa.sequenceRef = datasetSequence;
1195 _aa.adjustForAlignment(); // uses annotation's own record of
1196 // sequence-column mapping
1197 datasetSequence.addAlignmentAnnotation(_aa);
1201 return datasetSequence;
1208 * jalview.datamodel.SequenceI#setAlignmentAnnotation(AlignmmentAnnotation[]
1212 public void setAlignmentAnnotation(AlignmentAnnotation[] annotations)
1214 if (annotation != null)
1216 annotation.removeAllElements();
1218 if (annotations != null)
1220 for (int i = 0; i < annotations.length; i++)
1222 if (annotations[i] != null)
1224 addAlignmentAnnotation(annotations[i]);
1231 public AlignmentAnnotation[] getAnnotation(String label)
1233 if (annotation == null || annotation.size() == 0)
1238 Vector subset = new Vector();
1239 Enumeration e = annotation.elements();
1240 while (e.hasMoreElements())
1242 AlignmentAnnotation ann = (AlignmentAnnotation) e.nextElement();
1243 if (ann.label != null && ann.label.equals(label))
1245 subset.addElement(ann);
1248 if (subset.size() == 0)
1252 AlignmentAnnotation[] anns = new AlignmentAnnotation[subset.size()];
1254 e = subset.elements();
1255 while (e.hasMoreElements())
1257 anns[i++] = (AlignmentAnnotation) e.nextElement();
1259 subset.removeAllElements();
1264 public boolean updatePDBIds()
1266 if (datasetSequence != null)
1268 // TODO: could merge DBRefs
1269 return datasetSequence.updatePDBIds();
1271 if (dbrefs == null || dbrefs.length == 0)
1275 boolean added = false;
1276 for (DBRefEntry dbr : dbrefs)
1278 if (DBRefSource.PDB.equals(dbr.getSource()))
1281 * 'Add' any PDB dbrefs as a PDBEntry - add is only performed if the
1282 * PDB id is not already present in a 'matching' PDBEntry
1283 * Constructor parses out a chain code if appended to the accession id
1284 * (a fudge used to 'store' the chain code in the DBRef)
1286 PDBEntry pdbe = new PDBEntry(dbr);
1287 added |= addPDBId(pdbe);
1294 public void transferAnnotation(SequenceI entry, Mapping mp)
1296 if (datasetSequence != null)
1298 datasetSequence.transferAnnotation(entry, mp);
1301 if (entry.getDatasetSequence() != null)
1303 transferAnnotation(entry.getDatasetSequence(), mp);
1306 // transfer any new features from entry onto sequence
1307 if (entry.getSequenceFeatures() != null)
1310 SequenceFeature[] sfs = entry.getSequenceFeatures();
1311 for (int si = 0; si < sfs.length; si++)
1313 SequenceFeature sf[] = (mp != null) ? mp.locateFeature(sfs[si])
1314 : new SequenceFeature[] { new SequenceFeature(sfs[si]) };
1315 if (sf != null && sf.length > 0)
1317 for (int sfi = 0; sfi < sf.length; sfi++)
1319 addSequenceFeature(sf[sfi]);
1325 // transfer PDB entries
1326 if (entry.getAllPDBEntries() != null)
1328 Enumeration e = entry.getAllPDBEntries().elements();
1329 while (e.hasMoreElements())
1331 PDBEntry pdb = (PDBEntry) e.nextElement();
1335 // transfer database references
1336 DBRefEntry[] entryRefs = entry.getDBRefs();
1337 if (entryRefs != null)
1339 for (int r = 0; r < entryRefs.length; r++)
1341 DBRefEntry newref = new DBRefEntry(entryRefs[r]);
1342 if (newref.getMap() != null && mp != null)
1344 // remap ref using our local mapping
1346 // we also assume all version string setting is done by dbSourceProxy
1348 * if (!newref.getSource().equalsIgnoreCase(dbSource)) {
1349 * newref.setSource(dbSource); }
1357 * @return The index (zero-based) on this sequence in the MSA. It returns
1358 * {@code -1} if this information is not available.
1361 public int getIndex()
1367 * Defines the position of this sequence in the MSA. Use the value {@code -1}
1368 * if this information is undefined.
1371 * position for this sequence. This value is zero-based (zero for
1372 * this first sequence)
1375 public void setIndex(int value)
1381 public void setRNA(RNA r)
1393 public List<AlignmentAnnotation> getAlignmentAnnotations(String calcId,
1396 List<AlignmentAnnotation> result = new ArrayList<AlignmentAnnotation>();
1397 if (this.annotation != null)
1399 for (AlignmentAnnotation ann : annotation)
1401 if (ann.calcId != null && ann.calcId.equals(calcId)
1402 && ann.label != null && ann.label.equals(label))
1412 public String toString()
1414 return getDisplayId(false);
1418 public PDBEntry getPDBEntry(String pdbIdStr)
1420 if (getDatasetSequence() != null)
1422 return getDatasetSequence().getPDBEntry(pdbIdStr);
1428 List<PDBEntry> entries = getAllPDBEntries();
1429 for (PDBEntry entry : entries)
1431 if (entry.getId().equalsIgnoreCase(pdbIdStr))
1440 public List<DBRefEntry> getPrimaryDBRefs()
1442 if (datasetSequence != null)
1444 return datasetSequence.getPrimaryDBRefs();
1446 if (dbrefs == null || dbrefs.length == 0)
1448 return Collections.emptyList();
1450 synchronized (dbrefs)
1452 List<DBRefEntry> primaries = new ArrayList<DBRefEntry>();
1453 DBRefEntry[] tmp = new DBRefEntry[1];
1454 for (DBRefEntry ref : dbrefs)
1456 if (!ref.isPrimaryCandidate())
1462 MapList mp = ref.getMap().getMap();
1463 if (mp.getFromLowest() > start || mp.getFromHighest() < end)
1465 // map only involves a subsequence, so cannot be primary
1469 // whilst it looks like it is a primary ref, we also sanity check type
1470 if (DBRefUtils.getCanonicalName(DBRefSource.PDB).equals(
1471 DBRefUtils.getCanonicalName(ref.getSource())))
1473 // PDB dbrefs imply there should be a PDBEntry associated
1474 // TODO: tighten PDB dbrefs
1475 // formally imply Jalview has actually downloaded and
1476 // parsed the pdb file. That means there should be a cached file
1477 // handle on the PDBEntry, and a real mapping between sequence and
1478 // extracted sequence from PDB file
1479 PDBEntry pdbentry = getPDBEntry(ref.getAccessionId());
1480 if (pdbentry != null && pdbentry.getFile() != null)
1486 // check standard protein or dna sources
1488 DBRefEntry[] res = DBRefUtils.selectDbRefs(!isProtein(), tmp);
1489 if (res != null && res[0] == tmp[0])
1500 public List<SequenceFeature> findFeatures(String type, int from, int to)
1502 if (datasetSequence != null)
1504 return datasetSequence.findFeatures(type, from, to);
1506 return sequenceFeatureStore.findFeatures(from, to, type);