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.util.Comparison;
26 import jalview.util.DBRefUtils;
27 import jalview.util.MapList;
28 import jalview.util.StringUtils;
30 import java.util.ArrayList;
31 import java.util.Arrays;
32 import java.util.BitSet;
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;
86 * Creates a new Sequence object.
91 * string to form a possibly gapped sequence out of
93 * first position of non-gap residue in the sequence
95 * last position of ungapped residues (nearly always only used for
98 public Sequence(String name, String sequence, int start, int end)
100 initSeqAndName(name, sequence.toCharArray(), start, end);
103 public Sequence(String name, char[] sequence, int start, int end)
105 initSeqAndName(name, sequence, start, end);
109 * Stage 1 constructor - assign name, sequence, and set start and end fields.
110 * start and end are updated values from name2 if it ends with /start-end
117 protected void initSeqAndName(String name2, char[] sequence2, int start2,
121 this.sequence = sequence2;
128 com.stevesoft.pat.Regex limitrx = new com.stevesoft.pat.Regex(
129 "[/][0-9]{1,}[-][0-9]{1,}$");
131 com.stevesoft.pat.Regex endrx = new com.stevesoft.pat.Regex("[0-9]{1,}$");
138 .println("POSSIBLE IMPLEMENTATION ERROR: null sequence name passed to constructor.");
141 // Does sequence have the /start-end signature?
142 if (limitrx.search(name))
144 name = limitrx.left();
145 endrx.search(limitrx.stringMatched());
146 setStart(Integer.parseInt(limitrx.stringMatched().substring(1,
147 endrx.matchedFrom() - 1)));
148 setEnd(Integer.parseInt(endrx.stringMatched()));
152 void checkValidRange()
155 // http://issues.jalview.org/browse/JAL-774?focusedCommentId=11239&page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel#comment-11239
158 for (int j = 0; j < sequence.length; j++)
160 if (!jalview.util.Comparison.isGap(sequence[j]))
179 * Creates a new Sequence object.
186 public Sequence(String name, String sequence)
188 this(name, sequence, 1, -1);
192 * Creates a new Sequence object with new AlignmentAnnotations but inherits
193 * any existing dataset sequence reference. If non exists, everything is
197 * if seq is a dataset sequence, behaves like a plain old copy
200 public Sequence(SequenceI seq)
202 this(seq, seq.getAnnotation());
206 * Create a new sequence object with new features, DBRefEntries, and PDBIds
207 * but inherits any existing dataset sequence reference, and duplicate of any
208 * annotation that is present in the given annotation array.
211 * the sequence to be copied
212 * @param alAnnotation
213 * an array of annotation including some associated with seq
215 public Sequence(SequenceI seq, AlignmentAnnotation[] alAnnotation)
217 initSeqFrom(seq, alAnnotation);
222 * does the heavy lifting when cloning a dataset sequence, or coping data from
223 * dataset to a new derived sequence.
226 * - source of attributes.
227 * @param alAnnotation
228 * - alignment annotation present on seq that should be copied onto
231 protected void initSeqFrom(SequenceI seq,
232 AlignmentAnnotation[] alAnnotation)
235 char[] oseq = seq.getSequence();
236 initSeqAndName(seq.getName(), Arrays.copyOf(oseq, oseq.length),
237 seq.getStart(), seq.getEnd());
239 description = seq.getDescription();
240 if (seq != datasetSequence)
242 setDatasetSequence(seq.getDatasetSequence());
244 if (datasetSequence == null && seq.getDBRefs() != null)
246 // only copy DBRefs and seqfeatures if we really are a dataset sequence
247 DBRefEntry[] dbr = seq.getDBRefs();
248 for (int i = 0; i < dbr.length; i++)
250 addDBRef(new DBRefEntry(dbr[i]));
252 if (seq.getSequenceFeatures() != null)
254 SequenceFeature[] sf = seq.getSequenceFeatures();
255 for (int i = 0; i < sf.length; i++)
257 addSequenceFeature(new SequenceFeature(sf[i]));
261 if (seq.getAnnotation() != null)
263 AlignmentAnnotation[] sqann = seq.getAnnotation();
264 for (int i = 0; i < sqann.length; i++)
266 if (sqann[i] == null)
270 boolean found = (alAnnotation == null);
273 for (int apos = 0; !found && apos < alAnnotation.length; apos++)
275 found = (alAnnotation[apos] == sqann[i]);
280 // only copy the given annotation
281 AlignmentAnnotation newann = new AlignmentAnnotation(sqann[i]);
282 addAlignmentAnnotation(newann);
286 if (seq.getAllPDBEntries() != null)
288 Vector<PDBEntry> ids = seq.getAllPDBEntries();
289 for (PDBEntry pdb : ids)
291 this.addPDBId(new PDBEntry(pdb));
297 public void setSequenceFeatures(SequenceFeature[] features)
299 if (datasetSequence == null)
301 sequenceFeatures = features;
305 if (datasetSequence.getSequenceFeatures() != features
306 && datasetSequence.getSequenceFeatures() != null
307 && datasetSequence.getSequenceFeatures().length > 0)
310 "Warning: JAL-2046 side effect ? Possible implementation error: overwriting dataset sequence features by setting sequence features on alignment")
313 datasetSequence.setSequenceFeatures(features);
318 public synchronized boolean addSequenceFeature(SequenceFeature sf)
320 if (sequenceFeatures == null && datasetSequence != null)
322 return datasetSequence.addSequenceFeature(sf);
324 if (sequenceFeatures == null)
326 sequenceFeatures = new SequenceFeature[0];
329 for (int i = 0; i < sequenceFeatures.length; i++)
331 if (sequenceFeatures[i].equals(sf))
337 SequenceFeature[] temp = new SequenceFeature[sequenceFeatures.length + 1];
338 System.arraycopy(sequenceFeatures, 0, temp, 0, sequenceFeatures.length);
339 temp[sequenceFeatures.length] = sf;
341 sequenceFeatures = temp;
346 public void deleteFeature(SequenceFeature sf)
348 if (sequenceFeatures == null)
350 if (datasetSequence != null)
352 datasetSequence.deleteFeature(sf);
358 for (index = 0; index < sequenceFeatures.length; index++)
360 if (sequenceFeatures[index].equals(sf))
366 if (index == sequenceFeatures.length)
371 int sfLength = sequenceFeatures.length;
374 sequenceFeatures = null;
378 SequenceFeature[] temp = new SequenceFeature[sfLength - 1];
379 System.arraycopy(sequenceFeatures, 0, temp, 0, index);
381 if (index < sfLength)
383 System.arraycopy(sequenceFeatures, index + 1, temp, index,
384 sequenceFeatures.length - index - 1);
387 sequenceFeatures = temp;
392 * Returns the sequence features (if any), looking first on the sequence, then
393 * on its dataset sequence, and so on until a non-null value is found (or
394 * none). This supports retrieval of sequence features stored on the sequence
395 * (as in the applet) or on the dataset sequence (as in the Desktop version).
400 public SequenceFeature[] getSequenceFeatures()
402 SequenceFeature[] features = sequenceFeatures;
404 SequenceI seq = this;
405 int count = 0; // failsafe against loop in sequence.datasetsequence...
406 while (features == null && seq.getDatasetSequence() != null
409 seq = seq.getDatasetSequence();
410 features = ((Sequence) seq).sequenceFeatures;
416 public boolean addPDBId(PDBEntry entry)
420 pdbIds = new Vector<PDBEntry>();
425 for (PDBEntry pdbe : pdbIds)
427 if (pdbe.updateFrom(entry))
432 pdbIds.addElement(entry);
443 public void setPDBId(Vector<PDBEntry> id)
451 * @return DOCUMENT ME!
454 public Vector<PDBEntry> getAllPDBEntries()
456 return pdbIds == null ? new Vector<PDBEntry>() : pdbIds;
462 * @return DOCUMENT ME!
465 public String getDisplayId(boolean jvsuffix)
467 StringBuffer result = new StringBuffer(name);
470 result.append("/" + start + "-" + end);
473 return result.toString();
483 public void setName(String name)
492 * @return DOCUMENT ME!
495 public String getName()
507 public void setStart(int start)
515 * @return DOCUMENT ME!
518 public int getStart()
530 public void setEnd(int end)
538 * @return DOCUMENT ME!
549 * @return DOCUMENT ME!
552 public int getLength()
554 return this.sequence.length;
564 public void setSequence(String seq)
566 this.sequence = seq.toCharArray();
571 public String getSequenceAsString()
573 return new String(sequence);
577 public String getSequenceAsString(int start, int end)
579 return new String(getSequence(start, end));
583 public char[] getSequence()
591 * @see jalview.datamodel.SequenceI#getSequence(int, int)
594 public char[] getSequence(int start, int end)
600 // JBPNote - left to user to pad the result here (TODO:Decide on this
602 if (start >= sequence.length)
607 if (end >= sequence.length)
609 end = sequence.length;
612 char[] reply = new char[end - start];
613 System.arraycopy(sequence, start, reply, 0, end - start);
619 public SequenceI getSubSequence(int start, int end)
625 char[] seq = getSequence(start, end);
630 int nstart = findPosition(start);
631 int nend = findPosition(end) - 1;
632 // JBPNote - this is an incomplete copy.
633 SequenceI nseq = new Sequence(this.getName(), seq, nstart, nend);
634 nseq.setDescription(description);
635 if (datasetSequence != null)
637 nseq.setDatasetSequence(datasetSequence);
641 nseq.setDatasetSequence(this);
647 * Returns the character of the aligned sequence at the given position (base
648 * zero), or space if the position is not within the sequence's bounds
653 public char getCharAt(int i)
655 if (i >= 0 && i < sequence.length)
672 public void setDescription(String desc)
674 this.description = desc;
680 * @return DOCUMENT ME!
683 public String getDescription()
685 return this.description;
691 * @see jalview.datamodel.SequenceI#findIndex(int)
694 public int findIndex(int pos)
696 // returns the alignment position for a residue
699 // Rely on end being at least as long as the length of the sequence.
700 while ((i < sequence.length) && (j <= end) && (j <= pos))
702 if (!jalview.util.Comparison.isGap(sequence[i]))
710 if ((j == end) && (j < pos))
721 public int findPosition(int i)
725 int seqlen = sequence.length;
726 while ((j < i) && (j < seqlen))
728 if (!jalview.util.Comparison.isGap(sequence[j]))
740 * Returns an int array where indices correspond to each residue in the
741 * sequence and the element value gives its position in the alignment
743 * @return int[SequenceI.getEnd()-SequenceI.getStart()+1] or null if no
744 * residues in SequenceI object
747 public int[] gapMap()
749 String seq = jalview.analysis.AlignSeq.extractGaps(
750 jalview.util.Comparison.GapChars, new String(sequence));
751 int[] map = new int[seq.length()];
755 while (j < sequence.length)
757 if (!jalview.util.Comparison.isGap(sequence[j]))
769 public int[] findPositionMap()
771 int map[] = new int[sequence.length];
774 int seqlen = sequence.length;
778 if (!jalview.util.Comparison.isGap(sequence[j]))
789 public List<int[]> getInsertions()
791 ArrayList<int[]> map = new ArrayList<int[]>();
792 int lastj = -1, j = 0;
794 int seqlen = sequence.length;
797 if (jalview.util.Comparison.isGap(sequence[j]))
808 map.add(new int[] { lastj, j - 1 });
816 map.add(new int[] { lastj, j - 1 });
823 public BitSet getInsertionsAsBits()
825 BitSet map = new BitSet();
826 int lastj = -1, j = 0;
828 int seqlen = sequence.length;
831 if (jalview.util.Comparison.isGap(sequence[j]))
857 public void deleteChars(int i, int j)
859 int newstart = start, newend = end;
860 if (i >= sequence.length || i < 0)
865 char[] tmp = StringUtils.deleteChars(sequence, i, j);
866 boolean createNewDs = false;
867 // TODO: take a (second look) at the dataset creation validation method for
868 // the very large sequence case
869 int eindex = -1, sindex = -1;
870 boolean ecalc = false, scalc = false;
871 for (int s = i; s < j; s++)
873 if (jalview.schemes.ResidueProperties.aaIndex[sequence[s]] != 23)
883 sindex = findIndex(start) - 1;
888 // delete characters including start of sequence
889 newstart = findPosition(j);
890 break; // don't need to search for any more residue characters.
894 // delete characters after start.
897 eindex = findIndex(end) - 1;
902 // delete characters at end of sequence
903 newend = findPosition(i - 1);
904 break; // don't need to search for any more residue characters.
909 newend--; // decrease end position by one for the deleted residue
910 // and search further
916 // deletion occured in the middle of the sequence
917 if (createNewDs && this.datasetSequence != null)
919 // construct a new sequence
920 Sequence ds = new Sequence(datasetSequence);
921 // TODO: remove any non-inheritable properties ?
922 // TODO: create a sequence mapping (since there is a relation here ?)
923 ds.deleteChars(i, j);
924 datasetSequence = ds;
932 public void insertCharAt(int i, int length, char c)
934 char[] tmp = new char[sequence.length + length];
936 if (i >= sequence.length)
938 System.arraycopy(sequence, 0, tmp, 0, sequence.length);
943 System.arraycopy(sequence, 0, tmp, 0, i);
953 if (i < sequence.length)
955 System.arraycopy(sequence, i, tmp, index, sequence.length - i);
962 public void insertCharAt(int i, char c)
964 insertCharAt(i, 1, c);
968 public String getVamsasId()
974 public void setVamsasId(String id)
980 public void setDBRefs(DBRefEntry[] dbref)
982 if (dbrefs == null && datasetSequence != null
983 && this != datasetSequence)
985 datasetSequence.setDBRefs(dbref);
991 DBRefUtils.ensurePrimaries(this);
996 public DBRefEntry[] getDBRefs()
998 if (dbrefs == null && datasetSequence != null
999 && this != datasetSequence)
1001 return datasetSequence.getDBRefs();
1007 public void addDBRef(DBRefEntry entry)
1009 if (datasetSequence != null)
1011 datasetSequence.addDBRef(entry);
1017 dbrefs = new DBRefEntry[0];
1020 for (DBRefEntryI dbr : dbrefs)
1022 if (dbr.updateFrom(entry))
1025 * found a dbref that either matched, or could be
1026 * updated from, the new entry - no need to add it
1033 * extend the array to make room for one more
1035 // TODO use an ArrayList instead
1036 int j = dbrefs.length;
1037 DBRefEntry[] temp = new DBRefEntry[j + 1];
1038 System.arraycopy(dbrefs, 0, temp, 0, j);
1039 temp[temp.length - 1] = entry;
1043 DBRefUtils.ensurePrimaries(this);
1047 public void setDatasetSequence(SequenceI seq)
1051 throw new IllegalArgumentException(
1052 "Implementation Error: self reference passed to SequenceI.setDatasetSequence");
1054 if (seq != null && seq.getDatasetSequence() != null)
1056 throw new IllegalArgumentException(
1057 "Implementation error: cascading dataset sequences are not allowed.");
1059 datasetSequence = seq;
1063 public SequenceI getDatasetSequence()
1065 return datasetSequence;
1069 public AlignmentAnnotation[] getAnnotation()
1071 return annotation == null ? null : annotation
1072 .toArray(new AlignmentAnnotation[annotation.size()]);
1076 public boolean hasAnnotation(AlignmentAnnotation ann)
1078 return annotation == null ? false : annotation.contains(ann);
1082 public void addAlignmentAnnotation(AlignmentAnnotation annotation)
1084 if (this.annotation == null)
1086 this.annotation = new Vector<AlignmentAnnotation>();
1088 if (!this.annotation.contains(annotation))
1090 this.annotation.addElement(annotation);
1092 annotation.setSequenceRef(this);
1096 public void removeAlignmentAnnotation(AlignmentAnnotation annotation)
1098 if (this.annotation != null)
1100 this.annotation.removeElement(annotation);
1101 if (this.annotation.size() == 0)
1103 this.annotation = null;
1109 * test if this is a valid candidate for another sequence's dataset sequence.
1112 private boolean isValidDatasetSequence()
1114 if (datasetSequence != null)
1118 for (int i = 0; i < sequence.length; i++)
1120 if (jalview.util.Comparison.isGap(sequence[i]))
1129 public SequenceI deriveSequence()
1131 Sequence seq = null;
1132 if (datasetSequence == null)
1134 if (isValidDatasetSequence())
1136 // Use this as dataset sequence
1137 seq = new Sequence(getName(), "", 1, -1);
1138 seq.setDatasetSequence(this);
1139 seq.initSeqFrom(this, getAnnotation());
1144 // Create a new, valid dataset sequence
1145 createDatasetSequence();
1148 return new Sequence(this);
1151 private boolean _isNa;
1153 private long _seqhash = 0;
1156 * Answers false if the sequence is more than 85% nucleotide (ACGTU), else
1160 public boolean isProtein()
1162 if (datasetSequence != null)
1164 return datasetSequence.isProtein();
1166 if (_seqhash != sequence.hashCode())
1168 _seqhash = sequence.hashCode();
1169 _isNa = Comparison.isNucleotide(this);
1177 * @see jalview.datamodel.SequenceI#createDatasetSequence()
1180 public SequenceI createDatasetSequence()
1182 if (datasetSequence == null)
1184 Sequence dsseq = new Sequence(getName(), AlignSeq.extractGaps(
1185 jalview.util.Comparison.GapChars, getSequenceAsString()),
1186 getStart(), getEnd());
1188 datasetSequence = dsseq;
1190 dsseq.setDescription(description);
1191 // move features and database references onto dataset sequence
1192 dsseq.sequenceFeatures = sequenceFeatures;
1193 sequenceFeatures = null;
1194 dsseq.dbrefs = dbrefs;
1196 // TODO: search and replace any references to this sequence with
1197 // references to the dataset sequence in Mappings on dbref
1198 dsseq.pdbIds = pdbIds;
1200 datasetSequence.updatePDBIds();
1201 if (annotation != null)
1203 // annotation is cloned rather than moved, to preserve what's currently
1205 for (AlignmentAnnotation aa : annotation)
1207 AlignmentAnnotation _aa = new AlignmentAnnotation(aa);
1208 _aa.sequenceRef = datasetSequence;
1209 _aa.adjustForAlignment(); // uses annotation's own record of
1210 // sequence-column mapping
1211 datasetSequence.addAlignmentAnnotation(_aa);
1215 return datasetSequence;
1222 * jalview.datamodel.SequenceI#setAlignmentAnnotation(AlignmmentAnnotation[]
1226 public void setAlignmentAnnotation(AlignmentAnnotation[] annotations)
1228 if (annotation != null)
1230 annotation.removeAllElements();
1232 if (annotations != null)
1234 for (int i = 0; i < annotations.length; i++)
1236 if (annotations[i] != null)
1238 addAlignmentAnnotation(annotations[i]);
1245 public AlignmentAnnotation[] getAnnotation(String label)
1247 if (annotation == null || annotation.size() == 0)
1252 Vector subset = new Vector();
1253 Enumeration e = annotation.elements();
1254 while (e.hasMoreElements())
1256 AlignmentAnnotation ann = (AlignmentAnnotation) e.nextElement();
1257 if (ann.label != null && ann.label.equals(label))
1259 subset.addElement(ann);
1262 if (subset.size() == 0)
1266 AlignmentAnnotation[] anns = new AlignmentAnnotation[subset.size()];
1268 e = subset.elements();
1269 while (e.hasMoreElements())
1271 anns[i++] = (AlignmentAnnotation) e.nextElement();
1273 subset.removeAllElements();
1278 public boolean updatePDBIds()
1280 if (datasetSequence != null)
1282 // TODO: could merge DBRefs
1283 return datasetSequence.updatePDBIds();
1285 if (dbrefs == null || dbrefs.length == 0)
1289 boolean added = false;
1290 for (DBRefEntry dbr : dbrefs)
1292 if (DBRefSource.PDB.equals(dbr.getSource()))
1295 * 'Add' any PDB dbrefs as a PDBEntry - add is only performed if the
1296 * PDB id is not already present in a 'matching' PDBEntry
1297 * Constructor parses out a chain code if appended to the accession id
1298 * (a fudge used to 'store' the chain code in the DBRef)
1300 PDBEntry pdbe = new PDBEntry(dbr);
1301 added |= addPDBId(pdbe);
1308 public void transferAnnotation(SequenceI entry, Mapping mp)
1310 if (datasetSequence != null)
1312 datasetSequence.transferAnnotation(entry, mp);
1315 if (entry.getDatasetSequence() != null)
1317 transferAnnotation(entry.getDatasetSequence(), mp);
1320 // transfer any new features from entry onto sequence
1321 if (entry.getSequenceFeatures() != null)
1324 SequenceFeature[] sfs = entry.getSequenceFeatures();
1325 for (int si = 0; si < sfs.length; si++)
1327 SequenceFeature sf[] = (mp != null) ? mp.locateFeature(sfs[si])
1328 : new SequenceFeature[] { new SequenceFeature(sfs[si]) };
1329 if (sf != null && sf.length > 0)
1331 for (int sfi = 0; sfi < sf.length; sfi++)
1333 addSequenceFeature(sf[sfi]);
1339 // transfer PDB entries
1340 if (entry.getAllPDBEntries() != null)
1342 Enumeration e = entry.getAllPDBEntries().elements();
1343 while (e.hasMoreElements())
1345 PDBEntry pdb = (PDBEntry) e.nextElement();
1349 // transfer database references
1350 DBRefEntry[] entryRefs = entry.getDBRefs();
1351 if (entryRefs != null)
1353 for (int r = 0; r < entryRefs.length; r++)
1355 DBRefEntry newref = new DBRefEntry(entryRefs[r]);
1356 if (newref.getMap() != null && mp != null)
1358 // remap ref using our local mapping
1360 // we also assume all version string setting is done by dbSourceProxy
1362 * if (!newref.getSource().equalsIgnoreCase(dbSource)) {
1363 * newref.setSource(dbSource); }
1371 * @return The index (zero-based) on this sequence in the MSA. It returns
1372 * {@code -1} if this information is not available.
1375 public int getIndex()
1381 * Defines the position of this sequence in the MSA. Use the value {@code -1}
1382 * if this information is undefined.
1385 * position for this sequence. This value is zero-based (zero for
1386 * this first sequence)
1389 public void setIndex(int value)
1395 public void setRNA(RNA r)
1407 public List<AlignmentAnnotation> getAlignmentAnnotations(String calcId,
1410 List<AlignmentAnnotation> result = new ArrayList<AlignmentAnnotation>();
1411 if (this.annotation != null)
1413 for (AlignmentAnnotation ann : annotation)
1415 if (ann.calcId != null && ann.calcId.equals(calcId)
1416 && ann.label != null && ann.label.equals(label))
1426 public String toString()
1428 return getDisplayId(false);
1432 public PDBEntry getPDBEntry(String pdbIdStr)
1434 if (getDatasetSequence() != null)
1436 return getDatasetSequence().getPDBEntry(pdbIdStr);
1442 List<PDBEntry> entries = getAllPDBEntries();
1443 for (PDBEntry entry : entries)
1445 if (entry.getId().equalsIgnoreCase(pdbIdStr))
1454 public List<DBRefEntry> getPrimaryDBRefs()
1456 if (datasetSequence != null)
1458 return datasetSequence.getPrimaryDBRefs();
1460 if (dbrefs == null || dbrefs.length == 0)
1462 return Collections.emptyList();
1464 synchronized (dbrefs)
1466 List<DBRefEntry> primaries = new ArrayList<DBRefEntry>();
1467 DBRefEntry[] tmp = new DBRefEntry[1];
1468 for (DBRefEntry ref : dbrefs)
1470 if (!ref.isPrimaryCandidate())
1476 MapList mp = ref.getMap().getMap();
1477 if (mp.getFromLowest() > start || mp.getFromHighest() < end)
1479 // map only involves a subsequence, so cannot be primary
1483 // whilst it looks like it is a primary ref, we also sanity check type
1484 if (DBRefUtils.getCanonicalName(DBRefSource.PDB).equals(
1485 DBRefUtils.getCanonicalName(ref.getSource())))
1487 // PDB dbrefs imply there should be a PDBEntry associated
1488 // TODO: tighten PDB dbrefs
1489 // formally imply Jalview has actually downloaded and
1490 // parsed the pdb file. That means there should be a cached file
1491 // handle on the PDBEntry, and a real mapping between sequence and
1492 // extracted sequence from PDB file
1493 PDBEntry pdbentry = getPDBEntry(ref.getAccessionId());
1494 if (pdbentry != null && pdbentry.getFile() != null)
1500 // check standard protein or dna sources
1502 DBRefEntry[] res = DBRefUtils.selectDbRefs(!isProtein(), tmp);
1503 if (res != null && res[0] == tmp[0])