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.isHMMConsensusSequence())
306 this.isHMMConsensusSequence = true;
308 if (seq.getHMM() != null)
310 this.hmm = new HiddenMarkovModel(seq.getHMM());
316 public void setSequenceFeatures(SequenceFeature[] features)
318 if (datasetSequence == null)
320 sequenceFeatures = features;
324 if (datasetSequence.getSequenceFeatures() != features
325 && datasetSequence.getSequenceFeatures() != null
326 && datasetSequence.getSequenceFeatures().length > 0)
329 "Warning: JAL-2046 side effect ? Possible implementation error: overwriting dataset sequence features by setting sequence features on alignment")
332 datasetSequence.setSequenceFeatures(features);
337 public synchronized boolean addSequenceFeature(SequenceFeature sf)
339 if (sequenceFeatures == null && datasetSequence != null)
341 return datasetSequence.addSequenceFeature(sf);
343 if (sequenceFeatures == null)
345 sequenceFeatures = new SequenceFeature[0];
348 for (int i = 0; i < sequenceFeatures.length; i++)
350 if (sequenceFeatures[i].equals(sf))
356 SequenceFeature[] temp = new SequenceFeature[sequenceFeatures.length
358 System.arraycopy(sequenceFeatures, 0, temp, 0, sequenceFeatures.length);
359 temp[sequenceFeatures.length] = sf;
361 sequenceFeatures = temp;
366 public void deleteFeature(SequenceFeature sf)
368 if (sequenceFeatures == null)
370 if (datasetSequence != null)
372 datasetSequence.deleteFeature(sf);
378 for (index = 0; index < sequenceFeatures.length; index++)
380 if (sequenceFeatures[index].equals(sf))
386 if (index == sequenceFeatures.length)
391 int sfLength = sequenceFeatures.length;
394 sequenceFeatures = null;
398 SequenceFeature[] temp = new SequenceFeature[sfLength - 1];
399 System.arraycopy(sequenceFeatures, 0, temp, 0, index);
401 if (index < sfLength)
403 System.arraycopy(sequenceFeatures, index + 1, temp, index,
404 sequenceFeatures.length - index - 1);
407 sequenceFeatures = temp;
412 * Returns the sequence features (if any), looking first on the sequence, then
413 * on its dataset sequence, and so on until a non-null value is found (or
414 * none). This supports retrieval of sequence features stored on the sequence
415 * (as in the applet) or on the dataset sequence (as in the Desktop version).
420 public SequenceFeature[] getSequenceFeatures()
422 SequenceFeature[] features = sequenceFeatures;
424 SequenceI seq = this;
425 int count = 0; // failsafe against loop in sequence.datasetsequence...
426 while (features == null && seq.getDatasetSequence() != null
429 seq = seq.getDatasetSequence();
430 features = ((Sequence) seq).sequenceFeatures;
436 public boolean addPDBId(PDBEntry entry)
440 pdbIds = new Vector<>();
445 for (PDBEntry pdbe : pdbIds)
447 if (pdbe.updateFrom(entry))
452 pdbIds.addElement(entry);
463 public void setPDBId(Vector<PDBEntry> id)
471 * @return DOCUMENT ME!
474 public Vector<PDBEntry> getAllPDBEntries()
476 return pdbIds == null ? new Vector<PDBEntry>() : pdbIds;
482 * @return DOCUMENT ME!
485 public String getDisplayId(boolean jvsuffix)
487 StringBuffer result = new StringBuffer(name);
490 result.append("/" + start + "-" + end);
493 return result.toString();
503 public void setName(String name)
512 * @return DOCUMENT ME!
515 public String getName()
527 public void setStart(int start)
535 * @return DOCUMENT ME!
538 public int getStart()
550 public void setEnd(int end)
558 * @return DOCUMENT ME!
569 * @return DOCUMENT ME!
572 public int getLength()
574 return this.sequence.length;
584 public void setSequence(String seq)
586 this.sequence = seq.toCharArray();
591 public String getSequenceAsString()
593 return new String(sequence);
597 public String getSequenceAsString(int start, int end)
599 return new String(getSequence(start, end));
603 public char[] getSequence()
611 * @see jalview.datamodel.SequenceI#getSequence(int, int)
614 public char[] getSequence(int start, int end)
620 // JBPNote - left to user to pad the result here (TODO:Decide on this
622 if (start >= sequence.length)
627 if (end >= sequence.length)
629 end = sequence.length;
632 char[] reply = new char[end - start];
633 System.arraycopy(sequence, start, reply, 0, end - start);
639 public SequenceI getSubSequence(int start, int end)
645 char[] seq = getSequence(start, end);
650 int nstart = findPosition(start);
651 int nend = findPosition(end) - 1;
652 // JBPNote - this is an incomplete copy.
653 SequenceI nseq = new Sequence(this.getName(), seq, nstart, nend);
654 nseq.setDescription(description);
655 if (datasetSequence != null)
657 nseq.setDatasetSequence(datasetSequence);
661 nseq.setDatasetSequence(this);
667 * Returns the character of the aligned sequence at the given position (base
668 * zero), or space if the position is not within the sequence's bounds
673 public char getCharAt(int i)
675 if (i >= 0 && i < sequence.length)
692 public void setDescription(String desc)
694 this.description = desc;
700 * @return DOCUMENT ME!
703 public String getDescription()
705 return this.description;
711 * @see jalview.datamodel.SequenceI#findIndex(int)
714 public int findIndex(int pos)
716 // returns the alignment position for a residue
719 // Rely on end being at least as long as the length of the sequence.
720 while ((i < sequence.length) && (j <= end) && (j <= pos))
722 if (!jalview.util.Comparison.isGap(sequence[i]))
730 if ((j == end) && (j < pos))
741 public int findPosition(int i)
745 int seqlen = sequence.length;
746 while ((j < i) && (j < seqlen))
748 if (!jalview.util.Comparison.isGap(sequence[j]))
760 * Returns an int array where indices correspond to each residue in the
761 * sequence and the element value gives its position in the alignment
763 * @return int[SequenceI.getEnd()-SequenceI.getStart()+1] or null if no
764 * residues in SequenceI object
767 public int[] gapMap()
769 String seq = jalview.analysis.AlignSeq.extractGaps(
770 jalview.util.Comparison.GapChars, new String(sequence));
771 int[] map = new int[seq.length()];
775 while (j < sequence.length)
777 if (!jalview.util.Comparison.isGap(sequence[j]))
789 public int[] findPositionMap()
791 int map[] = new int[sequence.length];
794 int seqlen = sequence.length;
798 if (!jalview.util.Comparison.isGap(sequence[j]))
809 public List<int[]> getInsertions()
811 ArrayList<int[]> map = new ArrayList<>();
812 int lastj = -1, j = 0;
814 int seqlen = sequence.length;
817 if (jalview.util.Comparison.isGap(sequence[j]))
828 map.add(new int[] { lastj, j - 1 });
836 map.add(new int[] { lastj, j - 1 });
843 public BitSet getInsertionsAsBits()
845 BitSet map = new BitSet();
846 int lastj = -1, j = 0;
848 int seqlen = sequence.length;
851 if (jalview.util.Comparison.isGap(sequence[j]))
877 public void deleteChars(int i, int j)
879 int newstart = start, newend = end;
880 if (i >= sequence.length || i < 0)
885 char[] tmp = StringUtils.deleteChars(sequence, i, j);
886 boolean createNewDs = false;
887 // TODO: take a (second look) at the dataset creation validation method for
888 // the very large sequence case
889 int eindex = -1, sindex = -1;
890 boolean ecalc = false, scalc = false;
891 for (int s = i; s < j; s++)
893 if (jalview.schemes.ResidueProperties.aaIndex[sequence[s]] != 23)
903 sindex = findIndex(start) - 1;
908 // delete characters including start of sequence
909 newstart = findPosition(j);
910 break; // don't need to search for any more residue characters.
914 // delete characters after start.
917 eindex = findIndex(end) - 1;
922 // delete characters at end of sequence
923 newend = findPosition(i - 1);
924 break; // don't need to search for any more residue characters.
929 newend--; // decrease end position by one for the deleted residue
930 // and search further
936 // deletion occured in the middle of the sequence
937 if (createNewDs && this.datasetSequence != null)
939 // construct a new sequence
940 Sequence ds = new Sequence(datasetSequence);
941 // TODO: remove any non-inheritable properties ?
942 // TODO: create a sequence mapping (since there is a relation here ?)
943 ds.deleteChars(i, j);
944 datasetSequence = ds;
952 public void insertCharAt(int i, int length, char c)
954 char[] tmp = new char[sequence.length + length];
956 if (i >= sequence.length)
958 System.arraycopy(sequence, 0, tmp, 0, sequence.length);
963 System.arraycopy(sequence, 0, tmp, 0, i);
973 if (i < sequence.length)
975 System.arraycopy(sequence, i, tmp, index, sequence.length - i);
982 public void insertCharAt(int i, char c)
984 insertCharAt(i, 1, c);
988 public String getVamsasId()
994 public void setVamsasId(String id)
1000 public void setDBRefs(DBRefEntry[] dbref)
1002 if (dbrefs == null && datasetSequence != null
1003 && this != datasetSequence)
1005 datasetSequence.setDBRefs(dbref);
1011 DBRefUtils.ensurePrimaries(this);
1016 public DBRefEntry[] getDBRefs()
1018 if (dbrefs == null && datasetSequence != null
1019 && this != datasetSequence)
1021 return datasetSequence.getDBRefs();
1027 public void addDBRef(DBRefEntry entry)
1029 if (datasetSequence != null)
1031 datasetSequence.addDBRef(entry);
1037 dbrefs = new DBRefEntry[0];
1040 for (DBRefEntryI dbr : dbrefs)
1042 if (dbr.updateFrom(entry))
1045 * found a dbref that either matched, or could be
1046 * updated from, the new entry - no need to add it
1053 * extend the array to make room for one more
1055 // TODO use an ArrayList instead
1056 int j = dbrefs.length;
1057 DBRefEntry[] temp = new DBRefEntry[j + 1];
1058 System.arraycopy(dbrefs, 0, temp, 0, j);
1059 temp[temp.length - 1] = entry;
1063 DBRefUtils.ensurePrimaries(this);
1067 public void setDatasetSequence(SequenceI seq)
1071 throw new IllegalArgumentException(
1072 "Implementation Error: self reference passed to SequenceI.setDatasetSequence");
1074 if (seq != null && seq.getDatasetSequence() != null)
1076 throw new IllegalArgumentException(
1077 "Implementation error: cascading dataset sequences are not allowed.");
1079 datasetSequence = seq;
1083 public SequenceI getDatasetSequence()
1085 return datasetSequence;
1089 public AlignmentAnnotation[] getAnnotation()
1091 return annotation == null ? null
1093 .toArray(new AlignmentAnnotation[annotation.size()]);
1097 public boolean hasAnnotation(AlignmentAnnotation ann)
1099 return annotation == null ? false : annotation.contains(ann);
1103 public void addAlignmentAnnotation(AlignmentAnnotation annotation)
1105 if (this.annotation == null)
1107 this.annotation = new Vector<>();
1109 if (!this.annotation.contains(annotation))
1111 this.annotation.addElement(annotation);
1113 annotation.setSequenceRef(this);
1117 public void removeAlignmentAnnotation(AlignmentAnnotation annotation)
1119 if (this.annotation != null)
1121 this.annotation.removeElement(annotation);
1122 if (this.annotation.size() == 0)
1124 this.annotation = null;
1130 * test if this is a valid candidate for another sequence's dataset sequence.
1133 private boolean isValidDatasetSequence()
1135 if (datasetSequence != null)
1139 for (int i = 0; i < sequence.length; i++)
1141 if (jalview.util.Comparison.isGap(sequence[i]))
1150 public SequenceI deriveSequence()
1152 Sequence seq = null;
1153 if (datasetSequence == null)
1155 if (isValidDatasetSequence())
1157 // Use this as dataset sequence
1158 seq = new Sequence(getName(), "", 1, -1);
1159 seq.setDatasetSequence(this);
1160 seq.initSeqFrom(this, getAnnotation());
1165 // Create a new, valid dataset sequence
1166 createDatasetSequence();
1169 return new Sequence(this);
1172 private boolean _isNa;
1174 private long _seqhash = 0;
1177 * Answers false if the sequence is more than 85% nucleotide (ACGTU), else
1181 public boolean isProtein()
1183 if (datasetSequence != null)
1185 return datasetSequence.isProtein();
1187 if (_seqhash != sequence.hashCode())
1189 _seqhash = sequence.hashCode();
1190 _isNa = Comparison.isNucleotide(this);
1198 * @see jalview.datamodel.SequenceI#createDatasetSequence()
1201 public SequenceI createDatasetSequence()
1203 if (datasetSequence == null)
1205 Sequence dsseq = new Sequence(getName(),
1206 AlignSeq.extractGaps(jalview.util.Comparison.GapChars,
1207 getSequenceAsString()),
1208 getStart(), getEnd());
1210 datasetSequence = dsseq;
1212 dsseq.setDescription(description);
1213 // move features and database references onto dataset sequence
1214 dsseq.sequenceFeatures = sequenceFeatures;
1215 sequenceFeatures = null;
1216 dsseq.dbrefs = dbrefs;
1218 // TODO: search and replace any references to this sequence with
1219 // references to the dataset sequence in Mappings on dbref
1220 dsseq.pdbIds = pdbIds;
1222 datasetSequence.updatePDBIds();
1223 if (annotation != null)
1225 // annotation is cloned rather than moved, to preserve what's currently
1227 for (AlignmentAnnotation aa : annotation)
1229 AlignmentAnnotation _aa = new AlignmentAnnotation(aa);
1230 _aa.sequenceRef = datasetSequence;
1231 _aa.adjustForAlignment(); // uses annotation's own record of
1232 // sequence-column mapping
1233 datasetSequence.addAlignmentAnnotation(_aa);
1237 return datasetSequence;
1244 * jalview.datamodel.SequenceI#setAlignmentAnnotation(AlignmmentAnnotation[]
1248 public void setAlignmentAnnotation(AlignmentAnnotation[] annotations)
1250 if (annotation != null)
1252 annotation.removeAllElements();
1254 if (annotations != null)
1256 for (int i = 0; i < annotations.length; i++)
1258 if (annotations[i] != null)
1260 addAlignmentAnnotation(annotations[i]);
1267 public AlignmentAnnotation[] getAnnotation(String label)
1269 if (annotation == null || annotation.size() == 0)
1274 Vector subset = new Vector();
1275 Enumeration e = annotation.elements();
1276 while (e.hasMoreElements())
1278 AlignmentAnnotation ann = (AlignmentAnnotation) e.nextElement();
1279 if (ann.label != null && ann.label.equals(label))
1281 subset.addElement(ann);
1284 if (subset.size() == 0)
1288 AlignmentAnnotation[] anns = new AlignmentAnnotation[subset.size()];
1290 e = subset.elements();
1291 while (e.hasMoreElements())
1293 anns[i++] = (AlignmentAnnotation) e.nextElement();
1295 subset.removeAllElements();
1300 public boolean updatePDBIds()
1302 if (datasetSequence != null)
1304 // TODO: could merge DBRefs
1305 return datasetSequence.updatePDBIds();
1307 if (dbrefs == null || dbrefs.length == 0)
1311 boolean added = false;
1312 for (DBRefEntry dbr : dbrefs)
1314 if (DBRefSource.PDB.equals(dbr.getSource()))
1317 * 'Add' any PDB dbrefs as a PDBEntry - add is only performed if the
1318 * PDB id is not already present in a 'matching' PDBEntry
1319 * Constructor parses out a chain code if appended to the accession id
1320 * (a fudge used to 'store' the chain code in the DBRef)
1322 PDBEntry pdbe = new PDBEntry(dbr);
1323 added |= addPDBId(pdbe);
1330 public void transferAnnotation(SequenceI entry, Mapping mp)
1332 if (datasetSequence != null)
1334 datasetSequence.transferAnnotation(entry, mp);
1337 if (entry.getDatasetSequence() != null)
1339 transferAnnotation(entry.getDatasetSequence(), mp);
1342 // transfer any new features from entry onto sequence
1343 if (entry.getSequenceFeatures() != null)
1346 SequenceFeature[] sfs = entry.getSequenceFeatures();
1347 for (int si = 0; si < sfs.length; si++)
1349 SequenceFeature sf[] = (mp != null) ? mp.locateFeature(sfs[si])
1350 : new SequenceFeature[]
1351 { new SequenceFeature(sfs[si]) };
1352 if (sf != null && sf.length > 0)
1354 for (int sfi = 0; sfi < sf.length; sfi++)
1356 addSequenceFeature(sf[sfi]);
1362 // transfer PDB entries
1363 if (entry.getAllPDBEntries() != null)
1365 Enumeration e = entry.getAllPDBEntries().elements();
1366 while (e.hasMoreElements())
1368 PDBEntry pdb = (PDBEntry) e.nextElement();
1372 // transfer database references
1373 DBRefEntry[] entryRefs = entry.getDBRefs();
1374 if (entryRefs != null)
1376 for (int r = 0; r < entryRefs.length; r++)
1378 DBRefEntry newref = new DBRefEntry(entryRefs[r]);
1379 if (newref.getMap() != null && mp != null)
1381 // remap ref using our local mapping
1383 // we also assume all version string setting is done by dbSourceProxy
1385 * if (!newref.getSource().equalsIgnoreCase(dbSource)) {
1386 * newref.setSource(dbSource); }
1394 * @return The index (zero-based) on this sequence in the MSA. It returns
1395 * {@code -1} if this information is not available.
1398 public int getIndex()
1404 * Defines the position of this sequence in the MSA. Use the value {@code -1}
1405 * if this information is undefined.
1408 * position for this sequence. This value is zero-based (zero for
1409 * this first sequence)
1412 public void setIndex(int value)
1418 public void setRNA(RNA r)
1430 public List<AlignmentAnnotation> getAlignmentAnnotations(String calcId,
1433 List<AlignmentAnnotation> result = new ArrayList<>();
1434 if (this.annotation != null)
1436 for (AlignmentAnnotation ann : annotation)
1438 if (ann.calcId != null && ann.calcId.equals(calcId)
1439 && ann.label != null && ann.label.equals(label))
1449 public String toString()
1451 return getDisplayId(false);
1455 public PDBEntry getPDBEntry(String pdbIdStr)
1457 if (getDatasetSequence() != null)
1459 return getDatasetSequence().getPDBEntry(pdbIdStr);
1465 List<PDBEntry> entries = getAllPDBEntries();
1466 for (PDBEntry entry : entries)
1468 if (entry.getId().equalsIgnoreCase(pdbIdStr))
1477 public List<DBRefEntry> getPrimaryDBRefs()
1479 if (datasetSequence != null)
1481 return datasetSequence.getPrimaryDBRefs();
1483 if (dbrefs == null || dbrefs.length == 0)
1485 return Collections.emptyList();
1487 synchronized (dbrefs)
1489 List<DBRefEntry> primaries = new ArrayList<>();
1490 DBRefEntry[] tmp = new DBRefEntry[1];
1491 for (DBRefEntry ref : dbrefs)
1493 if (!ref.isPrimaryCandidate())
1499 MapList mp = ref.getMap().getMap();
1500 if (mp.getFromLowest() > start || mp.getFromHighest() < end)
1502 // map only involves a subsequence, so cannot be primary
1506 // whilst it looks like it is a primary ref, we also sanity check type
1507 if (DBRefUtils.getCanonicalName(DBRefSource.PDB)
1508 .equals(DBRefUtils.getCanonicalName(ref.getSource())))
1510 // PDB dbrefs imply there should be a PDBEntry associated
1511 // TODO: tighten PDB dbrefs
1512 // formally imply Jalview has actually downloaded and
1513 // parsed the pdb file. That means there should be a cached file
1514 // handle on the PDBEntry, and a real mapping between sequence and
1515 // extracted sequence from PDB file
1516 PDBEntry pdbentry = getPDBEntry(ref.getAccessionId());
1517 if (pdbentry != null && pdbentry.getFile() != null)
1523 // check standard protein or dna sources
1525 DBRefEntry[] res = DBRefUtils.selectDbRefs(!isProtein(), tmp);
1526 if (res != null && res[0] == tmp[0])
1537 public HiddenMarkovModel getHMM()
1543 public void setHMM(HiddenMarkovModel hmm)
1549 public void updateHMMMapping()
1553 hmm.emptyNodeLookup();
1554 for (char residue : sequence)
1556 if (!Comparison.isGap(residue))
1558 hmm.setAlignmentColumn(node, column);
1567 public boolean isHMMConsensusSequence()
1569 return isHMMConsensusSequence;
1573 public void setIsHMMConsensusSequence(boolean isHMMConsensusSequence)
1575 this.isHMMConsensusSequence = isHMMConsensusSequence;
1579 public boolean hasHMMAnnotation()
1585 public void setHasInfo(boolean status)
1591 public int getPreviousPosition()
1593 return previousPosition;
1597 public void setPreviousPosition(int previousPosition)
1599 this.previousPosition = previousPosition;