Merge branch 'features/JAL-4071_visibleFeaturesCounter' into features/JAL-3417_sdppre...
[jalview.git] / src / jalview / datamodel / Alignment.java
index 300c950..f389ad8 100755 (executable)
@@ -21,6 +21,7 @@
 package jalview.datamodel;
 
 import jalview.analysis.AlignmentUtils;
+import jalview.analysis.Conservation;
 import jalview.datamodel.AlignedCodonFrame.SequenceToSequenceMapping;
 import jalview.io.FastaFile;
 import jalview.util.Comparison;
@@ -47,7 +48,7 @@ import java.util.Vector;
  * @author JimP
  * 
  */
-public class Alignment implements AlignmentI
+public class Alignment implements AlignmentI, AutoCloseable
 {
   private Alignment dataset;
 
@@ -71,6 +72,12 @@ public class Alignment implements AlignmentI
 
   private List<AlignedCodonFrame> codonFrameList;
 
+  private Conservation conservation;
+
+  private ProfilesI consensus;
+
+  private Hashtable[] codonConsensus, rnaStructureConsensus;
+
   private void initAlignment(SequenceI[] seqs)
   {
     groups = Collections.synchronizedList(new ArrayList<SequenceGroup>());
@@ -195,7 +202,7 @@ public class Alignment implements AlignmentI
   {
     synchronized (sequences)
     {
-    
+
       if (i > -1 && i < sequences.size())
       {
         return sequences.get(i);
@@ -303,15 +310,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();
   }
 
   /**
@@ -711,7 +723,7 @@ public class Alignment implements AlignmentI
   public int getWidth()
   {
     int maxLength = -1;
-  
+
     for (int i = 0; i < sequences.size(); i++)
     {
       maxLength = Math.max(maxLength, getSequenceAt(i).getLength());
@@ -719,6 +731,17 @@ public class Alignment implements AlignmentI
     return maxLength;
   }
 
+  @Override
+  public int getVisibleWidth()
+  {
+    int w = getWidth();
+    if (hiddenCols != null)
+    {
+      w -= hiddenCols.getSize();
+    }
+    return w;
+  }
+
   /**
    * DOCUMENT ME!
    * 
@@ -1179,7 +1202,8 @@ public class Alignment implements AlignmentI
     int maxLength = -1;
 
     SequenceI current;
-    for (int i = 0; i < sequences.size(); i++)
+    int nseq = sequences.size();
+    for (int i = 0; i < nseq; i++)
     {
       current = getSequenceAt(i);
       for (int j = current.getLength(); j > maxLength; j--)
@@ -1196,7 +1220,7 @@ public class Alignment implements AlignmentI
     maxLength++;
 
     int cLength;
-    for (int i = 0; i < sequences.size(); i++)
+    for (int i = 0; i < nseq; i++)
     {
       current = getSequenceAt(i);
       cLength = current.getLength();
@@ -1895,9 +1919,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;
+    return changed;
   }
 
   @Override
@@ -2012,4 +2039,55 @@ public class Alignment implements AlignmentI
     }
   }
 
+  @Override
+  public Hashtable[] getComplementConsensusHash()
+  {
+    return codonConsensus;
+  }
+
+  @Override
+  public Conservation getConservation()
+  {
+    return conservation;
+  }
+
+  @Override
+  public Hashtable[] getRnaStructureConsensusHash()
+  {
+    return rnaStructureConsensus;
+  }
+
+  @Override
+  public ProfilesI getSequenceConsensusHash()
+  {
+    return consensus;
+  }
+
+  @Override
+  public void setComplementConsensusHash(Hashtable[] hconsensus)
+  {
+    codonConsensus = hconsensus;
+
+  }
+
+  @Override
+  public void setConservation(Conservation cons)
+  {
+    conservation = cons;
+
+  }
+
+  @Override
+  public void setRnaStructureConsensusHash(Hashtable[] hStrucConsensus)
+  {
+    rnaStructureConsensus = hStrucConsensus;
+
+  }
+
+  @Override
+  public void setSequenceConsensusHash(ProfilesI hconsensus)
+  {
+    consensus = hconsensus;
+
+  }
 }