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.BitSet;
33 import java.util.Collections;
34 import java.util.Enumeration;
35 import java.util.List;
36 import java.util.Vector;
38 import fr.orsay.lri.varna.models.rna.RNA;
42 * Implements the SequenceI interface for a char[] based sequence object.
47 public class Sequence extends ASequence implements SequenceI
49 SequenceI datasetSequence;
53 private char[] sequence;
65 HiddenMarkovModel hmm;
67 boolean isHMMConsensusSequence = false;
69 Vector<PDBEntry> pdbIds;
78 * This annotation is displayed below the alignment but the positions are tied
79 * to the residues of this sequence
81 * TODO: change to List<>
83 Vector<AlignmentAnnotation> annotation;
86 * The index of the sequence in a MSA
91 * array of sequence features - may not be null for a valid sequence object
93 public SequenceFeature[] sequenceFeatures;
96 * Creates a new Sequence object.
101 * string to form a possibly gapped sequence out of
103 * first position of non-gap residue in the sequence
105 * last position of ungapped residues (nearly always only used for
108 public Sequence(String name, String sequence, int start, int end)
110 initSeqAndName(name, sequence.toCharArray(), start, end);
113 public Sequence(String name, char[] sequence, int start, int end)
115 initSeqAndName(name, sequence, start, end);
119 * Stage 1 constructor - assign name, sequence, and set start and end fields.
120 * start and end are updated values from name2 if it ends with /start-end
127 protected void initSeqAndName(String name2, char[] sequence2, int start2,
131 this.sequence = sequence2;
138 com.stevesoft.pat.Regex limitrx = new com.stevesoft.pat.Regex(
139 "[/][0-9]{1,}[-][0-9]{1,}$");
141 com.stevesoft.pat.Regex endrx = new com.stevesoft.pat.Regex("[0-9]{1,}$");
148 "POSSIBLE IMPLEMENTATION ERROR: null sequence name passed to constructor.");
151 // Does sequence have the /start-end signature?
152 if (limitrx.search(name))
154 name = limitrx.left();
155 endrx.search(limitrx.stringMatched());
156 setStart(Integer.parseInt(limitrx.stringMatched().substring(1,
157 endrx.matchedFrom() - 1)));
158 setEnd(Integer.parseInt(endrx.stringMatched()));
162 void checkValidRange()
165 // http://issues.jalview.org/browse/JAL-774?focusedCommentId=11239&page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel#comment-11239
168 for (int j = 0; j < sequence.length; j++)
170 if (!jalview.util.Comparison.isGap(sequence[j]))
189 * Creates a new Sequence object.
196 public Sequence(String name, String sequence)
198 this(name, sequence, 1, -1);
202 * Creates a new Sequence object with new AlignmentAnnotations but inherits
203 * any existing dataset sequence reference. If non exists, everything is
207 * if seq is a dataset sequence, behaves like a plain old copy
210 public Sequence(SequenceI seq)
212 this(seq, seq.getAnnotation());
216 * Create a new sequence object with new features, DBRefEntries, and PDBIds
217 * but inherits any existing dataset sequence reference, and duplicate of any
218 * annotation that is present in the given annotation array.
221 * the sequence to be copied
222 * @param alAnnotation
223 * an array of annotation including some associated with seq
225 public Sequence(SequenceI seq, AlignmentAnnotation[] alAnnotation)
227 initSeqFrom(seq, alAnnotation);
232 * does the heavy lifting when cloning a dataset sequence, or coping data from
233 * dataset to a new derived sequence.
236 * - source of attributes.
237 * @param alAnnotation
238 * - alignment annotation present on seq that should be copied onto
241 protected void initSeqFrom(SequenceI seq,
242 AlignmentAnnotation[] alAnnotation)
245 char[] oseq = seq.getSequence();
246 initSeqAndName(seq.getName(), Arrays.copyOf(oseq, oseq.length),
247 seq.getStart(), seq.getEnd());
249 description = seq.getDescription();
250 if (seq != datasetSequence)
252 setDatasetSequence(seq.getDatasetSequence());
254 if (datasetSequence == null && seq.getDBRefs() != null)
256 // only copy DBRefs and seqfeatures if we really are a dataset sequence
257 DBRefEntry[] dbr = seq.getDBRefs();
258 for (int i = 0; i < dbr.length; i++)
260 addDBRef(new DBRefEntry(dbr[i]));
262 if (seq.getSequenceFeatures() != null)
264 SequenceFeature[] sf = seq.getSequenceFeatures();
265 for (int i = 0; i < sf.length; i++)
267 addSequenceFeature(new SequenceFeature(sf[i]));
271 if (seq.getAnnotation() != null)
273 AlignmentAnnotation[] sqann = seq.getAnnotation();
274 for (int i = 0; i < sqann.length; i++)
276 if (sqann[i] == null)
280 boolean found = (alAnnotation == null);
283 for (int apos = 0; !found && apos < alAnnotation.length; apos++)
285 found = (alAnnotation[apos] == sqann[i]);
290 // only copy the given annotation
291 AlignmentAnnotation newann = new AlignmentAnnotation(sqann[i]);
292 addAlignmentAnnotation(newann);
296 if (seq.getAllPDBEntries() != null)
298 Vector<PDBEntry> ids = seq.getAllPDBEntries();
299 for (PDBEntry pdb : ids)
301 this.addPDBId(new PDBEntry(pdb));
304 if (seq.getHMM() != null)
306 this.hmm = new HiddenMarkovModel(seq.getHMM());
311 public void setSequenceFeatures(SequenceFeature[] features)
313 if (datasetSequence == null)
315 sequenceFeatures = features;
319 if (datasetSequence.getSequenceFeatures() != features
320 && datasetSequence.getSequenceFeatures() != null
321 && datasetSequence.getSequenceFeatures().length > 0)
324 "Warning: JAL-2046 side effect ? Possible implementation error: overwriting dataset sequence features by setting sequence features on alignment")
327 datasetSequence.setSequenceFeatures(features);
332 public synchronized boolean addSequenceFeature(SequenceFeature sf)
334 if (sequenceFeatures == null && datasetSequence != null)
336 return datasetSequence.addSequenceFeature(sf);
338 if (sequenceFeatures == null)
340 sequenceFeatures = new SequenceFeature[0];
343 for (int i = 0; i < sequenceFeatures.length; i++)
345 if (sequenceFeatures[i].equals(sf))
351 SequenceFeature[] temp = new SequenceFeature[sequenceFeatures.length
353 System.arraycopy(sequenceFeatures, 0, temp, 0, sequenceFeatures.length);
354 temp[sequenceFeatures.length] = sf;
356 sequenceFeatures = temp;
361 public void deleteFeature(SequenceFeature sf)
363 if (sequenceFeatures == null)
365 if (datasetSequence != null)
367 datasetSequence.deleteFeature(sf);
373 for (index = 0; index < sequenceFeatures.length; index++)
375 if (sequenceFeatures[index].equals(sf))
381 if (index == sequenceFeatures.length)
386 int sfLength = sequenceFeatures.length;
389 sequenceFeatures = null;
393 SequenceFeature[] temp = new SequenceFeature[sfLength - 1];
394 System.arraycopy(sequenceFeatures, 0, temp, 0, index);
396 if (index < sfLength)
398 System.arraycopy(sequenceFeatures, index + 1, temp, index,
399 sequenceFeatures.length - index - 1);
402 sequenceFeatures = temp;
407 * Returns the sequence features (if any), looking first on the sequence, then
408 * on its dataset sequence, and so on until a non-null value is found (or
409 * none). This supports retrieval of sequence features stored on the sequence
410 * (as in the applet) or on the dataset sequence (as in the Desktop version).
415 public SequenceFeature[] getSequenceFeatures()
417 SequenceFeature[] features = sequenceFeatures;
419 SequenceI seq = this;
420 int count = 0; // failsafe against loop in sequence.datasetsequence...
421 while (features == null && seq.getDatasetSequence() != null
424 seq = seq.getDatasetSequence();
425 features = ((Sequence) seq).sequenceFeatures;
431 public boolean addPDBId(PDBEntry entry)
435 pdbIds = new Vector<>();
440 for (PDBEntry pdbe : pdbIds)
442 if (pdbe.updateFrom(entry))
447 pdbIds.addElement(entry);
458 public void setPDBId(Vector<PDBEntry> id)
466 * @return DOCUMENT ME!
469 public Vector<PDBEntry> getAllPDBEntries()
471 return pdbIds == null ? new Vector<PDBEntry>() : pdbIds;
477 * @return DOCUMENT ME!
480 public String getDisplayId(boolean jvsuffix)
482 StringBuffer result = new StringBuffer(name);
485 result.append("/" + start + "-" + end);
488 return result.toString();
498 public void setName(String name)
507 * @return DOCUMENT ME!
510 public String getName()
522 public void setStart(int start)
530 * @return DOCUMENT ME!
533 public int getStart()
545 public void setEnd(int end)
553 * @return DOCUMENT ME!
564 * @return DOCUMENT ME!
567 public int getLength()
569 return this.sequence.length;
579 public void setSequence(String seq)
581 this.sequence = seq.toCharArray();
586 public String getSequenceAsString()
588 return new String(sequence);
592 public String getSequenceAsString(int start, int end)
594 return new String(getSequence(start, end));
598 public char[] getSequence()
606 * @see jalview.datamodel.SequenceI#getSequence(int, int)
609 public char[] getSequence(int start, int end)
615 // JBPNote - left to user to pad the result here (TODO:Decide on this
617 if (start >= sequence.length)
622 if (end >= sequence.length)
624 end = sequence.length;
627 char[] reply = new char[end - start];
628 System.arraycopy(sequence, start, reply, 0, end - start);
634 public SequenceI getSubSequence(int start, int end)
640 char[] seq = getSequence(start, end);
645 int nstart = findPosition(start);
646 int nend = findPosition(end) - 1;
647 // JBPNote - this is an incomplete copy.
648 SequenceI nseq = new Sequence(this.getName(), seq, nstart, nend);
649 nseq.setDescription(description);
650 if (datasetSequence != null)
652 nseq.setDatasetSequence(datasetSequence);
656 nseq.setDatasetSequence(this);
662 * Returns the character of the aligned sequence at the given position (base
663 * zero), or space if the position is not within the sequence's bounds
668 public char getCharAt(int i)
670 if (i >= 0 && i < sequence.length)
687 public void setDescription(String desc)
689 this.description = desc;
695 * @return DOCUMENT ME!
698 public String getDescription()
700 return this.description;
706 * @see jalview.datamodel.SequenceI#findIndex(int)
709 public int findIndex(int pos)
711 // returns the alignment position for a residue
714 // Rely on end being at least as long as the length of the sequence.
715 while ((i < sequence.length) && (j <= end) && (j <= pos))
717 if (!jalview.util.Comparison.isGap(sequence[i]))
725 if ((j == end) && (j < pos))
736 public int findPosition(int i)
740 int seqlen = sequence.length;
741 while ((j < i) && (j < seqlen))
743 if (!jalview.util.Comparison.isGap(sequence[j]))
755 * Returns an int array where indices correspond to each residue in the
756 * sequence and the element value gives its position in the alignment
758 * @return int[SequenceI.getEnd()-SequenceI.getStart()+1] or null if no
759 * residues in SequenceI object
762 public int[] gapMap()
764 String seq = jalview.analysis.AlignSeq.extractGaps(
765 jalview.util.Comparison.GapChars, new String(sequence));
766 int[] map = new int[seq.length()];
770 while (j < sequence.length)
772 if (!jalview.util.Comparison.isGap(sequence[j]))
784 public int[] findPositionMap()
786 int map[] = new int[sequence.length];
789 int seqlen = sequence.length;
793 if (!jalview.util.Comparison.isGap(sequence[j]))
804 public List<int[]> getInsertions()
806 ArrayList<int[]> map = new ArrayList<>();
807 int lastj = -1, j = 0;
809 int seqlen = sequence.length;
812 if (jalview.util.Comparison.isGap(sequence[j]))
823 map.add(new int[] { lastj, j - 1 });
831 map.add(new int[] { lastj, j - 1 });
838 public BitSet getInsertionsAsBits()
840 BitSet map = new BitSet();
841 int lastj = -1, j = 0;
843 int seqlen = sequence.length;
846 if (jalview.util.Comparison.isGap(sequence[j]))
872 public void deleteChars(int i, int j)
874 int newstart = start, newend = end;
875 if (i >= sequence.length || i < 0)
880 char[] tmp = StringUtils.deleteChars(sequence, i, j);
881 boolean createNewDs = false;
882 // TODO: take a (second look) at the dataset creation validation method for
883 // the very large sequence case
884 int eindex = -1, sindex = -1;
885 boolean ecalc = false, scalc = false;
886 for (int s = i; s < j; s++)
888 if (jalview.schemes.ResidueProperties.aaIndex[sequence[s]] != 23)
898 sindex = findIndex(start) - 1;
903 // delete characters including start of sequence
904 newstart = findPosition(j);
905 break; // don't need to search for any more residue characters.
909 // delete characters after start.
912 eindex = findIndex(end) - 1;
917 // delete characters at end of sequence
918 newend = findPosition(i - 1);
919 break; // don't need to search for any more residue characters.
924 newend--; // decrease end position by one for the deleted residue
925 // and search further
931 // deletion occured in the middle of the sequence
932 if (createNewDs && this.datasetSequence != null)
934 // construct a new sequence
935 Sequence ds = new Sequence(datasetSequence);
936 // TODO: remove any non-inheritable properties ?
937 // TODO: create a sequence mapping (since there is a relation here ?)
938 ds.deleteChars(i, j);
939 datasetSequence = ds;
947 public void insertCharAt(int i, int length, char c)
949 char[] tmp = new char[sequence.length + length];
951 if (i >= sequence.length)
953 System.arraycopy(sequence, 0, tmp, 0, sequence.length);
958 System.arraycopy(sequence, 0, tmp, 0, i);
968 if (i < sequence.length)
970 System.arraycopy(sequence, i, tmp, index, sequence.length - i);
977 public void insertCharAt(int i, char c)
979 insertCharAt(i, 1, c);
983 public String getVamsasId()
989 public void setVamsasId(String id)
995 public void setDBRefs(DBRefEntry[] dbref)
997 if (dbrefs == null && datasetSequence != null
998 && this != datasetSequence)
1000 datasetSequence.setDBRefs(dbref);
1006 DBRefUtils.ensurePrimaries(this);
1011 public DBRefEntry[] getDBRefs()
1013 if (dbrefs == null && datasetSequence != null
1014 && this != datasetSequence)
1016 return datasetSequence.getDBRefs();
1022 public void addDBRef(DBRefEntry entry)
1024 if (datasetSequence != null)
1026 datasetSequence.addDBRef(entry);
1032 dbrefs = new DBRefEntry[0];
1035 for (DBRefEntryI dbr : dbrefs)
1037 if (dbr.updateFrom(entry))
1040 * found a dbref that either matched, or could be
1041 * updated from, the new entry - no need to add it
1048 * extend the array to make room for one more
1050 // TODO use an ArrayList instead
1051 int j = dbrefs.length;
1052 DBRefEntry[] temp = new DBRefEntry[j + 1];
1053 System.arraycopy(dbrefs, 0, temp, 0, j);
1054 temp[temp.length - 1] = entry;
1058 DBRefUtils.ensurePrimaries(this);
1062 public void setDatasetSequence(SequenceI seq)
1066 throw new IllegalArgumentException(
1067 "Implementation Error: self reference passed to SequenceI.setDatasetSequence");
1069 if (seq != null && seq.getDatasetSequence() != null)
1071 throw new IllegalArgumentException(
1072 "Implementation error: cascading dataset sequences are not allowed.");
1074 datasetSequence = seq;
1078 public SequenceI getDatasetSequence()
1080 return datasetSequence;
1084 public AlignmentAnnotation[] getAnnotation()
1086 return annotation == null ? null
1088 .toArray(new AlignmentAnnotation[annotation.size()]);
1092 public boolean hasAnnotation(AlignmentAnnotation ann)
1094 return annotation == null ? false : annotation.contains(ann);
1098 public void addAlignmentAnnotation(AlignmentAnnotation annotation)
1100 if (this.annotation == null)
1102 this.annotation = new Vector<>();
1104 if (!this.annotation.contains(annotation))
1106 this.annotation.addElement(annotation);
1108 annotation.setSequenceRef(this);
1112 public void removeAlignmentAnnotation(AlignmentAnnotation annotation)
1114 if (this.annotation != null)
1116 this.annotation.removeElement(annotation);
1117 if (this.annotation.size() == 0)
1119 this.annotation = null;
1125 * test if this is a valid candidate for another sequence's dataset sequence.
1128 private boolean isValidDatasetSequence()
1130 if (datasetSequence != null)
1134 for (int i = 0; i < sequence.length; i++)
1136 if (jalview.util.Comparison.isGap(sequence[i]))
1145 public SequenceI deriveSequence()
1147 Sequence seq = null;
1148 if (datasetSequence == null)
1150 if (isValidDatasetSequence())
1152 // Use this as dataset sequence
1153 seq = new Sequence(getName(), "", 1, -1);
1154 seq.setDatasetSequence(this);
1155 seq.initSeqFrom(this, getAnnotation());
1160 // Create a new, valid dataset sequence
1161 createDatasetSequence();
1164 return new Sequence(this);
1167 private boolean _isNa;
1169 private long _seqhash = 0;
1172 * Answers false if the sequence is more than 85% nucleotide (ACGTU), else
1176 public boolean isProtein()
1178 if (datasetSequence != null)
1180 return datasetSequence.isProtein();
1182 if (_seqhash != sequence.hashCode())
1184 _seqhash = sequence.hashCode();
1185 _isNa = Comparison.isNucleotide(this);
1193 * @see jalview.datamodel.SequenceI#createDatasetSequence()
1196 public SequenceI createDatasetSequence()
1198 if (datasetSequence == null)
1200 Sequence dsseq = new Sequence(getName(),
1201 AlignSeq.extractGaps(jalview.util.Comparison.GapChars,
1202 getSequenceAsString()),
1203 getStart(), getEnd());
1205 datasetSequence = dsseq;
1207 dsseq.setDescription(description);
1208 // move features and database references onto dataset sequence
1209 dsseq.sequenceFeatures = sequenceFeatures;
1210 sequenceFeatures = null;
1211 dsseq.dbrefs = dbrefs;
1213 // TODO: search and replace any references to this sequence with
1214 // references to the dataset sequence in Mappings on dbref
1215 dsseq.pdbIds = pdbIds;
1217 datasetSequence.updatePDBIds();
1218 if (annotation != null)
1220 // annotation is cloned rather than moved, to preserve what's currently
1222 for (AlignmentAnnotation aa : annotation)
1224 AlignmentAnnotation _aa = new AlignmentAnnotation(aa);
1225 _aa.sequenceRef = datasetSequence;
1226 _aa.adjustForAlignment(); // uses annotation's own record of
1227 // sequence-column mapping
1228 datasetSequence.addAlignmentAnnotation(_aa);
1232 return datasetSequence;
1239 * jalview.datamodel.SequenceI#setAlignmentAnnotation(AlignmmentAnnotation[]
1243 public void setAlignmentAnnotation(AlignmentAnnotation[] annotations)
1245 if (annotation != null)
1247 annotation.removeAllElements();
1249 if (annotations != null)
1251 for (int i = 0; i < annotations.length; i++)
1253 if (annotations[i] != null)
1255 addAlignmentAnnotation(annotations[i]);
1262 public AlignmentAnnotation[] getAnnotation(String label)
1264 if (annotation == null || annotation.size() == 0)
1269 Vector subset = new Vector();
1270 Enumeration e = annotation.elements();
1271 while (e.hasMoreElements())
1273 AlignmentAnnotation ann = (AlignmentAnnotation) e.nextElement();
1274 if (ann.label != null && ann.label.equals(label))
1276 subset.addElement(ann);
1279 if (subset.size() == 0)
1283 AlignmentAnnotation[] anns = new AlignmentAnnotation[subset.size()];
1285 e = subset.elements();
1286 while (e.hasMoreElements())
1288 anns[i++] = (AlignmentAnnotation) e.nextElement();
1290 subset.removeAllElements();
1295 public boolean updatePDBIds()
1297 if (datasetSequence != null)
1299 // TODO: could merge DBRefs
1300 return datasetSequence.updatePDBIds();
1302 if (dbrefs == null || dbrefs.length == 0)
1306 boolean added = false;
1307 for (DBRefEntry dbr : dbrefs)
1309 if (DBRefSource.PDB.equals(dbr.getSource()))
1312 * 'Add' any PDB dbrefs as a PDBEntry - add is only performed if the
1313 * PDB id is not already present in a 'matching' PDBEntry
1314 * Constructor parses out a chain code if appended to the accession id
1315 * (a fudge used to 'store' the chain code in the DBRef)
1317 PDBEntry pdbe = new PDBEntry(dbr);
1318 added |= addPDBId(pdbe);
1325 public void transferAnnotation(SequenceI entry, Mapping mp)
1327 if (datasetSequence != null)
1329 datasetSequence.transferAnnotation(entry, mp);
1332 if (entry.getDatasetSequence() != null)
1334 transferAnnotation(entry.getDatasetSequence(), mp);
1337 // transfer any new features from entry onto sequence
1338 if (entry.getSequenceFeatures() != null)
1341 SequenceFeature[] sfs = entry.getSequenceFeatures();
1342 for (int si = 0; si < sfs.length; si++)
1344 SequenceFeature sf[] = (mp != null) ? mp.locateFeature(sfs[si])
1345 : new SequenceFeature[]
1346 { new SequenceFeature(sfs[si]) };
1347 if (sf != null && sf.length > 0)
1349 for (int sfi = 0; sfi < sf.length; sfi++)
1351 addSequenceFeature(sf[sfi]);
1357 // transfer PDB entries
1358 if (entry.getAllPDBEntries() != null)
1360 Enumeration e = entry.getAllPDBEntries().elements();
1361 while (e.hasMoreElements())
1363 PDBEntry pdb = (PDBEntry) e.nextElement();
1367 // transfer database references
1368 DBRefEntry[] entryRefs = entry.getDBRefs();
1369 if (entryRefs != null)
1371 for (int r = 0; r < entryRefs.length; r++)
1373 DBRefEntry newref = new DBRefEntry(entryRefs[r]);
1374 if (newref.getMap() != null && mp != null)
1376 // remap ref using our local mapping
1378 // we also assume all version string setting is done by dbSourceProxy
1380 * if (!newref.getSource().equalsIgnoreCase(dbSource)) {
1381 * newref.setSource(dbSource); }
1389 * @return The index (zero-based) on this sequence in the MSA. It returns
1390 * {@code -1} if this information is not available.
1393 public int getIndex()
1399 * Defines the position of this sequence in the MSA. Use the value {@code -1}
1400 * if this information is undefined.
1403 * position for this sequence. This value is zero-based (zero for
1404 * this first sequence)
1407 public void setIndex(int value)
1413 public void setRNA(RNA r)
1425 public List<AlignmentAnnotation> getAlignmentAnnotations(String calcId,
1428 List<AlignmentAnnotation> result = new ArrayList<>();
1429 if (this.annotation != null)
1431 for (AlignmentAnnotation ann : annotation)
1433 if (ann.calcId != null && ann.calcId.equals(calcId)
1434 && ann.label != null && ann.label.equals(label))
1444 public String toString()
1446 return getDisplayId(false);
1450 public PDBEntry getPDBEntry(String pdbIdStr)
1452 if (getDatasetSequence() != null)
1454 return getDatasetSequence().getPDBEntry(pdbIdStr);
1460 List<PDBEntry> entries = getAllPDBEntries();
1461 for (PDBEntry entry : entries)
1463 if (entry.getId().equalsIgnoreCase(pdbIdStr))
1472 public List<DBRefEntry> getPrimaryDBRefs()
1474 if (datasetSequence != null)
1476 return datasetSequence.getPrimaryDBRefs();
1478 if (dbrefs == null || dbrefs.length == 0)
1480 return Collections.emptyList();
1482 synchronized (dbrefs)
1484 List<DBRefEntry> primaries = new ArrayList<>();
1485 DBRefEntry[] tmp = new DBRefEntry[1];
1486 for (DBRefEntry ref : dbrefs)
1488 if (!ref.isPrimaryCandidate())
1494 MapList mp = ref.getMap().getMap();
1495 if (mp.getFromLowest() > start || mp.getFromHighest() < end)
1497 // map only involves a subsequence, so cannot be primary
1501 // whilst it looks like it is a primary ref, we also sanity check type
1502 if (DBRefUtils.getCanonicalName(DBRefSource.PDB)
1503 .equals(DBRefUtils.getCanonicalName(ref.getSource())))
1505 // PDB dbrefs imply there should be a PDBEntry associated
1506 // TODO: tighten PDB dbrefs
1507 // formally imply Jalview has actually downloaded and
1508 // parsed the pdb file. That means there should be a cached file
1509 // handle on the PDBEntry, and a real mapping between sequence and
1510 // extracted sequence from PDB file
1511 PDBEntry pdbentry = getPDBEntry(ref.getAccessionId());
1512 if (pdbentry != null && pdbentry.getFile() != null)
1518 // check standard protein or dna sources
1520 DBRefEntry[] res = DBRefUtils.selectDbRefs(!isProtein(), tmp);
1521 if (res != null && res[0] == tmp[0])
1532 public HiddenMarkovModel getHMM()
1538 public void setHMM(HiddenMarkovModel hmm)
1544 public void updateHMMMapping()
1548 for (char residue : sequence)
1550 if (!Comparison.isGap(residue))
1552 hmm.setAlignmentColumn(node, column);
1553 hmm.getNodeLookup().put(column, node);
1558 hmm.getNodeLookup().remove(column);
1566 public boolean isHMMConsensusSequence()
1568 return isHMMConsensusSequence;
1572 public void setIsHMMConsensusSequence(boolean isHMMConsensusSequence)
1574 this.isHMMConsensusSequence = isHMMConsensusSequence;
1578 public boolean hasHMMAnnotation()
1582 if (annotation == null)
1587 for (AlignmentAnnotation annot : annotation)
1589 if (annot.label.contains("_HMM"))
1599 public void setHasInfo(boolean status)
1605 public int getPreviousPosition()
1607 return previousPosition;
1611 public void setPreviousPosition(int previousPosition)
1613 this.previousPosition = previousPosition;