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.Collections;
32 import java.util.Enumeration;
33 import java.util.List;
34 import java.util.Vector;
36 import fr.orsay.lri.varna.models.rna.RNA;
40 * Implements the SequenceI interface for a char[] based sequence object.
45 public class Sequence extends ASequence implements SequenceI
47 SequenceI datasetSequence;
51 private char[] sequence;
59 Vector<PDBEntry> pdbIds;
68 * This annotation is displayed below the alignment but the positions are tied
69 * to the residues of this sequence
71 * TODO: change to List<>
73 Vector<AlignmentAnnotation> annotation;
76 * The index of the sequence in a MSA
80 /** array of sequence features - may not be null for a valid sequence object */
81 public SequenceFeature[] sequenceFeatures;
84 * Creates a new Sequence object.
89 * string to form a possibly gapped sequence out of
91 * first position of non-gap residue in the sequence
93 * last position of ungapped residues (nearly always only used for
96 public Sequence(String name, String sequence, int start, int end)
98 initSeqAndName(name, sequence.toCharArray(), start, end);
101 public Sequence(String name, char[] sequence, int start, int end)
103 initSeqAndName(name, sequence, start, end);
107 * Stage 1 constructor - assign name, sequence, and set start and end fields.
108 * start and end are updated values from name2 if it ends with /start-end
115 protected void initSeqAndName(String name2, char[] sequence2, int start2,
119 this.sequence = sequence2;
126 com.stevesoft.pat.Regex limitrx = new com.stevesoft.pat.Regex(
127 "[/][0-9]{1,}[-][0-9]{1,}$");
129 com.stevesoft.pat.Regex endrx = new com.stevesoft.pat.Regex("[0-9]{1,}$");
136 .println("POSSIBLE IMPLEMENTATION ERROR: null sequence name passed to constructor.");
139 // Does sequence have the /start-end signature?
140 if (limitrx.search(name))
142 name = limitrx.left();
143 endrx.search(limitrx.stringMatched());
144 setStart(Integer.parseInt(limitrx.stringMatched().substring(1,
145 endrx.matchedFrom() - 1)));
146 setEnd(Integer.parseInt(endrx.stringMatched()));
150 void checkValidRange()
153 // http://issues.jalview.org/browse/JAL-774?focusedCommentId=11239&page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel#comment-11239
156 for (int j = 0; j < sequence.length; j++)
158 if (!jalview.util.Comparison.isGap(sequence[j]))
177 * Creates a new Sequence object.
184 public Sequence(String name, String sequence)
186 this(name, sequence, 1, -1);
190 * Creates a new Sequence object with new AlignmentAnnotations but inherits
191 * any existing dataset sequence reference. If non exists, everything is
195 * if seq is a dataset sequence, behaves like a plain old copy
198 public Sequence(SequenceI seq)
200 this(seq, seq.getAnnotation());
204 * Create a new sequence object with new features, DBRefEntries, and PDBIds
205 * but inherits any existing dataset sequence reference, and duplicate of any
206 * annotation that is present in the given annotation array.
209 * the sequence to be copied
210 * @param alAnnotation
211 * an array of annotation including some associated with seq
213 public Sequence(SequenceI seq, AlignmentAnnotation[] alAnnotation)
215 initSeqFrom(seq, alAnnotation);
220 * does the heavy lifting when cloning a dataset sequence, or coping data from
221 * dataset to a new derived sequence.
224 * - source of attributes.
225 * @param alAnnotation
226 * - alignment annotation present on seq that should be copied onto
229 protected void initSeqFrom(SequenceI seq,
230 AlignmentAnnotation[] alAnnotation)
233 char[] oseq = seq.getSequence();
234 initSeqAndName(seq.getName(), Arrays.copyOf(oseq, oseq.length),
238 description = seq.getDescription();
239 if (seq != datasetSequence)
241 setDatasetSequence(seq.getDatasetSequence());
243 if (datasetSequence == null && seq.getDBRefs() != null)
245 // only copy DBRefs and seqfeatures if we really are a dataset sequence
246 DBRefEntry[] dbr = seq.getDBRefs();
247 for (int i = 0; i < dbr.length; i++)
249 addDBRef(new DBRefEntry(dbr[i]));
251 if (seq.getSequenceFeatures() != null)
253 SequenceFeature[] sf = seq.getSequenceFeatures();
254 for (int i = 0; i < sf.length; i++)
256 addSequenceFeature(new SequenceFeature(sf[i]));
260 if (seq.getAnnotation() != null)
262 AlignmentAnnotation[] sqann = seq.getAnnotation();
263 for (int i = 0; i < sqann.length; i++)
265 if (sqann[i] == null)
269 boolean found = (alAnnotation == null);
272 for (int apos = 0; !found && apos < alAnnotation.length; apos++)
274 found = (alAnnotation[apos] == sqann[i]);
279 // only copy the given annotation
280 AlignmentAnnotation newann = new AlignmentAnnotation(sqann[i]);
281 addAlignmentAnnotation(newann);
285 if (seq.getAllPDBEntries() != null)
287 Vector<PDBEntry> ids = seq.getAllPDBEntries();
288 for (PDBEntry pdb : ids)
290 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 void addSequenceFeature(SequenceFeature sf)
320 if (sequenceFeatures==null && datasetSequence != null)
322 datasetSequence.addSequenceFeature(sf);
325 if (sequenceFeatures == null)
327 sequenceFeatures = new SequenceFeature[0];
330 for (int i = 0; i < sequenceFeatures.length; i++)
332 if (sequenceFeatures[i].equals(sf))
338 SequenceFeature[] temp = new SequenceFeature[sequenceFeatures.length + 1];
339 System.arraycopy(sequenceFeatures, 0, temp, 0, sequenceFeatures.length);
340 temp[sequenceFeatures.length] = sf;
342 sequenceFeatures = temp;
346 public void deleteFeature(SequenceFeature sf)
348 if (sequenceFeatures == null)
350 if (datasetSequence!=null) {
351 datasetSequence.deleteFeature(sf);
357 for (index = 0; index < sequenceFeatures.length; index++)
359 if (sequenceFeatures[index].equals(sf))
365 if (index == sequenceFeatures.length)
370 int sfLength = sequenceFeatures.length;
373 sequenceFeatures = null;
377 SequenceFeature[] temp = new SequenceFeature[sfLength - 1];
378 System.arraycopy(sequenceFeatures, 0, temp, 0, index);
380 if (index < sfLength)
382 System.arraycopy(sequenceFeatures, index + 1, temp, index,
383 sequenceFeatures.length - index - 1);
386 sequenceFeatures = temp;
391 * Returns the sequence features (if any), looking first on the sequence, then
392 * on its dataset sequence, and so on until a non-null value is found (or
393 * none). This supports retrieval of sequence features stored on the sequence
394 * (as in the applet) or on the dataset sequence (as in the Desktop version).
399 public SequenceFeature[] getSequenceFeatures()
401 SequenceFeature[] features = sequenceFeatures;
403 SequenceI seq = this;
404 int count = 0; // failsafe against loop in sequence.datasetsequence...
405 while (features == null && seq.getDatasetSequence() != null
408 seq = seq.getDatasetSequence();
409 features = ((Sequence) seq).sequenceFeatures;
415 public void addPDBId(PDBEntry entry)
419 pdbIds = new Vector<PDBEntry>();
421 if (!updatedPDBEntry(pdbIds, entry))
423 pdbIds.addElement(entry);
427 private static boolean updatedPDBEntry(List<PDBEntry> entries,
430 for (PDBEntry xtant : entries)
432 if (xtant.getFile() != null && newEntry.getFile() != null
433 && !xtant.getFile().equals(newEntry.getFile()))
435 // different structure data, so leave alone.
438 // loop through to check whether we can find a matching ID
441 if (!xtant.getId().equals(newEntry.getId()))
443 /* TODO: support stemming to group PDB IDs.
444 // or stemming, with exactly one alphanumeric character difference
445 if (xtant.getId().length() < newEntry.getId().length())
447 if (!newEntry.getId().startsWith(xtant.getId()))
451 // newEntry may be chain specific PDBEntry
452 // TODO: copy/update details from newEntry to xtant
456 if (!xtant.getId().startsWith(newEntry.getId()))
460 // xtant may be chain specific PDBEntry
461 // TODO: copy/update missing details from newEntry
465 if (xtant.getChainCode() != null && xtant.getChainCode().length() > 0
466 && newEntry.getChainCode() != null
467 && !newEntry.getChainCode().equals(xtant.getChainCode()))
469 // don't overwrite - multiple chain mappings for a sequence yield
470 // multiple PDBEntries
471 // each with different chaincode
475 xtant.updateFrom(newEntry);
479 // if we got to the end of the loop, nothing was updated.
490 public void setPDBId(Vector<PDBEntry> id)
498 * @return DOCUMENT ME!
501 public Vector<PDBEntry> getAllPDBEntries()
503 return pdbIds == null ? new Vector<PDBEntry>() : pdbIds;
509 * @return DOCUMENT ME!
512 public String getDisplayId(boolean jvsuffix)
514 StringBuffer result = new StringBuffer(name);
517 result.append("/" + start + "-" + end);
520 return result.toString();
530 public void setName(String name)
539 * @return DOCUMENT ME!
542 public String getName()
554 public void setStart(int start)
562 * @return DOCUMENT ME!
565 public int getStart()
577 public void setEnd(int end)
585 * @return DOCUMENT ME!
596 * @return DOCUMENT ME!
599 public int getLength()
601 return this.sequence.length;
611 public void setSequence(String seq)
613 this.sequence = seq.toCharArray();
618 public String getSequenceAsString()
620 return new String(sequence);
624 public String getSequenceAsString(int start, int end)
626 return new String(getSequence(start, end));
630 public char[] getSequence()
638 * @see jalview.datamodel.SequenceI#getSequence(int, int)
641 public char[] getSequence(int start, int end)
647 // JBPNote - left to user to pad the result here (TODO:Decide on this
649 if (start >= sequence.length)
654 if (end >= sequence.length)
656 end = sequence.length;
659 char[] reply = new char[end - start];
660 System.arraycopy(sequence, start, reply, 0, end - start);
666 public SequenceI getSubSequence(int start, int end)
672 char[] seq = getSequence(start, end);
677 int nstart = findPosition(start);
678 int nend = findPosition(end) - 1;
679 // JBPNote - this is an incomplete copy.
680 SequenceI nseq = new Sequence(this.getName(), seq, nstart, nend);
681 nseq.setDescription(description);
682 if (datasetSequence != null)
684 nseq.setDatasetSequence(datasetSequence);
688 nseq.setDatasetSequence(this);
694 * Returns the character of the aligned sequence at the given position (base
695 * zero), or space if the position is not within the sequence's bounds
700 public char getCharAt(int i)
702 if (i >= 0 && i < sequence.length)
719 public void setDescription(String desc)
721 this.description = desc;
727 * @return DOCUMENT ME!
730 public String getDescription()
732 return this.description;
738 * @see jalview.datamodel.SequenceI#findIndex(int)
741 public int findIndex(int pos)
743 // returns the alignment position for a residue
746 // Rely on end being at least as long as the length of the sequence.
747 while ((i < sequence.length) && (j <= end) && (j <= pos))
749 if (!jalview.util.Comparison.isGap(sequence[i]))
757 if ((j == end) && (j < pos))
768 public int findPosition(int i)
772 int seqlen = sequence.length;
773 while ((j < i) && (j < seqlen))
775 if (!jalview.util.Comparison.isGap(sequence[j]))
787 * Returns an int array where indices correspond to each residue in the
788 * sequence and the element value gives its position in the alignment
790 * @return int[SequenceI.getEnd()-SequenceI.getStart()+1] or null if no
791 * residues in SequenceI object
794 public int[] gapMap()
796 String seq = jalview.analysis.AlignSeq.extractGaps(
797 jalview.util.Comparison.GapChars, new String(sequence));
798 int[] map = new int[seq.length()];
802 while (j < sequence.length)
804 if (!jalview.util.Comparison.isGap(sequence[j]))
816 public int[] findPositionMap()
818 int map[] = new int[sequence.length];
821 int seqlen = sequence.length;
825 if (!jalview.util.Comparison.isGap(sequence[j]))
836 public List<int[]> getInsertions()
838 ArrayList<int[]> map = new ArrayList<int[]>();
839 int lastj = -1, j = 0;
841 int seqlen = sequence.length;
844 if (jalview.util.Comparison.isGap(sequence[j]))
855 map.add(new int[] { lastj, j - 1 });
863 map.add(new int[] { lastj, j - 1 });
870 public void deleteChars(int i, int j)
872 int newstart = start, newend = end;
873 if (i >= sequence.length || i < 0)
878 char[] tmp = StringUtils.deleteChars(sequence, i, j);
879 boolean createNewDs = false;
880 // TODO: take a (second look) at the dataset creation validation method for
881 // the very large sequence case
882 int eindex = -1, sindex = -1;
883 boolean ecalc = false, scalc = false;
884 for (int s = i; s < j; s++)
886 if (jalview.schemes.ResidueProperties.aaIndex[sequence[s]] != 23)
896 sindex = findIndex(start) - 1;
901 // delete characters including start of sequence
902 newstart = findPosition(j);
903 break; // don't need to search for any more residue characters.
907 // delete characters after start.
910 eindex = findIndex(end) - 1;
915 // delete characters at end of sequence
916 newend = findPosition(i - 1);
917 break; // don't need to search for any more residue characters.
922 newend--; // decrease end position by one for the deleted residue
923 // and search further
929 // deletion occured in the middle of the sequence
930 if (createNewDs && this.datasetSequence != null)
932 // construct a new sequence
933 Sequence ds = new Sequence(datasetSequence);
934 // TODO: remove any non-inheritable properties ?
935 // TODO: create a sequence mapping (since there is a relation here ?)
936 ds.deleteChars(i, j);
937 datasetSequence = ds;
945 public void insertCharAt(int i, int length, char c)
947 char[] tmp = new char[sequence.length + length];
949 if (i >= sequence.length)
951 System.arraycopy(sequence, 0, tmp, 0, sequence.length);
956 System.arraycopy(sequence, 0, tmp, 0, i);
966 if (i < sequence.length)
968 System.arraycopy(sequence, i, tmp, index, sequence.length - i);
975 public void insertCharAt(int i, char c)
977 insertCharAt(i, 1, c);
981 public String getVamsasId()
987 public void setVamsasId(String id)
993 public void setDBRefs(DBRefEntry[] dbref)
999 public DBRefEntry[] getDBRefs()
1001 if (dbrefs == null && datasetSequence != null
1002 && this != datasetSequence)
1004 return datasetSequence.getDBRefs();
1010 public void addDBRef(DBRefEntry entry)
1012 // TODO add to dataset sequence instead if there is one?
1015 dbrefs = new DBRefEntry[0];
1018 for (DBRefEntryI dbr : dbrefs)
1020 if (dbr.updateFrom(entry))
1023 * found a dbref that either matched, or could be
1024 * updated from, the new entry - no need to add it
1031 * extend the array to make room for one more
1033 // TODO use an ArrayList instead
1034 int j = dbrefs.length;
1035 DBRefEntry[] temp = new DBRefEntry[j + 1];
1036 System.arraycopy(dbrefs, 0, temp, 0, j);
1037 temp[temp.length - 1] = entry;
1043 public void setDatasetSequence(SequenceI seq)
1045 // TODO check for circular reference before setting?
1046 datasetSequence = seq;
1050 public SequenceI getDatasetSequence()
1052 return datasetSequence;
1056 public AlignmentAnnotation[] getAnnotation()
1058 return annotation == null ? null : annotation
1059 .toArray(new AlignmentAnnotation[annotation.size()]);
1063 public boolean hasAnnotation(AlignmentAnnotation ann)
1065 return annotation == null ? false : annotation.contains(ann);
1069 public void addAlignmentAnnotation(AlignmentAnnotation annotation)
1071 if (this.annotation == null)
1073 this.annotation = new Vector<AlignmentAnnotation>();
1075 if (!this.annotation.contains(annotation))
1077 this.annotation.addElement(annotation);
1079 annotation.setSequenceRef(this);
1083 public void removeAlignmentAnnotation(AlignmentAnnotation annotation)
1085 if (this.annotation != null)
1087 this.annotation.removeElement(annotation);
1088 if (this.annotation.size() == 0)
1090 this.annotation = null;
1096 * test if this is a valid candidate for another sequence's dataset sequence.
1099 private boolean isValidDatasetSequence()
1101 if (datasetSequence != null)
1105 for (int i = 0; i < sequence.length; i++)
1107 if (jalview.util.Comparison.isGap(sequence[i]))
1116 public SequenceI deriveSequence()
1119 if (datasetSequence == null)
1121 if (isValidDatasetSequence())
1123 // Use this as dataset sequence
1124 seq = new Sequence(getName(), "", 1, -1);
1125 seq.setDatasetSequence(this);
1126 seq.initSeqFrom(this, getAnnotation());
1131 // Create a new, valid dataset sequence
1132 createDatasetSequence();
1135 return new Sequence(this);
1138 private boolean _isNa;
1140 private long _seqhash = 0;
1143 public boolean isProtein()
1145 if (datasetSequence != null)
1147 return datasetSequence.isProtein();
1149 if (_seqhash != sequence.hashCode())
1151 _seqhash = sequence.hashCode();
1152 _isNa=jalview.util.Comparison.isNucleotide(new SequenceI[] { this });
1160 * @see jalview.datamodel.SequenceI#createDatasetSequence()
1163 public SequenceI createDatasetSequence()
1165 if (datasetSequence == null)
1167 Sequence dsseq = new Sequence(getName(), AlignSeq.extractGaps(
1168 jalview.util.Comparison.GapChars, getSequenceAsString()),
1169 getStart(), getEnd());
1171 datasetSequence = dsseq;
1173 dsseq.setDescription(description);
1174 // move features and database references onto dataset sequence
1175 dsseq.sequenceFeatures = sequenceFeatures;
1176 sequenceFeatures=null;
1177 dsseq.dbrefs = dbrefs;
1179 // TODO: search and replace any references to this sequence with
1180 // references to the dataset sequence in Mappings on dbref
1181 dsseq.pdbIds = pdbIds;
1183 datasetSequence.updatePDBIds();
1184 if (annotation != null)
1186 // annotation is cloned rather than moved, to preserve what's currently
1188 for (AlignmentAnnotation aa : annotation)
1190 AlignmentAnnotation _aa = new AlignmentAnnotation(aa);
1191 _aa.sequenceRef = datasetSequence;
1192 _aa.adjustForAlignment(); // uses annotation's own record of
1193 // sequence-column mapping
1194 datasetSequence.addAlignmentAnnotation(_aa);
1198 return datasetSequence;
1205 * jalview.datamodel.SequenceI#setAlignmentAnnotation(AlignmmentAnnotation[]
1209 public void setAlignmentAnnotation(AlignmentAnnotation[] annotations)
1211 if (annotation != null)
1213 annotation.removeAllElements();
1215 if (annotations != null)
1217 for (int i = 0; i < annotations.length; i++)
1219 if (annotations[i] != null)
1221 addAlignmentAnnotation(annotations[i]);
1228 public AlignmentAnnotation[] getAnnotation(String label)
1230 if (annotation == null || annotation.size() == 0)
1235 Vector subset = new Vector();
1236 Enumeration e = annotation.elements();
1237 while (e.hasMoreElements())
1239 AlignmentAnnotation ann = (AlignmentAnnotation) e.nextElement();
1240 if (ann.label != null && ann.label.equals(label))
1242 subset.addElement(ann);
1245 if (subset.size() == 0)
1249 AlignmentAnnotation[] anns = new AlignmentAnnotation[subset.size()];
1251 e = subset.elements();
1252 while (e.hasMoreElements())
1254 anns[i++] = (AlignmentAnnotation) e.nextElement();
1256 subset.removeAllElements();
1261 public boolean updatePDBIds()
1263 if (datasetSequence != null)
1265 // TODO: could merge DBRefs
1266 return datasetSequence.updatePDBIds();
1268 if (dbrefs == null || dbrefs.length == 0)
1272 Vector newpdb = new Vector();
1273 for (int i = 0; i < dbrefs.length; i++)
1275 if (DBRefSource.PDB.equals(dbrefs[i].getSource()))
1277 PDBEntry pdbe = new PDBEntry();
1278 pdbe.setId(dbrefs[i].getAccessionId());
1279 if (pdbIds == null || pdbIds.size() == 0)
1281 newpdb.addElement(pdbe);
1285 Enumeration en = pdbIds.elements();
1286 boolean matched = false;
1287 while (!matched && en.hasMoreElements())
1289 PDBEntry anentry = (PDBEntry) en.nextElement();
1290 if (anentry.getId().equals(pdbe.getId()))
1297 newpdb.addElement(pdbe);
1302 if (newpdb.size() > 0)
1304 Enumeration en = newpdb.elements();
1305 while (en.hasMoreElements())
1307 addPDBId((PDBEntry) en.nextElement());
1315 public void transferAnnotation(SequenceI entry, Mapping mp)
1317 if (datasetSequence != null)
1319 datasetSequence.transferAnnotation(entry, mp);
1322 if (entry.getDatasetSequence() != null)
1324 transferAnnotation(entry.getDatasetSequence(), mp);
1327 // transfer any new features from entry onto sequence
1328 if (entry.getSequenceFeatures() != null)
1331 SequenceFeature[] sfs = entry.getSequenceFeatures();
1332 for (int si = 0; si < sfs.length; si++)
1334 SequenceFeature sf[] = (mp != null) ? mp.locateFeature(sfs[si])
1335 : new SequenceFeature[] { new SequenceFeature(sfs[si]) };
1336 if (sf != null && sf.length > 0)
1338 for (int sfi = 0; sfi < sf.length; sfi++)
1340 addSequenceFeature(sf[sfi]);
1346 // transfer PDB entries
1347 if (entry.getAllPDBEntries() != null)
1349 Enumeration e = entry.getAllPDBEntries().elements();
1350 while (e.hasMoreElements())
1352 PDBEntry pdb = (PDBEntry) e.nextElement();
1356 // transfer database references
1357 DBRefEntry[] entryRefs = entry.getDBRefs();
1358 if (entryRefs != null)
1360 for (int r = 0; r < entryRefs.length; r++)
1362 DBRefEntry newref = new DBRefEntry(entryRefs[r]);
1363 if (newref.getMap() != null && mp != null)
1365 // remap ref using our local mapping
1367 // we also assume all version string setting is done by dbSourceProxy
1369 * if (!newref.getSource().equalsIgnoreCase(dbSource)) {
1370 * newref.setSource(dbSource); }
1378 * @return The index (zero-based) on this sequence in the MSA. It returns
1379 * {@code -1} if this information is not available.
1382 public int getIndex()
1388 * Defines the position of this sequence in the MSA. Use the value {@code -1}
1389 * if this information is undefined.
1392 * position for this sequence. This value is zero-based (zero for
1393 * this first sequence)
1396 public void setIndex(int value)
1402 public void setRNA(RNA r)
1414 public List<AlignmentAnnotation> getAlignmentAnnotations(String calcId,
1417 List<AlignmentAnnotation> result = new ArrayList<AlignmentAnnotation>();
1418 if (this.annotation != null)
1420 for (AlignmentAnnotation ann : annotation)
1422 if (ann.calcId != null && ann.calcId.equals(calcId)
1423 && ann.label != null && ann.label.equals(label))
1433 public String toString()
1435 return getDisplayId(false);
1439 public PDBEntry getPDBEntry(String pdbIdStr)
1441 if (getDatasetSequence() != null)
1443 return getDatasetSequence().getPDBEntry(pdbIdStr);
1449 List<PDBEntry> entries = getAllPDBEntries();
1450 for (PDBEntry entry : entries)
1452 if (entry.getId().equalsIgnoreCase(pdbIdStr))
1462 public List<DBRefEntry> getPrimaryDBRefs()
1464 if (datasetSequence!=null)
1466 return datasetSequence.getPrimaryDBRefs();
1468 if (dbrefs==null || dbrefs.length==0)
1470 return Collections.emptyList();
1472 synchronized (dbrefs)
1474 List<DBRefEntry> primaries = new ArrayList<DBRefEntry>();
1475 DBRefEntry[] tmp = new DBRefEntry[1];
1476 for (DBRefEntry ref : dbrefs)
1478 if (!ref.isPrimaryCandidate())
1484 MapList mp = ref.getMap().getMap();
1485 if (mp.getFromLowest() > start || mp.getFromHighest() < end)
1487 // map only involves a subsequence, so cannot be primary
1491 // whilst it looks like it is a primary ref, we also sanity check type
1492 if (DBRefUtils.getCanonicalName(DBRefSource.PDB).equals(
1493 DBRefUtils.getCanonicalName(ref.getSource())))
1495 // PDB dbrefs imply there should be a PDBEntry associated
1496 // TODO: tighten PDB dbrefs
1497 // formally imply Jalview has actually downloaded and
1498 // parsed the pdb file. That means there should be a cached file
1499 // handle on the PDBEntry, and a real mapping between sequence and
1500 // extracted sequence from PDB file
1501 PDBEntry pdbentry = getPDBEntry(ref.getAccessionId());
1502 if (pdbentry != null && pdbentry.getFile() != null)
1508 // check standard protein or dna sources
1510 DBRefEntry[] res = DBRefUtils.selectDbRefs(!isProtein(), tmp);
1511 if (res != null && res[0] == tmp[0])