JAL-2629 hmmer searches include seqs past inclusion threshold in output
[jalview.git] / src / jalview / datamodel / Alignment.java
index 3ae46b8..70a3cc2 100755 (executable)
@@ -47,14 +47,12 @@ import java.util.Vector;
  * @author JimP
  * 
  */
-public class Alignment implements AlignmentI
+public class Alignment implements AlignmentI, AutoCloseable
 {
   private Alignment dataset;
 
   private List<SequenceI> sequences;
 
-  private SequenceI hmmConsensus;
-
   protected List<SequenceGroup> groups;
 
   protected char gapCharacter = '-';
@@ -330,15 +328,20 @@ public class Alignment implements AlignmentI
   }
 
   @Override
-  public void finalize() throws Throwable
+  public void close()
   {
     if (getDataset() != null)
     {
-      getDataset().removeAlignmentRef();
+      try
+      {
+        getDataset().removeAlignmentRef();
+      } catch (Throwable e)
+      {
+        e.printStackTrace();
+      }
     }
 
     nullReferences();
-    super.finalize();
   }
 
   /**
@@ -740,39 +743,21 @@ public class Alignment implements AlignmentI
   
     for (int i = 0; i < sequences.size(); i++)
     {
-      if (getSequenceAt(i).getLength() > maxLength)
-      {
-        maxLength = getSequenceAt(i).getLength();
-      }
+      maxLength = Math.max(maxLength, getSequenceAt(i).getLength());
     }
-  
     return maxLength;
   }
-  /*
+
   @Override
-  public int getWidth()
+  public int getVisibleWidth()
   {
-    final Wrapper temp = new Wrapper();
-  
-    forEachSequence(new Consumer<SequenceI>()
+    int w = getWidth();
+    if (hiddenCols != null)
     {
-      @Override
-      public void accept(SequenceI s)
-      {
-        if (s.getLength() > temp.inner)
-        {
-          temp.inner = s.getLength();
-        }
-      }
-    }, 0, sequences.size() - 1);
-  
-    return temp.inner;
+      w -= hiddenCols.getSize();
+    }
+    return w;
   }
-  
-  public static class Wrapper
-  {
-    public int inner;
-  }*/
 
   /**
    * DOCUMENT ME!
@@ -1661,7 +1646,7 @@ public class Alignment implements AlignmentI
     annot.hasText = false;
     if (calcId != null)
     {
-      annot.setCalcId(new String(calcId));
+      annot.setCalcId(calcId);
     }
     annot.autoCalculated = autoCalc;
     if (seqRef != null)
@@ -1950,21 +1935,12 @@ public class Alignment implements AlignmentI
   }
 
   @Override
-  public void setHiddenColumns(HiddenColumns cols)
+  public boolean setHiddenColumns(HiddenColumns cols)
   {
+    boolean changed = cols == null ? hiddenCols != null
+            : !cols.equals(hiddenCols);
     hiddenCols = cols;
-  }
-
-  @Override
-  public SequenceI getHmmConsensus()
-  {
-    return hmmConsensus;
-  }
-
-  @Override
-  public void setHmmConsensus(SequenceI hmmConsensus)
-  {
-    this.hmmConsensus = hmmConsensus;
+    return changed;
   }
 
   @Override
@@ -2078,4 +2054,19 @@ public class Alignment implements AlignmentI
       }
     }
   }
+
+  @Override
+  public List<SequenceI> getHmmSequences()
+  {
+    List<SequenceI> result = new ArrayList<>();
+    for (int i = 0; i < sequences.size(); i++)
+    {
+      SequenceI seq = sequences.get(i);
+      if (seq.hasHMMProfile())
+      {
+        result.add(seq);
+      }
+    }
+    return result;
+  }
 }