JAL-2629 fix file format issues preventing hmmsearch, jackhmmer running
[jalview.git] / src / jalview / hmmer / HmmerCommand.java
index 79fcb4c..dd6adc8 100644 (file)
@@ -23,7 +23,6 @@ import jalview.ws.params.ArgumentI;
 
 import java.io.BufferedReader;
 import java.io.File;
-import java.io.FileNotFoundException;
 import java.io.IOException;
 import java.io.InputStreamReader;
 import java.io.PrintWriter;
@@ -237,13 +236,15 @@ public abstract class HmmerCommand implements Runnable
    * @throws IOException
    */
   public void exportStockholm(SequenceI[] seqs, File toFile,
-          AnnotatedCollectionI annotated) throws IOException
+          AnnotatedCollectionI annotated, boolean removeSS)
+          throws IOException
   {
     if (seqs == null)
     {
       return;
     }
     AlignmentI newAl = new Alignment(seqs);
+
     if (!newAl.isAligned())
     {
       newAl.padGaps();
@@ -277,6 +278,24 @@ public abstract class HmmerCommand implements Runnable
       }
     }
 
+    for (SequenceI seq : newAl.getSequencesArray())
+    {
+      if (removeSS && seq.getAnnotation() != null)
+      {
+        for (AlignmentAnnotation ann : seq.getAnnotation())
+        {
+          // TODO investigate how to make hmmsearch and jackhmmer work with annotations
+          /*
+          if (ann.label.equals("Secondary Structure"))
+          {
+            seq.removeAlignmentAnnotation(ann);
+          }
+          */
+          seq.removeAlignmentAnnotation(ann);
+        }
+      }
+    }
+
     StockholmFile file = new StockholmFile(newAl);
     String output = file.print(seqs, false);
     PrintWriter writer = new PrintWriter(toFile);
@@ -285,30 +304,6 @@ public abstract class HmmerCommand implements Runnable
   }
 
   /**
-   * 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(al.getSequencesArray(), false);
-    PrintWriter writer;
-    try
-    {
-      writer = new PrintWriter(toFile);
-      writer.println(output);
-      writer.close();
-    } catch (FileNotFoundException e)
-    {
-      e.printStackTrace();
-    }
-
-  }
-
-  /**
    * Answers the full path to the given hmmer executable, or null if file cannot
    * be found or is not executable
    * 
@@ -475,4 +470,33 @@ public abstract class HmmerCommand implements Runnable
       }
     }
   }
+
+  void renameDuplicates(SequenceI[] seqs)
+  {
+    // rename duplicate sequences, hmmsearch fails db contains duplicates
+    for (int i = 0; i < seqs.length; i++)
+    {
+      boolean renamed = false;
+      for (int j = 0; j < seqs.length; j++)
+      {
+        renamed = true;
+        if (seqs[i].getName().equals(seqs[j].getName()) && i != j)
+        {
+          String range = "/" + seqs[j].getStart() + "-" + seqs[j].getEnd();
+          // setting sequence name to include range - to differentiate between
+          // sequences of the same name. Currently have to include the range twice
+          // because the range is removed (once) when setting the name
+          // TODO come up with a better way of doing this
+          seqs[j].setName(seqs[j].getName() + range + range);
+        }
+
+      }
+      if (renamed)
+      {
+        String range = "/" + seqs[i].getStart() + "-" + seqs[i].getEnd();
+        seqs[i].setName(seqs[i].getName() + range + range);
+      }
+    }
+  }
+
 }