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
56 public List<Pair<String, String>> ReadProteinData(long day) {
57 final long startTime = System.currentTimeMillis();
58 String com = "SELECT JobID, Protein FROM ProteinData WHERE jobtime = " + day + ";";
59 System.out.println("Command: " + com);
60 ResultSet results = session.execute(com);
61 if (results.isExhausted())
63 final long queryTime = System.currentTimeMillis();
64 List<Row> rows = results.all();
65 System.out.println("Query time is " + (queryTime - startTime) + " msec");
66 List<Pair<String, String>> res = new ArrayList<Pair<String, String>>();
69 Pair<String, String> pair = new Pair<String, String>(r.getString("JobID"), r.getString("Protein"));
73 final long endTime = System.currentTimeMillis();
74 System.out.println(c + " rows analysed, execution time is " + (endTime - startTime) + " msec");
78 * getting data from the db JobDateInfo
80 public List<Long> ReadDateTable(long queryDate) {
81 ResultSet results = session.execute("SELECT * FROM JobDateInfo WHERE jobday = " + queryDate + ";");
82 if (results.isExhausted())
84 Row therow = results.one();
85 List<Long> res = new ArrayList<Long>();
86 res.add(therow.getLong("Total"));
87 res.add(therow.getLong("TotalOK"));
88 res.add(therow.getLong("TotalStopped"));
89 res.add(therow.getLong("TotalError"));
90 res.add(therow.getLong("TotalTimeOut"));
91 if (!results.isExhausted()) {
92 Date date = new Date (queryDate);
93 log.warn("CassandraReader.ReadDateTable: date row for " + date.toString () + " ("+ queryDate + ") duplicated ");
98 * getting whole protein sequence from the db ProteinRow
100 public List<StructureProteinPrediction> ReadWholeSequence(String queryProtein) {
101 final long startTime = System.currentTimeMillis();
102 String com = "SELECT JobID, Predictions FROM ProteinRow WHERE Protein = '" + queryProtein + "';";
103 System.out.println("Command: " + com);
104 ResultSet results = session.execute(com);
105 if (results.isExhausted())
107 final long queryTime = System.currentTimeMillis();
108 List<Row> rows = results.all();
109 System.out.println("Query time is " + (queryTime - startTime) + " msec");
110 System.out.println(" rows analysed, " + rows.size());
111 List<StructureProteinPrediction> res = new ArrayList<StructureProteinPrediction>();
114 StructureProteinPrediction structure = new StructureProteinPrediction(queryProtein, r.getString("JobID"), r.getMap(
115 "Predictions", String.class, String.class));
116 if (structure.getPrediction().containsKey("jnetpred"))
117 structure.setJnetpred(structure.getPrediction().get("jnetpred"));
119 structure.setJnetpred("");
123 final long endTime = System.currentTimeMillis();
124 System.out.println(c + " rows analysed, execution time is " + (endTime - startTime) + " msec");
129 * getting part of protein sequence from the db ProteinRow
131 public List<StructureProteinPrediction> ReadPartOfSequence(String queryProtein) {
132 final long startTime = System.currentTimeMillis();
133 String com = "SELECT * FROM ProteinRow;";
134 System.out.println("Command: " + com);
135 ResultSet results = session.execute(com);
136 if (results.isExhausted())
138 final long queryTime = System.currentTimeMillis();
139 List<Row> rows = results.all();
140 System.out.println("Query time is " + (queryTime - startTime) + " msec");
141 System.out.println(" rows analysed, " + rows.size());
142 List<StructureProteinPrediction> res = new ArrayList<StructureProteinPrediction>();
145 String prot = r.getString("Protein");
146 if (prot.matches("(.*)" + queryProtein + "(.*)")) {
147 StructureProteinPrediction structure = new StructureProteinPrediction(prot, r.getString("JobID"), r.getMap("Predictions",
148 String.class, String.class));
153 final long endTime = System.currentTimeMillis();
154 System.out.println(c + " rows analysed, execution time is " + (endTime - startTime) + " msec");
159 * getting protein sequences by counter
161 public Map<String, Integer> ReadProteinSequenceByCounter() {
162 final long startTime = System.currentTimeMillis();
163 String com = "SELECT Protein, JobID FROM ProteinRow;";
164 System.out.println("Command: " + com);
165 ResultSet results = session.execute(com);
166 if (results.isExhausted())
168 final long queryTime = System.currentTimeMillis();
169 List<Row> rows = results.all();
170 System.out.println("Query time is " + (queryTime - startTime) + " msec");
171 System.out.println(" rows analysed, " + rows.size());
172 Map<String, Integer> res = new HashMap<String, Integer>();
175 String protein = r.getString("Protein");
176 String id = r.getString("JobID");
177 if (res.containsKey(protein))
178 res.put(protein, res.get(protein) + 1);
182 final long endTime = System.currentTimeMillis();
183 System.out.println(c + " rows analysed, execution time is " + (endTime - startTime) + " msec");
188 * getting log info for jobid
190 public StructureJobLog ReadJobLog(String jobid) {
191 final long startTime = System.currentTimeMillis();
192 String com = "SELECT * FROM ProteinLog WHERE JobID = '" + jobid + "';";
193 System.out.println("Command: " + com);
194 ResultSet results = session.execute(com);
195 if (results.isExhausted())
197 final long queryTime = System.currentTimeMillis();
198 Row row = results.one();
199 String com1 = "SELECT * FROM ProteinRow WHERE JobID = '" + jobid + "' ALLOW FILTERING;";
200 System.out.println("Command: " + com1);
201 ResultSet results1 = session.execute(com1);
202 if (results1.isExhausted())
204 Row row1 = results1.one();
205 StructureJobLog res = new StructureJobLog(row.getString("Protein"), row.getString("JobID"), row.getString("DataBegin"),
206 row.getString("DataEnd"), row.getString("ip"), row1.getMap("Predictions", String.class, String.class));
207 System.out.println("Query time is " + (queryTime - startTime) + " msec");
208 final long endTime = System.currentTimeMillis();
209 System.out.println(" rows analysed, execution time is " + (endTime - startTime) + " msec");