Merge branch 'develop' into update_212_Dec_merge_with_21125_chamges
[jalview.git] / src / jalview / hmmer / JackHMMER.java
index e6bb5f4..00314f0 100644 (file)
@@ -1,8 +1,8 @@
 package jalview.hmmer;
 
 import jalview.bin.Cache;
+import jalview.bin.Console;
 import jalview.datamodel.Alignment;
-import jalview.datamodel.AlignmentAnnotation;
 import jalview.datamodel.AlignmentI;
 import jalview.datamodel.SequenceI;
 import jalview.gui.AlignFrame;
@@ -20,29 +20,14 @@ import java.io.File;
 import java.io.FileReader;
 import java.io.IOException;
 import java.util.ArrayList;
-import java.util.Hashtable;
 import java.util.List;
-import java.util.Scanner;
 
 import javax.swing.JOptionPane;
 
-public class JackHMMER extends HmmerCommand
+public class JackHMMER extends Search
 {
-  static final String JACKHMMER = "jackhmmer";
 
-  boolean realign = false;
-
-  boolean trim = false;
-
-  int seqsToReturn = Integer.MAX_VALUE;
-
-  SequenceI[] seqs;
-
-  private String databaseName;
-
-  boolean searchAlignment = true;
-
-  Hashtable sequencesHash;
+  SequenceI seq = null;
 
   /**
    * Constructor for the JackhmmerThread
@@ -63,11 +48,11 @@ public class JackHMMER extends HmmerCommand
   @Override
   public void run()
   {
-    SequenceI seq = getSequence();
+    seq = getSequence();
     if (seq == null)
     {
       // shouldn't happen if we got this far
-      Cache.log.error("Error: no sequence for jackhmmer");
+      Console.error("Error: no sequence for jackhmmer");
       return;
     }
 
@@ -136,123 +121,6 @@ public class JackHMMER extends HmmerCommand
   }
 
   /**
-   * Appends command line arguments to the given list, to specify input and output
-   * files for the search, and any additional options that may have been passed
-   * from the parameters dialog
-   * 
-   * @param args
-   * @param searchOutputFile
-   * @param hitsAlignmentFile
-   * @param seqFile
-   * @throws IOException
-   */
-  protected void buildArguments(List<String> args, File searchOutputFile,
-          File hitsAlignmentFile, File seqFile) throws IOException
-  {
-    args.add("-o");
-    args.add(getFilePath(searchOutputFile, true));
-    args.add("-A");
-    args.add(getFilePath(hitsAlignmentFile, true));
-
-    File databaseFile = null;
-
-    boolean useEvalueCutoff = false;
-    boolean useScoreCutoff = false;
-    String seqEvalueCutoff = null;
-    String domEvalueCutoff = null;
-    String seqScoreCutoff = null;
-    String domScoreCutoff = null;
-    databaseName = "Alignment";
-
-    if (params != null)
-    {
-      for (ArgumentI arg : params)
-      {
-        String name = arg.getName();
-
-        if (MessageManager.getString(REPORTING_CUTOFF_KEY)
-                .equals(name))
-        {
-          if (MessageManager.getString(CUTOFF_EVALUE)
-                  .equals(arg.getValue()))
-          {
-            useEvalueCutoff = true;
-          }
-          else if (MessageManager.getString(CUTOFF_SCORE)
-                  .equals(arg.getValue()))
-          {
-            useScoreCutoff = true;
-          }
-        }
-        else if (MessageManager.getString(SEQ_EVALUE_KEY).equals(name))
-        {
-          seqEvalueCutoff = arg.getValue();
-        }
-        else if (MessageManager.getString(SEQ_SCORE_KEY).equals(name))
-        {
-          seqScoreCutoff = arg.getValue();
-        }
-        else if (MessageManager.getString(DOM_EVALUE_KEY).equals(name))
-        {
-          domEvalueCutoff = arg.getValue();
-        }
-        else if (MessageManager.getString(DOM_SCORE_KEY).equals(name))
-        {
-          domScoreCutoff = arg.getValue();
-        }
-        else if (MessageManager.getString(DATABASE_KEY).equals(name))
-        {
-          databaseFile = new File(arg.getValue());
-          if (!arg.getValue().isEmpty())
-          {
-            searchAlignment = false;
-          }
-        }
-      }
-    }
-
-    if (useEvalueCutoff)
-    {
-      args.add("-E");
-      args.add(seqEvalueCutoff);
-      args.add("--domE");
-      args.add(domEvalueCutoff);
-    }
-    else if (useScoreCutoff)
-    {
-      args.add("-T");
-      args.add(seqScoreCutoff);
-      args.add("--domT");
-      args.add(domScoreCutoff);
-    }
-
-    // if (!dbFound || MessageManager.getString(THIS_ALIGNMENT_KEY)
-    // .equals(dbPath))
-    if (searchAlignment)
-    {
-      /*
-       * no external database specified for search, so
-       * export current alignment as 'database' to search
-       */
-      databaseFile = FileUtils.createTempFile("database", ".sto");
-      AlignmentI al = af.getViewport().getAlignment();
-      AlignmentI copy = new Alignment(al);
-
-      deleteHmmSequences(copy);
-
-      if (searchAlignment)
-      {
-        sequencesHash = stashSequences(copy.getSequencesArray());
-      }
-
-      exportStockholm(copy.getSequencesArray(), databaseFile, null);
-    }
-
-    args.add(getFilePath(seqFile, true));
-    args.add(getFilePath(databaseFile, true));
-  }
-
-  /**
    * Imports the data from the temporary file to which the output of jackhmmer was
    * directed.
    */
@@ -273,14 +141,17 @@ public class JackHMMER extends HmmerCommand
               inputAlignmentTemp.getAbsolutePath(), DataSourceType.FILE));
       seqs = file.getSeqsAsArray();
 
