JAL-2136 added improvement to parse crudelist file instead of scrapping 'summary...
[jalview.git] / src / jalview / ws / phyre2 / Phyre2Client.java
index 0a29412..e980a19 100644 (file)
@@ -14,7 +14,9 @@ import jalview.structures.models.MappingOutputModel;
 import jalview.util.Comparison;
 import jalview.util.Format;
 
+import java.io.BufferedReader;
 import java.io.File;
+import java.io.FileReader;
 import java.io.IOException;
 import java.io.PrintStream;
 import java.util.ArrayList;
@@ -24,11 +26,6 @@ import java.util.List;
 import javax.swing.JTable;
 import javax.swing.table.DefaultTableModel;
 
-import org.jsoup.Jsoup;
-import org.jsoup.nodes.Document;
-import org.jsoup.nodes.Element;
-import org.jsoup.select.Elements;
-
 public class Phyre2Client extends StructureMappingClient
 {
   private final static String NEWLINE = System.lineSeparator();
@@ -293,73 +290,30 @@ public class Phyre2Client extends StructureMappingClient
   }
 
 
-
-  public static List<Phyre2SummaryPojo> parsePhyre2ResultSummaryTable(
-          String html)
+  public static List<Phyre2SummaryPojo> parsePhyreCrudeList(String crudeList)
   {
     List<Phyre2SummaryPojo> phyre2Results = new ArrayList<Phyre2SummaryPojo>();
-    try
+    try (BufferedReader br = new BufferedReader(new FileReader(crudeList)))
     {
-      File in = new File(html);
-      Document doc = Jsoup.parse(in, null);
-      // Document doc = Jsoup.connect(html).get();
-      Elements tableElements = doc.select("table.midshade");
-      for (Element table : tableElements)
+      String line;
+      while ((line = br.readLine()) != null)
       {
-        System.out.println();
-        Elements tableRowElements = table.select(":not(thead) tr");
-        for (int i = 0; i < tableRowElements.size(); i++)
-        {
-          Element row = tableRowElements.get(i);
-          Elements rowItems = row.select("td");
-          if (rowItems.size() > 11)
-          {
-            // for (int j = 0; j < rowItems.size(); j++)
-            // {
-            // System.out.println(">>> r:" + j + "  =  "
-            // + rowItems.get(j).text());
-            // }
-
-            String c = rowItems.get(6).select("input").attr("onmouseover");
-            String alignedRange = c.substring(c.indexOf("Residues ") + 9,
-                    c.indexOf(" of your sequence aligned "));
-            String coverage = c.substring(c.lastIndexOf(" (") + 2,
-                    c.lastIndexOf(" coverage). Click to view detailed"));
-            // System.out.println("coverage" + coverage);
-            try
-            {
-              Phyre2SummaryPojo psp = new Phyre2SummaryPojo();
-              String sn = rowItems.get(0).text();
-              psp.setSerialNo(Integer.valueOf(sn));
-              psp.setTemplateId(rowItems.get(1).text());
-              psp.setCoverage(coverage);
-              psp.setAlignedRange(alignedRange);
-              psp.setConfidence(Double.valueOf(rowItems.get(8).text()));
-              psp.setPid(Integer.valueOf(rowItems.get(9).text()));
-              psp.setTemplateSummary(rowItems.get(10).text());
-              // System.out.println("row  >>>> " + psp.toString());
-              // System.out.println();
-              phyre2Results.add(psp);
-            } catch (NumberFormatException e)
-            {
-              e.printStackTrace();
-            } catch (IndexOutOfBoundsException e)
-            {
-              e.printStackTrace();
-            } catch (Exception e)
-            {
-              e.printStackTrace();
-            }
-          }
-        }
+        String[] lineData = line.split(" ");
+        Phyre2SummaryPojo psp = new Phyre2SummaryPojo();
+        psp.setSerialNo(Integer.valueOf(lineData[0]));
+        psp.setTemplateId(lineData[1]);
+        psp.setConfidence(100 * Double.valueOf(lineData[2]));
+        psp.setPid(Integer.valueOf(lineData[3]));
+        psp.setAlignedRange(lineData[4] + " - " + lineData[5]);
+        // psp.setCoverage(coverage);
+        // psp.setTemplateSummary(templateSummary);
+        phyre2Results.add(psp);
       }
-      return phyre2Results;
-
     } catch (Exception e)
     {
       e.printStackTrace();
-      return null;
     }
+    return phyre2Results;
   }
 
   public static DefaultTableModel getTableModel(
@@ -436,8 +390,8 @@ public class Phyre2Client extends StructureMappingClient
     phyreResultTable.getColumn("#").setCellRenderer(idCellRender);
 
     phyreResultTable.getColumn("Template").setMinWidth(60);
-    phyreResultTable.getColumn("Template").setPreferredWidth(60);
-    phyreResultTable.getColumn("Template").setMaxWidth(90);
+    phyreResultTable.getColumn("Template").setPreferredWidth(90);
+    phyreResultTable.getColumn("Template").setMaxWidth(150);
 
     phyreResultTable.getColumn("Aligned Range").setMinWidth(80);
     phyreResultTable.getColumn("Aligned Range").setPreferredWidth(80);