Add new still not-working code for native binary protocol version
[proteocache.git] / datadb / compbio / cassandra / JpredParserHTTP.java
index 3616818..d03ac79 100644 (file)
@@ -1,6 +1,7 @@
 package compbio.cassandra;
 
 import java.io.BufferedReader;
+import java.io.FileNotFoundException;
 import java.io.IOException;
 import java.io.InputStreamReader;
 import java.net.HttpURLConnection;
@@ -17,22 +18,22 @@ import java.util.List;
 import compbio.cassandra.JpredParser;
 
 public class JpredParserHTTP implements JpredParser {
-       private CassandraCreate cc = new CassandraCreate();
+       private CassandraNativeConnector cc = new CassandraNativeConnector();
        private String dirprefix;
-       
+
        JpredParserHTTP() {
-               this.dirprefix = "http://www.compbio.dundee.ac.uk/www-jpred/results";
+               dirprefix = "http://www.compbio.dundee.ac.uk/www-jpred/results";
        }
-       
+
        JpredParserHTTP(String sourceurl) {
-               this.dirprefix = sourceurl;
+               dirprefix = sourceurl;
        }
 
-       public void setSource (String newsourceprefix) {
-               this.dirprefix = newsourceprefix;
+       public void setSource(String newsourceprefix) {
+               dirprefix = newsourceprefix;
        }
 
-       public void Parsing(String source, int nDays) {
+       public void Parsing(String source, int nDays) throws IOException {
                Calendar cal = Calendar.getInstance();
                cal.add(Calendar.DATE, -nDays);
                for (int i = 0; i < nDays; ++i) {
@@ -45,7 +46,7 @@ public class JpredParserHTTP implements JpredParser {
                }
        }
 
-       private void ParsingForDate(String input, String date) {
+       private int ParsingForDate(String input, String date) {
                int totalcount = 0;
                int countNoData = 0;
                int countUnclearFASTAid = 0;
@@ -53,6 +54,7 @@ public class JpredParserHTTP implements JpredParser {
                int countinserted = 0;
                int counAlignments = 0;
                int countStrange = 0;
+               int njobs = 0;
 
                System.out.println("Inserting jobs for " + date);
                try {
@@ -64,10 +66,14 @@ public class JpredParserHTTP implements JpredParser {
                        while ((line = alljobs.readLine()) != null) {
                                if (line.matches(date + "(.*)jp_[^\\s]+")) {
                                        String[] table = line.split("\\s+");
+                                       // Format of a record:
+                                       // starttime endtime ip email jobid (directory)
+                                       // 013/10/25:21:55:7 2013/10/25:21:59:13 201.239.98.172 unknown_email jp_J9HBCBT
                                        String id = table[table.length - 1];
                                        totalcount++;
                                        if (!cc.CheckID(id)) {
-                                               URL urltable = new URL(dirprefix + "/" + id + "/" + id + ".concise.fasta");
+                                               String datalink = dirprefix + "/" + id + "/" + id + ".concise.fasta";
+                                               URL urltable = new URL(datalink);
                                                HttpURLConnection httpConnection = (HttpURLConnection) urltable.openConnection();
                                                int responsecode = httpConnection.getResponseCode();
                                                if (199 < responsecode && responsecode < 300) {
@@ -79,8 +85,9 @@ public class JpredParserHTTP implements JpredParser {
                                                                        final FastaSequence fs = fr.next();
                                                                        if (fs.getId().equals("QUERY") || fs.getId().equals(id))
                                                                                newprotein = fs.getSequence().replaceAll("\n", "");
-                                                                       else
+                                                                       else if (fs.getId().equals("jnetpred") || fs.getId().equals("JNETPRED")) {
                                                                                seqs.add(fs);
+                                                                       }
                                                                }
                                                                if (newprotein.equals("")) {
                                                                        countUnclearFASTAid++;
@@ -96,10 +103,12 @@ public class JpredParserHTTP implements JpredParser {
                                                                        }
                                                                        cc.InsertData(dateWork1, table[0], table[1], table[2], id, "OK", "OK", newprotein, seqs);
                                                                        ++countinsertions;
-                                                                       // flush every 100 insertions
-                                                                       if (0 == countinsertions % 100) {
-                                                                               cc.flushData();
-                                                                       }
+                                                                       ++njobs;
+                                                                       // flush every 50 insertions
+                                                                       //if (0 == countinsertions % 50) {
+                                                                       //      cc.flushData();
+                                                                       //      njobs -= 50;
+                                                                       //}
                                                                }
                                                        } catch (IOException e) {
                                                                e.printStackTrace();
@@ -131,5 +140,6 @@ public class JpredParserHTTP implements JpredParser {
                } catch (IOException e) {
                        e.printStackTrace();
                }
+               return njobs;
        }
 }