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.Collections;
33 import java.util.Enumeration;
34 import java.util.List;
35 import java.util.Vector;
37 import fr.orsay.lri.varna.models.rna.RNA;
41 * Implements the SequenceI interface for a char[] based sequence object.
46 public class Sequence extends ASequence implements SequenceI
48 SequenceI datasetSequence;
52 private char[] sequence;
60 Vector<PDBEntry> pdbIds;
69 * This annotation is displayed below the alignment but the positions are tied
70 * to the residues of this sequence
72 * TODO: change to List<>
74 Vector<AlignmentAnnotation> annotation;
77 * The index of the sequence in a MSA
81 /** array of sequence features - may not be null for a valid sequence object */
82 public SequenceFeature[] sequenceFeatures;
85 * Creates a new Sequence object.
90 * string to form a possibly gapped sequence out of
92 * first position of non-gap residue in the sequence
94 * last position of ungapped residues (nearly always only used for
97 public Sequence(String name, String sequence, int start, int end)
99 initSeqAndName(name, sequence.toCharArray(), start, end);
102 public Sequence(String name, char[] sequence, int start, int end)
104 initSeqAndName(name, sequence, start, end);
108 * Stage 1 constructor - assign name, sequence, and set start and end fields.
109 * start and end are updated values from name2 if it ends with /start-end
116 protected void initSeqAndName(String name2, char[] sequence2, int start2,
120 this.sequence = sequence2;
127 com.stevesoft.pat.Regex limitrx = new com.stevesoft.pat.Regex(
128 "[/][0-9]{1,}[-][0-9]{1,}$");
130 com.stevesoft.pat.Regex endrx = new com.stevesoft.pat.Regex("[0-9]{1,}$");
137 .println("POSSIBLE IMPLEMENTATION ERROR: null sequence name passed to constructor.");
140 // Does sequence have the /start-end signature?
141 if (limitrx.search(name))
143 name = limitrx.left();
144 endrx.search(limitrx.stringMatched());
145 setStart(Integer.parseInt(limitrx.stringMatched().substring(1,
146 endrx.matchedFrom() - 1)));
147 setEnd(Integer.parseInt(endrx.stringMatched()));
151 void checkValidRange()
154 // http://issues.jalview.org/browse/JAL-774?focusedCommentId=11239&page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel#comment-11239
157 for (int j = 0; j < sequence.length; j++)
159 if (!jalview.util.Comparison.isGap(sequence[j]))
178 * Creates a new Sequence object.
185 public Sequence(String name, String sequence)
187 this(name, sequence, 1, -1);
191 * Creates a new Sequence object with new AlignmentAnnotations but inherits
192 * any existing dataset sequence reference. If non exists, everything is
196 * if seq is a dataset sequence, behaves like a plain old copy
199 public Sequence(SequenceI seq)
201 this(seq, seq.getAnnotation());
205 * Create a new sequence object with new features, DBRefEntries, and PDBIds
206 * but inherits any existing dataset sequence reference, and duplicate of any
207 * annotation that is present in the given annotation array.
210 * the sequence to be copied
211 * @param alAnnotation
212 * an array of annotation including some associated with seq
214 public Sequence(SequenceI seq, AlignmentAnnotation[] alAnnotation)
216 initSeqFrom(seq, alAnnotation);
221 * does the heavy lifting when cloning a dataset sequence, or coping data from
222 * dataset to a new derived sequence.
225 * - source of attributes.
226 * @param alAnnotation
227 * - alignment annotation present on seq that should be copied onto
230 protected void initSeqFrom(SequenceI seq,
231 AlignmentAnnotation[] alAnnotation)
234 char[] oseq = seq.getSequence();
235 initSeqAndName(seq.getName(), Arrays.copyOf(oseq, oseq.length),
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));
298 public void setSequenceFeatures(SequenceFeature[] features)
300 if (datasetSequence == null)
302 sequenceFeatures = features;
306 if (datasetSequence.getSequenceFeatures() != features
307 && datasetSequence.getSequenceFeatures() != null
308 && datasetSequence.getSequenceFeatures().length > 0)
311 "Warning: JAL-2046 side effect ? Possible implementation error: overwriting dataset sequence features by setting sequence features on alignment")
314 datasetSequence.setSequenceFeatures(features);
319 public synchronized void addSequenceFeature(SequenceFeature sf)
321 if (sequenceFeatures==null && datasetSequence != null)
323 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 + 1];
340 System.arraycopy(sequenceFeatures, 0, temp, 0, sequenceFeatures.length);
341 temp[sequenceFeatures.length] = sf;
343 sequenceFeatures = temp;
347 public void deleteFeature(SequenceFeature sf)
349 if (sequenceFeatures == null)
351 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 void deleteChars(int i, int j)
825 int newstart = start, newend = end;
826 if (i >= sequence.length || i < 0)
831 char[] tmp = StringUtils.deleteChars(sequence, i, j);
832 boolean createNewDs = false;
833 // TODO: take a (second look) at the dataset creation validation method for
834 // the very large sequence case
835 int eindex = -1, sindex = -1;
836 boolean ecalc = false, scalc = false;
837 for (int s = i; s < j; s++)
839 if (jalview.schemes.ResidueProperties.aaIndex[sequence[s]] != 23)
849 sindex = findIndex(start) - 1;
854 // delete characters including start of sequence
855 newstart = findPosition(j);
856 break; // don't need to search for any more residue characters.
860 // delete characters after start.
863 eindex = findIndex(end) - 1;
868 // delete characters at end of sequence
869 newend = findPosition(i - 1);
870 break; // don't need to search for any more residue characters.
875 newend--; // decrease end position by one for the deleted residue
876 // and search further
882 // deletion occured in the middle of the sequence
883 if (createNewDs && this.datasetSequence != null)
885 // construct a new sequence
886 Sequence ds = new Sequence(datasetSequence);
887 // TODO: remove any non-inheritable properties ?
888 // TODO: create a sequence mapping (since there is a relation here ?)
889 ds.deleteChars(i, j);
890 datasetSequence = ds;
898 public void insertCharAt(int i, int length, char c)
900 char[] tmp = new char[sequence.length + length];
902 if (i >= sequence.length)
904 System.arraycopy(sequence, 0, tmp, 0, sequence.length);
909 System.arraycopy(sequence, 0, tmp, 0, i);
919 if (i < sequence.length)
921 System.arraycopy(sequence, i, tmp, index, sequence.length - i);
928 public void insertCharAt(int i, char c)
930 insertCharAt(i, 1, c);
934 public String getVamsasId()
940 public void setVamsasId(String id)
946 public void setDBRefs(DBRefEntry[] dbref)
948 if (dbrefs == null && datasetSequence != null
949 && this != datasetSequence)
951 datasetSequence.setDBRefs(dbref);
957 DBRefUtils.ensurePrimaries(this);
962 public DBRefEntry[] getDBRefs()
964 if (dbrefs == null && datasetSequence != null
965 && this != datasetSequence)
967 return datasetSequence.getDBRefs();
973 public void addDBRef(DBRefEntry entry)
975 if (datasetSequence != null)
977 datasetSequence.addDBRef(entry);
983 dbrefs = new DBRefEntry[0];
986 for (DBRefEntryI dbr : dbrefs)
988 if (dbr.updateFrom(entry))
991 * found a dbref that either matched, or could be
992 * updated from, the new entry - no need to add it
999 * extend the array to make room for one more
1001 // TODO use an ArrayList instead
1002 int j = dbrefs.length;
1003 DBRefEntry[] temp = new DBRefEntry[j + 1];
1004 System.arraycopy(dbrefs, 0, temp, 0, j);
1005 temp[temp.length - 1] = entry;
1009 DBRefUtils.ensurePrimaries(this);
1013 public void setDatasetSequence(SequenceI seq)
1017 throw new IllegalArgumentException(
1018 "Implementation Error: self reference passed to SequenceI.setDatasetSequence");
1020 if (seq != null && seq.getDatasetSequence() != null)
1022 throw new IllegalArgumentException(
1023 "Implementation error: cascading dataset sequences are not allowed.");
1025 datasetSequence = seq;
1029 public SequenceI getDatasetSequence()
1031 return datasetSequence;
1035 public AlignmentAnnotation[] getAnnotation()
1037 return annotation == null ? null : annotation
1038 .toArray(new AlignmentAnnotation[annotation.size()]);
1042 public boolean hasAnnotation(AlignmentAnnotation ann)
1044 return annotation == null ? false : annotation.contains(ann);
1048 public void addAlignmentAnnotation(AlignmentAnnotation annotation)
1050 if (this.annotation == null)
1052 this.annotation = new Vector<AlignmentAnnotation>();
1054 if (!this.annotation.contains(annotation))
1056 this.annotation.addElement(annotation);
1058 annotation.setSequenceRef(this);
1062 public void removeAlignmentAnnotation(AlignmentAnnotation annotation)
1064 if (this.annotation != null)
1066 this.annotation.removeElement(annotation);
1067 if (this.annotation.size() == 0)
1069 this.annotation = null;
1075 * test if this is a valid candidate for another sequence's dataset sequence.
1078 private boolean isValidDatasetSequence()
1080 if (datasetSequence != null)
1084 for (int i = 0; i < sequence.length; i++)
1086 if (jalview.util.Comparison.isGap(sequence[i]))
1095 public SequenceI deriveSequence()
1098 if (datasetSequence == null)
1100 if (isValidDatasetSequence())
1102 // Use this as dataset sequence
1103 seq = new Sequence(getName(), "", 1, -1);
1104 seq.setDatasetSequence(this);
1105 seq.initSeqFrom(this, getAnnotation());
1110 // Create a new, valid dataset sequence
1111 createDatasetSequence();
1114 return new Sequence(this);
1117 private boolean _isNa;
1119 private long _seqhash = 0;
1122 * Answers false if the sequence is more than 85% nucleotide (ACGTU), else
1126 public boolean isProtein()
1128 if (datasetSequence != null)
1130 return datasetSequence.isProtein();
1132 if (_seqhash != sequence.hashCode())
1134 _seqhash = sequence.hashCode();
1135 _isNa = Comparison.isNucleotide(this);
1143 * @see jalview.datamodel.SequenceI#createDatasetSequence()
1146 public SequenceI createDatasetSequence()
1148 if (datasetSequence == null)
1150 Sequence dsseq = new Sequence(getName(), AlignSeq.extractGaps(
1151 jalview.util.Comparison.GapChars, getSequenceAsString()),
1152 getStart(), getEnd());
1154 datasetSequence = dsseq;
1156 dsseq.setDescription(description);
1157 // move features and database references onto dataset sequence
1158 dsseq.sequenceFeatures = sequenceFeatures;
1159 sequenceFeatures=null;
1160 dsseq.dbrefs = dbrefs;
1162 // TODO: search and replace any references to this sequence with
1163 // references to the dataset sequence in Mappings on dbref
1164 dsseq.pdbIds = pdbIds;
1166 datasetSequence.updatePDBIds();
1167 if (annotation != null)
1169 // annotation is cloned rather than moved, to preserve what's currently
1171 for (AlignmentAnnotation aa : annotation)
1173 AlignmentAnnotation _aa = new AlignmentAnnotation(aa);
1174 _aa.sequenceRef = datasetSequence;
1175 _aa.adjustForAlignment(); // uses annotation's own record of
1176 // sequence-column mapping
1177 datasetSequence.addAlignmentAnnotation(_aa);
1181 return datasetSequence;
1188 * jalview.datamodel.SequenceI#setAlignmentAnnotation(AlignmmentAnnotation[]
1192 public void setAlignmentAnnotation(AlignmentAnnotation[] annotations)
1194 if (annotation != null)
1196 annotation.removeAllElements();
1198 if (annotations != null)
1200 for (int i = 0; i < annotations.length; i++)
1202 if (annotations[i] != null)
1204 addAlignmentAnnotation(annotations[i]);
1211 public AlignmentAnnotation[] getAnnotation(String label)
1213 if (annotation == null || annotation.size() == 0)
1218 Vector subset = new Vector();
1219 Enumeration e = annotation.elements();
1220 while (e.hasMoreElements())
1222 AlignmentAnnotation ann = (AlignmentAnnotation) e.nextElement();
1223 if (ann.label != null && ann.label.equals(label))
1225 subset.addElement(ann);
1228 if (subset.size() == 0)
1232 AlignmentAnnotation[] anns = new AlignmentAnnotation[subset.size()];
1234 e = subset.elements();
1235 while (e.hasMoreElements())
1237 anns[i++] = (AlignmentAnnotation) e.nextElement();
1239 subset.removeAllElements();
1244 public boolean updatePDBIds()
1246 if (datasetSequence != null)
1248 // TODO: could merge DBRefs
1249 return datasetSequence.updatePDBIds();
1251 if (dbrefs == null || dbrefs.length == 0)
1255 boolean added = false;
1256 for (DBRefEntry dbr : dbrefs)
1258 if (DBRefSource.PDB.equals(dbr.getSource()))
1261 * 'Add' any PDB dbrefs as a PDBEntry - add is only performed if the
1262 * PDB id is not already present in a 'matching' PDBEntry
1263 * Constructor parses out a chain code if appended to the accession id
1264 * (a fudge used to 'store' the chain code in the DBRef)
1266 PDBEntry pdbe = new PDBEntry(dbr);
1267 added |= addPDBId(pdbe);
1274 public void transferAnnotation(SequenceI entry, Mapping mp)
1276 if (datasetSequence != null)
1278 datasetSequence.transferAnnotation(entry, mp);
1281 if (entry.getDatasetSequence() != null)
1283 transferAnnotation(entry.getDatasetSequence(), mp);
1286 // transfer any new features from entry onto sequence
1287 if (entry.getSequenceFeatures() != null)
1290 SequenceFeature[] sfs = entry.getSequenceFeatures();
1291 for (int si = 0; si < sfs.length; si++)
1293 SequenceFeature sf[] = (mp != null) ? mp.locateFeature(sfs[si])
1294 : new SequenceFeature[] { new SequenceFeature(sfs[si]) };
1295 if (sf != null && sf.length > 0)
1297 for (int sfi = 0; sfi < sf.length; sfi++)
1299 addSequenceFeature(sf[sfi]);
1305 // transfer PDB entries
1306 if (entry.getAllPDBEntries() != null)
1308 Enumeration e = entry.getAllPDBEntries().elements();
1309 while (e.hasMoreElements())
1311 PDBEntry pdb = (PDBEntry) e.nextElement();
1315 // transfer database references
1316 DBRefEntry[] entryRefs = entry.getDBRefs();
1317 if (entryRefs != null)
1319 for (int r = 0; r < entryRefs.length; r++)
1321 DBRefEntry newref = new DBRefEntry(entryRefs[r]);
1322 if (newref.getMap() != null && mp != null)
1324 // remap ref using our local mapping
1326 // we also assume all version string setting is done by dbSourceProxy
1328 * if (!newref.getSource().equalsIgnoreCase(dbSource)) {
1329 * newref.setSource(dbSource); }
1337 * @return The index (zero-based) on this sequence in the MSA. It returns
1338 * {@code -1} if this information is not available.
1341 public int getIndex()
1347 * Defines the position of this sequence in the MSA. Use the value {@code -1}
1348 * if this information is undefined.
1351 * position for this sequence. This value is zero-based (zero for
1352 * this first sequence)
1355 public void setIndex(int value)
1361 public void setRNA(RNA r)
1373 public List<AlignmentAnnotation> getAlignmentAnnotations(String calcId,
1376 List<AlignmentAnnotation> result = new ArrayList<AlignmentAnnotation>();
1377 if (this.annotation != null)
1379 for (AlignmentAnnotation ann : annotation)
1381 if (ann.calcId != null && ann.calcId.equals(calcId)
1382 && ann.label != null && ann.label.equals(label))
1392 public String toString()
1394 return getDisplayId(false);
1398 public PDBEntry getPDBEntry(String pdbIdStr)
1400 if (getDatasetSequence() != null)
1402 return getDatasetSequence().getPDBEntry(pdbIdStr);
1408 List<PDBEntry> entries = getAllPDBEntries();
1409 for (PDBEntry entry : entries)
1411 if (entry.getId().equalsIgnoreCase(pdbIdStr))
1421 public List<DBRefEntry> getPrimaryDBRefs()
1423 if (datasetSequence!=null)
1425 return datasetSequence.getPrimaryDBRefs();
1427 if (dbrefs==null || dbrefs.length==0)
1429 return Collections.emptyList();
1431 synchronized (dbrefs)
1433 List<DBRefEntry> primaries = new ArrayList<DBRefEntry>();
1434 DBRefEntry[] tmp = new DBRefEntry[1];
1435 for (DBRefEntry ref : dbrefs)
1437 if (!ref.isPrimaryCandidate())
1443 MapList mp = ref.getMap().getMap();
1444 if (mp.getFromLowest() > start || mp.getFromHighest() < end)
1446 // map only involves a subsequence, so cannot be primary
1450 // whilst it looks like it is a primary ref, we also sanity check type
1451 if (DBRefUtils.getCanonicalName(DBRefSource.PDB).equals(
1452 DBRefUtils.getCanonicalName(ref.getSource())))
1454 // PDB dbrefs imply there should be a PDBEntry associated
1455 // TODO: tighten PDB dbrefs
1456 // formally imply Jalview has actually downloaded and
1457 // parsed the pdb file. That means there should be a cached file
1458 // handle on the PDBEntry, and a real mapping between sequence and
1459 // extracted sequence from PDB file
1460 PDBEntry pdbentry = getPDBEntry(ref.getAccessionId());
1461 if (pdbentry != null && pdbentry.getFile() != null)
1467 // check standard protein or dna sources
1469 DBRefEntry[] res = DBRefUtils.selectDbRefs(!isProtein(), tmp);
1470 if (res != null && res[0] == tmp[0])