+      readDomainTable(searchOutputFile, true);
+
       if (searchAlignment)
       {
         recoverSequences(sequencesHash, seqs);
       }
 
-      readTable(searchOutputFile);
 
-      int seqCount = Math.min(seqs.length, seqsToReturn);
+
+      int seqCount = seqs.length;
+
 
       AlignmentI al = new Alignment(seqs);
 
@@ -303,103 +174,6 @@ public class JackHMMER extends HmmerCommand
     }
   }
 
-  /**
-   * Reads in the scores table output by jackhmmer and adds annotation to
-   * sequences for E-value and bit score
-   * 
-   * @param inputTableTemp
-   * @throws IOException
-   */
-  void readTable(File inputTableTemp) throws IOException
-  {
-    BufferedReader br = new BufferedReader(new FileReader(inputTableTemp));
-    String line = "";
-    while (!line.startsWith("Query:"))
-    {
-      line = br.readLine();
-    }
-    while (!line.contains("-------"))
-    {
-      line = br.readLine();
-    }
-    line = br.readLine();
-
-    int index = 0;
-    while (!"  ------ inclusion threshold ------".equals(line)
-            && !"".equals(line))
-    {
-
-      Scanner scanner = new Scanner(line);
-      String evalue = scanner.next();
-      evalue = scanner.next();
-      checkSequenceOrder(index, scanner);
-      SequenceI seq = seqs[index];
-      String score = scanner.next();
-      addScoreAnnotations(evalue, score, seq);
-      scanner.close();
-      line = br.readLine();
-      index++;
-    }
-
-    br.close();
-  }
-
-  private void checkSequenceOrder(int index, Scanner scanner)
-  {
-    String seqName = null;
-
-    for (int i = 0; i < 8; i++)
-    {
-      seqName = scanner.next();
-    }
-
-    if (!seqs[index + 1].getName().equals(seqName))
-    {
-      SequenceI temp = seqs[index + 1];
-
-      for (int j = 0; j < seqs.length; j++)
-      {
-        if (seqs[j].getName().equals(seqName))
-        {
-          seqs[index + 1] = seqs[j];
-          seqs[j] = temp;
-          break;
-        }
-      }
-    }
-  }
-
-  protected void addScoreAnnotations(String eValue, String bitScore,
-          SequenceI seq)
-  {
-    String label = "Search Scores";
-    String description = "Full sequence bit score and E-Value";
-
-    try
-    {
-      AlignmentAnnotation annot = new AlignmentAnnotation(label,
-              description, null);
-
-      annot.label = label;
-      annot.description = description;
-
-      annot.setCalcId(JACKHMMER);
-
-      double dEValue = Double.parseDouble(eValue);
-      annot.setEValue(dEValue);
-
-      double dBitScore = Double.parseDouble(bitScore);
-      annot.setBitScore(dBitScore);
-
-      annot.setSequenceRef(seq);
-      seq.addAlignmentAnnotation(annot);
-
-    } catch (NumberFormatException e)
-    {
-      System.err.println("Error parsing " + label + " from " + eValue
-              + " & " + bitScore);
-    }
-  }