JAL-2629 hmmsearch now works for different databases
authorTZVanaalten <TZVanaalten@LS30916.ad.lifesci.dundee.ac.uk>
Thu, 24 Aug 2017 13:12:45 +0000 (14:12 +0100)
committerTZVanaalten <TZVanaalten@LS30916.ad.lifesci.dundee.ac.uk>
Fri, 25 Aug 2017 16:21:01 +0000 (17:21 +0100)
resources/lang/Messages.properties
src/jalview/hmmer/HMMERParamStore.java
src/jalview/hmmer/HMMSearchThread.java

index a7623f7..38e29ed 100644 (file)
@@ -1362,6 +1362,7 @@ label.dom_e_value_desc = The E-value cutoff for returned domains.
 label.dom_score_desc = The score threshold for returned domains.
 label.not_enough_sequences = There are not enough sequences to run {0}
 label.add_database = Add Database
+label.this_alignment = This alignment
 warn.file_not_exists = File does not exist
 warn.invalid_format = This is not a valid database file format. The current supported formats are Fasta, Stockholm and Pfam.
 label.database_for_hmmsearch = The database hmmsearch will search through.
\ No newline at end of file
index 3dad581..4791626 100644 (file)
@@ -60,7 +60,7 @@ public class HMMERParamStore implements ParamDatastoreI
       if (names != null && !names.isEmpty())
       {
         Collection<String> databases = new ArrayList<>();
-        databases.add("This Alignment");
+        databases.add(MessageManager.getString("label.this_alignment"));
         Scanner nameScanner = new Scanner(names);
 
         if (nameScanner.hasNext())
@@ -82,7 +82,9 @@ public class HMMERParamStore implements ParamDatastoreI
         nameScanner.close();
         args.add(new Option(MessageManager.getString("label.database"),
                 MessageManager.getString("label.database_for_hmmsearch"),
-                true, "This Alignment", "This Alignment", databases, null));
+                true, MessageManager.getString("label.this_alignment"),
+                MessageManager.getString("label.this_alignment"), databases,
+                null));
       }
       args.add(new BooleanOption(
               MessageManager.getString("label.auto_align_seqs"),
index c723d2f..b67ef6f 100644 (file)
@@ -19,6 +19,7 @@ import jalview.ws.params.simple.BooleanOption;
 
 import java.io.File;
 import java.io.IOException;
+import java.io.PrintWriter;
 import java.util.ArrayList;
 import java.util.List;
 
@@ -158,7 +159,6 @@ public class HMMSearchThread implements Runnable
     inputAlignmentTemp.deleteOnExit();
     inputTableTemp = File.createTempFile("buffer", ".sto");
     inputTableTemp.deleteOnExit();
-    databaseFile = new File("D:/Thomas/uniref50.fasta");
   }
 
   /**
@@ -170,6 +170,8 @@ public class HMMSearchThread implements Runnable
    */
   private boolean runCommand() throws IOException, InterruptedException
   {
+    Boolean dbFound = false;
+    String dbPath = "";
     File file = new File(cmds.HMMERFOLDER + "/hmmsearch");
     if (!file.canExecute())
     {
@@ -222,13 +224,36 @@ public class HMMSearchThread implements Runnable
           break;
         case "Trim Non-Matching Termini":
           trim = true;
-
+          break;
+        case "Database":
+          dbFound = true;
+          dbPath = arg.getValue();
+          if (!MessageManager.getString("label.this_alignment")
+                  .equals(dbPath))
+          {
+            databaseFile = new File(dbPath);
+          }
         }
-        
 
       }
     }
 
+    if (dbFound == false || MessageManager.getString("label.this_alignment")
+            .equals(dbPath))
+    {
+      AlignmentI alignment = af.getViewport().getAlignment();
+      AlignmentI copy = new Alignment(alignment);
+      copy.getHMMConsensusSequences(true);
+      StockholmFile stoFile = new StockholmFile(copy);
+      stoFile.setSeqs(copy.getSequencesArray());
+      String alignmentString = stoFile.print();
+      databaseFile = File.createTempFile("database", ".sto");
+      databaseFile.deleteOnExit();
+      PrintWriter writer = new PrintWriter(databaseFile);
+      writer.print(alignmentString);
+      writer.close();
+    }
+
     command += hmmTemp.getAbsolutePath() + cmds.SPACE
             + databaseFile.getAbsolutePath();
     return cmds.runCommand(command);
@@ -279,7 +304,6 @@ public class HMMSearchThread implements Runnable
     AlignmentI alignment = new Alignment(hmmAndSeqs);
     AlignFrame frame = new AlignFrame(alignment, 1, 1);
     frame.setSelectedHMMSequence(hmmSeq);
-    frame.getViewport().initInformation();
     List<ArgumentI> alignArgs = new ArrayList<>();
     if (trim)
     {