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 long ReadDateTable(long queryDate) {
57 ResultSet results = session.execute("SELECT Total FROM JobDateInfo WHERE jobday = " + queryDate + ";");
58 if (results.isExhausted())
60 Row therow = results.one();
61 long res = therow.getLong("Total");
62 if (!results.isExhausted()) {
63 Date date = new Date (queryDate);
64 log.warn("CassandraReader.ReadDateTable: date row for " + date.toString () + " ("+ queryDate + ") duplicated ");
69 * getting whole protein sequence from the db ProteinRow
71 public List<StructureProteinPrediction> ReadWholeSequence(String queryProtein) {
72 final long startTime = System.currentTimeMillis();
73 String com = "SELECT JobID, Predictions FROM ProteinRow WHERE Protein = '" + queryProtein + "';";
74 System.out.println("Command: " + com);
75 ResultSet results = session.execute(com);
76 if (results.isExhausted())
78 final long queryTime = System.currentTimeMillis();
79 List<Row> rows = results.all();
80 System.out.println("Query time is " + (queryTime - startTime) + " msec");
81 System.out.println(" rows analysed, " + rows.size());
82 List<StructureProteinPrediction> res = new ArrayList<StructureProteinPrediction>();
85 StructureProteinPrediction structure = new StructureProteinPrediction(queryProtein, r.getString("JobID"), r.getMap(
86 "Predictions", String.class, String.class));
90 final long endTime = System.currentTimeMillis();
91 System.out.println(c + " rows analysed, execution time is " + (endTime - startTime) + " msec");
96 * getting part of protein sequence from the db ProteinRow
98 public List<StructureProteinPrediction> ReadPartOfSequence(String queryProtein) {
99 final long startTime = System.currentTimeMillis();
100 String com = "SELECT * FROM ProteinRow;";
101 System.out.println("Command: " + com);
102 ResultSet results = session.execute(com);
103 if (results.isExhausted())
105 final long queryTime = System.currentTimeMillis();
106 List<Row> rows = results.all();
107 System.out.println("Query time is " + (queryTime - startTime) + " msec");
108 System.out.println(" rows analysed, " + rows.size());
109 List<StructureProteinPrediction> res = new ArrayList<StructureProteinPrediction>();
112 String prot = r.getString("Protein");
113 if (prot.matches("(.*)" + queryProtein + "(.*)")) {
114 StructureProteinPrediction structure = new StructureProteinPrediction(prot, r.getString("JobID"), r.getMap("Predictions",
115 String.class, String.class));
120 final long endTime = System.currentTimeMillis();
121 System.out.println(c + " rows analysed, execution time is " + (endTime - startTime) + " msec");
126 * getting protein sequences by counter
128 public Map<String, Integer> ReadProteinSequenceByCounter() {
129 final long startTime = System.currentTimeMillis();
130 String com = "SELECT Protein, JobID FROM ProteinRow;";
131 System.out.println("Command: " + com);
132 ResultSet results = session.execute(com);
133 if (results.isExhausted())
135 final long queryTime = System.currentTimeMillis();
136 List<Row> rows = results.all();
137 System.out.println("Query time is " + (queryTime - startTime) + " msec");
138 System.out.println(" rows analysed, " + rows.size());
139 Map<String, Integer> res = new HashMap<String, Integer>();
142 String protein = r.getString("Protein");
143 String id = r.getString("JobID");
144 System.out.println(id + ", " + protein);
145 if (res.containsKey(protein))
146 res.put(protein, res.get(protein) + 1);
150 final long endTime = System.currentTimeMillis();
151 System.out.println(c + " rows analysed, execution time is " + (endTime - startTime) + " msec");
156 * getting protein sequences by counter
158 public StructureJobLog ReadJobLog(String jobid) {
159 final long startTime = System.currentTimeMillis();
160 String com = "SELECT * FROM ProteinLog WHERE JobID = '" + jobid + "';";
161 System.out.println("Command: " + com);
162 ResultSet results = session.execute(com);
163 if (results.isExhausted())
165 final long queryTime = System.currentTimeMillis();
166 Row row = results.one();
167 String com1 = "SELECT * FROM ProteinRow WHERE JobID = '" + jobid + "' ALLOW FILTERING;";
168 System.out.println("Command: " + com1);
169 ResultSet results1 = session.execute(com1);
170 if (results1.isExhausted())
172 Row row1 = results1.one();
173 StructureJobLog res = new StructureJobLog(row.getString("Protein"), row.getString("JobID"), row.getString("DataBegin"),
174 row.getString("DataEnd"), row.getString("ip"), row1.getMap("Predictions", String.class, String.class));
175 System.out.println("Query time is " + (queryTime - startTime) + " msec");
176 final long endTime = System.currentTimeMillis();
177 System.out.println(" rows analysed, execution time is " + (endTime - startTime) + " msec");