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.util.Comparison;
27 import jalview.util.DBRefUtils;
28 import jalview.util.MapList;
29 import jalview.util.StringUtils;
31 import java.util.ArrayList;
32 import java.util.Arrays;
33 import java.util.Collections;
34 import java.util.Enumeration;
35 import java.util.List;
36 import java.util.Vector;
38 import fr.orsay.lri.varna.models.rna.RNA;
42 * Implements the SequenceI interface for a char[] based sequence object.
47 public class Sequence extends ASequence implements SequenceI
49 SequenceI datasetSequence;
53 private char[] sequence;
61 Vector<PDBEntry> pdbIds;
70 * This annotation is displayed below the alignment but the positions are tied
71 * to the residues of this sequence
73 * TODO: change to List<>
75 Vector<AlignmentAnnotation> annotation;
78 * The index of the sequence in a MSA
82 /** array of sequence features - may not be null for a valid sequence object */
83 public SequenceFeature[] sequenceFeatures;
85 private SequenceFeatures sequenceFeatureStore;
88 * Creates a new Sequence object.
93 * string to form a possibly gapped sequence out of
95 * first position of non-gap residue in the sequence
97 * last position of ungapped residues (nearly always only used for
100 public Sequence(String name, String sequence, int start, int end)
102 initSeqAndName(name, sequence.toCharArray(), start, end);
105 public Sequence(String name, char[] sequence, int start, int end)
107 initSeqAndName(name, sequence, start, end);
111 * Stage 1 constructor - assign name, sequence, and set start and end fields.
112 * start and end are updated values from name2 if it ends with /start-end
119 protected void initSeqAndName(String name2, char[] sequence2, int start2,
123 this.sequence = sequence2;
126 sequenceFeatureStore = new SequenceFeatures();
131 com.stevesoft.pat.Regex limitrx = new com.stevesoft.pat.Regex(
132 "[/][0-9]{1,}[-][0-9]{1,}$");
134 com.stevesoft.pat.Regex endrx = new com.stevesoft.pat.Regex("[0-9]{1,}$");
141 .println("POSSIBLE IMPLEMENTATION ERROR: null sequence name passed to constructor.");
144 // Does sequence have the /start-end signature?
145 if (limitrx.search(name))
147 name = limitrx.left();
148 endrx.search(limitrx.stringMatched());
149 setStart(Integer.parseInt(limitrx.stringMatched().substring(1,
150 endrx.matchedFrom() - 1)));
151 setEnd(Integer.parseInt(endrx.stringMatched()));
155 void checkValidRange()
158 // http://issues.jalview.org/browse/JAL-774?focusedCommentId=11239&page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel#comment-11239
161 for (int j = 0; j < sequence.length; j++)
163 if (!jalview.util.Comparison.isGap(sequence[j]))
182 * Creates a new Sequence object.
189 public Sequence(String name, String sequence)
191 this(name, sequence, 1, -1);
195 * Creates a new Sequence object with new AlignmentAnnotations but inherits
196 * any existing dataset sequence reference. If non exists, everything is
200 * if seq is a dataset sequence, behaves like a plain old copy
203 public Sequence(SequenceI seq)
205 this(seq, seq.getAnnotation());
209 * Create a new sequence object with new features, DBRefEntries, and PDBIds
210 * but inherits any existing dataset sequence reference, and duplicate of any
211 * annotation that is present in the given annotation array.
214 * the sequence to be copied
215 * @param alAnnotation
216 * an array of annotation including some associated with seq
218 public Sequence(SequenceI seq, AlignmentAnnotation[] alAnnotation)
220 initSeqFrom(seq, alAnnotation);
225 * does the heavy lifting when cloning a dataset sequence, or coping data from
226 * dataset to a new derived sequence.
229 * - source of attributes.
230 * @param alAnnotation
231 * - alignment annotation present on seq that should be copied onto
234 protected void initSeqFrom(SequenceI seq,
235 AlignmentAnnotation[] alAnnotation)
238 char[] oseq = seq.getSequence();
239 initSeqAndName(seq.getName(), Arrays.copyOf(oseq, oseq.length),
240 seq.getStart(), seq.getEnd());
242 description = seq.getDescription();
243 if (seq != datasetSequence)
245 setDatasetSequence(seq.getDatasetSequence());
247 if (datasetSequence == null && seq.getDBRefs() != null)
249 // only copy DBRefs and seqfeatures if we really are a dataset sequence
250 DBRefEntry[] dbr = seq.getDBRefs();
251 for (int i = 0; i < dbr.length; i++)
253 addDBRef(new DBRefEntry(dbr[i]));
255 if (seq.getSequenceFeatures() != null)
257 SequenceFeature[] sf = seq.getSequenceFeatures();
258 for (int i = 0; i < sf.length; i++)
260 addSequenceFeature(new SequenceFeature(sf[i]));
264 if (seq.getAnnotation() != null)
266 AlignmentAnnotation[] sqann = seq.getAnnotation();
267 for (int i = 0; i < sqann.length; i++)
269 if (sqann[i] == null)
273 boolean found = (alAnnotation == null);
276 for (int apos = 0; !found && apos < alAnnotation.length; apos++)
278 found = (alAnnotation[apos] == sqann[i]);
283 // only copy the given annotation
284 AlignmentAnnotation newann = new AlignmentAnnotation(sqann[i]);
285 addAlignmentAnnotation(newann);
289 if (seq.getAllPDBEntries() != null)
291 Vector<PDBEntry> ids = seq.getAllPDBEntries();
292 for (PDBEntry pdb : ids)
294 this.addPDBId(new PDBEntry(pdb));
300 public void setSequenceFeatures(SequenceFeature[] features)
302 if (datasetSequence == null)
304 sequenceFeatures = features;
308 if (datasetSequence.getSequenceFeatures() != features
309 && datasetSequence.getSequenceFeatures() != null
310 && datasetSequence.getSequenceFeatures().length > 0)
313 "Warning: JAL-2046 side effect ? Possible implementation error: overwriting dataset sequence features by setting sequence features on alignment")
316 datasetSequence.setSequenceFeatures(features);
321 public synchronized boolean addSequenceFeature(SequenceFeature sf)
323 if (sequenceFeatures == null && datasetSequence != null)
325 return datasetSequence.addSequenceFeature(sf);
327 if (sequenceFeatures == null)
329 sequenceFeatures = new SequenceFeature[0];
332 for (int i = 0; i < sequenceFeatures.length; i++)
334 if (sequenceFeatures[i].equals(sf))
340 SequenceFeature[] temp = new SequenceFeature[sequenceFeatures.length + 1];
341 System.arraycopy(sequenceFeatures, 0, temp, 0, sequenceFeatures.length);
342 temp[sequenceFeatures.length] = sf;
344 sequenceFeatures = temp;
346 sequenceFeatureStore.add(sf);
351 public void deleteFeature(SequenceFeature sf)
353 if (sequenceFeatures == null)
355 if (datasetSequence != null)
357 datasetSequence.deleteFeature(sf);
363 for (index = 0; index < sequenceFeatures.length; index++)
365 if (sequenceFeatures[index].equals(sf))
371 if (index == sequenceFeatures.length)
376 int sfLength = sequenceFeatures.length;
379 sequenceFeatures = null;
383 SequenceFeature[] temp = new SequenceFeature[sfLength - 1];
384 System.arraycopy(sequenceFeatures, 0, temp, 0, index);
386 if (index < sfLength)
388 System.arraycopy(sequenceFeatures, index + 1, temp, index,
389 sequenceFeatures.length - index - 1);
392 sequenceFeatures = temp;
397 * Returns the sequence features (if any), looking first on the sequence, then
398 * on its dataset sequence, and so on until a non-null value is found (or
399 * none). This supports retrieval of sequence features stored on the sequence
400 * (as in the applet) or on the dataset sequence (as in the Desktop version).
405 public SequenceFeature[] getSequenceFeatures()
407 SequenceFeature[] features = sequenceFeatures;
409 SequenceI seq = this;
410 int count = 0; // failsafe against loop in sequence.datasetsequence...
411 while (features == null && seq.getDatasetSequence() != null
414 seq = seq.getDatasetSequence();
415 features = ((Sequence) seq).sequenceFeatures;
421 public boolean addPDBId(PDBEntry entry)
425 pdbIds = new Vector<PDBEntry>();
430 for (PDBEntry pdbe : pdbIds)
432 if (pdbe.updateFrom(entry))
437 pdbIds.addElement(entry);
448 public void setPDBId(Vector<PDBEntry> id)
456 * @return DOCUMENT ME!
459 public Vector<PDBEntry> getAllPDBEntries()
461 return pdbIds == null ? new Vector<PDBEntry>() : pdbIds;
467 * @return DOCUMENT ME!
470 public String getDisplayId(boolean jvsuffix)
472 StringBuffer result = new StringBuffer(name);
475 result.append("/" + start + "-" + end);
478 return result.toString();
488 public void setName(String name)
497 * @return DOCUMENT ME!
500 public String getName()
512 public void setStart(int start)
520 * @return DOCUMENT ME!
523 public int getStart()
535 public void setEnd(int end)
543 * @return DOCUMENT ME!
554 * @return DOCUMENT ME!
557 public int getLength()
559 return this.sequence.length;
569 public void setSequence(String seq)
571 this.sequence = seq.toCharArray();
576 public String getSequenceAsString()
578 return new String(sequence);
582 public String getSequenceAsString(int start, int end)
584 return new String(getSequence(start, end));
588 public char[] getSequence()
596 * @see jalview.datamodel.SequenceI#getSequence(int, int)
599 public char[] getSequence(int start, int end)
605 // JBPNote - left to user to pad the result here (TODO:Decide on this
607 if (start >= sequence.length)
612 if (end >= sequence.length)
614 end = sequence.length;
617 char[] reply = new char[end - start];
618 System.arraycopy(sequence, start, reply, 0, end - start);
624 public SequenceI getSubSequence(int start, int end)
630 char[] seq = getSequence(start, end);
635 int nstart = findPosition(start);
636 int nend = findPosition(end) - 1;
637 // JBPNote - this is an incomplete copy.
638 SequenceI nseq = new Sequence(this.getName(), seq, nstart, nend);
639 nseq.setDescription(description);
640 if (datasetSequence != null)
642 nseq.setDatasetSequence(datasetSequence);
646 nseq.setDatasetSequence(this);
652 * Returns the character of the aligned sequence at the given position (base
653 * zero), or space if the position is not within the sequence's bounds
658 public char getCharAt(int i)
660 if (i >= 0 && i < sequence.length)
677 public void setDescription(String desc)
679 this.description = desc;
685 * @return DOCUMENT ME!
688 public String getDescription()
690 return this.description;
696 * @see jalview.datamodel.SequenceI#findIndex(int)
699 public int findIndex(int pos)
701 // returns the alignment position for a residue
704 // Rely on end being at least as long as the length of the sequence.
705 while ((i < sequence.length) && (j <= end) && (j <= pos))
707 if (!jalview.util.Comparison.isGap(sequence[i]))
715 if ((j == end) && (j < pos))
726 public int findPosition(int i)
730 int seqlen = sequence.length;
731 while ((j < i) && (j < seqlen))
733 if (!jalview.util.Comparison.isGap(sequence[j]))
745 * Returns an int array where indices correspond to each residue in the
746 * sequence and the element value gives its position in the alignment
748 * @return int[SequenceI.getEnd()-SequenceI.getStart()+1] or null if no
749 * residues in SequenceI object
752 public int[] gapMap()
754 String seq = jalview.analysis.AlignSeq.extractGaps(
755 jalview.util.Comparison.GapChars, new String(sequence));
756 int[] map = new int[seq.length()];
760 while (j < sequence.length)
762 if (!jalview.util.Comparison.isGap(sequence[j]))
774 public int[] findPositionMap()
776 int map[] = new int[sequence.length];
779 int seqlen = sequence.length;
783 if (!jalview.util.Comparison.isGap(sequence[j]))
794 public List<int[]> getInsertions()
796 ArrayList<int[]> map = new ArrayList<int[]>();
797 int lastj = -1, j = 0;
799 int seqlen = sequence.length;
802 if (jalview.util.Comparison.isGap(sequence[j]))
813 map.add(new int[] { lastj, j - 1 });
821 map.add(new int[] { lastj, j - 1 });
828 public void deleteChars(int i, int j)
830 int newstart = start, newend = end;
831 if (i >= sequence.length || i < 0)
836 char[] tmp = StringUtils.deleteChars(sequence, i, j);
837 boolean createNewDs = false;
838 // TODO: take a (second look) at the dataset creation validation method for
839 // the very large sequence case
840 int eindex = -1, sindex = -1;
841 boolean ecalc = false, scalc = false;
842 for (int s = i; s < j; s++)
844 if (jalview.schemes.ResidueProperties.aaIndex[sequence[s]] != 23)
854 sindex = findIndex(start) - 1;
859 // delete characters including start of sequence
860 newstart = findPosition(j);
861 break; // don't need to search for any more residue characters.
865 // delete characters after start.
868 eindex = findIndex(end) - 1;
873 // delete characters at end of sequence
874 newend = findPosition(i - 1);
875 break; // don't need to search for any more residue characters.
880 newend--; // decrease end position by one for the deleted residue
881 // and search further
887 // deletion occured in the middle of the sequence
888 if (createNewDs && this.datasetSequence != null)
890 // construct a new sequence
891 Sequence ds = new Sequence(datasetSequence);
892 // TODO: remove any non-inheritable properties ?
893 // TODO: create a sequence mapping (since there is a relation here ?)
894 ds.deleteChars(i, j);
895 datasetSequence = ds;
903 public void insertCharAt(int i, int length, char c)
905 char[] tmp = new char[sequence.length + length];
907 if (i >= sequence.length)
909 System.arraycopy(sequence, 0, tmp, 0, sequence.length);
914 System.arraycopy(sequence, 0, tmp, 0, i);
924 if (i < sequence.length)
926 System.arraycopy(sequence, i, tmp, index, sequence.length - i);
933 public void insertCharAt(int i, char c)
935 insertCharAt(i, 1, c);
939 public String getVamsasId()
945 public void setVamsasId(String id)
951 public void setDBRefs(DBRefEntry[] dbref)
953 if (dbrefs == null && datasetSequence != null
954 && this != datasetSequence)
956 datasetSequence.setDBRefs(dbref);
962 DBRefUtils.ensurePrimaries(this);
967 public DBRefEntry[] getDBRefs()
969 if (dbrefs == null && datasetSequence != null
970 && this != datasetSequence)
972 return datasetSequence.getDBRefs();
978 public void addDBRef(DBRefEntry entry)
980 if (datasetSequence != null)
982 datasetSequence.addDBRef(entry);
988 dbrefs = new DBRefEntry[0];
991 for (DBRefEntryI dbr : dbrefs)
993 if (dbr.updateFrom(entry))
996 * found a dbref that either matched, or could be
997 * updated from, the new entry - no need to add it
1004 * extend the array to make room for one more
1006 // TODO use an ArrayList instead
1007 int j = dbrefs.length;
1008 DBRefEntry[] temp = new DBRefEntry[j + 1];
1009 System.arraycopy(dbrefs, 0, temp, 0, j);
1010 temp[temp.length - 1] = entry;
1014 DBRefUtils.ensurePrimaries(this);
1018 public void setDatasetSequence(SequenceI seq)
1022 throw new IllegalArgumentException(
1023 "Implementation Error: self reference passed to SequenceI.setDatasetSequence");
1025 if (seq != null && seq.getDatasetSequence() != null)
1027 throw new IllegalArgumentException(
1028 "Implementation error: cascading dataset sequences are not allowed.");
1030 datasetSequence = seq;
1034 public SequenceI getDatasetSequence()
1036 return datasetSequence;
1040 public AlignmentAnnotation[] getAnnotation()
1042 return annotation == null ? null : annotation
1043 .toArray(new AlignmentAnnotation[annotation.size()]);
1047 public boolean hasAnnotation(AlignmentAnnotation ann)
1049 return annotation == null ? false : annotation.contains(ann);
1053 public void addAlignmentAnnotation(AlignmentAnnotation annotation)
1055 if (this.annotation == null)
1057 this.annotation = new Vector<AlignmentAnnotation>();
1059 if (!this.annotation.contains(annotation))
1061 this.annotation.addElement(annotation);
1063 annotation.setSequenceRef(this);
1067 public void removeAlignmentAnnotation(AlignmentAnnotation annotation)
1069 if (this.annotation != null)
1071 this.annotation.removeElement(annotation);
1072 if (this.annotation.size() == 0)
1074 this.annotation = null;
1080 * test if this is a valid candidate for another sequence's dataset sequence.
1083 private boolean isValidDatasetSequence()
1085 if (datasetSequence != null)
1089 for (int i = 0; i < sequence.length; i++)
1091 if (jalview.util.Comparison.isGap(sequence[i]))
1100 public SequenceI deriveSequence()
1102 Sequence seq = null;
1103 if (datasetSequence == null)
1105 if (isValidDatasetSequence())
1107 // Use this as dataset sequence
1108 seq = new Sequence(getName(), "", 1, -1);
1109 seq.setDatasetSequence(this);
1110 seq.initSeqFrom(this, getAnnotation());
1115 // Create a new, valid dataset sequence
1116 createDatasetSequence();
1119 return new Sequence(this);
1122 private boolean _isNa;
1124 private long _seqhash = 0;
1127 * Answers false if the sequence is more than 85% nucleotide (ACGTU), else
1131 public boolean isProtein()
1133 if (datasetSequence != null)
1135 return datasetSequence.isProtein();
1137 if (_seqhash != sequence.hashCode())
1139 _seqhash = sequence.hashCode();
1140 _isNa = Comparison.isNucleotide(this);
1148 * @see jalview.datamodel.SequenceI#createDatasetSequence()
1151 public SequenceI createDatasetSequence()
1153 if (datasetSequence == null)
1155 Sequence dsseq = new Sequence(getName(), AlignSeq.extractGaps(
1156 jalview.util.Comparison.GapChars, getSequenceAsString()),
1157 getStart(), getEnd());
1159 datasetSequence = dsseq;
1161 dsseq.setDescription(description);
1162 // move features and database references onto dataset sequence
1163 dsseq.sequenceFeatures = sequenceFeatures;
1164 sequenceFeatures = null;
1165 dsseq.dbrefs = dbrefs;
1167 // TODO: search and replace any references to this sequence with
1168 // references to the dataset sequence in Mappings on dbref
1169 dsseq.pdbIds = pdbIds;
1171 datasetSequence.updatePDBIds();
1172 if (annotation != null)
1174 // annotation is cloned rather than moved, to preserve what's currently
1176 for (AlignmentAnnotation aa : annotation)
1178 AlignmentAnnotation _aa = new AlignmentAnnotation(aa);
1179 _aa.sequenceRef = datasetSequence;
1180 _aa.adjustForAlignment(); // uses annotation's own record of
1181 // sequence-column mapping
1182 datasetSequence.addAlignmentAnnotation(_aa);
1186 return datasetSequence;
1193 * jalview.datamodel.SequenceI#setAlignmentAnnotation(AlignmmentAnnotation[]
1197 public void setAlignmentAnnotation(AlignmentAnnotation[] annotations)
1199 if (annotation != null)
1201 annotation.removeAllElements();
1203 if (annotations != null)
1205 for (int i = 0; i < annotations.length; i++)
1207 if (annotations[i] != null)
1209 addAlignmentAnnotation(annotations[i]);
1216 public AlignmentAnnotation[] getAnnotation(String label)
1218 if (annotation == null || annotation.size() == 0)
1223 Vector subset = new Vector();
1224 Enumeration e = annotation.elements();
1225 while (e.hasMoreElements())
1227 AlignmentAnnotation ann = (AlignmentAnnotation) e.nextElement();
1228 if (ann.label != null && ann.label.equals(label))
1230 subset.addElement(ann);
1233 if (subset.size() == 0)
1237 AlignmentAnnotation[] anns = new AlignmentAnnotation[subset.size()];
1239 e = subset.elements();
1240 while (e.hasMoreElements())
1242 anns[i++] = (AlignmentAnnotation) e.nextElement();
1244 subset.removeAllElements();
1249 public boolean updatePDBIds()
1251 if (datasetSequence != null)
1253 // TODO: could merge DBRefs
1254 return datasetSequence.updatePDBIds();
1256 if (dbrefs == null || dbrefs.length == 0)
1260 boolean added = false;
1261 for (DBRefEntry dbr : dbrefs)
1263 if (DBRefSource.PDB.equals(dbr.getSource()))
1266 * 'Add' any PDB dbrefs as a PDBEntry - add is only performed if the
1267 * PDB id is not already present in a 'matching' PDBEntry
1268 * Constructor parses out a chain code if appended to the accession id
1269 * (a fudge used to 'store' the chain code in the DBRef)
1271 PDBEntry pdbe = new PDBEntry(dbr);
1272 added |= addPDBId(pdbe);
1279 public void transferAnnotation(SequenceI entry, Mapping mp)
1281 if (datasetSequence != null)
1283 datasetSequence.transferAnnotation(entry, mp);
1286 if (entry.getDatasetSequence() != null)
1288 transferAnnotation(entry.getDatasetSequence(), mp);
1291 // transfer any new features from entry onto sequence
1292 if (entry.getSequenceFeatures() != null)
1295 SequenceFeature[] sfs = entry.getSequenceFeatures();
1296 for (int si = 0; si < sfs.length; si++)
1298 SequenceFeature sf[] = (mp != null) ? mp.locateFeature(sfs[si])
1299 : new SequenceFeature[] { new SequenceFeature(sfs[si]) };
1300 if (sf != null && sf.length > 0)
1302 for (int sfi = 0; sfi < sf.length; sfi++)
1304 addSequenceFeature(sf[sfi]);
1310 // transfer PDB entries
1311 if (entry.getAllPDBEntries() != null)
1313 Enumeration e = entry.getAllPDBEntries().elements();
1314 while (e.hasMoreElements())
1316 PDBEntry pdb = (PDBEntry) e.nextElement();
1320 // transfer database references
1321 DBRefEntry[] entryRefs = entry.getDBRefs();
1322 if (entryRefs != null)
1324 for (int r = 0; r < entryRefs.length; r++)
1326 DBRefEntry newref = new DBRefEntry(entryRefs[r]);
1327 if (newref.getMap() != null && mp != null)
1329 // remap ref using our local mapping
1331 // we also assume all version string setting is done by dbSourceProxy
1333 * if (!newref.getSource().equalsIgnoreCase(dbSource)) {
1334 * newref.setSource(dbSource); }
1342 * @return The index (zero-based) on this sequence in the MSA. It returns
1343 * {@code -1} if this information is not available.
1346 public int getIndex()
1352 * Defines the position of this sequence in the MSA. Use the value {@code -1}
1353 * if this information is undefined.
1356 * position for this sequence. This value is zero-based (zero for
1357 * this first sequence)
1360 public void setIndex(int value)
1366 public void setRNA(RNA r)
1378 public List<AlignmentAnnotation> getAlignmentAnnotations(String calcId,
1381 List<AlignmentAnnotation> result = new ArrayList<AlignmentAnnotation>();
1382 if (this.annotation != null)
1384 for (AlignmentAnnotation ann : annotation)
1386 if (ann.calcId != null && ann.calcId.equals(calcId)
1387 && ann.label != null && ann.label.equals(label))
1397 public String toString()
1399 return getDisplayId(false);
1403 public PDBEntry getPDBEntry(String pdbIdStr)
1405 if (getDatasetSequence() != null)
1407 return getDatasetSequence().getPDBEntry(pdbIdStr);
1413 List<PDBEntry> entries = getAllPDBEntries();
1414 for (PDBEntry entry : entries)
1416 if (entry.getId().equalsIgnoreCase(pdbIdStr))
1425 public List<DBRefEntry> getPrimaryDBRefs()
1427 if (datasetSequence != null)
1429 return datasetSequence.getPrimaryDBRefs();
1431 if (dbrefs == null || dbrefs.length == 0)
1433 return Collections.emptyList();
1435 synchronized (dbrefs)
1437 List<DBRefEntry> primaries = new ArrayList<DBRefEntry>();
1438 DBRefEntry[] tmp = new DBRefEntry[1];
1439 for (DBRefEntry ref : dbrefs)
1441 if (!ref.isPrimaryCandidate())
1447 MapList mp = ref.getMap().getMap();
1448 if (mp.getFromLowest() > start || mp.getFromHighest() < end)
1450 // map only involves a subsequence, so cannot be primary
1454 // whilst it looks like it is a primary ref, we also sanity check type
1455 if (DBRefUtils.getCanonicalName(DBRefSource.PDB).equals(
1456 DBRefUtils.getCanonicalName(ref.getSource())))
1458 // PDB dbrefs imply there should be a PDBEntry associated
1459 // TODO: tighten PDB dbrefs
1460 // formally imply Jalview has actually downloaded and
1461 // parsed the pdb file. That means there should be a cached file
1462 // handle on the PDBEntry, and a real mapping between sequence and
1463 // extracted sequence from PDB file
1464 PDBEntry pdbentry = getPDBEntry(ref.getAccessionId());
1465 if (pdbentry != null && pdbentry.getFile() != null)
1471 // check standard protein or dna sources
1473 DBRefEntry[] res = DBRefUtils.selectDbRefs(!isProtein(), tmp);
1474 if (res != null && res[0] == tmp[0])
1485 public List<SequenceFeature> findFeatures(String type, int from, int to)
1487 if (datasetSequence != null)
1489 return datasetSequence.findFeatures(type, from, to);
1491 return sequenceFeatureStore.findFeatures(type, from, to);