1 package compbio.cassandra;
3 import java.io.BufferedReader;
4 import java.io.IOException;
5 import java.io.InputStreamReader;
6 import java.net.HttpURLConnection;
7 import java.net.MalformedURLException;
9 import java.net.URLConnection;
10 import java.text.ParseException;
11 import java.text.SimpleDateFormat;
12 import java.util.ArrayList;
13 import java.util.Calendar;
14 import java.util.Date;
15 import java.util.List;
17 import compbio.cassandra.JpredParser;
19 public class JpredParserHTTP implements JpredParser {
20 private CassandraCreate cc = new CassandraCreate();
21 private String dirprefix;
24 this.dirprefix = "http://www.compbio.dundee.ac.uk/www-jpred/results";
27 JpredParserHTTP(String sourceurl) {
28 this.dirprefix = sourceurl;
31 public void setSource (String newsourceprefix) {
32 this.dirprefix = newsourceprefix;
35 public void Parsing(String source, int nDays) {
36 Calendar cal = Calendar.getInstance();
37 cal.add(Calendar.DATE, -nDays);
38 for (int i = 0; i < nDays; ++i) {
39 cal.add(Calendar.DATE, 1);
40 int month = cal.get(Calendar.MONTH) + 1;
41 int year = cal.get(Calendar.YEAR);
42 int day = cal.get(Calendar.DATE);
43 String date = year + "/" + month + "/" + day;
44 ParsingForDate(source, date);
48 private void ParsingForDate(String input, String date) {
51 int countUnclearFASTAid = 0;
52 int countinsertions = 0;
53 int countinserted = 0;
54 int counAlignments = 0;
57 System.out.println("Inserting jobs for " + date);
59 URL url = new URL(input);
60 URLConnection conn = url.openConnection();
61 BufferedReader alljobs = new BufferedReader(new InputStreamReader(conn.getInputStream()));
64 while ((line = alljobs.readLine()) != null) {
65 if (line.matches(date + "(.*)jp_[^\\s]+")) {
66 String[] table = line.split("\\s+");
67 String id = table[table.length - 1];
69 if (!cc.CheckID(id)) {
70 URL urltable = new URL(dirprefix + "/" + id + "/" + id + ".concise.fasta");
71 HttpURLConnection httpConnection = (HttpURLConnection) urltable.openConnection();
72 int responsecode = httpConnection.getResponseCode();
73 if (199 < responsecode && responsecode < 300) {
75 final FastaReader fr = new FastaReader(urltable.openStream());
76 final List<FastaSequence> seqs = new ArrayList<FastaSequence>();
77 String newprotein = "";
78 while (fr.hasNext()) {
79 final FastaSequence fs = fr.next();
80 if (fs.getId().equals("QUERY") || fs.getId().equals(id))
81 newprotein = fs.getSequence().replaceAll("\n", "");
85 if (newprotein.equals("")) {
86 countUnclearFASTAid++;
88 SimpleDateFormat formatter = new SimpleDateFormat("yyyy/MM/dd");
89 String dateInString1 = table[0].substring(0, table[0].indexOf(":"));
92 Date dat1 = formatter.parse(dateInString1);
93 dateWork1 = dat1.getTime();
94 } catch (ParseException e) {
97 cc.InsertData(dateWork1, table[0], table[1], table[2], id, "OK", "OK", newprotein, seqs);
99 // flush every 100 insertions
100 if (0 == countinsertions % 100) {
104 } catch (IOException e) {
114 if (line.matches(date + "(.*)Sequence0/(.*)")) {
122 System.out.println("Total number of jobs = " + totalcount);
123 System.out.println(" " + countinserted + " jobs inserted already");
124 System.out.println(" " + counAlignments + " jalview jobs");
125 System.out.println(" " + countStrange + " not analysed jobs");
126 System.out.println(" " + countNoData + " jobs without *.concise.fasta file");
127 System.out.println(" " + countUnclearFASTAid + " jobs with unclear FASTA protein id in *.concise.fasta");
128 System.out.println(" " + countinsertions + " new job insertions\n");
129 } catch (MalformedURLException e) {
131 } catch (IOException e) {