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 datasetSequence != null ? datasetSequence.getFeatures()
433 : sequenceFeatureStore;
437 public boolean addPDBId(PDBEntry entry)
441 pdbIds = new Vector<PDBEntry>();
446 for (PDBEntry pdbe : pdbIds)
448 if (pdbe.updateFrom(entry))
453 pdbIds.addElement(entry);
464 public void setPDBId(Vector<PDBEntry> id)
472 * @return DOCUMENT ME!
475 public Vector<PDBEntry> getAllPDBEntries()
477 return pdbIds == null ? new Vector<PDBEntry>() : pdbIds;
483 * @return DOCUMENT ME!
486 public String getDisplayId(boolean jvsuffix)
488 StringBuffer result = new StringBuffer(name);
491 result.append("/" + start + "-" + end);
494 return result.toString();
504 public void setName(String name)
513 * @return DOCUMENT ME!
516 public String getName()
528 public void setStart(int start)
536 * @return DOCUMENT ME!
539 public int getStart()
551 public void setEnd(int end)
559 * @return DOCUMENT ME!
570 * @return DOCUMENT ME!
573 public int getLength()
575 return this.sequence.length;
585 public void setSequence(String seq)
587 this.sequence = seq.toCharArray();
592 public String getSequenceAsString()
594 return new String(sequence);
598 public String getSequenceAsString(int start, int end)
600 return new String(getSequence(start, end));
604 public char[] getSequence()
612 * @see jalview.datamodel.SequenceI#getSequence(int, int)
615 public char[] getSequence(int start, int end)
621 // JBPNote - left to user to pad the result here (TODO:Decide on this
623 if (start >= sequence.length)
628 if (end >= sequence.length)
630 end = sequence.length;
633 char[] reply = new char[end - start];
634 System.arraycopy(sequence, start, reply, 0, end - start);
640 public SequenceI getSubSequence(int start, int end)
646 char[] seq = getSequence(start, end);
651 int nstart = findPosition(start);
652 int nend = findPosition(end) - 1;
653 // JBPNote - this is an incomplete copy.
654 SequenceI nseq = new Sequence(this.getName(), seq, nstart, nend);
655 nseq.setDescription(description);
656 if (datasetSequence != null)
658 nseq.setDatasetSequence(datasetSequence);
662 nseq.setDatasetSequence(this);
668 * Returns the character of the aligned sequence at the given position (base
669 * zero), or space if the position is not within the sequence's bounds
674 public char getCharAt(int i)
676 if (i >= 0 && i < sequence.length)
693 public void setDescription(String desc)
695 this.description = desc;
701 * @return DOCUMENT ME!
704 public String getDescription()
706 return this.description;
712 * @see jalview.datamodel.SequenceI#findIndex(int)
715 public int findIndex(int pos)
717 // returns the alignment position for a residue
720 // Rely on end being at least as long as the length of the sequence.
721 while ((i < sequence.length) && (j <= end) && (j <= pos))
723 if (!jalview.util.Comparison.isGap(sequence[i]))
731 if ((j == end) && (j < pos))
742 public int findPosition(int i)
746 int seqlen = sequence.length;
747 while ((j < i) && (j < seqlen))
749 if (!jalview.util.Comparison.isGap(sequence[j]))
761 * Returns an int array where indices correspond to each residue in the
762 * sequence and the element value gives its position in the alignment
764 * @return int[SequenceI.getEnd()-SequenceI.getStart()+1] or null if no
765 * residues in SequenceI object
768 public int[] gapMap()
770 String seq = jalview.analysis.AlignSeq.extractGaps(
771 jalview.util.Comparison.GapChars, new String(sequence));
772 int[] map = new int[seq.length()];
776 while (j < sequence.length)
778 if (!jalview.util.Comparison.isGap(sequence[j]))
790 public int[] findPositionMap()
792 int map[] = new int[sequence.length];
795 int seqlen = sequence.length;
799 if (!jalview.util.Comparison.isGap(sequence[j]))
810 public List<int[]> getInsertions()
812 ArrayList<int[]> map = new ArrayList<int[]>();
813 int lastj = -1, j = 0;
815 int seqlen = sequence.length;
818 if (jalview.util.Comparison.isGap(sequence[j]))
829 map.add(new int[] { lastj, j - 1 });
837 map.add(new int[] { lastj, j - 1 });
844 public void deleteChars(int i, int j)
846 int newstart = start, newend = end;
847 if (i >= sequence.length || i < 0)
852 char[] tmp = StringUtils.deleteChars(sequence, i, j);
853 boolean createNewDs = false;
854 // TODO: take a (second look) at the dataset creation validation method for
855 // the very large sequence case
856 int eindex = -1, sindex = -1;
857 boolean ecalc = false, scalc = false;
858 for (int s = i; s < j; s++)
860 if (jalview.schemes.ResidueProperties.aaIndex[sequence[s]] != 23)
870 sindex = findIndex(start) - 1;
875 // delete characters including start of sequence
876 newstart = findPosition(j);
877 break; // don't need to search for any more residue characters.
881 // delete characters after start.
884 eindex = findIndex(end) - 1;
889 // delete characters at end of sequence
890 newend = findPosition(i - 1);
891 break; // don't need to search for any more residue characters.
896 newend--; // decrease end position by one for the deleted residue
897 // and search further
903 // deletion occured in the middle of the sequence
904 if (createNewDs && this.datasetSequence != null)
906 // construct a new sequence
907 Sequence ds = new Sequence(datasetSequence);
908 // TODO: remove any non-inheritable properties ?
909 // TODO: create a sequence mapping (since there is a relation here ?)
910 ds.deleteChars(i, j);
911 datasetSequence = ds;
919 public void insertCharAt(int i, int length, char c)
921 char[] tmp = new char[sequence.length + length];
923 if (i >= sequence.length)
925 System.arraycopy(sequence, 0, tmp, 0, sequence.length);
930 System.arraycopy(sequence, 0, tmp, 0, i);
940 if (i < sequence.length)
942 System.arraycopy(sequence, i, tmp, index, sequence.length - i);
949 public void insertCharAt(int i, char c)
951 insertCharAt(i, 1, c);
955 public String getVamsasId()
961 public void setVamsasId(String id)
967 public void setDBRefs(DBRefEntry[] dbref)
969 if (dbrefs == null && datasetSequence != null
970 && this != datasetSequence)
972 datasetSequence.setDBRefs(dbref);
978 DBRefUtils.ensurePrimaries(this);
983 public DBRefEntry[] getDBRefs()
985 if (dbrefs == null && datasetSequence != null
986 && this != datasetSequence)
988 return datasetSequence.getDBRefs();
994 public void addDBRef(DBRefEntry entry)
996 if (datasetSequence != null)
998 datasetSequence.addDBRef(entry);
1004 dbrefs = new DBRefEntry[0];
1007 for (DBRefEntryI dbr : dbrefs)
1009 if (dbr.updateFrom(entry))
1012 * found a dbref that either matched, or could be
1013 * updated from, the new entry - no need to add it
1020 * extend the array to make room for one more
1022 // TODO use an ArrayList instead
1023 int j = dbrefs.length;
1024 DBRefEntry[] temp = new DBRefEntry[j + 1];
1025 System.arraycopy(dbrefs, 0, temp, 0, j);
1026 temp[temp.length - 1] = entry;
1030 DBRefUtils.ensurePrimaries(this);
1034 public void setDatasetSequence(SequenceI seq)
1038 throw new IllegalArgumentException(
1039 "Implementation Error: self reference passed to SequenceI.setDatasetSequence");
1041 if (seq != null && seq.getDatasetSequence() != null)
1043 throw new IllegalArgumentException(
1044 "Implementation error: cascading dataset sequences are not allowed.");
1046 datasetSequence = seq;
1050 public SequenceI getDatasetSequence()
1052 return datasetSequence;
1056 public AlignmentAnnotation[] getAnnotation()
1058 return annotation == null ? null : annotation
1059 .toArray(new AlignmentAnnotation[annotation.size()]);
1063 public boolean hasAnnotation(AlignmentAnnotation ann)
1065 return annotation == null ? false : annotation.contains(ann);
1069 public void addAlignmentAnnotation(AlignmentAnnotation annotation)
1071 if (this.annotation == null)
1073 this.annotation = new Vector<AlignmentAnnotation>();
1075 if (!this.annotation.contains(annotation))
1077 this.annotation.addElement(annotation);
1079 annotation.setSequenceRef(this);
1083 public void removeAlignmentAnnotation(AlignmentAnnotation annotation)
1085 if (this.annotation != null)
1087 this.annotation.removeElement(annotation);
1088 if (this.annotation.size() == 0)
1090 this.annotation = null;
1096 * test if this is a valid candidate for another sequence's dataset sequence.
1099 private boolean isValidDatasetSequence()
1101 if (datasetSequence != null)
1105 for (int i = 0; i < sequence.length; i++)
1107 if (jalview.util.Comparison.isGap(sequence[i]))
1116 public SequenceI deriveSequence()
1118 Sequence seq = null;
1119 if (datasetSequence == null)
1121 if (isValidDatasetSequence())
1123 // Use this as dataset sequence
1124 seq = new Sequence(getName(), "", 1, -1);
1125 seq.setDatasetSequence(this);
1126 seq.initSeqFrom(this, getAnnotation());
1131 // Create a new, valid dataset sequence
1132 createDatasetSequence();
1135 return new Sequence(this);
1138 private boolean _isNa;
1140 private long _seqhash = 0;
1143 * Answers false if the sequence is more than 85% nucleotide (ACGTU), else
1147 public boolean isProtein()
1149 if (datasetSequence != null)
1151 return datasetSequence.isProtein();
1153 if (_seqhash != sequence.hashCode())
1155 _seqhash = sequence.hashCode();
1156 _isNa = Comparison.isNucleotide(this);
1164 * @see jalview.datamodel.SequenceI#createDatasetSequence()
1167 public SequenceI createDatasetSequence()
1169 if (datasetSequence == null)
1171 Sequence dsseq = new Sequence(getName(), AlignSeq.extractGaps(
1172 jalview.util.Comparison.GapChars, getSequenceAsString()),
1173 getStart(), getEnd());
1175 datasetSequence = dsseq;
1177 dsseq.setDescription(description);
1178 // move features and database references onto dataset sequence
1179 dsseq.sequenceFeatures = sequenceFeatures;
1180 sequenceFeatures = null;
1181 dsseq.dbrefs = dbrefs;
1183 // TODO: search and replace any references to this sequence with
1184 // references to the dataset sequence in Mappings on dbref
1185 dsseq.pdbIds = pdbIds;
1187 datasetSequence.updatePDBIds();
1188 if (annotation != null)
1190 // annotation is cloned rather than moved, to preserve what's currently
1192 for (AlignmentAnnotation aa : annotation)
1194 AlignmentAnnotation _aa = new AlignmentAnnotation(aa);
1195 _aa.sequenceRef = datasetSequence;
1196 _aa.adjustForAlignment(); // uses annotation's own record of
1197 // sequence-column mapping
1198 datasetSequence.addAlignmentAnnotation(_aa);
1202 return datasetSequence;
1209 * jalview.datamodel.SequenceI#setAlignmentAnnotation(AlignmmentAnnotation[]
1213 public void setAlignmentAnnotation(AlignmentAnnotation[] annotations)
1215 if (annotation != null)
1217 annotation.removeAllElements();
1219 if (annotations != null)
1221 for (int i = 0; i < annotations.length; i++)
1223 if (annotations[i] != null)
1225 addAlignmentAnnotation(annotations[i]);
1232 public AlignmentAnnotation[] getAnnotation(String label)
1234 if (annotation == null || annotation.size() == 0)
1239 Vector subset = new Vector();
1240 Enumeration e = annotation.elements();
1241 while (e.hasMoreElements())
1243 AlignmentAnnotation ann = (AlignmentAnnotation) e.nextElement();
1244 if (ann.label != null && ann.label.equals(label))
1246 subset.addElement(ann);
1249 if (subset.size() == 0)
1253 AlignmentAnnotation[] anns = new AlignmentAnnotation[subset.size()];
1255 e = subset.elements();
1256 while (e.hasMoreElements())
1258 anns[i++] = (AlignmentAnnotation) e.nextElement();
1260 subset.removeAllElements();
1265 public boolean updatePDBIds()
1267 if (datasetSequence != null)
1269 // TODO: could merge DBRefs
1270 return datasetSequence.updatePDBIds();
1272 if (dbrefs == null || dbrefs.length == 0)
1276 boolean added = false;
1277 for (DBRefEntry dbr : dbrefs)
1279 if (DBRefSource.PDB.equals(dbr.getSource()))
1282 * 'Add' any PDB dbrefs as a PDBEntry - add is only performed if the
1283 * PDB id is not already present in a 'matching' PDBEntry
1284 * Constructor parses out a chain code if appended to the accession id
1285 * (a fudge used to 'store' the chain code in the DBRef)
1287 PDBEntry pdbe = new PDBEntry(dbr);
1288 added |= addPDBId(pdbe);
1295 public void transferAnnotation(SequenceI entry, Mapping mp)
1297 if (datasetSequence != null)
1299 datasetSequence.transferAnnotation(entry, mp);
1302 if (entry.getDatasetSequence() != null)
1304 transferAnnotation(entry.getDatasetSequence(), mp);
1307 // transfer any new features from entry onto sequence
1308 if (entry.getSequenceFeatures() != null)
1311 SequenceFeature[] sfs = entry.getSequenceFeatures();
1312 for (int si = 0; si < sfs.length; si++)
1314 SequenceFeature sf[] = (mp != null) ? mp.locateFeature(sfs[si])
1315 : new SequenceFeature[] { new SequenceFeature(sfs[si]) };
1316 if (sf != null && sf.length > 0)
1318 for (int sfi = 0; sfi < sf.length; sfi++)
1320 addSequenceFeature(sf[sfi]);
1326 // transfer PDB entries
1327 if (entry.getAllPDBEntries() != null)
1329 Enumeration e = entry.getAllPDBEntries().elements();
1330 while (e.hasMoreElements())
1332 PDBEntry pdb = (PDBEntry) e.nextElement();
1336 // transfer database references
1337 DBRefEntry[] entryRefs = entry.getDBRefs();
1338 if (entryRefs != null)
1340 for (int r = 0; r < entryRefs.length; r++)
1342 DBRefEntry newref = new DBRefEntry(entryRefs[r]);
1343 if (newref.getMap() != null && mp != null)
1345 // remap ref using our local mapping
1347 // we also assume all version string setting is done by dbSourceProxy
1349 * if (!newref.getSource().equalsIgnoreCase(dbSource)) {
1350 * newref.setSource(dbSource); }
1358 * @return The index (zero-based) on this sequence in the MSA. It returns
1359 * {@code -1} if this information is not available.
1362 public int getIndex()
1368 * Defines the position of this sequence in the MSA. Use the value {@code -1}
1369 * if this information is undefined.
1372 * position for this sequence. This value is zero-based (zero for
1373 * this first sequence)
1376 public void setIndex(int value)
1382 public void setRNA(RNA r)
1394 public List<AlignmentAnnotation> getAlignmentAnnotations(String calcId,
1397 List<AlignmentAnnotation> result = new ArrayList<AlignmentAnnotation>();
1398 if (this.annotation != null)
1400 for (AlignmentAnnotation ann : annotation)
1402 if (ann.calcId != null && ann.calcId.equals(calcId)
1403 && ann.label != null && ann.label.equals(label))
1413 public String toString()
1415 return getDisplayId(false);
1419 public PDBEntry getPDBEntry(String pdbIdStr)
1421 if (getDatasetSequence() != null)
1423 return getDatasetSequence().getPDBEntry(pdbIdStr);
1429 List<PDBEntry> entries = getAllPDBEntries();
1430 for (PDBEntry entry : entries)
1432 if (entry.getId().equalsIgnoreCase(pdbIdStr))
1441 public List<DBRefEntry> getPrimaryDBRefs()
1443 if (datasetSequence != null)
1445 return datasetSequence.getPrimaryDBRefs();
1447 if (dbrefs == null || dbrefs.length == 0)
1449 return Collections.emptyList();
1451 synchronized (dbrefs)
1453 List<DBRefEntry> primaries = new ArrayList<DBRefEntry>();
1454 DBRefEntry[] tmp = new DBRefEntry[1];
1455 for (DBRefEntry ref : dbrefs)
1457 if (!ref.isPrimaryCandidate())
1463 MapList mp = ref.getMap().getMap();
1464 if (mp.getFromLowest() > start || mp.getFromHighest() < end)
1466 // map only involves a subsequence, so cannot be primary
1470 // whilst it looks like it is a primary ref, we also sanity check type
1471 if (DBRefUtils.getCanonicalName(DBRefSource.PDB).equals(
1472 DBRefUtils.getCanonicalName(ref.getSource())))
1474 // PDB dbrefs imply there should be a PDBEntry associated
1475 // TODO: tighten PDB dbrefs
1476 // formally imply Jalview has actually downloaded and
1477 // parsed the pdb file. That means there should be a cached file
1478 // handle on the PDBEntry, and a real mapping between sequence and
1479 // extracted sequence from PDB file
1480 PDBEntry pdbentry = getPDBEntry(ref.getAccessionId());
1481 if (pdbentry != null && pdbentry.getFile() != null)
1487 // check standard protein or dna sources
1489 DBRefEntry[] res = DBRefUtils.selectDbRefs(!isProtein(), tmp);
1490 if (res != null && res[0] == tmp[0])
1504 public List<SequenceFeature> findFeatures(int from, int to,
1507 if (datasetSequence != null)
1509 return datasetSequence.findFeatures(from, to, types);
1511 return sequenceFeatureStore.findFeatures(from, to, types);