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 import compbio.beans.DateBean;
16 import compbio.beans.JobBean;
17 import compbio.beans.ProteinBean;
18 import compbio.beans.Total;
19 import compbio.engine.JobStatus;
21 public class CassandraReaderOld {
22 private Session session;
23 private static Logger log = Logger.getLogger(CassandraNativeConnector.class);
25 public CassandraReaderOld() {
26 Session inis = CassandraNativeConnector.getSession();
30 public void setSession(Session s) {
36 * getting data from the db
38 public List<Pair<String, String>> ReadProteinDataTable() {
39 final long startTime = System.currentTimeMillis();
40 String com = "SELECT DataBegin,DataEnd FROM ProteinLog;";
41 System.out.println("Command: " + com);
42 ResultSet results = session.execute(com);
43 final long queryTime = System.currentTimeMillis();
44 List<Row> rows = results.all();
45 System.out.println("Query time is " + (queryTime - startTime) + " msec");
47 List<Pair<String, String>> res = new ArrayList<Pair<String, String>>();
50 Pair<String, String> pair = new Pair<String, String>(r.getString("DataBegin"), r.getString("DataEnd"));
54 final long endTime = System.currentTimeMillis();
55 System.out.println(c + " rows analysed, execution time is " + (endTime - startTime) + " msec");
60 * getting data from the db
62 public DateBean ReadProteinData(long day, String date) {
63 String com = "SELECT JobID, Protein FROM ProteinData WHERE jobtime = " + day + ";";
64 System.out.println("Command: " + com);
65 ResultSet results = session.execute(com);
66 if (results.isExhausted())
68 List<Row> rows = results.all();
69 DateBean res = new DateBean(date);
71 res.setJobidAndSeq(r.getString("JobID"), r.getString("Protein"));
77 * getting data from the db
79 public DateBean ReadFailedJobs(long day, String date, JobStatus status) {
80 // FailLog (jobtime, JobID, ExecTime, ip, FinalStatus)
81 String com = "SELECT JobID FROM FailLog WHERE jobtime = " + day + " and FinalStatus = '" + status.name() + "';";
82 ResultSet results = session.execute(com);
83 if (results.isExhausted())
85 List<Row> rows = results.all();
86 DateBean res = new DateBean(date);
88 String jobid = r.getString("JobID");
89 String com1 = "SELECT Protein FROM ProteinLog WHERE JobID = '" + jobid + "';";
90 System.out.println("Command: " + com1);
91 ResultSet results2 = session.execute(com1);
92 List<Row> jrows = results2.all();
93 if (1 == jrows.size()) {
94 String protein = jrows.get(0).getString("Protein");
95 res.setJobidAndSeq(jobid, protein);
102 * getting data from the db JobDateInfo
104 public Total ReadDateTable(long queryDate) {
105 ResultSet results = session.execute("SELECT * FROM JobDateInfo WHERE jobday = " + queryDate + ";");
106 if (results.isExhausted())
108 Row therow = results.one();
109 Total res = new Total(therow.getLong("Total"), therow.getLong("TotalOK"), therow.getLong("TotalStopped"),
110 therow.getLong("TotalError"), therow.getLong("TotalTimeOut"));
111 if (!results.isExhausted()) {
112 Date date = new Date(queryDate);
113 log.warn("CassandraReader.ReadDateTable: date row for " + date.toString() + " (" + queryDate + ") duplicated ");
119 * getting whole protein sequence from the db ProteinRow
121 public List<ProteinBean> ReadWholeSequence(String queryProtein) {
122 final long startTime = System.currentTimeMillis();
123 String com = "SELECT JobID, Predictions FROM ProteinRow WHERE Protein = '" + queryProtein + "';";
124 System.out.println("Command: " + com);
125 ResultSet results = session.execute(com);
126 if (results.isExhausted())
128 final long queryTime = System.currentTimeMillis();
129 List<Row> rows = results.all();
130 System.out.println("first size : " + rows.size());
131 System.out.println("Query time is " + (queryTime - startTime) + " msec");
132 System.out.println(" rows analysed, " + rows.size());
133 List<ProteinBean> res = new ArrayList<ProteinBean>();
134 ProteinBean structure = new ProteinBean(queryProtein, rows.get(0).getMap("Predictions", String.class, String.class));
135 System.out.println("second size : " + rows.size());
138 structure.setJobid(r.getString("JobID"));
142 final long endTime = System.currentTimeMillis();
143 System.out.println(c + " rows analysed, execution time is " + (endTime - startTime) + " msec");
150 public Map<String, String[]> ReadIpWithJobs(String ip) {
151 final long startTime = System.currentTimeMillis();
152 String com = "SELECT JobID, Protein, FinalStatus, DataBegin FROM ProteinLog WHERE ip = '" + ip + "';";
153 System.out.println("Command: " + com);
154 ResultSet results = session.execute(com);
155 if (results.isExhausted())
157 final long queryTime = System.currentTimeMillis();
158 List<Row> rows = results.all();
159 Map<String, String[]> res = new HashMap<String, String[]>();
160 System.out.println("Query time is " + (queryTime - startTime) + " msec");
161 System.out.println(" rows analysed, " + rows.size());
164 if (r.getString("FinalStatus").equals("OK")) {
165 String date = r.getString("DataBegin");
166 res.put(r.getString("JobID"), new String[] { date.substring(0, date.indexOf(":")), r.getString("Protein") });
170 final long endTime = System.currentTimeMillis();
171 System.out.println(c + " rows analysed, execution time is " + (endTime - startTime) + " msec");
176 * getting part of protein sequence from the db ProteinRow
178 public List<ProteinBean> ReadPartOfSequence(String queryProtein) {
179 final long startTime = System.currentTimeMillis();
180 String com = "SELECT * FROM ProteinRow;";
181 System.out.println("Command: " + com);
182 ResultSet results = session.execute(com);
183 if (results.isExhausted())
185 final long queryTime = System.currentTimeMillis();
186 List<Row> rows = results.all();
187 System.out.println("Query time is " + (queryTime - startTime) + " msec");
188 System.out.println(" rows analysed, " + rows.size());
189 List<ProteinBean> res = new ArrayList<ProteinBean>();
192 String prot = r.getString("Protein");
193 if (prot.matches("(.*)" + queryProtein + "(.*)")) {
194 ProteinBean structure = new ProteinBean(prot, r.getMap("Predictions", String.class, String.class));
195 structure.setJobid(r.getString("JobID"));
200 final long endTime = System.currentTimeMillis();
201 System.out.println(c + " rows analysed, execution time is " + (endTime - startTime) + " msec");
206 * getting protein sequence from the db ProteinRow
208 public Map<String, String> ReadProtein() {
209 final long startTime = System.currentTimeMillis();
210 String com = "SELECT * FROM ProteinRow;";
211 System.out.println("Command: " + com);
212 ResultSet results = session.execute(com);
213 if (results.isExhausted())
215 final long queryTime = System.currentTimeMillis();
216 List<Row> rows = results.all();
217 System.out.println("Query time is " + (queryTime - startTime) + " msec");
218 System.out.println(" rows analysed, " + rows.size());
219 Map<String, String> res = new HashMap<String, String>();
222 String prot = r.getString("Protein");
223 String prediction = findJnetpred(r.getMap("Predictions", String.class, String.class));
224 if (prot != null || prediction != null)
225 res.put(prot, prediction);
227 final long endTime = System.currentTimeMillis();
228 System.out.println(c + " rows analysed, execution time is " + (endTime - startTime) + " msec");
232 private String findJnetpred(Map<String, String> pred) {
234 if (pred.containsKey("jnetpred"))
235 return pred.get("jnetpred");
241 * getting protein sequences by counter
243 public Map<String, Integer> ReadProteinSequenceByCounter() {
244 final long startTime = System.currentTimeMillis();
245 String com = "SELECT Protein, JobID FROM ProteinRow;";
246 System.out.println("Command: " + com);
247 ResultSet results = session.execute(com);
248 if (results.isExhausted())
250 final long queryTime = System.currentTimeMillis();
251 List<Row> rows = results.all();
252 System.out.println("Query time is " + (queryTime - startTime) + " msec");
253 System.out.println(" rows analysed, " + rows.size());
254 Map<String, Integer> res = new HashMap<String, Integer>();
257 String protein = r.getString("Protein");
258 String id = r.getString("JobID");
259 if (res.containsKey(protein))
260 res.put(protein, res.get(protein) + 1);
264 final long endTime = System.currentTimeMillis();
265 System.out.println(c + " rows analysed, execution time is " + (endTime - startTime) + " msec");
270 * getting ip by counter
272 public Map<String, Integer> ReadIpByCounter() {
273 final long startTime = System.currentTimeMillis();
274 String com = "SELECT JobID, ip FROM ProteinLog;";
275 System.out.println("Command: " + com);
276 ResultSet results = session.execute(com);
277 if (results.isExhausted())
279 final long queryTime = System.currentTimeMillis();
280 List<Row> rows = results.all();
281 System.out.println("Query time is " + (queryTime - startTime) + " msec");
282 System.out.println(" rows analysed, " + rows.size());
283 Map<String, Integer> res = new HashMap<String, Integer>();
286 String ip = r.getString("ip");
287 String id = r.getString("JobID");
288 if (res.containsKey(ip))
289 res.put(ip, res.get(ip) + 1);
293 final long endTime = System.currentTimeMillis();
294 System.out.println(c + " rows analysed, execution time is " + (endTime - startTime) + " msec");
299 * getting log info for jobid
301 public JobBean ReadJobLog(String jobid) {
302 final long startTime = System.currentTimeMillis();
303 String com = "SELECT * FROM ProteinLog WHERE JobID = '" + jobid + "';";
304 System.out.println("Command: " + com);
305 ResultSet results = session.execute(com);
306 if (results.isExhausted())
308 final long queryTime = System.currentTimeMillis();
309 Row row = results.one();
310 String com1 = "SELECT * FROM ProteinRow WHERE JobID = '" + jobid + "' ALLOW FILTERING;";
311 System.out.println("Command: " + com1);
312 ResultSet results1 = session.execute(com1);
313 if (results1.isExhausted())
315 Row row1 = results1.one();
316 JobBean res = new JobBean(row.getString("Protein"), row.getString("JobID"), row.getString("DataBegin"), row.getString("DataEnd"),
317 row.getString("ip"), row1.getMap("Predictions", String.class, String.class), row.getString("ProgramName"),
318 row.getString("ProgramVersion"));
319 System.out.println("Query time is " + (queryTime - startTime) + " msec");
320 final long endTime = System.currentTimeMillis();
321 System.out.println(" rows analysed, execution time is " + (endTime - startTime) + " msec");