JAL-3899 Update usages of uniquify and deuniquify.
[jalview.git] / src / jalview / hmmer / Search.java
index 24bd6b7..6c3a71d 100644 (file)
@@ -1,5 +1,6 @@
 package jalview.hmmer;
 
+import jalview.analysis.SeqsetUtils.SequenceInfo;
 import jalview.datamodel.Alignment;
 import jalview.datamodel.AlignmentAnnotation;
 import jalview.datamodel.AlignmentI;
@@ -15,6 +16,7 @@ import java.io.FileReader;
 import java.io.IOException;
 import java.util.Hashtable;
 import java.util.List;
+import java.util.Map;
 import java.util.Scanner;
 
 public abstract class Search extends HmmerCommand
@@ -34,7 +36,7 @@ public abstract class Search extends HmmerCommand
 
   boolean searchAlignment = true;
 
-  Hashtable sequencesHash;
+  Map<String, SequenceInfo> sequencesHash;
 
   public Search(AlignFrame alignFrame, List<ArgumentI> args)
   {
@@ -46,6 +48,59 @@ public abstract class Search extends HmmerCommand
   {
   }
 
+  /*
+  void readOutputFile(File inputTableTemp) throws IOException
+  {
+    BufferedReader br = new BufferedReader(new FileReader(inputTableTemp));
+  
+  
+    String line = "";
+    while (!line.startsWith("//"))
+    {
+  
+      while (!line.startsWith(">> ") && !line.startsWith("//"))
+      {
+        line = br.readLine();
+      }
+  
+      if (line.startsWith("//"))
+      {
+        break;
+      }
+  
+      Scanner scanner = new Scanner(line);
+      String name = scanner.next();
+      name = scanner.next();
+  
+      br.readLine();
+      br.readLine();
+  
+      List<SequenceI> domains = new ArrayList<>();
+  
+      for (SequenceI seq : seqs)
+      {
+        if (seq.getName().contains(name))
+        {
+          domains.add(seq);
+        }
+      }
+  
+      if (domains.contains(getSequence()))
+      {
+        domains.remove(getSequence());
+      }
+  
+      if (domains.size() > 0)
+      {
+        readOutputTable(br, domains);
+      }
+  
+      line = br.readLine();
+    }
+  
+  }
+  
+  
   /**
    * Reads in the scores table output by jackhmmer and adds annotation to
    * sequences for E-value and bit score
@@ -53,70 +108,108 @@ public abstract class Search extends HmmerCommand
    * @param inputTableTemp
    * @throws IOException
    */
-  void readTable(File inputTableTemp) throws IOException
+  /*
+  void readOutputTable(BufferedReader br, List<SequenceI> seqs) throws IOException
   {
-    BufferedReader br = new BufferedReader(new FileReader(inputTableTemp));
-    String line = "";
-    while (!line.startsWith("Query:"))
-    {
-      line = br.readLine();
-    }
-    while (!line.contains("-------"))
+    String line = br.readLine();
+  
+    while (!"".equals(line) && line != null)
     {
+      if ("  ------ inclusion threshold ------".equals(line))
+      {
+        line = br.readLine();
+        continue;
+      }
+  
+      Scanner scanner = new Scanner(line);
+      scanner.next();
+      scanner.next();
+      String score = scanner.next();
+  
+      scanner.next();
+  
+      String evalue = scanner.next();
+  
+      scanner.next();
+      scanner.next();
+      scanner.next();
+      scanner.next();
+  
+      int start = scanner.nextInt();
+      int end = scanner.nextInt();
+  
+      SequenceI seq = null;
+      for (SequenceI sequence : seqs)
+      {
+        if (sequence.getStart() >= start && sequence.getEnd() <= end)
+        {
+          seq = sequence;
+          break;
+        }
+      }
+  
+      if (seq != null)
+      {
+        addScoreAnnotations(evalue, score, seq);
+      }
+  
+      scanner.close();
       line = br.readLine();
     }
+  }
+  */
+
+  void readDomainTable(File inputTableTemp, boolean includesQuery)
+          throws IOException
+  {
+    BufferedReader br = new BufferedReader(new FileReader(inputTableTemp));
+
+    String line = br.readLine();
+    br.readLine();
+    br.readLine();
     line = br.readLine();
 
-    int index = 0;
+    int index;
 
-    while (!"  ------ inclusion threshold ------".equals(line)
-            && !"".equals(line))
+    if (includesQuery)
+    {
+      index = 1;
+    }
+    else
+    {
+      index = 0;
+    }
+    while (!line.startsWith("#"))
     {
+      if (line.contains("inclusion threshold"))
+      {
+        line = br.readLine();
+        continue;
+      }
 
       Scanner scanner = new Scanner(line);
-      String evalue = scanner.next();
+      String name = scanner.next();
 
-      if (evalue.equals("+") || evalue.equals("-"))
+      for (int i = 0; i < 10; i++)
       {
-        evalue = scanner.next();
+        scanner.next();
       }
 
+      String evalue = scanner.next();
+      scanner.next();
       String score = scanner.next();
-      checkSequenceOrder(index, scanner);
-      SequenceI seq = seqs[index];
-      addScoreAnnotations(evalue, score, seq);
+
+      addScoreAnnotations(evalue, score, seqs[index]);
+      index++;
+
       scanner.close();
       line = br.readLine();
-      index++;
     }
-
     br.close();
   }
 
-  void checkSequenceOrder(int index, Scanner scanner)
-  {
-    String seqName = null;
 
-    for (int i = 0; i < 7; i++)
-    {
-      seqName = scanner.next();
-    }
-
-    if (!seqs[index].getName().equals(seqName))
-    {
-      SequenceI temp = seqs[index];
 
-      for (int j = 0; j < seqs.length; j++)
-      {
-        if (seqs[j].getName().equals(seqName))
-        {
-          seqs[index] = seqs[j];
-          seqs[j] = temp;
-          break;
-        }
-      }
-    }
-  }
 
   void addScoreAnnotations(String eValue, String bitScore, SequenceI seq)
   {
@@ -152,7 +245,7 @@ public abstract class Search extends HmmerCommand
   void buildArguments(List<String> args, File searchOutputFile,
           File hitsAlignmentFile, File queryFile) throws IOException
   {
-    args.add("-o");
+    args.add("--domtblout");
     args.add(getFilePath(searchOutputFile, true));
     args.add("-A");
     args.add(getFilePath(hitsAlignmentFile, true));
@@ -238,6 +331,15 @@ public abstract class Search extends HmmerCommand
             searchAlignment = false;
           }
         }
+        else if (MessageManager.getString(NUMBER_OF_ITERATIONS)
+                .equals(name))
+        {
+          if (!arg.getValue().isEmpty())
+          {
+            args.add("-N");
+            args.add(arg.getValue());
+          }
+        }
       }
     }