Deleted CassandraRequest.java and CassandraReaderOld.java
[proteocache.git] / datadb / compbio / cassandra / readers / FeaturesReader.java
1 package compbio.cassandra.readers;
2
3 import java.util.HashMap;
4 import java.util.List;
5 import java.util.Map;
6
7 import com.datastax.driver.core.ResultSet;
8 import com.datastax.driver.core.Row;
9
10
11 public class FeaturesReader extends CassandraReader {
12
13         public FeaturesReader() {
14                 super();
15         }
16
17         /**
18          * query protein feature
19          * 
20          * @param feature
21          *                      protein SS feature
22          * 
23          * @param percent
24          *                      percent SS feature in protein sequence
25          * 
26          * @return UserBean to the controller SSFeaturesController
27          **/
28          
29          public Map<String, String> readProteinsPrediction(String feature, int percent) {
30                  ResultSet results = CassandraQuery("SELECT * FROM ProteinRow;");
31                  if (results.isExhausted())
32                                 return null;
33                 List<Row> rows = results.all();
34                 Map<String, String> query = new HashMap<String, String>();
35                 for (Row r : rows) {
36                         String prot = r.getString("Protein");
37                         String prediction = findJnetpred(r.getMap("Predictions", String.class, String.class));
38                         if (prot != null && prediction != null && (!prot.equals(""))) {
39                                 if (prediction.replaceAll("[^" + feature + "]", "").length() > prediction.length() * percent / 100 ) {
40                                         query.put(prot, prediction);
41                                 }
42                         }
43                 }
44                 return query;
45         }
46
47          
48         private String findJnetpred(Map<String, String> pred) {
49                 if (pred != null) {
50                         if (pred.containsKey("jnetpred"))
51                                 return pred.get("jnetpred");
52                 }
53                 return null;
54         }
55
56
57 }