1 package compbio.cassandra;
4 import java.util.HashMap;
6 import java.util.ArrayList;
9 import org.apache.log4j.Logger;
11 import com.datastax.driver.core.Row;
12 import com.datastax.driver.core.Session;
13 import com.datastax.driver.core.ResultSet;
15 public class CassandraReader {
16 private Session session;
17 private static Logger log = Logger.getLogger(CassandraNativeConnector.class);
19 public CassandraReader() {
20 Session inis = CassandraNativeConnector.getSession();
24 public void setSession(Session s) {
30 * getting data from the db
32 public List<Pair<String, String>> ReadProteinDataTable() {
33 final long startTime = System.currentTimeMillis();
34 String com = "SELECT DataBegin,DataEnd FROM ProteinLog;";
35 System.out.println("Command: " + com);
36 ResultSet results = session.execute(com);
37 final long queryTime = System.currentTimeMillis();
38 List<Row> rows = results.all();
39 System.out.println("Query time is " + (queryTime - startTime) + " msec");
41 List<Pair<String, String>> res = new ArrayList<Pair<String, String>>();
44 Pair<String, String> pair = new Pair<String, String>(r.getString("DataBegin"), r.getString("DataEnd"));
48 final long endTime = System.currentTimeMillis();
49 System.out.println(c + " rows analysed, execution time is " + (endTime - startTime) + " msec");
54 * getting data from the db JobDateInfo
56 public List<Long> ReadDateTable(long queryDate) {
57 ResultSet results = session.execute("SELECT * FROM JobDateInfo WHERE jobday = " + queryDate + ";");
58 if (results.isExhausted())
60 Row therow = results.one();
61 List<Long> res = new ArrayList<Long>();
62 res.add(therow.getLong("Total"));
63 res.add(therow.getLong("TotalOK"));
64 res.add(therow.getLong("TotalStopped"));
65 res.add(therow.getLong("TotalError"));
66 res.add(therow.getLong("TotalTimeOut"));
67 if (!results.isExhausted()) {
68 Date date = new Date (queryDate);
69 log.warn("CassandraReader.ReadDateTable: date row for " + date.toString () + " ("+ queryDate + ") duplicated ");
74 * getting whole protein sequence from the db ProteinRow
76 public List<StructureProteinPrediction> ReadWholeSequence(String queryProtein) {
77 final long startTime = System.currentTimeMillis();
78 String com = "SELECT JobID, Predictions FROM ProteinRow WHERE Protein = '" + queryProtein + "';";
79 System.out.println("Command: " + com);
80 ResultSet results = session.execute(com);
81 if (results.isExhausted())
83 final long queryTime = System.currentTimeMillis();
84 List<Row> rows = results.all();
85 System.out.println("Query time is " + (queryTime - startTime) + " msec");
86 System.out.println(" rows analysed, " + rows.size());
87 List<StructureProteinPrediction> res = new ArrayList<StructureProteinPrediction>();
90 StructureProteinPrediction structure = new StructureProteinPrediction(queryProtein, r.getString("JobID"), r.getMap(
91 "Predictions", String.class, String.class));
95 final long endTime = System.currentTimeMillis();
96 System.out.println(c + " rows analysed, execution time is " + (endTime - startTime) + " msec");
101 * getting part of protein sequence from the db ProteinRow
103 public List<StructureProteinPrediction> ReadPartOfSequence(String queryProtein) {
104 final long startTime = System.currentTimeMillis();
105 String com = "SELECT * FROM ProteinRow;";
106 System.out.println("Command: " + com);
107 ResultSet results = session.execute(com);
108 if (results.isExhausted())
110 final long queryTime = System.currentTimeMillis();
111 List<Row> rows = results.all();
112 System.out.println("Query time is " + (queryTime - startTime) + " msec");
113 System.out.println(" rows analysed, " + rows.size());
114 List<StructureProteinPrediction> res = new ArrayList<StructureProteinPrediction>();
117 String prot = r.getString("Protein");
118 if (prot.matches("(.*)" + queryProtein + "(.*)")) {
119 StructureProteinPrediction structure = new StructureProteinPrediction(prot, r.getString("JobID"), r.getMap("Predictions",
120 String.class, String.class));
125 final long endTime = System.currentTimeMillis();
126 System.out.println(c + " rows analysed, execution time is " + (endTime - startTime) + " msec");
131 * getting protein sequences by counter
133 public Map<String, Integer> ReadProteinSequenceByCounter() {
134 final long startTime = System.currentTimeMillis();
135 String com = "SELECT Protein, JobID FROM ProteinRow;";
136 System.out.println("Command: " + com);
137 ResultSet results = session.execute(com);
138 if (results.isExhausted())
140 final long queryTime = System.currentTimeMillis();
141 List<Row> rows = results.all();
142 System.out.println("Query time is " + (queryTime - startTime) + " msec");
143 System.out.println(" rows analysed, " + rows.size());
144 Map<String, Integer> res = new HashMap<String, Integer>();
147 String protein = r.getString("Protein");
148 String id = r.getString("JobID");
149 if (res.containsKey(protein))
150 res.put(protein, res.get(protein) + 1);
154 final long endTime = System.currentTimeMillis();
155 System.out.println(c + " rows analysed, execution time is " + (endTime - startTime) + " msec");
160 * getting protein sequences by counter
162 public StructureJobLog ReadJobLog(String jobid) {
163 final long startTime = System.currentTimeMillis();
164 String com = "SELECT * FROM ProteinLog WHERE JobID = '" + jobid + "';";
165 System.out.println("Command: " + com);
166 ResultSet results = session.execute(com);
167 if (results.isExhausted())
169 final long queryTime = System.currentTimeMillis();
170 Row row = results.one();
171 String com1 = "SELECT * FROM ProteinRow WHERE JobID = '" + jobid + "' ALLOW FILTERING;";
172 System.out.println("Command: " + com1);
173 ResultSet results1 = session.execute(com1);
174 if (results1.isExhausted())
176 Row row1 = results1.one();
177 StructureJobLog res = new StructureJobLog(row.getString("Protein"), row.getString("JobID"), row.getString("DataBegin"),
178 row.getString("DataEnd"), row.getString("ip"), row1.getMap("Predictions", String.class, String.class));
179 System.out.println("Query time is " + (queryTime - startTime) + " msec");
180 final long endTime = System.currentTimeMillis();
181 System.out.println(" rows analysed, execution time is " + (endTime - startTime) + " msec");