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.DBRefUtils;
26 import jalview.util.MapList;
27 import jalview.util.StringUtils;
29 import java.util.ArrayList;
30 import java.util.Arrays;
31 import java.util.Enumeration;
32 import java.util.List;
33 import java.util.Vector;
35 import fr.orsay.lri.varna.models.rna.RNA;
39 * Implements the SequenceI interface for a char[] based sequence object.
44 public class Sequence extends ASequence implements SequenceI
46 SequenceI datasetSequence;
50 private char[] sequence;
58 Vector<PDBEntry> pdbIds;
67 * This annotation is displayed below the alignment but the positions are tied
68 * to the residues of this sequence
70 * TODO: change to List<>
72 Vector<AlignmentAnnotation> annotation;
75 * The index of the sequence in a MSA
79 /** array of sequence features - may not be null for a valid sequence object */
80 public SequenceFeature[] sequenceFeatures;
83 * Creates a new Sequence object.
88 * string to form a possibly gapped sequence out of
90 * first position of non-gap residue in the sequence
92 * last position of ungapped residues (nearly always only used for
95 public Sequence(String name, String sequence, int start, int end)
97 initSeqAndName(name, sequence.toCharArray(), start, end);
100 public Sequence(String name, char[] sequence, int start, int end)
102 initSeqAndName(name, sequence, start, end);
106 * Stage 1 constructor - assign name, sequence, and set start and end fields.
107 * start and end are updated values from name2 if it ends with /start-end
114 protected void initSeqAndName(String name2, char[] sequence2, int start2,
118 this.sequence = sequence2;
125 com.stevesoft.pat.Regex limitrx = new com.stevesoft.pat.Regex(
126 "[/][0-9]{1,}[-][0-9]{1,}$");
128 com.stevesoft.pat.Regex endrx = new com.stevesoft.pat.Regex("[0-9]{1,}$");
135 .println("POSSIBLE IMPLEMENTATION ERROR: null sequence name passed to constructor.");
138 // Does sequence have the /start-end signature?
139 if (limitrx.search(name))
141 name = limitrx.left();
142 endrx.search(limitrx.stringMatched());
143 setStart(Integer.parseInt(limitrx.stringMatched().substring(1,
144 endrx.matchedFrom() - 1)));
145 setEnd(Integer.parseInt(endrx.stringMatched()));
149 void checkValidRange()
152 // http://issues.jalview.org/browse/JAL-774?focusedCommentId=11239&page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel#comment-11239
155 for (int j = 0; j < sequence.length; j++)
157 if (!jalview.util.Comparison.isGap(sequence[j]))
176 * Creates a new Sequence object.
183 public Sequence(String name, String sequence)
185 this(name, sequence, 1, -1);
189 * Creates a new Sequence object with new AlignmentAnnotations but inherits
190 * any existing dataset sequence reference. If non exists, everything is
194 * if seq is a dataset sequence, behaves like a plain old copy
197 public Sequence(SequenceI seq)
199 this(seq, seq.getAnnotation());
203 * Create a new sequence object with new features, DBRefEntries, and PDBIds
204 * but inherits any existing dataset sequence reference, and duplicate of any
205 * annotation that is present in the given annotation array.
208 * the sequence to be copied
209 * @param alAnnotation
210 * an array of annotation including some associated with seq
212 public Sequence(SequenceI seq, AlignmentAnnotation[] alAnnotation)
214 initSeqFrom(seq, alAnnotation);
219 * does the heavy lifting when cloning a dataset sequence, or coping data from
220 * dataset to a new derived sequence.
223 * - source of attributes.
224 * @param alAnnotation
225 * - alignment annotation present on seq that should be copied onto
228 protected void initSeqFrom(SequenceI seq,
229 AlignmentAnnotation[] alAnnotation)
232 char[] oseq = seq.getSequence();
233 initSeqAndName(seq.getName(), Arrays.copyOf(oseq, oseq.length),
237 description = seq.getDescription();
238 if (seq != datasetSequence)
240 setDatasetSequence(seq.getDatasetSequence());
242 if (datasetSequence == null && seq.getDBRefs() != null)
244 // only copy DBRefs and seqfeatures if we really are a dataset sequence
245 DBRefEntry[] dbr = seq.getDBRefs();
246 for (int i = 0; i < dbr.length; i++)
248 addDBRef(new DBRefEntry(dbr[i]));
250 if (seq.getSequenceFeatures() != null)
252 SequenceFeature[] sf = seq.getSequenceFeatures();
253 for (int i = 0; i < sf.length; i++)
255 addSequenceFeature(new SequenceFeature(sf[i]));
259 if (seq.getAnnotation() != null)
261 AlignmentAnnotation[] sqann = seq.getAnnotation();
262 for (int i = 0; i < sqann.length; i++)
264 if (sqann[i] == null)
268 boolean found = (alAnnotation == null);
271 for (int apos = 0; !found && apos < alAnnotation.length; apos++)
273 found = (alAnnotation[apos] == sqann[i]);
278 // only copy the given annotation
279 AlignmentAnnotation newann = new AlignmentAnnotation(sqann[i]);
280 addAlignmentAnnotation(newann);
284 if (seq.getAllPDBEntries() != null)
286 Vector<PDBEntry> ids = seq.getAllPDBEntries();
287 for (PDBEntry pdb : ids)
289 this.addPDBId(new PDBEntry(pdb));
296 public void setSequenceFeatures(SequenceFeature[] features)
298 if (datasetSequence == null)
300 sequenceFeatures = features;
304 if (datasetSequence.getSequenceFeatures() != features
305 && datasetSequence.getSequenceFeatures() != null
306 && datasetSequence.getSequenceFeatures().length > 0)
309 "Warning: JAL-2046 side effect ? Possible implementation error: overwriting dataset sequence features by setting sequence features on alignment")
312 datasetSequence.setSequenceFeatures(features);
317 public synchronized void addSequenceFeature(SequenceFeature sf)
319 if (sequenceFeatures==null && datasetSequence != null)
321 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;
345 public void deleteFeature(SequenceFeature sf)
347 if (sequenceFeatures == null)
349 if (datasetSequence!=null) {
350 datasetSequence.deleteFeature(sf);
356 for (index = 0; index < sequenceFeatures.length; index++)
358 if (sequenceFeatures[index].equals(sf))
364 if (index == sequenceFeatures.length)
369 int sfLength = sequenceFeatures.length;
372 sequenceFeatures = null;
376 SequenceFeature[] temp = new SequenceFeature[sfLength - 1];
377 System.arraycopy(sequenceFeatures, 0, temp, 0, index);
379 if (index < sfLength)
381 System.arraycopy(sequenceFeatures, index + 1, temp, index,
382 sequenceFeatures.length - index - 1);
385 sequenceFeatures = temp;
390 * Returns the sequence features (if any), looking first on the sequence, then
391 * on its dataset sequence, and so on until a non-null value is found (or
392 * none). This supports retrieval of sequence features stored on the sequence
393 * (as in the applet) or on the dataset sequence (as in the Desktop version).
398 public SequenceFeature[] getSequenceFeatures()
400 SequenceFeature[] features = sequenceFeatures;
402 SequenceI seq = this;
403 int count = 0; // failsafe against loop in sequence.datasetsequence...
404 while (features == null && seq.getDatasetSequence() != null
407 seq = seq.getDatasetSequence();
408 features = ((Sequence) seq).sequenceFeatures;
414 public void addPDBId(PDBEntry entry)
418 pdbIds = new Vector<PDBEntry>();
420 if (pdbIds.contains(entry))
422 updatePDBEntry(pdbIds.get(pdbIds.indexOf(entry)), entry);
426 pdbIds.addElement(entry);
430 private static void updatePDBEntry(PDBEntry oldEntry, PDBEntry newEntry)
432 if (newEntry.getFile() != null)
434 oldEntry.setFile(newEntry.getFile());
445 public void setPDBId(Vector<PDBEntry> id)
453 * @return DOCUMENT ME!
456 public Vector<PDBEntry> getAllPDBEntries()
458 return pdbIds == null ? new Vector<PDBEntry>() : pdbIds;
464 * @return DOCUMENT ME!
467 public String getDisplayId(boolean jvsuffix)
469 StringBuffer result = new StringBuffer(name);
472 result.append("/" + start + "-" + end);
475 return result.toString();
485 public void setName(String name)
494 * @return DOCUMENT ME!
497 public String getName()
509 public void setStart(int start)
517 * @return DOCUMENT ME!
520 public int getStart()
532 public void setEnd(int end)
540 * @return DOCUMENT ME!
551 * @return DOCUMENT ME!
554 public int getLength()
556 return this.sequence.length;
566 public void setSequence(String seq)
568 this.sequence = seq.toCharArray();
573 public String getSequenceAsString()
575 return new String(sequence);
579 public String getSequenceAsString(int start, int end)
581 return new String(getSequence(start, end));
585 public char[] getSequence()
593 * @see jalview.datamodel.SequenceI#getSequence(int, int)
596 public char[] getSequence(int start, int end)
602 // JBPNote - left to user to pad the result here (TODO:Decide on this
604 if (start >= sequence.length)
609 if (end >= sequence.length)
611 end = sequence.length;
614 char[] reply = new char[end - start];
615 System.arraycopy(sequence, start, reply, 0, end - start);
621 public SequenceI getSubSequence(int start, int end)
627 char[] seq = getSequence(start, end);
632 int nstart = findPosition(start);
633 int nend = findPosition(end) - 1;
634 // JBPNote - this is an incomplete copy.
635 SequenceI nseq = new Sequence(this.getName(), seq, nstart, nend);
636 nseq.setDescription(description);
637 if (datasetSequence != null)
639 nseq.setDatasetSequence(datasetSequence);
643 nseq.setDatasetSequence(this);
649 * Returns the character of the aligned sequence at the given position (base
650 * zero), or space if the position is not within the sequence's bounds
655 public char getCharAt(int i)
657 if (i >= 0 && i < sequence.length)
674 public void setDescription(String desc)
676 this.description = desc;
682 * @return DOCUMENT ME!
685 public String getDescription()
687 return this.description;
693 * @see jalview.datamodel.SequenceI#findIndex(int)
696 public int findIndex(int pos)
698 // returns the alignment position for a residue
701 // Rely on end being at least as long as the length of the sequence.
702 while ((i < sequence.length) && (j <= end) && (j <= pos))
704 if (!jalview.util.Comparison.isGap(sequence[i]))
712 if ((j == end) && (j < pos))
723 public int findPosition(int i)
727 int seqlen = sequence.length;
728 while ((j < i) && (j < seqlen))
730 if (!jalview.util.Comparison.isGap(sequence[j]))
742 * Returns an int array where indices correspond to each residue in the
743 * sequence and the element value gives its position in the alignment
745 * @return int[SequenceI.getEnd()-SequenceI.getStart()+1] or null if no
746 * residues in SequenceI object
749 public int[] gapMap()
751 String seq = jalview.analysis.AlignSeq.extractGaps(
752 jalview.util.Comparison.GapChars, new String(sequence));
753 int[] map = new int[seq.length()];
757 while (j < sequence.length)
759 if (!jalview.util.Comparison.isGap(sequence[j]))
771 public int[] findPositionMap()
773 int map[] = new int[sequence.length];
776 int seqlen = sequence.length;
780 if (!jalview.util.Comparison.isGap(sequence[j]))
791 public List<int[]> getInsertions()
793 ArrayList<int[]> map = new ArrayList<int[]>();
794 int lastj = -1, j = 0;
796 int seqlen = sequence.length;
799 if (jalview.util.Comparison.isGap(sequence[j]))
810 map.add(new int[] { lastj, j - 1 });
818 map.add(new int[] { lastj, j - 1 });
825 public void deleteChars(int i, int j)
827 int newstart = start, newend = end;
828 if (i >= sequence.length || i < 0)
833 char[] tmp = StringUtils.deleteChars(sequence, i, j);
834 boolean createNewDs = false;
835 // TODO: take a (second look) at the dataset creation validation method for
836 // the very large sequence case
837 int eindex = -1, sindex = -1;
838 boolean ecalc = false, scalc = false;
839 for (int s = i; s < j; s++)
841 if (jalview.schemes.ResidueProperties.aaIndex[sequence[s]] != 23)
851 sindex = findIndex(start) - 1;
856 // delete characters including start of sequence
857 newstart = findPosition(j);
858 break; // don't need to search for any more residue characters.
862 // delete characters after start.
865 eindex = findIndex(end) - 1;
870 // delete characters at end of sequence
871 newend = findPosition(i - 1);
872 break; // don't need to search for any more residue characters.
877 newend--; // decrease end position by one for the deleted residue
878 // and search further
884 // deletion occured in the middle of the sequence
885 if (createNewDs && this.datasetSequence != null)
887 // construct a new sequence
888 Sequence ds = new Sequence(datasetSequence);
889 // TODO: remove any non-inheritable properties ?
890 // TODO: create a sequence mapping (since there is a relation here ?)
891 ds.deleteChars(i, j);
892 datasetSequence = ds;
900 public void insertCharAt(int i, int length, char c)
902 char[] tmp = new char[sequence.length + length];
904 if (i >= sequence.length)
906 System.arraycopy(sequence, 0, tmp, 0, sequence.length);
911 System.arraycopy(sequence, 0, tmp, 0, i);
921 if (i < sequence.length)
923 System.arraycopy(sequence, i, tmp, index, sequence.length - i);
930 public void insertCharAt(int i, char c)
932 insertCharAt(i, 1, c);
936 public String getVamsasId()
942 public void setVamsasId(String id)
948 public void setDBRefs(DBRefEntry[] dbref)
954 public DBRefEntry[] getDBRefs()
956 if (dbrefs == null && datasetSequence != null
957 && this != datasetSequence)
959 return datasetSequence.getDBRefs();
965 public void addDBRef(DBRefEntry entry)
967 // TODO add to dataset sequence instead if there is one?
970 dbrefs = new DBRefEntry[0];
973 for (DBRefEntryI dbr : dbrefs)
975 if (dbr.updateFrom(entry))
978 * found a dbref that either matched, or could be
979 * updated from, the new entry - no need to add it
986 * extend the array to make room for one more
988 // TODO use an ArrayList instead
989 int j = dbrefs.length;
990 DBRefEntry[] temp = new DBRefEntry[j + 1];
991 System.arraycopy(dbrefs, 0, temp, 0, j);
992 temp[temp.length - 1] = entry;
998 public void setDatasetSequence(SequenceI seq)
1000 // TODO check for circular reference before setting?
1001 datasetSequence = seq;
1005 public SequenceI getDatasetSequence()
1007 return datasetSequence;
1011 public AlignmentAnnotation[] getAnnotation()
1013 return annotation == null ? null : annotation
1014 .toArray(new AlignmentAnnotation[annotation.size()]);
1018 public boolean hasAnnotation(AlignmentAnnotation ann)
1020 return annotation == null ? false : annotation.contains(ann);
1024 public void addAlignmentAnnotation(AlignmentAnnotation annotation)
1026 if (this.annotation == null)
1028 this.annotation = new Vector<AlignmentAnnotation>();
1030 if (!this.annotation.contains(annotation))
1032 this.annotation.addElement(annotation);
1034 annotation.setSequenceRef(this);
1038 public void removeAlignmentAnnotation(AlignmentAnnotation annotation)
1040 if (this.annotation != null)
1042 this.annotation.removeElement(annotation);
1043 if (this.annotation.size() == 0)
1045 this.annotation = null;
1051 * test if this is a valid candidate for another sequence's dataset sequence.
1054 private boolean isValidDatasetSequence()
1056 if (datasetSequence != null)
1060 for (int i = 0; i < sequence.length; i++)
1062 if (jalview.util.Comparison.isGap(sequence[i]))
1071 public SequenceI deriveSequence()
1074 if (datasetSequence == null)
1076 if (isValidDatasetSequence())
1078 // Use this as dataset sequence
1079 seq = new Sequence(getName(), "", 1, -1);
1080 seq.setDatasetSequence(this);
1081 seq.initSeqFrom(this, getAnnotation());
1086 // Create a new, valid dataset sequence
1087 createDatasetSequence();
1090 return new Sequence(this);
1093 private boolean _isNa;
1095 private long _seqhash = 0;
1098 public boolean isProtein()
1100 if (datasetSequence != null)
1102 return datasetSequence.isProtein();
1104 if (_seqhash != sequence.hashCode())
1106 _seqhash = sequence.hashCode();
1107 _isNa=jalview.util.Comparison.isNucleotide(new SequenceI[] { this });
1115 * @see jalview.datamodel.SequenceI#createDatasetSequence()
1118 public SequenceI createDatasetSequence()
1120 if (datasetSequence == null)
1122 Sequence dsseq = new Sequence(getName(), AlignSeq.extractGaps(
1123 jalview.util.Comparison.GapChars, getSequenceAsString()),
1124 getStart(), getEnd());
1126 datasetSequence = dsseq;
1128 dsseq.setDescription(description);
1129 // move features and database references onto dataset sequence
1130 dsseq.sequenceFeatures = sequenceFeatures;
1131 sequenceFeatures=null;
1132 dsseq.dbrefs = dbrefs;
1134 // TODO: search and replace any references to this sequence with
1135 // references to the dataset sequence in Mappings on dbref
1136 dsseq.pdbIds = pdbIds;
1138 datasetSequence.updatePDBIds();
1139 if (annotation != null)
1141 // annotation is cloned rather than moved, to preserve what's currently
1143 for (AlignmentAnnotation aa : annotation)
1145 AlignmentAnnotation _aa = new AlignmentAnnotation(aa);
1146 _aa.sequenceRef = datasetSequence;
1147 _aa.adjustForAlignment(); // uses annotation's own record of
1148 // sequence-column mapping
1149 datasetSequence.addAlignmentAnnotation(_aa);
1153 return datasetSequence;
1160 * jalview.datamodel.SequenceI#setAlignmentAnnotation(AlignmmentAnnotation[]
1164 public void setAlignmentAnnotation(AlignmentAnnotation[] annotations)
1166 if (annotation != null)
1168 annotation.removeAllElements();
1170 if (annotations != null)
1172 for (int i = 0; i < annotations.length; i++)
1174 if (annotations[i] != null)
1176 addAlignmentAnnotation(annotations[i]);
1183 public AlignmentAnnotation[] getAnnotation(String label)
1185 if (annotation == null || annotation.size() == 0)
1190 Vector subset = new Vector();
1191 Enumeration e = annotation.elements();
1192 while (e.hasMoreElements())
1194 AlignmentAnnotation ann = (AlignmentAnnotation) e.nextElement();
1195 if (ann.label != null && ann.label.equals(label))
1197 subset.addElement(ann);
1200 if (subset.size() == 0)
1204 AlignmentAnnotation[] anns = new AlignmentAnnotation[subset.size()];
1206 e = subset.elements();
1207 while (e.hasMoreElements())
1209 anns[i++] = (AlignmentAnnotation) e.nextElement();
1211 subset.removeAllElements();
1216 public boolean updatePDBIds()
1218 if (datasetSequence != null)
1220 // TODO: could merge DBRefs
1221 return datasetSequence.updatePDBIds();
1223 if (dbrefs == null || dbrefs.length == 0)
1227 Vector newpdb = new Vector();
1228 for (int i = 0; i < dbrefs.length; i++)
1230 if (DBRefSource.PDB.equals(dbrefs[i].getSource()))
1232 PDBEntry pdbe = new PDBEntry();
1233 pdbe.setId(dbrefs[i].getAccessionId());
1234 if (pdbIds == null || pdbIds.size() == 0)
1236 newpdb.addElement(pdbe);
1240 Enumeration en = pdbIds.elements();
1241 boolean matched = false;
1242 while (!matched && en.hasMoreElements())
1244 PDBEntry anentry = (PDBEntry) en.nextElement();
1245 if (anentry.getId().equals(pdbe.getId()))
1252 newpdb.addElement(pdbe);
1257 if (newpdb.size() > 0)
1259 Enumeration en = newpdb.elements();
1260 while (en.hasMoreElements())
1262 addPDBId((PDBEntry) en.nextElement());
1270 public void transferAnnotation(SequenceI entry, Mapping mp)
1272 if (datasetSequence != null)
1274 datasetSequence.transferAnnotation(entry, mp);
1277 if (entry.getDatasetSequence() != null)
1279 transferAnnotation(entry.getDatasetSequence(), mp);
1282 // transfer any new features from entry onto sequence
1283 if (entry.getSequenceFeatures() != null)
1286 SequenceFeature[] sfs = entry.getSequenceFeatures();
1287 for (int si = 0; si < sfs.length; si++)
1289 SequenceFeature sf[] = (mp != null) ? mp.locateFeature(sfs[si])
1290 : new SequenceFeature[] { new SequenceFeature(sfs[si]) };
1291 if (sf != null && sf.length > 0)
1293 for (int sfi = 0; sfi < sf.length; sfi++)
1295 addSequenceFeature(sf[sfi]);
1301 // transfer PDB entries
1302 if (entry.getAllPDBEntries() != null)
1304 Enumeration e = entry.getAllPDBEntries().elements();
1305 while (e.hasMoreElements())
1307 PDBEntry pdb = (PDBEntry) e.nextElement();
1311 // transfer database references
1312 DBRefEntry[] entryRefs = entry.getDBRefs();
1313 if (entryRefs != null)
1315 for (int r = 0; r < entryRefs.length; r++)
1317 DBRefEntry newref = new DBRefEntry(entryRefs[r]);
1318 if (newref.getMap() != null && mp != null)
1320 // remap ref using our local mapping
1322 // we also assume all version string setting is done by dbSourceProxy
1324 * if (!newref.getSource().equalsIgnoreCase(dbSource)) {
1325 * newref.setSource(dbSource); }
1333 * @return The index (zero-based) on this sequence in the MSA. It returns
1334 * {@code -1} if this information is not available.
1337 public int getIndex()
1343 * Defines the position of this sequence in the MSA. Use the value {@code -1}
1344 * if this information is undefined.
1347 * position for this sequence. This value is zero-based (zero for
1348 * this first sequence)
1351 public void setIndex(int value)
1357 public void setRNA(RNA r)
1369 public List<AlignmentAnnotation> getAlignmentAnnotations(String calcId,
1372 List<AlignmentAnnotation> result = new ArrayList<AlignmentAnnotation>();
1373 if (this.annotation != null)
1375 for (AlignmentAnnotation ann : annotation)
1377 if (ann.calcId != null && ann.calcId.equals(calcId)
1378 && ann.label != null && ann.label.equals(label))
1388 public String toString()
1390 return getDisplayId(false);
1394 public PDBEntry getPDBEntry(String pdbIdStr)
1396 if (getDatasetSequence() != null)
1398 return getDatasetSequence().getPDBEntry(pdbIdStr);
1404 List<PDBEntry> entries = getAllPDBEntries();
1405 for (PDBEntry entry : entries)
1407 if (entry.getId().equalsIgnoreCase(pdbIdStr))
1417 public List<DBRefEntry> getPrimaryDBRefs()
1419 if (datasetSequence!=null)
1421 return datasetSequence.getPrimaryDBRefs();
1423 if (dbrefs==null || dbrefs.length==0)
1425 return Arrays.asList(new DBRefEntry[0]);
1427 synchronized (dbrefs)
1429 List<DBRefEntry> primaries = new ArrayList<DBRefEntry>();
1430 DBRefEntry tmp[] = new DBRefEntry[1], res[] = null;
1431 for (DBRefEntry ref : dbrefs)
1433 if (!ref.isPrimary())
1439 MapList mp = ref.getMap().getMap();
1440 if (mp.getFromLowest() > start || mp.getFromHighest() < end)
1442 // map only involves a subsequence, so cannot be primary
1446 // whilst it looks like it is a primary ref, we also sanity check type
1447 if (DBRefUtils.getCanonicalName(DBRefSource.PDB).equals(
1448 DBRefUtils.getCanonicalName(ref.getSource())))
1450 // PDB dbrefs imply there should be a PDBEntry associated
1451 // TODO: tighten PDB dbrefs
1452 // formally imply Jalview has actually downlaoded and
1453 // parsed the pdb file. That means there should be a cached file
1454 // handle on the PDBEntry, and a real mapping between sequence and
1455 // extracted sequence from PDB file
1456 PDBEntry pdbentry = getPDBEntry(ref.getAccessionId());
1457 if (pdbentry != null && pdbentry.getType() != null
1458 && pdbentry.getType().equalsIgnoreCase("PDB"))
1464 // check standard protein or dna sources
1466 res = DBRefUtils.selectDbRefs(!isProtein(), tmp);
1467 if (res != null && res[0] == tmp[0])