1 package compbio.cassandra;
3 import java.util.Calendar;
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.engine.ProteoCachePropertyHelperManager;
16 import compbio.util.PropertyHelper;
18 public class CassandraReader {
19 private Session session;
20 private static Logger log = Logger.getLogger(CassandraNativeConnector.class);
22 public CassandraReader() {
23 Session inis = CassandraNativeConnector.getSession();
27 public void setSession(Session s) {
33 * getting data from the db
35 public List<Pair<String, String>> ReadProteinDataTable() {
36 final long startTime = System.currentTimeMillis();
37 String com = "SELECT DataBegin,DataEnd FROM ProteinLog;";
38 System.out.println("Command: " + com);
39 ResultSet results = session.execute(com);
40 final long queryTime = System.currentTimeMillis();
41 List<Row> rows = results.all();
42 System.out.println("Query time is " + (queryTime - startTime) + " msec");
44 List<Pair<String, String>> res = new ArrayList<Pair<String, String>>();
47 Pair<String, String> pair = new Pair<String, String>(r.getString("DataBegin"), r.getString("DataEnd"));
51 final long endTime = System.currentTimeMillis();
52 System.out.println(c + " rows analysed, execution time is " + (endTime - startTime) + " msec");
57 * getting data from the db ProteinData
59 public Integer ReadDateTable(long queryDate) {
60 final long startTime = System.currentTimeMillis();
61 String com = "SELECT jobtime, JobID FROM ProteinData WHERE jobtime = " + queryDate + ";";
62 System.out.println("Command: " + com);
63 ResultSet results = session.execute(com);
64 final long queryTime = System.currentTimeMillis();
65 System.out.println("Query time is " + (queryTime - startTime) + " msec");
66 if (results.isExhausted())
68 List<Row> rows = results.all();
69 final long endTime = System.currentTimeMillis();
70 System.out.println("Processing time is " + (endTime - queryTime) + " msec");
75 * getting whole protein sequence from the db ProteinRow
77 public List<StructureProteinPrediction> ReadWholeSequence(String queryProtein) {
78 final long startTime = System.currentTimeMillis();
79 String com = "SELECT JobID, Predictions FROM ProteinRow WHERE Protein = '" + queryProtein + "';";
80 System.out.println("Command: " + com);
81 ResultSet results = session.execute(com);
82 if (results.isExhausted())
84 final long queryTime = System.currentTimeMillis();
85 List<Row> rows = results.all();
86 System.out.println("Query time is " + (queryTime - startTime) + " msec");
87 System.out.println(" rows analysed, " + rows.size());
88 List<StructureProteinPrediction> res = new ArrayList<StructureProteinPrediction>();
91 StructureProteinPrediction structure = new StructureProteinPrediction(queryProtein, r.getString("JobID"), r.getMap(
92 "Predictions", String.class, String.class));
96 final long endTime = System.currentTimeMillis();
97 System.out.println(c + " rows analysed, execution time is " + (endTime - startTime) + " msec");
102 * getting part of protein sequence from the db ProteinRow
104 public List<StructureProteinPrediction> ReadPartOfSequence(String queryProtein) {
105 final long startTime = System.currentTimeMillis();
106 String com = "SELECT * FROM ProteinRow;";
107 System.out.println("Command: " + com);
108 ResultSet results = session.execute(com);
109 if (results.isExhausted())
111 final long queryTime = System.currentTimeMillis();
112 List<Row> rows = results.all();
113 System.out.println("Query time is " + (queryTime - startTime) + " msec");
114 System.out.println(" rows analysed, " + rows.size());
115 List<StructureProteinPrediction> res = new ArrayList<StructureProteinPrediction>();
118 String prot = r.getString("Protein");
119 if (prot.matches("(.*)" + queryProtein + "(.*)")) {
120 StructureProteinPrediction structure = new StructureProteinPrediction(prot, r.getString("JobID"), r.getMap("Predictions",
121 String.class, String.class));
126 final long endTime = System.currentTimeMillis();
127 System.out.println(c + " rows analysed, execution time is " + (endTime - startTime) + " msec");
132 * getting protein sequences by counter
134 public Map<String, Integer> ReadProteinDataByCounter() {
135 final long startTime = System.currentTimeMillis();
136 String com = "SELECT Protein FROM ProteinRow;";
137 System.out.println("Command: " + com);
138 ResultSet results = session.execute(com);
139 if (results.isExhausted())
141 final long queryTime = System.currentTimeMillis();
142 List<Row> rows = results.all();
143 System.out.println("Query time is " + (queryTime - startTime) + " msec");
144 System.out.println(" rows analysed, " + rows.size());
145 Map<String, Integer> res = new HashMap<String, Integer>();
148 String protein = r.getString("Protein");
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");