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);
365 sequenceFeatureStore.delete(sf);
368 * old way - to be removed
371 for (index = 0; index < sequenceFeatures.length; index++)
373 if (sequenceFeatures[index].equals(sf))
379 if (index == sequenceFeatures.length)
384 int sfLength = sequenceFeatures.length;
387 sequenceFeatures = null;
391 SequenceFeature[] temp = new SequenceFeature[sfLength - 1];
392 System.arraycopy(sequenceFeatures, 0, temp, 0, index);
394 if (index < sfLength)
396 System.arraycopy(sequenceFeatures, index + 1, temp, index,
397 sequenceFeatures.length - index - 1);
400 sequenceFeatures = temp;
405 * Returns the sequence features (if any), looking first on the sequence, then
406 * on its dataset sequence, and so on until a non-null value is found (or
407 * none). This supports retrieval of sequence features stored on the sequence
408 * (as in the applet) or on the dataset sequence (as in the Desktop version).
413 public SequenceFeature[] getSequenceFeatures()
415 SequenceFeature[] features = sequenceFeatures;
417 SequenceI seq = this;
418 int count = 0; // failsafe against loop in sequence.datasetsequence...
419 while (features == null && seq.getDatasetSequence() != null
422 seq = seq.getDatasetSequence();
423 features = ((Sequence) seq).sequenceFeatures;
429 public boolean addPDBId(PDBEntry entry)
433 pdbIds = new Vector<PDBEntry>();
438 for (PDBEntry pdbe : pdbIds)
440 if (pdbe.updateFrom(entry))
445 pdbIds.addElement(entry);
456 public void setPDBId(Vector<PDBEntry> id)
464 * @return DOCUMENT ME!
467 public Vector<PDBEntry> getAllPDBEntries()
469 return pdbIds == null ? new Vector<PDBEntry>() : pdbIds;
475 * @return DOCUMENT ME!
478 public String getDisplayId(boolean jvsuffix)
480 StringBuffer result = new StringBuffer(name);
483 result.append("/" + start + "-" + end);
486 return result.toString();
496 public void setName(String name)
505 * @return DOCUMENT ME!
508 public String getName()
520 public void setStart(int start)
528 * @return DOCUMENT ME!
531 public int getStart()
543 public void setEnd(int end)
551 * @return DOCUMENT ME!
562 * @return DOCUMENT ME!
565 public int getLength()
567 return this.sequence.length;
577 public void setSequence(String seq)
579 this.sequence = seq.toCharArray();
584 public String getSequenceAsString()
586 return new String(sequence);
590 public String getSequenceAsString(int start, int end)
592 return new String(getSequence(start, end));
596 public char[] getSequence()
604 * @see jalview.datamodel.SequenceI#getSequence(int, int)
607 public char[] getSequence(int start, int end)
613 // JBPNote - left to user to pad the result here (TODO:Decide on this
615 if (start >= sequence.length)
620 if (end >= sequence.length)
622 end = sequence.length;
625 char[] reply = new char[end - start];
626 System.arraycopy(sequence, start, reply, 0, end - start);
632 public SequenceI getSubSequence(int start, int end)
638 char[] seq = getSequence(start, end);
643 int nstart = findPosition(start);
644 int nend = findPosition(end) - 1;
645 // JBPNote - this is an incomplete copy.
646 SequenceI nseq = new Sequence(this.getName(), seq, nstart, nend);
647 nseq.setDescription(description);
648 if (datasetSequence != null)
650 nseq.setDatasetSequence(datasetSequence);
654 nseq.setDatasetSequence(this);
660 * Returns the character of the aligned sequence at the given position (base
661 * zero), or space if the position is not within the sequence's bounds
666 public char getCharAt(int i)
668 if (i >= 0 && i < sequence.length)
685 public void setDescription(String desc)
687 this.description = desc;
693 * @return DOCUMENT ME!
696 public String getDescription()
698 return this.description;
704 * @see jalview.datamodel.SequenceI#findIndex(int)
707 public int findIndex(int pos)
709 // returns the alignment position for a residue
712 // Rely on end being at least as long as the length of the sequence.
713 while ((i < sequence.length) && (j <= end) && (j <= pos))
715 if (!jalview.util.Comparison.isGap(sequence[i]))
723 if ((j == end) && (j < pos))
734 public int findPosition(int i)
738 int seqlen = sequence.length;
739 while ((j < i) && (j < seqlen))
741 if (!jalview.util.Comparison.isGap(sequence[j]))
753 * Returns an int array where indices correspond to each residue in the
754 * sequence and the element value gives its position in the alignment
756 * @return int[SequenceI.getEnd()-SequenceI.getStart()+1] or null if no
757 * residues in SequenceI object
760 public int[] gapMap()
762 String seq = jalview.analysis.AlignSeq.extractGaps(
763 jalview.util.Comparison.GapChars, new String(sequence));
764 int[] map = new int[seq.length()];
768 while (j < sequence.length)
770 if (!jalview.util.Comparison.isGap(sequence[j]))
782 public int[] findPositionMap()
784 int map[] = new int[sequence.length];
787 int seqlen = sequence.length;
791 if (!jalview.util.Comparison.isGap(sequence[j]))
802 public List<int[]> getInsertions()
804 ArrayList<int[]> map = new ArrayList<int[]>();
805 int lastj = -1, j = 0;
807 int seqlen = sequence.length;
810 if (jalview.util.Comparison.isGap(sequence[j]))
821 map.add(new int[] { lastj, j - 1 });
829 map.add(new int[] { lastj, j - 1 });
836 public void deleteChars(int i, int j)
838 int newstart = start, newend = end;
839 if (i >= sequence.length || i < 0)
844 char[] tmp = StringUtils.deleteChars(sequence, i, j);
845 boolean createNewDs = false;
846 // TODO: take a (second look) at the dataset creation validation method for
847 // the very large sequence case
848 int eindex = -1, sindex = -1;
849 boolean ecalc = false, scalc = false;
850 for (int s = i; s < j; s++)
852 if (jalview.schemes.ResidueProperties.aaIndex[sequence[s]] != 23)
862 sindex = findIndex(start) - 1;
867 // delete characters including start of sequence
868 newstart = findPosition(j);
869 break; // don't need to search for any more residue characters.
873 // delete characters after start.
876 eindex = findIndex(end) - 1;
881 // delete characters at end of sequence
882 newend = findPosition(i - 1);
883 break; // don't need to search for any more residue characters.
888 newend--; // decrease end position by one for the deleted residue
889 // and search further
895 // deletion occured in the middle of the sequence
896 if (createNewDs && this.datasetSequence != null)
898 // construct a new sequence
899 Sequence ds = new Sequence(datasetSequence);
900 // TODO: remove any non-inheritable properties ?
901 // TODO: create a sequence mapping (since there is a relation here ?)
902 ds.deleteChars(i, j);
903 datasetSequence = ds;
911 public void insertCharAt(int i, int length, char c)
913 char[] tmp = new char[sequence.length + length];
915 if (i >= sequence.length)
917 System.arraycopy(sequence, 0, tmp, 0, sequence.length);
922 System.arraycopy(sequence, 0, tmp, 0, i);
932 if (i < sequence.length)
934 System.arraycopy(sequence, i, tmp, index, sequence.length - i);
941 public void insertCharAt(int i, char c)
943 insertCharAt(i, 1, c);
947 public String getVamsasId()
953 public void setVamsasId(String id)
959 public void setDBRefs(DBRefEntry[] dbref)
961 if (dbrefs == null && datasetSequence != null
962 && this != datasetSequence)
964 datasetSequence.setDBRefs(dbref);
970 DBRefUtils.ensurePrimaries(this);
975 public DBRefEntry[] getDBRefs()
977 if (dbrefs == null && datasetSequence != null
978 && this != datasetSequence)
980 return datasetSequence.getDBRefs();
986 public void addDBRef(DBRefEntry entry)
988 if (datasetSequence != null)
990 datasetSequence.addDBRef(entry);
996 dbrefs = new DBRefEntry[0];
999 for (DBRefEntryI dbr : dbrefs)
1001 if (dbr.updateFrom(entry))
1004 * found a dbref that either matched, or could be
1005 * updated from, the new entry - no need to add it
1012 * extend the array to make room for one more
1014 // TODO use an ArrayList instead
1015 int j = dbrefs.length;
1016 DBRefEntry[] temp = new DBRefEntry[j + 1];
1017 System.arraycopy(dbrefs, 0, temp, 0, j);
1018 temp[temp.length - 1] = entry;
1022 DBRefUtils.ensurePrimaries(this);
1026 public void setDatasetSequence(SequenceI seq)
1030 throw new IllegalArgumentException(
1031 "Implementation Error: self reference passed to SequenceI.setDatasetSequence");
1033 if (seq != null && seq.getDatasetSequence() != null)
1035 throw new IllegalArgumentException(
1036 "Implementation error: cascading dataset sequences are not allowed.");
1038 datasetSequence = seq;
1042 public SequenceI getDatasetSequence()
1044 return datasetSequence;
1048 public AlignmentAnnotation[] getAnnotation()
1050 return annotation == null ? null : annotation
1051 .toArray(new AlignmentAnnotation[annotation.size()]);
1055 public boolean hasAnnotation(AlignmentAnnotation ann)
1057 return annotation == null ? false : annotation.contains(ann);
1061 public void addAlignmentAnnotation(AlignmentAnnotation annotation)
1063 if (this.annotation == null)
1065 this.annotation = new Vector<AlignmentAnnotation>();
1067 if (!this.annotation.contains(annotation))
1069 this.annotation.addElement(annotation);
1071 annotation.setSequenceRef(this);
1075 public void removeAlignmentAnnotation(AlignmentAnnotation annotation)
1077 if (this.annotation != null)
1079 this.annotation.removeElement(annotation);
1080 if (this.annotation.size() == 0)
1082 this.annotation = null;
1088 * test if this is a valid candidate for another sequence's dataset sequence.
1091 private boolean isValidDatasetSequence()
1093 if (datasetSequence != null)
1097 for (int i = 0; i < sequence.length; i++)
1099 if (jalview.util.Comparison.isGap(sequence[i]))
1108 public SequenceI deriveSequence()
1110 Sequence seq = null;
1111 if (datasetSequence == null)
1113 if (isValidDatasetSequence())
1115 // Use this as dataset sequence
1116 seq = new Sequence(getName(), "", 1, -1);
1117 seq.setDatasetSequence(this);
1118 seq.initSeqFrom(this, getAnnotation());
1123 // Create a new, valid dataset sequence
1124 createDatasetSequence();
1127 return new Sequence(this);
1130 private boolean _isNa;
1132 private long _seqhash = 0;
1135 * Answers false if the sequence is more than 85% nucleotide (ACGTU), else
1139 public boolean isProtein()
1141 if (datasetSequence != null)
1143 return datasetSequence.isProtein();
1145 if (_seqhash != sequence.hashCode())
1147 _seqhash = sequence.hashCode();
1148 _isNa = Comparison.isNucleotide(this);
1156 * @see jalview.datamodel.SequenceI#createDatasetSequence()
1159 public SequenceI createDatasetSequence()
1161 if (datasetSequence == null)
1163 Sequence dsseq = new Sequence(getName(), AlignSeq.extractGaps(
1164 jalview.util.Comparison.GapChars, getSequenceAsString()),
1165 getStart(), getEnd());
1167 datasetSequence = dsseq;
1169 dsseq.setDescription(description);
1170 // move features and database references onto dataset sequence
1171 dsseq.sequenceFeatures = sequenceFeatures;
1172 sequenceFeatures = null;
1173 dsseq.dbrefs = dbrefs;
1175 // TODO: search and replace any references to this sequence with
1176 // references to the dataset sequence in Mappings on dbref
1177 dsseq.pdbIds = pdbIds;
1179 datasetSequence.updatePDBIds();
1180 if (annotation != null)
1182 // annotation is cloned rather than moved, to preserve what's currently
1184 for (AlignmentAnnotation aa : annotation)
1186 AlignmentAnnotation _aa = new AlignmentAnnotation(aa);
1187 _aa.sequenceRef = datasetSequence;
1188 _aa.adjustForAlignment(); // uses annotation's own record of
1189 // sequence-column mapping
1190 datasetSequence.addAlignmentAnnotation(_aa);
1194 return datasetSequence;
1201 * jalview.datamodel.SequenceI#setAlignmentAnnotation(AlignmmentAnnotation[]
1205 public void setAlignmentAnnotation(AlignmentAnnotation[] annotations)
1207 if (annotation != null)
1209 annotation.removeAllElements();
1211 if (annotations != null)
1213 for (int i = 0; i < annotations.length; i++)
1215 if (annotations[i] != null)
1217 addAlignmentAnnotation(annotations[i]);
1224 public AlignmentAnnotation[] getAnnotation(String label)
1226 if (annotation == null || annotation.size() == 0)
1231 Vector subset = new Vector();
1232 Enumeration e = annotation.elements();
1233 while (e.hasMoreElements())
1235 AlignmentAnnotation ann = (AlignmentAnnotation) e.nextElement();
1236 if (ann.label != null && ann.label.equals(label))
1238 subset.addElement(ann);
1241 if (subset.size() == 0)
1245 AlignmentAnnotation[] anns = new AlignmentAnnotation[subset.size()];
1247 e = subset.elements();
1248 while (e.hasMoreElements())
1250 anns[i++] = (AlignmentAnnotation) e.nextElement();
1252 subset.removeAllElements();
1257 public boolean updatePDBIds()
1259 if (datasetSequence != null)
1261 // TODO: could merge DBRefs
1262 return datasetSequence.updatePDBIds();
1264 if (dbrefs == null || dbrefs.length == 0)
1268 boolean added = false;
1269 for (DBRefEntry dbr : dbrefs)
1271 if (DBRefSource.PDB.equals(dbr.getSource()))
1274 * 'Add' any PDB dbrefs as a PDBEntry - add is only performed if the
1275 * PDB id is not already present in a 'matching' PDBEntry
1276 * Constructor parses out a chain code if appended to the accession id
1277 * (a fudge used to 'store' the chain code in the DBRef)
1279 PDBEntry pdbe = new PDBEntry(dbr);
1280 added |= addPDBId(pdbe);
1287 public void transferAnnotation(SequenceI entry, Mapping mp)
1289 if (datasetSequence != null)
1291 datasetSequence.transferAnnotation(entry, mp);
1294 if (entry.getDatasetSequence() != null)
1296 transferAnnotation(entry.getDatasetSequence(), mp);
1299 // transfer any new features from entry onto sequence
1300 if (entry.getSequenceFeatures() != null)
1303 SequenceFeature[] sfs = entry.getSequenceFeatures();
1304 for (int si = 0; si < sfs.length; si++)
1306 SequenceFeature sf[] = (mp != null) ? mp.locateFeature(sfs[si])
1307 : new SequenceFeature[] { new SequenceFeature(sfs[si]) };
1308 if (sf != null && sf.length > 0)
1310 for (int sfi = 0; sfi < sf.length; sfi++)
1312 addSequenceFeature(sf[sfi]);
1318 // transfer PDB entries
1319 if (entry.getAllPDBEntries() != null)
1321 Enumeration e = entry.getAllPDBEntries().elements();
1322 while (e.hasMoreElements())
1324 PDBEntry pdb = (PDBEntry) e.nextElement();
1328 // transfer database references
1329 DBRefEntry[] entryRefs = entry.getDBRefs();
1330 if (entryRefs != null)
1332 for (int r = 0; r < entryRefs.length; r++)
1334 DBRefEntry newref = new DBRefEntry(entryRefs[r]);
1335 if (newref.getMap() != null && mp != null)
1337 // remap ref using our local mapping
1339 // we also assume all version string setting is done by dbSourceProxy
1341 * if (!newref.getSource().equalsIgnoreCase(dbSource)) {
1342 * newref.setSource(dbSource); }
1350 * @return The index (zero-based) on this sequence in the MSA. It returns
1351 * {@code -1} if this information is not available.
1354 public int getIndex()
1360 * Defines the position of this sequence in the MSA. Use the value {@code -1}
1361 * if this information is undefined.
1364 * position for this sequence. This value is zero-based (zero for
1365 * this first sequence)
1368 public void setIndex(int value)
1374 public void setRNA(RNA r)
1386 public List<AlignmentAnnotation> getAlignmentAnnotations(String calcId,
1389 List<AlignmentAnnotation> result = new ArrayList<AlignmentAnnotation>();
1390 if (this.annotation != null)
1392 for (AlignmentAnnotation ann : annotation)
1394 if (ann.calcId != null && ann.calcId.equals(calcId)
1395 && ann.label != null && ann.label.equals(label))
1405 public String toString()
1407 return getDisplayId(false);
1411 public PDBEntry getPDBEntry(String pdbIdStr)
1413 if (getDatasetSequence() != null)
1415 return getDatasetSequence().getPDBEntry(pdbIdStr);
1421 List<PDBEntry> entries = getAllPDBEntries();
1422 for (PDBEntry entry : entries)
1424 if (entry.getId().equalsIgnoreCase(pdbIdStr))
1433 public List<DBRefEntry> getPrimaryDBRefs()
1435 if (datasetSequence != null)
1437 return datasetSequence.getPrimaryDBRefs();
1439 if (dbrefs == null || dbrefs.length == 0)
1441 return Collections.emptyList();
1443 synchronized (dbrefs)
1445 List<DBRefEntry> primaries = new ArrayList<DBRefEntry>();
1446 DBRefEntry[] tmp = new DBRefEntry[1];
1447 for (DBRefEntry ref : dbrefs)
1449 if (!ref.isPrimaryCandidate())
1455 MapList mp = ref.getMap().getMap();
1456 if (mp.getFromLowest() > start || mp.getFromHighest() < end)
1458 // map only involves a subsequence, so cannot be primary
1462 // whilst it looks like it is a primary ref, we also sanity check type
1463 if (DBRefUtils.getCanonicalName(DBRefSource.PDB).equals(
1464 DBRefUtils.getCanonicalName(ref.getSource())))
1466 // PDB dbrefs imply there should be a PDBEntry associated
1467 // TODO: tighten PDB dbrefs
1468 // formally imply Jalview has actually downloaded and
1469 // parsed the pdb file. That means there should be a cached file
1470 // handle on the PDBEntry, and a real mapping between sequence and
1471 // extracted sequence from PDB file
1472 PDBEntry pdbentry = getPDBEntry(ref.getAccessionId());
1473 if (pdbentry != null && pdbentry.getFile() != null)
1479 // check standard protein or dna sources
1481 DBRefEntry[] res = DBRefUtils.selectDbRefs(!isProtein(), tmp);
1482 if (res != null && res[0] == tmp[0])
1493 public List<SequenceFeature> findFeatures(String type, int from, int to)
1495 if (datasetSequence != null)
1497 return datasetSequence.findFeatures(type, from, to);
1499 return sequenceFeatureStore.findFeatures(from, to, type);