X-Git-Url: http://source.jalview.org/gitweb/?a=blobdiff_plain;f=src%2Fjalview%2Fdatamodel%2FSequence.java;h=755abbb18e74ad3a976c435bbcb90c1d1c17f0ba;hb=04a4d60a50394d846d0479c442facebe360b5b9c;hp=441d8d04df759b273b8bf56b519e1fc02b3c20a4;hpb=653e250e0a2a5dd455ae4c52794c4ce0de340418;p=jalview.git diff --git a/src/jalview/datamodel/Sequence.java b/src/jalview/datamodel/Sequence.java index 441d8d0..755abbb 100755 --- a/src/jalview/datamodel/Sequence.java +++ b/src/jalview/datamodel/Sequence.java @@ -28,12 +28,14 @@ import jalview.util.Comparison; import jalview.util.DBRefUtils; import jalview.util.MapList; import jalview.util.StringUtils; +import jalview.workers.InformationThread; import java.util.ArrayList; import java.util.Arrays; import java.util.BitSet; import java.util.Collections; import java.util.Enumeration; +import java.util.Iterator; import java.util.List; import java.util.ListIterator; import java.util.Vector; @@ -61,6 +63,10 @@ public class Sequence extends ASequence implements SequenceI int end; + HiddenMarkovModel hmm; + + boolean isHMMConsensusSequence = false; + Vector pdbIds; String vamsasId; @@ -337,6 +343,15 @@ public class Sequence extends ASequence implements SequenceI this.addPDBId(new PDBEntry(pdb)); } } + if (seq.isHMMConsensusSequence()) + { + this.isHMMConsensusSequence = true; + } + if (seq.getHMM() != null) + { + this.hmm = new HiddenMarkovModel(seq.getHMM()); + } + } @Override @@ -408,7 +423,7 @@ public class Sequence extends ASequence implements SequenceI { if (pdbIds == null) { - pdbIds = new Vector(); + pdbIds = new Vector<>(); pdbIds.add(entry); return true; } @@ -444,7 +459,7 @@ public class Sequence extends ASequence implements SequenceI @Override public Vector getAllPDBEntries() { - return pdbIds == null ? new Vector() : pdbIds; + return pdbIds == null ? new Vector<>() : pdbIds; } /** @@ -1128,6 +1143,27 @@ public class Sequence extends ASequence implements SequenceI return map; } + /** + * Build a bitset corresponding to sequence gaps + * + * @return a BitSet where set values correspond to gaps in the sequence + */ + @Override + public BitSet gapBitset() + { + BitSet gaps = new BitSet(sequence.length); + int j = 0; + while (j < sequence.length) + { + if (jalview.util.Comparison.isGap(sequence[j])) + { + gaps.set(j); + } + j++; + } + return gaps; + } + @Override public int[] findPositionMap() { @@ -1151,7 +1187,7 @@ public class Sequence extends ASequence implements SequenceI @Override public List getInsertions() { - ArrayList map = new ArrayList(); + ArrayList map = new ArrayList<>(); int lastj = -1, j = 0; int pos = start; int seqlen = sequence.length; @@ -1462,7 +1498,7 @@ public class Sequence extends ASequence implements SequenceI { if (this.annotation == null) { - this.annotation = new Vector(); + this.annotation = new Vector<>(); } if (!this.annotation.contains(annotation)) { @@ -1629,7 +1665,7 @@ public class Sequence extends ASequence implements SequenceI return null; } - Vector subset = new Vector(); + Vector subset = new Vector<>(); Enumeration e = annotation.elements(); while (e.hasMoreElements()) { @@ -1763,12 +1799,13 @@ public class Sequence extends ASequence implements SequenceI public List getAlignmentAnnotations(String calcId, String label) { - List result = new ArrayList(); + List result = new ArrayList<>(); if (this.annotation != null) { for (AlignmentAnnotation ann : annotation) { - if (ann.calcId != null && ann.calcId.equals(calcId) + String id = ann.getCalcId(); + if (id != null && id.equals(calcId) && ann.label != null && ann.label.equals(label)) { result.add(ann); @@ -1819,7 +1856,7 @@ public class Sequence extends ASequence implements SequenceI } synchronized (dbrefs) { - List primaries = new ArrayList(); + List primaries = new ArrayList<>(); DBRefEntry[] tmp = new DBRefEntry[1]; for (DBRefEntry ref : dbrefs) { @@ -1866,6 +1903,46 @@ public class Sequence extends ASequence implements SequenceI } } + @Override + public HiddenMarkovModel getHMM() + { + return hmm; + } + + @Override + public void setHMM(HiddenMarkovModel hmm) + { + this.hmm = hmm; + } + + @Override + public boolean isHMMConsensusSequence() + { + return isHMMConsensusSequence; + } + + @Override + public void setIsHMMConsensusSequence(boolean value) + { + this.isHMMConsensusSequence = value; + } + + @Override + public boolean hasHMMAnnotation() + { + if (this.annotation == null) { + return false; + } + for (AlignmentAnnotation ann : annotation) + { + if (InformationThread.HMM_CALC_ID.equals(ann.getCalcId())) + { + return true; + } + } + return false; + } + /** * {@inheritDoc} */ @@ -1961,4 +2038,73 @@ public class Sequence extends ASequence implements SequenceI return count; } + + @Override + public String getSequenceStringFromIterator(Iterator it) + { + StringBuilder newSequence = new StringBuilder(); + while (it.hasNext()) + { + int[] block = it.next(); + if (it.hasNext()) + { + newSequence.append(getSequence(block[0], block[1] + 1)); + } + else + { + newSequence.append(getSequence(block[0], block[1])); + } + } + + return newSequence.toString(); + } + + @Override + public int firstResidueOutsideIterator(Iterator regions) + { + int start = 0; + + if (!regions.hasNext()) + { + return findIndex(getStart()) - 1; + } + + // Simply walk along the sequence whilst watching for region + // boundaries + int hideStart = getLength(); + int hideEnd = -1; + boolean foundStart = false; + + // step through the non-gapped positions of the sequence + for (int i = getStart(); i <= getEnd() && (!foundStart); i++) + { + // get alignment position of this residue in the sequence + int p = findIndex(i) - 1; + + // update region start/end + while (hideEnd < p && regions.hasNext()) + { + int[] region = regions.next(); + hideStart = region[0]; + hideEnd = region[1]; + } + if (hideEnd < p) + { + hideStart = getLength(); + } + // update boundary for sequence + if (p < hideStart) + { + start = p; + foundStart = true; + } + } + + if (foundStart) + { + return start; + } + // otherwise, sequence was completely hidden + return 0; + } }