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
83 * array of sequence features - may not be null for a valid sequence object
85 public SequenceFeature[] sequenceFeatures;
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;
130 com.stevesoft.pat.Regex limitrx = new com.stevesoft.pat.Regex(
131 "[/][0-9]{1,}[-][0-9]{1,}$");
133 com.stevesoft.pat.Regex endrx = new com.stevesoft.pat.Regex("[0-9]{1,}$");
140 "POSSIBLE IMPLEMENTATION ERROR: null sequence name passed to constructor.");
143 // Does sequence have the /start-end signature?
144 if (limitrx.search(name))
146 name = limitrx.left();
147 endrx.search(limitrx.stringMatched());
148 setStart(Integer.parseInt(limitrx.stringMatched().substring(1,
149 endrx.matchedFrom() - 1)));
150 setEnd(Integer.parseInt(endrx.stringMatched()));
154 void checkValidRange()
157 // http://issues.jalview.org/browse/JAL-774?focusedCommentId=11239&page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel#comment-11239
160 for (int j = 0; j < sequence.length; j++)
162 if (!jalview.util.Comparison.isGap(sequence[j]))
181 * Creates a new Sequence object.
188 public Sequence(String name, String sequence)
190 this(name, sequence, 1, -1);
194 * Creates a new Sequence object with new AlignmentAnnotations but inherits
195 * any existing dataset sequence reference. If non exists, everything is
199 * if seq is a dataset sequence, behaves like a plain old copy
202 public Sequence(SequenceI seq)
204 this(seq, seq.getAnnotation());
208 * Create a new sequence object with new features, DBRefEntries, and PDBIds
209 * but inherits any existing dataset sequence reference, and duplicate of any
210 * annotation that is present in the given annotation array.
213 * the sequence to be copied
214 * @param alAnnotation
215 * an array of annotation including some associated with seq
217 public Sequence(SequenceI seq, AlignmentAnnotation[] alAnnotation)
219 initSeqFrom(seq, alAnnotation);
224 * does the heavy lifting when cloning a dataset sequence, or coping data from
225 * dataset to a new derived sequence.
228 * - source of attributes.
229 * @param alAnnotation
230 * - alignment annotation present on seq that should be copied onto
233 protected void initSeqFrom(SequenceI seq,
234 AlignmentAnnotation[] alAnnotation)
237 char[] oseq = seq.getSequence();
238 initSeqAndName(seq.getName(), Arrays.copyOf(oseq, oseq.length),
239 seq.getStart(), seq.getEnd());
241 description = seq.getDescription();
242 if (seq != datasetSequence)
244 setDatasetSequence(seq.getDatasetSequence());
246 if (datasetSequence == null && seq.getDBRefs() != null)
248 // only copy DBRefs and seqfeatures if we really are a dataset sequence
249 DBRefEntry[] dbr = seq.getDBRefs();
250 for (int i = 0; i < dbr.length; i++)
252 addDBRef(new DBRefEntry(dbr[i]));
254 if (seq.getSequenceFeatures() != null)
256 SequenceFeature[] sf = seq.getSequenceFeatures();
257 for (int i = 0; i < sf.length; i++)
259 addSequenceFeature(new SequenceFeature(sf[i]));
263 if (seq.getAnnotation() != null)
265 AlignmentAnnotation[] sqann = seq.getAnnotation();
266 for (int i = 0; i < sqann.length; i++)
268 if (sqann[i] == null)
272 boolean found = (alAnnotation == null);
275 for (int apos = 0; !found && apos < alAnnotation.length; apos++)
277 found = (alAnnotation[apos] == sqann[i]);
282 // only copy the given annotation
283 AlignmentAnnotation newann = new AlignmentAnnotation(sqann[i]);
284 addAlignmentAnnotation(newann);
288 if (seq.getAllPDBEntries() != null)
290 Vector<PDBEntry> ids = seq.getAllPDBEntries();
291 for (PDBEntry pdb : ids)
293 this.addPDBId(new PDBEntry(pdb));
299 public void setSequenceFeatures(SequenceFeature[] features)
301 if (datasetSequence == null)
303 sequenceFeatures = features;
307 if (datasetSequence.getSequenceFeatures() != features
308 && datasetSequence.getSequenceFeatures() != null
309 && datasetSequence.getSequenceFeatures().length > 0)
312 "Warning: JAL-2046 side effect ? Possible implementation error: overwriting dataset sequence features by setting sequence features on alignment")
315 datasetSequence.setSequenceFeatures(features);
320 public synchronized boolean addSequenceFeature(SequenceFeature sf)
322 if (sequenceFeatures == null && datasetSequence != null)
324 return datasetSequence.addSequenceFeature(sf);
326 if (sequenceFeatures == null)
328 sequenceFeatures = new SequenceFeature[0];
331 for (int i = 0; i < sequenceFeatures.length; i++)
333 if (sequenceFeatures[i].equals(sf))
339 SequenceFeature[] temp = new SequenceFeature[sequenceFeatures.length
341 System.arraycopy(sequenceFeatures, 0, temp, 0, sequenceFeatures.length);
342 temp[sequenceFeatures.length] = sf;
344 sequenceFeatures = temp;
349 public void deleteFeature(SequenceFeature sf)
351 if (sequenceFeatures == null)
353 if (datasetSequence != null)
355 datasetSequence.deleteFeature(sf);
361 for (index = 0; index < sequenceFeatures.length; index++)
363 if (sequenceFeatures[index].equals(sf))
369 if (index == sequenceFeatures.length)
374 int sfLength = sequenceFeatures.length;
377 sequenceFeatures = null;
381 SequenceFeature[] temp = new SequenceFeature[sfLength - 1];
382 System.arraycopy(sequenceFeatures, 0, temp, 0, index);
384 if (index < sfLength)
386 System.arraycopy(sequenceFeatures, index + 1, temp, index,
387 sequenceFeatures.length - index - 1);
390 sequenceFeatures = temp;
395 * Returns the sequence features (if any), looking first on the sequence, then
396 * on its dataset sequence, and so on until a non-null value is found (or
397 * none). This supports retrieval of sequence features stored on the sequence
398 * (as in the applet) or on the dataset sequence (as in the Desktop version).
403 public SequenceFeature[] getSequenceFeatures()
405 SequenceFeature[] features = sequenceFeatures;
407 SequenceI seq = this;
408 int count = 0; // failsafe against loop in sequence.datasetsequence...
409 while (features == null && seq.getDatasetSequence() != null
412 seq = seq.getDatasetSequence();
413 features = ((Sequence) seq).sequenceFeatures;
419 public boolean addPDBId(PDBEntry entry)
423 pdbIds = new Vector<PDBEntry>();
428 for (PDBEntry pdbe : pdbIds)
430 if (pdbe.updateFrom(entry))
435 pdbIds.addElement(entry);
446 public void setPDBId(Vector<PDBEntry> id)
454 * @return DOCUMENT ME!
457 public Vector<PDBEntry> getAllPDBEntries()
459 return pdbIds == null ? new Vector<PDBEntry>() : pdbIds;
465 * @return DOCUMENT ME!
468 public String getDisplayId(boolean jvsuffix)
470 StringBuffer result = new StringBuffer(name);
473 result.append("/" + start + "-" + end);
476 return result.toString();
486 public void setName(String name)
495 * @return DOCUMENT ME!
498 public String getName()
510 public void setStart(int start)
518 * @return DOCUMENT ME!
521 public int getStart()
533 public void setEnd(int end)
541 * @return DOCUMENT ME!
552 * @return DOCUMENT ME!
555 public int getLength()
557 return this.sequence.length;
567 public void setSequence(String seq)
569 this.sequence = seq.toCharArray();
574 public String getSequenceAsString()
576 return new String(sequence);
580 public String getSequenceAsString(int start, int end)
582 return new String(getSequence(start, end));
586 public char[] getSequence()
594 * @see jalview.datamodel.SequenceI#getSequence(int, int)
597 public char[] getSequence(int start, int end)
603 // JBPNote - left to user to pad the result here (TODO:Decide on this
605 if (start >= sequence.length)
610 if (end >= sequence.length)
612 end = sequence.length;
615 char[] reply = new char[end - start];
616 System.arraycopy(sequence, start, reply, 0, end - start);
622 public SequenceI getSubSequence(int start, int end)
628 char[] seq = getSequence(start, end);
633 int nstart = findPosition(start);
634 int nend = findPosition(end) - 1;
635 // JBPNote - this is an incomplete copy.
636 SequenceI nseq = new Sequence(this.getName(), seq, nstart, nend);
637 nseq.setDescription(description);
638 if (datasetSequence != null)
640 nseq.setDatasetSequence(datasetSequence);
644 nseq.setDatasetSequence(this);
650 * Returns the character of the aligned sequence at the given position (base
651 * zero), or space if the position is not within the sequence's bounds
656 public char getCharAt(int i)
658 if (i >= 0 && i < sequence.length)
675 public void setDescription(String desc)
677 this.description = desc;
683 * @return DOCUMENT ME!
686 public String getDescription()
688 return this.description;
694 * @see jalview.datamodel.SequenceI#findIndex(int)
697 public int findIndex(int pos)
699 // returns the alignment position for a residue
702 // Rely on end being at least as long as the length of the sequence.
703 while ((i < sequence.length) && (j <= end) && (j <= pos))
705 if (!jalview.util.Comparison.isGap(sequence[i]))
713 if ((j == end) && (j < pos))
724 public int findPosition(int i)
728 int seqlen = sequence.length;
729 while ((j < i) && (j < seqlen))
731 if (!jalview.util.Comparison.isGap(sequence[j]))
743 * Returns an int array where indices correspond to each residue in the
744 * sequence and the element value gives its position in the alignment
746 * @return int[SequenceI.getEnd()-SequenceI.getStart()+1] or null if no
747 * residues in SequenceI object
750 public int[] gapMap()
752 String seq = jalview.analysis.AlignSeq.extractGaps(
753 jalview.util.Comparison.GapChars, new String(sequence));
754 int[] map = new int[seq.length()];
758 while (j < sequence.length)
760 if (!jalview.util.Comparison.isGap(sequence[j]))
772 public int[] findPositionMap()
774 int map[] = new int[sequence.length];
777 int seqlen = sequence.length;
781 if (!jalview.util.Comparison.isGap(sequence[j]))
792 public List<int[]> getInsertions()
794 ArrayList<int[]> map = new ArrayList<int[]>();
795 int lastj = -1, j = 0;
797 int seqlen = sequence.length;
800 if (jalview.util.Comparison.isGap(sequence[j]))
811 map.add(new int[] { lastj, j - 1 });
819 map.add(new int[] { lastj, j - 1 });
826 public BitSet getInsertionsAsBits()
828 BitSet map = new BitSet();
829 int lastj = -1, j = 0;
831 int seqlen = sequence.length;
834 if (jalview.util.Comparison.isGap(sequence[j]))
860 public void deleteChars(int i, int j)
862 int newstart = start, newend = end;
863 if (i >= sequence.length || i < 0)
868 char[] tmp = StringUtils.deleteChars(sequence, i, j);
869 boolean createNewDs = false;
870 // TODO: take a (second look) at the dataset creation validation method for
871 // the very large sequence case
872 int eindex = -1, sindex = -1;
873 boolean ecalc = false, scalc = false;
874 for (int s = i; s < j; s++)
876 if (jalview.schemes.ResidueProperties.aaIndex[sequence[s]] != 23)
886 sindex = findIndex(start) - 1;
891 // delete characters including start of sequence
892 newstart = findPosition(j);
893 break; // don't need to search for any more residue characters.
897 // delete characters after start.
900 eindex = findIndex(end) - 1;
905 // delete characters at end of sequence
906 newend = findPosition(i - 1);
907 break; // don't need to search for any more residue characters.
912 newend--; // decrease end position by one for the deleted residue
913 // and search further
919 // deletion occured in the middle of the sequence
920 if (createNewDs && this.datasetSequence != null)
922 // construct a new sequence
923 Sequence ds = new Sequence(datasetSequence);
924 // TODO: remove any non-inheritable properties ?
925 // TODO: create a sequence mapping (since there is a relation here ?)
926 ds.deleteChars(i, j);
927 datasetSequence = ds;
935 public void insertCharAt(int i, int length, char c)
937 char[] tmp = new char[sequence.length + length];
939 if (i >= sequence.length)
941 System.arraycopy(sequence, 0, tmp, 0, sequence.length);
946 System.arraycopy(sequence, 0, tmp, 0, i);
956 if (i < sequence.length)
958 System.arraycopy(sequence, i, tmp, index, sequence.length - i);
965 public void insertCharAt(int i, char c)
967 insertCharAt(i, 1, c);
971 public String getVamsasId()
977 public void setVamsasId(String id)
983 public void setDBRefs(DBRefEntry[] dbref)
985 if (dbrefs == null && datasetSequence != null
986 && this != datasetSequence)
988 datasetSequence.setDBRefs(dbref);
994 DBRefUtils.ensurePrimaries(this);
999 public DBRefEntry[] getDBRefs()
1001 if (dbrefs == null && datasetSequence != null
1002 && this != datasetSequence)
1004 return datasetSequence.getDBRefs();
1010 public void addDBRef(DBRefEntry entry)
1012 if (datasetSequence != null)
1014 datasetSequence.addDBRef(entry);
1020 dbrefs = new DBRefEntry[0];
1023 for (DBRefEntryI dbr : dbrefs)
1025 if (dbr.updateFrom(entry))
1028 * found a dbref that either matched, or could be
1029 * updated from, the new entry - no need to add it
1036 * extend the array to make room for one more
1038 // TODO use an ArrayList instead
1039 int j = dbrefs.length;
1040 DBRefEntry[] temp = new DBRefEntry[j + 1];
1041 System.arraycopy(dbrefs, 0, temp, 0, j);
1042 temp[temp.length - 1] = entry;
1046 DBRefUtils.ensurePrimaries(this);
1050 public void setDatasetSequence(SequenceI seq)
1054 throw new IllegalArgumentException(
1055 "Implementation Error: self reference passed to SequenceI.setDatasetSequence");
1057 if (seq != null && seq.getDatasetSequence() != null)
1059 throw new IllegalArgumentException(
1060 "Implementation error: cascading dataset sequences are not allowed.");
1062 datasetSequence = seq;
1066 public SequenceI getDatasetSequence()
1068 return datasetSequence;
1072 public AlignmentAnnotation[] getAnnotation()
1074 return annotation == null ? null
1076 .toArray(new AlignmentAnnotation[annotation.size()]);
1080 public boolean hasAnnotation(AlignmentAnnotation ann)
1082 return annotation == null ? false : annotation.contains(ann);
1086 public void addAlignmentAnnotation(AlignmentAnnotation annotation)
1088 if (this.annotation == null)
1090 this.annotation = new Vector<AlignmentAnnotation>();
1092 if (!this.annotation.contains(annotation))
1094 this.annotation.addElement(annotation);
1096 annotation.setSequenceRef(this);
1100 public void removeAlignmentAnnotation(AlignmentAnnotation annotation)
1102 if (this.annotation != null)
1104 this.annotation.removeElement(annotation);
1105 if (this.annotation.size() == 0)
1107 this.annotation = null;
1113 * test if this is a valid candidate for another sequence's dataset sequence.
1116 private boolean isValidDatasetSequence()
1118 if (datasetSequence != null)
1122 for (int i = 0; i < sequence.length; i++)
1124 if (jalview.util.Comparison.isGap(sequence[i]))
1133 public SequenceI deriveSequence()
1135 Sequence seq = null;
1136 if (datasetSequence == null)
1138 if (isValidDatasetSequence())
1140 // Use this as dataset sequence
1141 seq = new Sequence(getName(), "", 1, -1);
1142 seq.setDatasetSequence(this);
1143 seq.initSeqFrom(this, getAnnotation());
1148 // Create a new, valid dataset sequence
1149 createDatasetSequence();
1152 return new Sequence(this);
1155 private boolean _isNa;
1157 private long _seqhash = 0;
1160 * Answers false if the sequence is more than 85% nucleotide (ACGTU), else
1164 public boolean isProtein()
1166 if (datasetSequence != null)
1168 return datasetSequence.isProtein();
1170 if (_seqhash != sequence.hashCode())
1172 _seqhash = sequence.hashCode();
1173 _isNa = Comparison.isNucleotide(this);
1181 * @see jalview.datamodel.SequenceI#createDatasetSequence()
1184 public SequenceI createDatasetSequence()
1186 if (datasetSequence == null)
1188 Sequence dsseq = new Sequence(getName(),
1189 AlignSeq.extractGaps(jalview.util.Comparison.GapChars,
1190 getSequenceAsString()),
1191 getStart(), getEnd());
1193 datasetSequence = dsseq;
1195 dsseq.setDescription(description);
1196 // move features and database references onto dataset sequence
1197 dsseq.sequenceFeatures = sequenceFeatures;
1198 sequenceFeatures = null;
1199 dsseq.dbrefs = dbrefs;
1201 // TODO: search and replace any references to this sequence with
1202 // references to the dataset sequence in Mappings on dbref
1203 dsseq.pdbIds = pdbIds;
1205 datasetSequence.updatePDBIds();
1206 if (annotation != null)
1208 // annotation is cloned rather than moved, to preserve what's currently
1210 for (AlignmentAnnotation aa : annotation)
1212 AlignmentAnnotation _aa = new AlignmentAnnotation(aa);
1213 _aa.sequenceRef = datasetSequence;
1214 _aa.adjustForAlignment(); // uses annotation's own record of
1215 // sequence-column mapping
1216 datasetSequence.addAlignmentAnnotation(_aa);
1220 return datasetSequence;
1227 * jalview.datamodel.SequenceI#setAlignmentAnnotation(AlignmmentAnnotation[]
1231 public void setAlignmentAnnotation(AlignmentAnnotation[] annotations)
1233 if (annotation != null)
1235 annotation.removeAllElements();
1237 if (annotations != null)
1239 for (int i = 0; i < annotations.length; i++)
1241 if (annotations[i] != null)
1243 addAlignmentAnnotation(annotations[i]);
1250 public AlignmentAnnotation[] getAnnotation(String label)
1252 if (annotation == null || annotation.size() == 0)
1257 Vector subset = new Vector();
1258 Enumeration e = annotation.elements();
1259 while (e.hasMoreElements())
1261 AlignmentAnnotation ann = (AlignmentAnnotation) e.nextElement();
1262 if (ann.label != null && ann.label.equals(label))
1264 subset.addElement(ann);
1267 if (subset.size() == 0)
1271 AlignmentAnnotation[] anns = new AlignmentAnnotation[subset.size()];
1273 e = subset.elements();
1274 while (e.hasMoreElements())
1276 anns[i++] = (AlignmentAnnotation) e.nextElement();
1278 subset.removeAllElements();
1283 public boolean updatePDBIds()
1285 if (datasetSequence != null)
1287 // TODO: could merge DBRefs
1288 return datasetSequence.updatePDBIds();
1290 if (dbrefs == null || dbrefs.length == 0)
1294 boolean added = false;
1295 for (DBRefEntry dbr : dbrefs)
1297 if (DBRefSource.PDB.equals(dbr.getSource()))
1300 * 'Add' any PDB dbrefs as a PDBEntry - add is only performed if the
1301 * PDB id is not already present in a 'matching' PDBEntry
1302 * Constructor parses out a chain code if appended to the accession id
1303 * (a fudge used to 'store' the chain code in the DBRef)
1305 PDBEntry pdbe = new PDBEntry(dbr);
1306 added |= addPDBId(pdbe);
1313 public void transferAnnotation(SequenceI entry, Mapping mp)
1315 if (datasetSequence != null)
1317 datasetSequence.transferAnnotation(entry, mp);
1320 if (entry.getDatasetSequence() != null)
1322 transferAnnotation(entry.getDatasetSequence(), mp);
1325 // transfer any new features from entry onto sequence
1326 if (entry.getSequenceFeatures() != null)
1329 SequenceFeature[] sfs = entry.getSequenceFeatures();
1330 for (int si = 0; si < sfs.length; si++)
1332 SequenceFeature sf[] = (mp != null) ? mp.locateFeature(sfs[si])
1333 : new SequenceFeature[]
1334 { new SequenceFeature(sfs[si]) };
1335 if (sf != null && sf.length > 0)
1337 for (int sfi = 0; sfi < sf.length; sfi++)
1339 addSequenceFeature(sf[sfi]);
1345 // transfer PDB entries
1346 if (entry.getAllPDBEntries() != null)
1348 Enumeration e = entry.getAllPDBEntries().elements();
1349 while (e.hasMoreElements())
1351 PDBEntry pdb = (PDBEntry) e.nextElement();
1355 // transfer database references
1356 DBRefEntry[] entryRefs = entry.getDBRefs();
1357 if (entryRefs != null)
1359 for (int r = 0; r < entryRefs.length; r++)
1361 DBRefEntry newref = new DBRefEntry(entryRefs[r]);
1362 if (newref.getMap() != null && mp != null)
1364 // remap ref using our local mapping
1366 // we also assume all version string setting is done by dbSourceProxy
1368 * if (!newref.getSource().equalsIgnoreCase(dbSource)) {
1369 * newref.setSource(dbSource); }
1377 * @return The index (zero-based) on this sequence in the MSA. It returns
1378 * {@code -1} if this information is not available.
1381 public int getIndex()
1387 * Defines the position of this sequence in the MSA. Use the value {@code -1}
1388 * if this information is undefined.
1391 * position for this sequence. This value is zero-based (zero for
1392 * this first sequence)
1395 public void setIndex(int value)
1401 public void setRNA(RNA r)
1413 public List<AlignmentAnnotation> getAlignmentAnnotations(String calcId,
1416 List<AlignmentAnnotation> result = new ArrayList<AlignmentAnnotation>();
1417 if (this.annotation != null)
1419 for (AlignmentAnnotation ann : annotation)
1421 if (ann.calcId != null && ann.calcId.equals(calcId)
1422 && ann.label != null && ann.label.equals(label))
1432 public String toString()
1434 return getDisplayId(false);
1438 public PDBEntry getPDBEntry(String pdbIdStr)
1440 if (getDatasetSequence() != null)
1442 return getDatasetSequence().getPDBEntry(pdbIdStr);
1448 List<PDBEntry> entries = getAllPDBEntries();
1449 for (PDBEntry entry : entries)
1451 if (entry.getId().equalsIgnoreCase(pdbIdStr))
1460 public List<DBRefEntry> getPrimaryDBRefs()
1462 if (datasetSequence != null)
1464 return datasetSequence.getPrimaryDBRefs();
1466 if (dbrefs == null || dbrefs.length == 0)
1468 return Collections.emptyList();
1470 synchronized (dbrefs)
1472 List<DBRefEntry> primaries = new ArrayList<DBRefEntry>();
1473 DBRefEntry[] tmp = new DBRefEntry[1];
1474 for (DBRefEntry ref : dbrefs)
1476 if (!ref.isPrimaryCandidate())
1482 MapList mp = ref.getMap().getMap();
1483 if (mp.getFromLowest() > start || mp.getFromHighest() < end)
1485 // map only involves a subsequence, so cannot be primary
1489 // whilst it looks like it is a primary ref, we also sanity check type
1490 if (DBRefUtils.getCanonicalName(DBRefSource.PDB)
1491 .equals(DBRefUtils.getCanonicalName(ref.getSource())))
1493 // PDB dbrefs imply there should be a PDBEntry associated
1494 // TODO: tighten PDB dbrefs
1495 // formally imply Jalview has actually downloaded and
1496 // parsed the pdb file. That means there should be a cached file
1497 // handle on the PDBEntry, and a real mapping between sequence and
1498 // extracted sequence from PDB file
1499 PDBEntry pdbentry = getPDBEntry(ref.getAccessionId());
1500 if (pdbentry != null && pdbentry.getFile() != null)
1506 // check standard protein or dna sources
1508 DBRefEntry[] res = DBRefUtils.selectDbRefs(!isProtein(), tmp);
1509 if (res != null && res[0] == tmp[0])