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 HiddenMarkovModel hmm;
62 boolean isHMMConsensusSequence = false;
64 Vector<PDBEntry> pdbIds;
73 * This annotation is displayed below the alignment but the positions are tied
74 * to the residues of this sequence
76 * TODO: change to List<>
78 Vector<AlignmentAnnotation> annotation;
81 * The index of the sequence in a MSA
85 /** array of sequence features - may not be null for a valid sequence object */
86 public SequenceFeature[] sequenceFeatures;
89 * Creates a new Sequence object.
94 * string to form a possibly gapped sequence out of
96 * first position of non-gap residue in the sequence
98 * last position of ungapped residues (nearly always only used for
101 public Sequence(String name, String sequence, int start, int end)
103 initSeqAndName(name, sequence.toCharArray(), start, end);
106 public Sequence(String name, char[] sequence, int start, int end)
108 initSeqAndName(name, sequence, start, end);
112 * Stage 1 constructor - assign name, sequence, and set start and end fields.
113 * start and end are updated values from name2 if it ends with /start-end
120 protected void initSeqAndName(String name2, char[] sequence2, int start2,
124 this.sequence = sequence2;
131 com.stevesoft.pat.Regex limitrx = new com.stevesoft.pat.Regex(
132 "[/][0-9]{1,}[-][0-9]{1,}$");
134 com.stevesoft.pat.Regex endrx = new com.stevesoft.pat.Regex("[0-9]{1,}$");
141 .println("POSSIBLE IMPLEMENTATION ERROR: null sequence name passed to constructor.");
144 // Does sequence have the /start-end signature?
145 if (limitrx.search(name))
147 name = limitrx.left();
148 endrx.search(limitrx.stringMatched());
149 setStart(Integer.parseInt(limitrx.stringMatched().substring(1,
150 endrx.matchedFrom() - 1)));
151 setEnd(Integer.parseInt(endrx.stringMatched()));
155 void checkValidRange()
158 // http://issues.jalview.org/browse/JAL-774?focusedCommentId=11239&page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel#comment-11239
161 for (int j = 0; j < sequence.length; j++)
163 if (!jalview.util.Comparison.isGap(sequence[j]))
182 * Creates a new Sequence object.
189 public Sequence(String name, String sequence)
191 this(name, sequence, 1, -1);
195 * Creates a new Sequence object with new AlignmentAnnotations but inherits
196 * any existing dataset sequence reference. If non exists, everything is
200 * if seq is a dataset sequence, behaves like a plain old copy
203 public Sequence(SequenceI seq)
205 this(seq, seq.getAnnotation());
209 * Create a new sequence object with new features, DBRefEntries, and PDBIds
210 * but inherits any existing dataset sequence reference, and duplicate of any
211 * annotation that is present in the given annotation array.
214 * the sequence to be copied
215 * @param alAnnotation
216 * an array of annotation including some associated with seq
218 public Sequence(SequenceI seq, AlignmentAnnotation[] alAnnotation)
220 initSeqFrom(seq, alAnnotation);
225 * does the heavy lifting when cloning a dataset sequence, or coping data from
226 * dataset to a new derived sequence.
229 * - source of attributes.
230 * @param alAnnotation
231 * - alignment annotation present on seq that should be copied onto
234 protected void initSeqFrom(SequenceI seq,
235 AlignmentAnnotation[] alAnnotation)
238 char[] oseq = seq.getSequence();
239 initSeqAndName(seq.getName(), Arrays.copyOf(oseq, oseq.length),
240 seq.getStart(), seq.getEnd());
242 description = seq.getDescription();
243 if (seq != datasetSequence)
245 setDatasetSequence(seq.getDatasetSequence());
247 if (datasetSequence == null && seq.getDBRefs() != null)
249 // only copy DBRefs and seqfeatures if we really are a dataset sequence
250 DBRefEntry[] dbr = seq.getDBRefs();
251 for (int i = 0; i < dbr.length; i++)
253 addDBRef(new DBRefEntry(dbr[i]));
255 if (seq.getSequenceFeatures() != null)
257 SequenceFeature[] sf = seq.getSequenceFeatures();
258 for (int i = 0; i < sf.length; i++)
260 addSequenceFeature(new SequenceFeature(sf[i]));
264 if (seq.getAnnotation() != null)
266 AlignmentAnnotation[] sqann = seq.getAnnotation();
267 for (int i = 0; i < sqann.length; i++)
269 if (sqann[i] == null)
273 boolean found = (alAnnotation == null);
276 for (int apos = 0; !found && apos < alAnnotation.length; apos++)
278 found = (alAnnotation[apos] == sqann[i]);
283 // only copy the given annotation
284 AlignmentAnnotation newann = new AlignmentAnnotation(sqann[i]);
285 addAlignmentAnnotation(newann);
289 if (seq.getAllPDBEntries() != null)
291 Vector<PDBEntry> ids = seq.getAllPDBEntries();
292 for (PDBEntry pdb : ids)
294 this.addPDBId(new PDBEntry(pdb));
297 if (seq.getHMM() != null)
299 this.hmm = new HiddenMarkovModel(seq.getHMM());
304 public void setSequenceFeatures(SequenceFeature[] features)
306 if (datasetSequence == null)
308 sequenceFeatures = features;
312 if (datasetSequence.getSequenceFeatures() != features
313 && datasetSequence.getSequenceFeatures() != null
314 && datasetSequence.getSequenceFeatures().length > 0)
317 "Warning: JAL-2046 side effect ? Possible implementation error: overwriting dataset sequence features by setting sequence features on alignment")
320 datasetSequence.setSequenceFeatures(features);
325 public synchronized boolean addSequenceFeature(SequenceFeature sf)
327 if (sequenceFeatures == null && datasetSequence != null)
329 return datasetSequence.addSequenceFeature(sf);
331 if (sequenceFeatures == null)
333 sequenceFeatures = new SequenceFeature[0];
336 for (int i = 0; i < sequenceFeatures.length; i++)
338 if (sequenceFeatures[i].equals(sf))
344 SequenceFeature[] temp = new SequenceFeature[sequenceFeatures.length + 1];
345 System.arraycopy(sequenceFeatures, 0, temp, 0, sequenceFeatures.length);
346 temp[sequenceFeatures.length] = sf;
348 sequenceFeatures = temp;
353 public void deleteFeature(SequenceFeature sf)
355 if (sequenceFeatures == null)
357 if (datasetSequence != null)
359 datasetSequence.deleteFeature(sf);
365 for (index = 0; index < sequenceFeatures.length; index++)
367 if (sequenceFeatures[index].equals(sf))
373 if (index == sequenceFeatures.length)
378 int sfLength = sequenceFeatures.length;
381 sequenceFeatures = null;
385 SequenceFeature[] temp = new SequenceFeature[sfLength - 1];
386 System.arraycopy(sequenceFeatures, 0, temp, 0, index);
388 if (index < sfLength)
390 System.arraycopy(sequenceFeatures, index + 1, temp, index,
391 sequenceFeatures.length - index - 1);
394 sequenceFeatures = temp;
399 * Returns the sequence features (if any), looking first on the sequence, then
400 * on its dataset sequence, and so on until a non-null value is found (or
401 * none). This supports retrieval of sequence features stored on the sequence
402 * (as in the applet) or on the dataset sequence (as in the Desktop version).
407 public SequenceFeature[] getSequenceFeatures()
409 SequenceFeature[] features = sequenceFeatures;
411 SequenceI seq = this;
412 int count = 0; // failsafe against loop in sequence.datasetsequence...
413 while (features == null && seq.getDatasetSequence() != null
416 seq = seq.getDatasetSequence();
417 features = ((Sequence) seq).sequenceFeatures;
423 public boolean addPDBId(PDBEntry entry)
427 pdbIds = new Vector<>();
432 for (PDBEntry pdbe : pdbIds)
434 if (pdbe.updateFrom(entry))
439 pdbIds.addElement(entry);
450 public void setPDBId(Vector<PDBEntry> id)
458 * @return DOCUMENT ME!
461 public Vector<PDBEntry> getAllPDBEntries()
463 return pdbIds == null ? new Vector<PDBEntry>() : pdbIds;
469 * @return DOCUMENT ME!
472 public String getDisplayId(boolean jvsuffix)
474 StringBuffer result = new StringBuffer(name);
477 result.append("/" + start + "-" + end);
480 return result.toString();
490 public void setName(String name)
499 * @return DOCUMENT ME!
502 public String getName()
514 public void setStart(int start)
522 * @return DOCUMENT ME!
525 public int getStart()
537 public void setEnd(int end)
545 * @return DOCUMENT ME!
556 * @return DOCUMENT ME!
559 public int getLength()
561 return this.sequence.length;
571 public void setSequence(String seq)
573 this.sequence = seq.toCharArray();
578 public String getSequenceAsString()
580 return new String(sequence);
584 public String getSequenceAsString(int start, int end)
586 return new String(getSequence(start, end));
590 public char[] getSequence()
598 * @see jalview.datamodel.SequenceI#getSequence(int, int)
601 public char[] getSequence(int start, int end)
607 // JBPNote - left to user to pad the result here (TODO:Decide on this
609 if (start >= sequence.length)
614 if (end >= sequence.length)
616 end = sequence.length;
619 char[] reply = new char[end - start];
620 System.arraycopy(sequence, start, reply, 0, end - start);
626 public SequenceI getSubSequence(int start, int end)
632 char[] seq = getSequence(start, end);
637 int nstart = findPosition(start);
638 int nend = findPosition(end) - 1;
639 // JBPNote - this is an incomplete copy.
640 SequenceI nseq = new Sequence(this.getName(), seq, nstart, nend);
641 nseq.setDescription(description);
642 if (datasetSequence != null)
644 nseq.setDatasetSequence(datasetSequence);
648 nseq.setDatasetSequence(this);
654 * Returns the character of the aligned sequence at the given position (base
655 * zero), or space if the position is not within the sequence's bounds
660 public char getCharAt(int i)
662 if (i >= 0 && i < sequence.length)
679 public void setDescription(String desc)
681 this.description = desc;
687 * @return DOCUMENT ME!
690 public String getDescription()
692 return this.description;
698 * @see jalview.datamodel.SequenceI#findIndex(int)
701 public int findIndex(int pos)
703 // returns the alignment position for a residue
706 // Rely on end being at least as long as the length of the sequence.
707 while ((i < sequence.length) && (j <= end) && (j <= pos))
709 if (!jalview.util.Comparison.isGap(sequence[i]))
717 if ((j == end) && (j < pos))
728 public int findPosition(int i)
732 int seqlen = sequence.length;
733 while ((j < i) && (j < seqlen))
735 if (!jalview.util.Comparison.isGap(sequence[j]))
747 * Returns an int array where indices correspond to each residue in the
748 * sequence and the element value gives its position in the alignment
750 * @return int[SequenceI.getEnd()-SequenceI.getStart()+1] or null if no
751 * residues in SequenceI object
754 public int[] gapMap()
756 String seq = jalview.analysis.AlignSeq.extractGaps(
757 jalview.util.Comparison.GapChars, new String(sequence));
758 int[] map = new int[seq.length()];
762 while (j < sequence.length)
764 if (!jalview.util.Comparison.isGap(sequence[j]))
776 public int[] findPositionMap()
778 int map[] = new int[sequence.length];
781 int seqlen = sequence.length;
785 if (!jalview.util.Comparison.isGap(sequence[j]))
796 public List<int[]> getInsertions()
798 ArrayList<int[]> map = new ArrayList<>();
799 int lastj = -1, j = 0;
801 int seqlen = sequence.length;
804 if (jalview.util.Comparison.isGap(sequence[j]))
815 map.add(new int[] { lastj, j - 1 });
823 map.add(new int[] { lastj, j - 1 });
830 public void deleteChars(int i, int j)
832 int newstart = start, newend = end;
833 if (i >= sequence.length || i < 0)
838 char[] tmp = StringUtils.deleteChars(sequence, i, j);
839 boolean createNewDs = false;
840 // TODO: take a (second look) at the dataset creation validation method for
841 // the very large sequence case
842 int eindex = -1, sindex = -1;
843 boolean ecalc = false, scalc = false;
844 for (int s = i; s < j; s++)
846 if (jalview.schemes.ResidueProperties.aaIndex[sequence[s]] != 23)
856 sindex = findIndex(start) - 1;
861 // delete characters including start of sequence
862 newstart = findPosition(j);
863 break; // don't need to search for any more residue characters.
867 // delete characters after start.
870 eindex = findIndex(end) - 1;
875 // delete characters at end of sequence
876 newend = findPosition(i - 1);
877 break; // don't need to search for any more residue characters.
882 newend--; // decrease end position by one for the deleted residue
883 // and search further
889 // deletion occured in the middle of the sequence
890 if (createNewDs && this.datasetSequence != null)
892 // construct a new sequence
893 Sequence ds = new Sequence(datasetSequence);
894 // TODO: remove any non-inheritable properties ?
895 // TODO: create a sequence mapping (since there is a relation here ?)
896 ds.deleteChars(i, j);
897 datasetSequence = ds;
905 public void insertCharAt(int i, int length, char c)
907 char[] tmp = new char[sequence.length + length];
909 if (i >= sequence.length)
911 System.arraycopy(sequence, 0, tmp, 0, sequence.length);
916 System.arraycopy(sequence, 0, tmp, 0, i);
926 if (i < sequence.length)
928 System.arraycopy(sequence, i, tmp, index, sequence.length - i);
935 public void insertCharAt(int i, char c)
937 insertCharAt(i, 1, c);
941 public String getVamsasId()
947 public void setVamsasId(String id)
953 public void setDBRefs(DBRefEntry[] dbref)
955 if (dbrefs == null && datasetSequence != null
956 && this != datasetSequence)
958 datasetSequence.setDBRefs(dbref);
964 DBRefUtils.ensurePrimaries(this);
969 public DBRefEntry[] getDBRefs()
971 if (dbrefs == null && datasetSequence != null
972 && this != datasetSequence)
974 return datasetSequence.getDBRefs();
980 public void addDBRef(DBRefEntry entry)
982 if (datasetSequence != null)
984 datasetSequence.addDBRef(entry);
990 dbrefs = new DBRefEntry[0];
993 for (DBRefEntryI dbr : dbrefs)
995 if (dbr.updateFrom(entry))
998 * found a dbref that either matched, or could be
999 * updated from, the new entry - no need to add it
1006 * extend the array to make room for one more
1008 // TODO use an ArrayList instead
1009 int j = dbrefs.length;
1010 DBRefEntry[] temp = new DBRefEntry[j + 1];
1011 System.arraycopy(dbrefs, 0, temp, 0, j);
1012 temp[temp.length - 1] = entry;
1016 DBRefUtils.ensurePrimaries(this);
1020 public void setDatasetSequence(SequenceI seq)
1024 throw new IllegalArgumentException(
1025 "Implementation Error: self reference passed to SequenceI.setDatasetSequence");
1027 if (seq != null && seq.getDatasetSequence() != null)
1029 throw new IllegalArgumentException(
1030 "Implementation error: cascading dataset sequences are not allowed.");
1032 datasetSequence = seq;
1036 public SequenceI getDatasetSequence()
1038 return datasetSequence;
1042 public AlignmentAnnotation[] getAnnotation()
1044 return annotation == null ? null : annotation
1045 .toArray(new AlignmentAnnotation[annotation.size()]);
1049 public boolean hasAnnotation(AlignmentAnnotation ann)
1051 return annotation == null ? false : annotation.contains(ann);
1055 public void addAlignmentAnnotation(AlignmentAnnotation annotation)
1057 if (this.annotation == null)
1059 this.annotation = new Vector<>();
1061 if (!this.annotation.contains(annotation))
1063 this.annotation.addElement(annotation);
1065 annotation.setSequenceRef(this);
1069 public void removeAlignmentAnnotation(AlignmentAnnotation annotation)
1071 if (this.annotation != null)
1073 this.annotation.removeElement(annotation);
1074 if (this.annotation.size() == 0)
1076 this.annotation = null;
1082 * test if this is a valid candidate for another sequence's dataset sequence.
1085 private boolean isValidDatasetSequence()
1087 if (datasetSequence != null)
1091 for (int i = 0; i < sequence.length; i++)
1093 if (jalview.util.Comparison.isGap(sequence[i]))
1102 public SequenceI deriveSequence()
1104 Sequence seq = null;
1105 if (datasetSequence == null)
1107 if (isValidDatasetSequence())
1109 // Use this as dataset sequence
1110 seq = new Sequence(getName(), "", 1, -1);
1111 seq.setDatasetSequence(this);
1112 seq.initSeqFrom(this, getAnnotation());
1117 // Create a new, valid dataset sequence
1118 createDatasetSequence();
1121 return new Sequence(this);
1124 private boolean _isNa;
1126 private long _seqhash = 0;
1129 * Answers false if the sequence is more than 85% nucleotide (ACGTU), else
1133 public boolean isProtein()
1135 if (datasetSequence != null)
1137 return datasetSequence.isProtein();
1139 if (_seqhash != sequence.hashCode())
1141 _seqhash = sequence.hashCode();
1142 _isNa = Comparison.isNucleotide(this);
1150 * @see jalview.datamodel.SequenceI#createDatasetSequence()
1153 public SequenceI createDatasetSequence()
1155 if (datasetSequence == null)
1157 Sequence dsseq = new Sequence(getName(), AlignSeq.extractGaps(
1158 jalview.util.Comparison.GapChars, getSequenceAsString()),
1159 getStart(), getEnd());
1161 datasetSequence = dsseq;
1163 dsseq.setDescription(description);
1164 // move features and database references onto dataset sequence
1165 dsseq.sequenceFeatures = sequenceFeatures;
1166 sequenceFeatures = null;
1167 dsseq.dbrefs = dbrefs;
1169 // TODO: search and replace any references to this sequence with
1170 // references to the dataset sequence in Mappings on dbref
1171 dsseq.pdbIds = pdbIds;
1173 datasetSequence.updatePDBIds();
1174 if (annotation != null)
1176 // annotation is cloned rather than moved, to preserve what's currently
1178 for (AlignmentAnnotation aa : annotation)
1180 AlignmentAnnotation _aa = new AlignmentAnnotation(aa);
1181 _aa.sequenceRef = datasetSequence;
1182 _aa.adjustForAlignment(); // uses annotation's own record of
1183 // sequence-column mapping
1184 datasetSequence.addAlignmentAnnotation(_aa);
1188 return datasetSequence;
1195 * jalview.datamodel.SequenceI#setAlignmentAnnotation(AlignmmentAnnotation[]
1199 public void setAlignmentAnnotation(AlignmentAnnotation[] annotations)
1201 if (annotation != null)
1203 annotation.removeAllElements();
1205 if (annotations != null)
1207 for (int i = 0; i < annotations.length; i++)
1209 if (annotations[i] != null)
1211 addAlignmentAnnotation(annotations[i]);
1218 public AlignmentAnnotation[] getAnnotation(String label)
1220 if (annotation == null || annotation.size() == 0)
1225 Vector subset = new Vector();
1226 Enumeration e = annotation.elements();
1227 while (e.hasMoreElements())
1229 AlignmentAnnotation ann = (AlignmentAnnotation) e.nextElement();
1230 if (ann.label != null && ann.label.equals(label))
1232 subset.addElement(ann);
1235 if (subset.size() == 0)
1239 AlignmentAnnotation[] anns = new AlignmentAnnotation[subset.size()];
1241 e = subset.elements();
1242 while (e.hasMoreElements())
1244 anns[i++] = (AlignmentAnnotation) e.nextElement();
1246 subset.removeAllElements();
1251 public boolean updatePDBIds()
1253 if (datasetSequence != null)
1255 // TODO: could merge DBRefs
1256 return datasetSequence.updatePDBIds();
1258 if (dbrefs == null || dbrefs.length == 0)
1262 boolean added = false;
1263 for (DBRefEntry dbr : dbrefs)
1265 if (DBRefSource.PDB.equals(dbr.getSource()))
1268 * 'Add' any PDB dbrefs as a PDBEntry - add is only performed if the
1269 * PDB id is not already present in a 'matching' PDBEntry
1270 * Constructor parses out a chain code if appended to the accession id
1271 * (a fudge used to 'store' the chain code in the DBRef)
1273 PDBEntry pdbe = new PDBEntry(dbr);
1274 added |= addPDBId(pdbe);
1281 public void transferAnnotation(SequenceI entry, Mapping mp)
1283 if (datasetSequence != null)
1285 datasetSequence.transferAnnotation(entry, mp);
1288 if (entry.getDatasetSequence() != null)
1290 transferAnnotation(entry.getDatasetSequence(), mp);
1293 // transfer any new features from entry onto sequence
1294 if (entry.getSequenceFeatures() != null)
1297 SequenceFeature[] sfs = entry.getSequenceFeatures();
1298 for (int si = 0; si < sfs.length; si++)
1300 SequenceFeature sf[] = (mp != null) ? mp.locateFeature(sfs[si])
1301 : new SequenceFeature[] { new SequenceFeature(sfs[si]) };
1302 if (sf != null && sf.length > 0)
1304 for (int sfi = 0; sfi < sf.length; sfi++)
1306 addSequenceFeature(sf[sfi]);
1312 // transfer PDB entries
1313 if (entry.getAllPDBEntries() != null)
1315 Enumeration e = entry.getAllPDBEntries().elements();
1316 while (e.hasMoreElements())
1318 PDBEntry pdb = (PDBEntry) e.nextElement();
1322 // transfer database references
1323 DBRefEntry[] entryRefs = entry.getDBRefs();
1324 if (entryRefs != null)
1326 for (int r = 0; r < entryRefs.length; r++)
1328 DBRefEntry newref = new DBRefEntry(entryRefs[r]);
1329 if (newref.getMap() != null && mp != null)
1331 // remap ref using our local mapping
1333 // we also assume all version string setting is done by dbSourceProxy
1335 * if (!newref.getSource().equalsIgnoreCase(dbSource)) {
1336 * newref.setSource(dbSource); }
1344 * @return The index (zero-based) on this sequence in the MSA. It returns
1345 * {@code -1} if this information is not available.
1348 public int getIndex()
1354 * Defines the position of this sequence in the MSA. Use the value {@code -1}
1355 * if this information is undefined.
1358 * position for this sequence. This value is zero-based (zero for
1359 * this first sequence)
1362 public void setIndex(int value)
1368 public void setRNA(RNA r)
1380 public List<AlignmentAnnotation> getAlignmentAnnotations(String calcId,
1383 List<AlignmentAnnotation> result = new ArrayList<>();
1384 if (this.annotation != null)
1386 for (AlignmentAnnotation ann : annotation)
1388 if (ann.calcId != null && ann.calcId.equals(calcId)
1389 && ann.label != null && ann.label.equals(label))
1399 public String toString()
1401 return getDisplayId(false);
1405 public PDBEntry getPDBEntry(String pdbIdStr)
1407 if (getDatasetSequence() != null)
1409 return getDatasetSequence().getPDBEntry(pdbIdStr);
1415 List<PDBEntry> entries = getAllPDBEntries();
1416 for (PDBEntry entry : entries)
1418 if (entry.getId().equalsIgnoreCase(pdbIdStr))
1427 public List<DBRefEntry> getPrimaryDBRefs()
1429 if (datasetSequence != null)
1431 return datasetSequence.getPrimaryDBRefs();
1433 if (dbrefs == null || dbrefs.length == 0)
1435 return Collections.emptyList();
1437 synchronized (dbrefs)
1439 List<DBRefEntry> primaries = new ArrayList<>();
1440 DBRefEntry[] tmp = new DBRefEntry[1];
1441 for (DBRefEntry ref : dbrefs)
1443 if (!ref.isPrimaryCandidate())
1449 MapList mp = ref.getMap().getMap();
1450 if (mp.getFromLowest() > start || mp.getFromHighest() < end)
1452 // map only involves a subsequence, so cannot be primary
1456 // whilst it looks like it is a primary ref, we also sanity check type
1457 if (DBRefUtils.getCanonicalName(DBRefSource.PDB).equals(
1458 DBRefUtils.getCanonicalName(ref.getSource())))
1460 // PDB dbrefs imply there should be a PDBEntry associated
1461 // TODO: tighten PDB dbrefs
1462 // formally imply Jalview has actually downloaded and
1463 // parsed the pdb file. That means there should be a cached file
1464 // handle on the PDBEntry, and a real mapping between sequence and
1465 // extracted sequence from PDB file
1466 PDBEntry pdbentry = getPDBEntry(ref.getAccessionId());
1467 if (pdbentry != null && pdbentry.getFile() != null)
1473 // check standard protein or dna sources
1475 DBRefEntry[] res = DBRefUtils.selectDbRefs(!isProtein(), tmp);
1476 if (res != null && res[0] == tmp[0])
1487 public HiddenMarkovModel getHMM()
1493 public void setHMM(HiddenMarkovModel hmm)
1499 public void updateHMMMapping()
1503 for (char residue : sequence)
1505 if (!Comparison.isGap(residue))
1507 hmm.setAlignmentColumn(node, column);
1508 hmm.getNodeLookup().put(column, node);
1513 hmm.getNodeLookup().remove(column);
1521 public boolean isHMMConsensusSequence()
1523 return isHMMConsensusSequence;
1527 public void setIsHMMConsensusSequence(boolean isHMMConsensusSequence)
1529 this.isHMMConsensusSequence = isHMMConsensusSequence;