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;
64 HiddenMarkovModel hmm;
66 boolean isHMMConsensusSequence = false;
68 Vector<PDBEntry> pdbIds;
77 * This annotation is displayed below the alignment but the positions are tied
78 * to the residues of this sequence
80 * TODO: change to List<>
82 Vector<AlignmentAnnotation> annotation;
85 * The index of the sequence in a MSA
89 /** array of sequence features - may not be null for a valid sequence object */
90 public SequenceFeature[] sequenceFeatures;
93 * Creates a new Sequence object.
98 * string to form a possibly gapped sequence out of
100 * first position of non-gap residue in the sequence
102 * last position of ungapped residues (nearly always only used for
105 public Sequence(String name, String sequence, int start, int end)
107 initSeqAndName(name, sequence.toCharArray(), start, end);
110 public Sequence(String name, char[] sequence, int start, int end)
112 initSeqAndName(name, sequence, start, end);
116 * Stage 1 constructor - assign name, sequence, and set start and end fields.
117 * start and end are updated values from name2 if it ends with /start-end
124 protected void initSeqAndName(String name2, char[] sequence2, int start2,
128 this.sequence = sequence2;
135 com.stevesoft.pat.Regex limitrx = new com.stevesoft.pat.Regex(
136 "[/][0-9]{1,}[-][0-9]{1,}$");
138 com.stevesoft.pat.Regex endrx = new com.stevesoft.pat.Regex("[0-9]{1,}$");
145 .println("POSSIBLE IMPLEMENTATION ERROR: null sequence name passed to constructor.");
148 // Does sequence have the /start-end signature?
149 if (limitrx.search(name))
151 name = limitrx.left();
152 endrx.search(limitrx.stringMatched());
153 setStart(Integer.parseInt(limitrx.stringMatched().substring(1,
154 endrx.matchedFrom() - 1)));
155 setEnd(Integer.parseInt(endrx.stringMatched()));
159 void checkValidRange()
162 // http://issues.jalview.org/browse/JAL-774?focusedCommentId=11239&page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel#comment-11239
165 for (int j = 0; j < sequence.length; j++)
167 if (!jalview.util.Comparison.isGap(sequence[j]))
186 * Creates a new Sequence object.
193 public Sequence(String name, String sequence)
195 this(name, sequence, 1, -1);
199 * Creates a new Sequence object with new AlignmentAnnotations but inherits
200 * any existing dataset sequence reference. If non exists, everything is
204 * if seq is a dataset sequence, behaves like a plain old copy
207 public Sequence(SequenceI seq)
209 this(seq, seq.getAnnotation());
213 * Create a new sequence object with new features, DBRefEntries, and PDBIds
214 * but inherits any existing dataset sequence reference, and duplicate of any
215 * annotation that is present in the given annotation array.
218 * the sequence to be copied
219 * @param alAnnotation
220 * an array of annotation including some associated with seq
222 public Sequence(SequenceI seq, AlignmentAnnotation[] alAnnotation)
224 initSeqFrom(seq, alAnnotation);
229 * does the heavy lifting when cloning a dataset sequence, or coping data from
230 * dataset to a new derived sequence.
233 * - source of attributes.
234 * @param alAnnotation
235 * - alignment annotation present on seq that should be copied onto
238 protected void initSeqFrom(SequenceI seq,
239 AlignmentAnnotation[] alAnnotation)
242 char[] oseq = seq.getSequence();
243 initSeqAndName(seq.getName(), Arrays.copyOf(oseq, oseq.length),
244 seq.getStart(), seq.getEnd());
246 description = seq.getDescription();
247 if (seq != datasetSequence)
249 setDatasetSequence(seq.getDatasetSequence());
251 if (datasetSequence == null && seq.getDBRefs() != null)
253 // only copy DBRefs and seqfeatures if we really are a dataset sequence
254 DBRefEntry[] dbr = seq.getDBRefs();
255 for (int i = 0; i < dbr.length; i++)
257 addDBRef(new DBRefEntry(dbr[i]));
259 if (seq.getSequenceFeatures() != null)
261 SequenceFeature[] sf = seq.getSequenceFeatures();
262 for (int i = 0; i < sf.length; i++)
264 addSequenceFeature(new SequenceFeature(sf[i]));
268 if (seq.getAnnotation() != null)
270 AlignmentAnnotation[] sqann = seq.getAnnotation();
271 for (int i = 0; i < sqann.length; i++)
273 if (sqann[i] == null)
277 boolean found = (alAnnotation == null);
280 for (int apos = 0; !found && apos < alAnnotation.length; apos++)
282 found = (alAnnotation[apos] == sqann[i]);
287 // only copy the given annotation
288 AlignmentAnnotation newann = new AlignmentAnnotation(sqann[i]);
289 addAlignmentAnnotation(newann);
293 if (seq.getAllPDBEntries() != null)
295 Vector<PDBEntry> ids = seq.getAllPDBEntries();
296 for (PDBEntry pdb : ids)
298 this.addPDBId(new PDBEntry(pdb));
301 if (seq.getHMM() != null)
303 this.hmm = new HiddenMarkovModel(seq.getHMM());
308 public void setSequenceFeatures(SequenceFeature[] features)
310 if (datasetSequence == null)
312 sequenceFeatures = features;
316 if (datasetSequence.getSequenceFeatures() != features
317 && datasetSequence.getSequenceFeatures() != null
318 && datasetSequence.getSequenceFeatures().length > 0)
321 "Warning: JAL-2046 side effect ? Possible implementation error: overwriting dataset sequence features by setting sequence features on alignment")
324 datasetSequence.setSequenceFeatures(features);
329 public synchronized boolean addSequenceFeature(SequenceFeature sf)
331 if (sequenceFeatures == null && datasetSequence != null)
333 return datasetSequence.addSequenceFeature(sf);
335 if (sequenceFeatures == null)
337 sequenceFeatures = new SequenceFeature[0];
340 for (int i = 0; i < sequenceFeatures.length; i++)
342 if (sequenceFeatures[i].equals(sf))
348 SequenceFeature[] temp = new SequenceFeature[sequenceFeatures.length + 1];
349 System.arraycopy(sequenceFeatures, 0, temp, 0, sequenceFeatures.length);
350 temp[sequenceFeatures.length] = sf;
352 sequenceFeatures = temp;
357 public void deleteFeature(SequenceFeature sf)
359 if (sequenceFeatures == null)
361 if (datasetSequence != null)
363 datasetSequence.deleteFeature(sf);
369 for (index = 0; index < sequenceFeatures.length; index++)
371 if (sequenceFeatures[index].equals(sf))
377 if (index == sequenceFeatures.length)
382 int sfLength = sequenceFeatures.length;
385 sequenceFeatures = null;
389 SequenceFeature[] temp = new SequenceFeature[sfLength - 1];
390 System.arraycopy(sequenceFeatures, 0, temp, 0, index);
392 if (index < sfLength)
394 System.arraycopy(sequenceFeatures, index + 1, temp, index,
395 sequenceFeatures.length - index - 1);
398 sequenceFeatures = temp;
403 * Returns the sequence features (if any), looking first on the sequence, then
404 * on its dataset sequence, and so on until a non-null value is found (or
405 * none). This supports retrieval of sequence features stored on the sequence
406 * (as in the applet) or on the dataset sequence (as in the Desktop version).
411 public SequenceFeature[] getSequenceFeatures()
413 SequenceFeature[] features = sequenceFeatures;
415 SequenceI seq = this;
416 int count = 0; // failsafe against loop in sequence.datasetsequence...
417 while (features == null && seq.getDatasetSequence() != null
420 seq = seq.getDatasetSequence();
421 features = ((Sequence) seq).sequenceFeatures;
427 public boolean addPDBId(PDBEntry entry)
431 pdbIds = new Vector<>();
436 for (PDBEntry pdbe : pdbIds)
438 if (pdbe.updateFrom(entry))
443 pdbIds.addElement(entry);
454 public void setPDBId(Vector<PDBEntry> id)
462 * @return DOCUMENT ME!
465 public Vector<PDBEntry> getAllPDBEntries()
467 return pdbIds == null ? new Vector<PDBEntry>() : pdbIds;
473 * @return DOCUMENT ME!
476 public String getDisplayId(boolean jvsuffix)
478 StringBuffer result = new StringBuffer(name);
481 result.append("/" + start + "-" + end);
484 return result.toString();
494 public void setName(String name)
503 * @return DOCUMENT ME!
506 public String getName()
518 public void setStart(int start)
526 * @return DOCUMENT ME!
529 public int getStart()
541 public void setEnd(int end)
549 * @return DOCUMENT ME!
560 * @return DOCUMENT ME!
563 public int getLength()
565 return this.sequence.length;
575 public void setSequence(String seq)
577 this.sequence = seq.toCharArray();
582 public String getSequenceAsString()
584 return new String(sequence);
588 public String getSequenceAsString(int start, int end)
590 return new String(getSequence(start, end));
594 public char[] getSequence()
602 * @see jalview.datamodel.SequenceI#getSequence(int, int)
605 public char[] getSequence(int start, int end)
611 // JBPNote - left to user to pad the result here (TODO:Decide on this
613 if (start >= sequence.length)
618 if (end >= sequence.length)
620 end = sequence.length;
623 char[] reply = new char[end - start];
624 System.arraycopy(sequence, start, reply, 0, end - start);
630 public SequenceI getSubSequence(int start, int end)
636 char[] seq = getSequence(start, end);
641 int nstart = findPosition(start);
642 int nend = findPosition(end) - 1;
643 // JBPNote - this is an incomplete copy.
644 SequenceI nseq = new Sequence(this.getName(), seq, nstart, nend);
645 nseq.setDescription(description);
646 if (datasetSequence != null)
648 nseq.setDatasetSequence(datasetSequence);
652 nseq.setDatasetSequence(this);
658 * Returns the character of the aligned sequence at the given position (base
659 * zero), or space if the position is not within the sequence's bounds
664 public char getCharAt(int i)
666 if (i >= 0 && i < sequence.length)
683 public void setDescription(String desc)
685 this.description = desc;
691 * @return DOCUMENT ME!
694 public String getDescription()
696 return this.description;
702 * @see jalview.datamodel.SequenceI#findIndex(int)
705 public int findIndex(int pos)
707 // returns the alignment position for a residue
710 // Rely on end being at least as long as the length of the sequence.
711 while ((i < sequence.length) && (j <= end) && (j <= pos))
713 if (!jalview.util.Comparison.isGap(sequence[i]))
721 if ((j == end) && (j < pos))
732 public int findPosition(int i)
736 int seqlen = sequence.length;
737 while ((j < i) && (j < seqlen))
739 if (!jalview.util.Comparison.isGap(sequence[j]))
751 * Returns an int array where indices correspond to each residue in the
752 * sequence and the element value gives its position in the alignment
754 * @return int[SequenceI.getEnd()-SequenceI.getStart()+1] or null if no
755 * residues in SequenceI object
758 public int[] gapMap()
760 String seq = jalview.analysis.AlignSeq.extractGaps(
761 jalview.util.Comparison.GapChars, new String(sequence));
762 int[] map = new int[seq.length()];
766 while (j < sequence.length)
768 if (!jalview.util.Comparison.isGap(sequence[j]))
780 public int[] findPositionMap()
782 int map[] = new int[sequence.length];
785 int seqlen = sequence.length;
789 if (!jalview.util.Comparison.isGap(sequence[j]))
800 public List<int[]> getInsertions()
802 ArrayList<int[]> map = new ArrayList<>();
803 int lastj = -1, j = 0;
805 int seqlen = sequence.length;
808 if (jalview.util.Comparison.isGap(sequence[j]))
819 map.add(new int[] { lastj, j - 1 });
827 map.add(new int[] { lastj, j - 1 });
834 public void deleteChars(int i, int j)
836 int newstart = start, newend = end;
837 if (i >= sequence.length || i < 0)
842 char[] tmp = StringUtils.deleteChars(sequence, i, j);
843 boolean createNewDs = false;
844 // TODO: take a (second look) at the dataset creation validation method for
845 // the very large sequence case
846 int eindex = -1, sindex = -1;
847 boolean ecalc = false, scalc = false;
848 for (int s = i; s < j; s++)
850 if (jalview.schemes.ResidueProperties.aaIndex[sequence[s]] != 23)
860 sindex = findIndex(start) - 1;
865 // delete characters including start of sequence
866 newstart = findPosition(j);
867 break; // don't need to search for any more residue characters.
871 // delete characters after start.
874 eindex = findIndex(end) - 1;
879 // delete characters at end of sequence
880 newend = findPosition(i - 1);
881 break; // don't need to search for any more residue characters.
886 newend--; // decrease end position by one for the deleted residue
887 // and search further
893 // deletion occured in the middle of the sequence
894 if (createNewDs && this.datasetSequence != null)
896 // construct a new sequence
897 Sequence ds = new Sequence(datasetSequence);
898 // TODO: remove any non-inheritable properties ?
899 // TODO: create a sequence mapping (since there is a relation here ?)
900 ds.deleteChars(i, j);
901 datasetSequence = ds;
909 public void insertCharAt(int i, int length, char c)
911 char[] tmp = new char[sequence.length + length];
913 if (i >= sequence.length)
915 System.arraycopy(sequence, 0, tmp, 0, sequence.length);
920 System.arraycopy(sequence, 0, tmp, 0, i);
930 if (i < sequence.length)
932 System.arraycopy(sequence, i, tmp, index, sequence.length - i);
939 public void insertCharAt(int i, char c)
941 insertCharAt(i, 1, c);
945 public String getVamsasId()
951 public void setVamsasId(String id)
957 public void setDBRefs(DBRefEntry[] dbref)
959 if (dbrefs == null && datasetSequence != null
960 && this != datasetSequence)
962 datasetSequence.setDBRefs(dbref);
968 DBRefUtils.ensurePrimaries(this);
973 public DBRefEntry[] getDBRefs()
975 if (dbrefs == null && datasetSequence != null
976 && this != datasetSequence)
978 return datasetSequence.getDBRefs();
984 public void addDBRef(DBRefEntry entry)
986 if (datasetSequence != null)
988 datasetSequence.addDBRef(entry);
994 dbrefs = new DBRefEntry[0];
997 for (DBRefEntryI dbr : dbrefs)
999 if (dbr.updateFrom(entry))
1002 * found a dbref that either matched, or could be
1003 * updated from, the new entry - no need to add it
1010 * extend the array to make room for one more
1012 // TODO use an ArrayList instead
1013 int j = dbrefs.length;
1014 DBRefEntry[] temp = new DBRefEntry[j + 1];
1015 System.arraycopy(dbrefs, 0, temp, 0, j);
1016 temp[temp.length - 1] = entry;
1020 DBRefUtils.ensurePrimaries(this);
1024 public void setDatasetSequence(SequenceI seq)
1028 throw new IllegalArgumentException(
1029 "Implementation Error: self reference passed to SequenceI.setDatasetSequence");
1031 if (seq != null && seq.getDatasetSequence() != null)
1033 throw new IllegalArgumentException(
1034 "Implementation error: cascading dataset sequences are not allowed.");
1036 datasetSequence = seq;
1040 public SequenceI getDatasetSequence()
1042 return datasetSequence;
1046 public AlignmentAnnotation[] getAnnotation()
1048 return annotation == null ? null : annotation
1049 .toArray(new AlignmentAnnotation[annotation.size()]);
1053 public boolean hasAnnotation(AlignmentAnnotation ann)
1055 return annotation == null ? false : annotation.contains(ann);
1059 public void addAlignmentAnnotation(AlignmentAnnotation annotation)
1061 if (this.annotation == null)
1063 this.annotation = new Vector<>();
1065 if (!this.annotation.contains(annotation))
1067 this.annotation.addElement(annotation);
1069 annotation.setSequenceRef(this);
1073 public void removeAlignmentAnnotation(AlignmentAnnotation annotation)
1075 if (this.annotation != null)
1077 this.annotation.removeElement(annotation);
1078 if (this.annotation.size() == 0)
1080 this.annotation = null;
1086 * test if this is a valid candidate for another sequence's dataset sequence.
1089 private boolean isValidDatasetSequence()
1091 if (datasetSequence != null)
1095 for (int i = 0; i < sequence.length; i++)
1097 if (jalview.util.Comparison.isGap(sequence[i]))
1106 public SequenceI deriveSequence()
1108 Sequence seq = null;
1109 if (datasetSequence == null)
1111 if (isValidDatasetSequence())
1113 // Use this as dataset sequence
1114 seq = new Sequence(getName(), "", 1, -1);
1115 seq.setDatasetSequence(this);
1116 seq.initSeqFrom(this, getAnnotation());
1121 // Create a new, valid dataset sequence
1122 createDatasetSequence();
1125 return new Sequence(this);
1128 private boolean _isNa;
1130 private long _seqhash = 0;
1133 * Answers false if the sequence is more than 85% nucleotide (ACGTU), else
1137 public boolean isProtein()
1139 if (datasetSequence != null)
1141 return datasetSequence.isProtein();
1143 if (_seqhash != sequence.hashCode())
1145 _seqhash = sequence.hashCode();
1146 _isNa = Comparison.isNucleotide(this);
1154 * @see jalview.datamodel.SequenceI#createDatasetSequence()
1157 public SequenceI createDatasetSequence()
1159 if (datasetSequence == null)
1161 Sequence dsseq = new Sequence(getName(), AlignSeq.extractGaps(
1162 jalview.util.Comparison.GapChars, getSequenceAsString()),
1163 getStart(), getEnd());
1165 datasetSequence = dsseq;
1167 dsseq.setDescription(description);
1168 // move features and database references onto dataset sequence
1169 dsseq.sequenceFeatures = sequenceFeatures;
1170 sequenceFeatures = null;
1171 dsseq.dbrefs = dbrefs;
1173 // TODO: search and replace any references to this sequence with
1174 // references to the dataset sequence in Mappings on dbref
1175 dsseq.pdbIds = pdbIds;
1177 datasetSequence.updatePDBIds();
1178 if (annotation != null)
1180 // annotation is cloned rather than moved, to preserve what's currently
1182 for (AlignmentAnnotation aa : annotation)
1184 AlignmentAnnotation _aa = new AlignmentAnnotation(aa);
1185 _aa.sequenceRef = datasetSequence;
1186 _aa.adjustForAlignment(); // uses annotation's own record of
1187 // sequence-column mapping
1188 datasetSequence.addAlignmentAnnotation(_aa);
1192 return datasetSequence;
1199 * jalview.datamodel.SequenceI#setAlignmentAnnotation(AlignmmentAnnotation[]
1203 public void setAlignmentAnnotation(AlignmentAnnotation[] annotations)
1205 if (annotation != null)
1207 annotation.removeAllElements();
1209 if (annotations != null)
1211 for (int i = 0; i < annotations.length; i++)
1213 if (annotations[i] != null)
1215 addAlignmentAnnotation(annotations[i]);
1222 public AlignmentAnnotation[] getAnnotation(String label)
1224 if (annotation == null || annotation.size() == 0)
1229 Vector subset = new Vector();
1230 Enumeration e = annotation.elements();
1231 while (e.hasMoreElements())
1233 AlignmentAnnotation ann = (AlignmentAnnotation) e.nextElement();
1234 if (ann.label != null && ann.label.equals(label))
1236 subset.addElement(ann);
1239 if (subset.size() == 0)
1243 AlignmentAnnotation[] anns = new AlignmentAnnotation[subset.size()];
1245 e = subset.elements();
1246 while (e.hasMoreElements())
1248 anns[i++] = (AlignmentAnnotation) e.nextElement();
1250 subset.removeAllElements();
1255 public boolean updatePDBIds()
1257 if (datasetSequence != null)
1259 // TODO: could merge DBRefs
1260 return datasetSequence.updatePDBIds();
1262 if (dbrefs == null || dbrefs.length == 0)
1266 boolean added = false;
1267 for (DBRefEntry dbr : dbrefs)
1269 if (DBRefSource.PDB.equals(dbr.getSource()))
1272 * 'Add' any PDB dbrefs as a PDBEntry - add is only performed if the
1273 * PDB id is not already present in a 'matching' PDBEntry
1274 * Constructor parses out a chain code if appended to the accession id
1275 * (a fudge used to 'store' the chain code in the DBRef)
1277 PDBEntry pdbe = new PDBEntry(dbr);
1278 added |= addPDBId(pdbe);
1285 public void transferAnnotation(SequenceI entry, Mapping mp)
1287 if (datasetSequence != null)
1289 datasetSequence.transferAnnotation(entry, mp);
1292 if (entry.getDatasetSequence() != null)
1294 transferAnnotation(entry.getDatasetSequence(), mp);
1297 // transfer any new features from entry onto sequence
1298 if (entry.getSequenceFeatures() != null)
1301 SequenceFeature[] sfs = entry.getSequenceFeatures();
1302 for (int si = 0; si < sfs.length; si++)
1304 SequenceFeature sf[] = (mp != null) ? mp.locateFeature(sfs[si])
1305 : new SequenceFeature[] { new SequenceFeature(sfs[si]) };
1306 if (sf != null && sf.length > 0)
1308 for (int sfi = 0; sfi < sf.length; sfi++)
1310 addSequenceFeature(sf[sfi]);
1316 // transfer PDB entries
1317 if (entry.getAllPDBEntries() != null)
1319 Enumeration e = entry.getAllPDBEntries().elements();
1320 while (e.hasMoreElements())
1322 PDBEntry pdb = (PDBEntry) e.nextElement();
1326 // transfer database references
1327 DBRefEntry[] entryRefs = entry.getDBRefs();
1328 if (entryRefs != null)
1330 for (int r = 0; r < entryRefs.length; r++)
1332 DBRefEntry newref = new DBRefEntry(entryRefs[r]);
1333 if (newref.getMap() != null && mp != null)
1335 // remap ref using our local mapping
1337 // we also assume all version string setting is done by dbSourceProxy
1339 * if (!newref.getSource().equalsIgnoreCase(dbSource)) {
1340 * newref.setSource(dbSource); }
1348 * @return The index (zero-based) on this sequence in the MSA. It returns
1349 * {@code -1} if this information is not available.
1352 public int getIndex()
1358 * Defines the position of this sequence in the MSA. Use the value {@code -1}
1359 * if this information is undefined.
1362 * position for this sequence. This value is zero-based (zero for
1363 * this first sequence)
1366 public void setIndex(int value)
1372 public void setRNA(RNA r)
1384 public List<AlignmentAnnotation> getAlignmentAnnotations(String calcId,
1387 List<AlignmentAnnotation> result = new ArrayList<>();
1388 if (this.annotation != null)
1390 for (AlignmentAnnotation ann : annotation)
1392 if (ann.calcId != null && ann.calcId.equals(calcId)
1393 && ann.label != null && ann.label.equals(label))
1403 public String toString()
1405 return getDisplayId(false);
1409 public PDBEntry getPDBEntry(String pdbIdStr)
1411 if (getDatasetSequence() != null)
1413 return getDatasetSequence().getPDBEntry(pdbIdStr);
1419 List<PDBEntry> entries = getAllPDBEntries();
1420 for (PDBEntry entry : entries)
1422 if (entry.getId().equalsIgnoreCase(pdbIdStr))
1431 public List<DBRefEntry> getPrimaryDBRefs()
1433 if (datasetSequence != null)
1435 return datasetSequence.getPrimaryDBRefs();
1437 if (dbrefs == null || dbrefs.length == 0)
1439 return Collections.emptyList();
1441 synchronized (dbrefs)
1443 List<DBRefEntry> primaries = new ArrayList<>();
1444 DBRefEntry[] tmp = new DBRefEntry[1];
1445 for (DBRefEntry ref : dbrefs)
1447 if (!ref.isPrimaryCandidate())
1453 MapList mp = ref.getMap().getMap();
1454 if (mp.getFromLowest() > start || mp.getFromHighest() < end)
1456 // map only involves a subsequence, so cannot be primary
1460 // whilst it looks like it is a primary ref, we also sanity check type
1461 if (DBRefUtils.getCanonicalName(DBRefSource.PDB).equals(
1462 DBRefUtils.getCanonicalName(ref.getSource())))
1464 // PDB dbrefs imply there should be a PDBEntry associated
1465 // TODO: tighten PDB dbrefs
1466 // formally imply Jalview has actually downloaded and
1467 // parsed the pdb file. That means there should be a cached file
1468 // handle on the PDBEntry, and a real mapping between sequence and
1469 // extracted sequence from PDB file
1470 PDBEntry pdbentry = getPDBEntry(ref.getAccessionId());
1471 if (pdbentry != null && pdbentry.getFile() != null)
1477 // check standard protein or dna sources
1479 DBRefEntry[] res = DBRefUtils.selectDbRefs(!isProtein(), tmp);
1480 if (res != null && res[0] == tmp[0])
1491 public HiddenMarkovModel getHMM()
1497 public void setHMM(HiddenMarkovModel hmm)
1503 public void updateHMMMapping()
1507 for (char residue : sequence)
1509 if (!Comparison.isGap(residue))
1511 hmm.setAlignmentColumn(node, column);
1512 hmm.getNodeLookup().put(column, node);
1517 hmm.getNodeLookup().remove(column);
1525 public boolean isHMMConsensusSequence()
1527 return isHMMConsensusSequence;
1531 public void setIsHMMConsensusSequence(boolean isHMMConsensusSequence)
1533 this.isHMMConsensusSequence = isHMMConsensusSequence;
1537 public boolean hasHMMAnnotation()
1541 if (annotation == null)
1546 for (AlignmentAnnotation annot : annotation)
1548 if (annot.label.contains("_HMM"))
1558 public void setHasInfo(boolean status)
1564 public int getPreviousPosition()
1566 return previousPosition;
1570 public void setPreviousPosition(int previousPosition)
1572 this.previousPosition = previousPosition;