JAL-2629 can now filter by sequence e-value or bit score
[jalview.git] / src / jalview / hmmer / HmmerCommand.java
index 85f64bf..79fcb4c 100644 (file)
@@ -8,6 +8,7 @@ import jalview.datamodel.AlignmentI;
 import jalview.datamodel.AnnotatedCollectionI;
 import jalview.datamodel.Annotation;
 import jalview.datamodel.HiddenMarkovModel;
+import jalview.datamodel.SequenceGroup;
 import jalview.datamodel.SequenceI;
 import jalview.gui.AlignFrame;
 import jalview.gui.JvOptionPane;
@@ -228,7 +229,7 @@ public abstract class HmmerCommand implements Runnable
 
   /**
    * Exports an alignment, and reference (RF) annotation if present, to the
-   * specified file, in Stockholm format
+   * specified file, in Stockholm format, removing all HMM sequences
    * 
    * @param seqs
    * @param toFile
@@ -283,10 +284,17 @@ public abstract class HmmerCommand implements Runnable
     writer.close();
   }
 
-  public void exportFasta(SequenceI[] seqs, File toFile)
+  /**
+   * Exports the given alignment withotu any anotations to a fasta file
+   * 
+   * @param seqs
+   * @param toFile
+   */
+  public void exportFasta(AlignmentI al, File toFile)
   {
     FastaFile file = new FastaFile();
-    String output = file.print(seqs, false);
+
+    String output = file.print(al.getSequencesArray(), false);
     PrintWriter writer;
     try
     {
@@ -440,4 +448,31 @@ public abstract class HmmerCommand implements Runnable
 
     return path;
   }
+
+  /**
+   * A helper method that deletes any HMM consensus sequence from the given
+   * collection, and from the parent alignment if <code>ac</code> is a subgroup
+   * 
+   * @param ac
+   */
+  void deleteHmmSequences(AnnotatedCollectionI ac)
+  {
+    List<SequenceI> hmmSeqs = ac.getHmmSequences();
+    for (SequenceI hmmSeq : hmmSeqs)
+    {
+      if (ac instanceof SequenceGroup)
+      {
+        ((SequenceGroup) ac).deleteSequence(hmmSeq, false);
+        AnnotatedCollectionI context = ac.getContext();
+        if (context != null && context instanceof AlignmentI)
+        {
+          ((AlignmentI) context).deleteSequence(hmmSeq);
+        }
+      }
+      else
+      {
+        ((AlignmentI) ac).deleteSequence(hmmSeq);
+      }
+    }
+  }
 }