JAL-2629 add basic parameter adjustment to hmmsearch/align
[jalview.git] / src / jalview / datamodel / Sequence.java
index 130af40..701ad7d 100755 (executable)
@@ -29,6 +29,7 @@ import jalview.util.StringUtils;
 
 import java.util.ArrayList;
 import java.util.Arrays;
+import java.util.BitSet;
 import java.util.Collections;
 import java.util.Enumeration;
 import java.util.List;
@@ -51,15 +52,19 @@ public class Sequence extends ASequence implements SequenceI
 
   private char[] sequence;
 
+  int previousPosition;
+
   String description;
 
   int start;
 
   int end;
 
+  boolean hasInfo;
+
   HiddenMarkovModel hmm;
 
-  boolean isHMMConsensusSequence;
+  boolean isHMMConsensusSequence = false;
 
   Vector<PDBEntry> pdbIds;
 
@@ -69,8 +74,6 @@ public class Sequence extends ASequence implements SequenceI
 
   RNA rna;
 
-  ProfilesI hinformation;
-
   /**
    * This annotation is displayed below the alignment but the positions are tied
    * to the residues of this sequence
@@ -84,7 +87,9 @@ public class Sequence extends ASequence implements SequenceI
    */
   int index = -1;
 
-  /** array of sequence features - may not be null for a valid sequence object */
+  /**
+   * array of sequence features - may not be null for a valid sequence object
+   */
   public SequenceFeature[] sequenceFeatures;
 
   /**
@@ -139,8 +144,8 @@ public class Sequence extends ASequence implements SequenceI
   {
     if (name == null)
     {
-      System.err
-              .println("POSSIBLE IMPLEMENTATION ERROR: null sequence name passed to constructor.");
+      System.err.println(
+              "POSSIBLE IMPLEMENTATION ERROR: null sequence name passed to constructor.");
       name = "";
     }
     // Does sequence have the /start-end signature?
@@ -296,6 +301,10 @@ public class Sequence extends ASequence implements SequenceI
         this.addPDBId(new PDBEntry(pdb));
       }
     }
+    if (seq.getHMM() != null)
+    {
+      this.hmm = new HiddenMarkovModel(seq.getHMM());
+    }
   }
 
   @Override
@@ -313,7 +322,7 @@ public class Sequence extends ASequence implements SequenceI
       {
         new Exception(
                 "Warning: JAL-2046 side effect ? Possible implementation error: overwriting dataset sequence features by setting sequence features on alignment")
-                .printStackTrace();
+                        .printStackTrace();
       }
       datasetSequence.setSequenceFeatures(features);
     }
@@ -339,7 +348,8 @@ public class Sequence extends ASequence implements SequenceI
       }
     }
 
-    SequenceFeature[] temp = new SequenceFeature[sequenceFeatures.length + 1];
+    SequenceFeature[] temp = new SequenceFeature[sequenceFeatures.length
+            + 1];
     System.arraycopy(sequenceFeatures, 0, temp, 0, sequenceFeatures.length);
     temp[sequenceFeatures.length] = sf;
 
@@ -825,6 +835,40 @@ public class Sequence extends ASequence implements SequenceI
   }
 
   @Override
+  public BitSet getInsertionsAsBits()
+  {
+    BitSet map = new BitSet();
+    int lastj = -1, j = 0;
+    int pos = start;
+    int seqlen = sequence.length;
+    while ((j < seqlen))
+    {
+      if (jalview.util.Comparison.isGap(sequence[j]))
+      {
+        if (lastj == -1)
+        {
+          lastj = j;
+        }
+      }
+      else
+      {
+        if (lastj != -1)
+        {
+          map.set(lastj, j);
+          lastj = -1;
+        }
+      }
+      j++;
+    }
+    if (lastj != -1)
+    {
+      map.set(lastj, j);
+      lastj = -1;
+    }
+    return map;
+  }
+
+  @Override
   public void deleteChars(int i, int j)
   {
     int newstart = start, newend = end;
@@ -1039,8 +1083,9 @@ public class Sequence extends ASequence implements SequenceI
   @Override
   public AlignmentAnnotation[] getAnnotation()
   {
-    return annotation == null ? null : annotation
-            .toArray(new AlignmentAnnotation[annotation.size()]);
+    return annotation == null ? null
+            : annotation
+                    .toArray(new AlignmentAnnotation[annotation.size()]);
   }
 
   @Override
@@ -1152,8 +1197,9 @@ public class Sequence extends ASequence implements SequenceI
   {
     if (datasetSequence == null)
     {
-      Sequence dsseq = new Sequence(getName(), AlignSeq.extractGaps(
-              jalview.util.Comparison.GapChars, getSequenceAsString()),
+      Sequence dsseq = new Sequence(getName(),
+              AlignSeq.extractGaps(jalview.util.Comparison.GapChars,
+                      getSequenceAsString()),
               getStart(), getEnd());
 
       datasetSequence = dsseq;
@@ -1296,7 +1342,8 @@ public class Sequence extends ASequence implements SequenceI
       for (int si = 0; si < sfs.length; si++)
       {
         SequenceFeature sf[] = (mp != null) ? mp.locateFeature(sfs[si])
-                : new SequenceFeature[] { new SequenceFeature(sfs[si]) };
+                : new SequenceFeature[]
+                { new SequenceFeature(sfs[si]) };
         if (sf != null && sf.length > 0)
         {
           for (int sfi = 0; sfi < sf.length; sfi++)
@@ -1452,8 +1499,8 @@ public class Sequence extends ASequence implements SequenceI
           }
         }
         // whilst it looks like it is a primary ref, we also sanity check type
-        if (DBRefUtils.getCanonicalName(DBRefSource.PDB).equals(
-                DBRefUtils.getCanonicalName(ref.getSource())))
+        if (DBRefUtils.getCanonicalName(DBRefSource.PDB)
+                .equals(DBRefUtils.getCanonicalName(ref.getSource())))
         {
           // PDB dbrefs imply there should be a PDBEntry associated
           // TODO: tighten PDB dbrefs
@@ -1527,6 +1574,43 @@ public class Sequence extends ASequence implements SequenceI
     this.isHMMConsensusSequence = isHMMConsensusSequence;
   }
 
+  @Override
+  public boolean hasHMMAnnotation()
+  {
+    return hasInfo;
+    /*
+    if (annotation == null)
+    {
+      return false;
+    }
+    
+    for (AlignmentAnnotation annot : annotation)
+    {
+      if (annot.label.contains("_HMM"))
+      {
+        return true;
+      }
+    }
+    return false;
+    */
+  }
+
+  @Override
+  public void setHasInfo(boolean status)
+  {
+    hasInfo = true;
+  }
 
+  @Override
+  public int getPreviousPosition()
+  {
+    return previousPosition;
+  }
+
+  @Override
+  public void setPreviousPosition(int previousPosition)
+  {
+    this.previousPosition = previousPosition;
+  }
 
 }