new readers for the queries
[proteocache.git] / datadb / compbio / cassandra / readers / PredictionReader.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 public class PredictionReader extends CassandraReader {
11         
12         public PredictionReader() {
13                 super();
14         }
15         
16         /**
17          * query: protein feature
18          * 
19          *  @param feature
20          *      a feature of secondary structure: Helix or Beta Sheet
21          *  
22          *  @param percent
23          *      fraction the feature in the protein
24          * 
25          * @return Map<String, String> to the controller SSFeaturesController
26          * 
27          **/
28         public Map<String, String> readProteinsPrediction(String feature, int percent) {
29                 ResultSet results = CassandraQuery("SELECT * FROM ProteinRow;");
30                 if (results.isExhausted())
31                         return null;
32                 List<Row> rows = results.all();
33                 Map<String, String> query = new HashMap<String, String>();
34                 for (Row r : rows) {
35                         String prot = r.getString("Protein");
36                         String prediction = findJnetpred(r.getMap("Predictions", String.class, String.class));
37                         if (prot != null || prediction != null) {
38                                 if (prediction.replaceAll("[^"+feature+"]", "").length() > prediction.length() * percent / 100) {
39                                         query.put(prot, prediction);
40                                 }
41                         }
42                 }
43                 return query;
44         }
45
46         private String findJnetpred (Map<String,String> pred) {
47                 if (pred != null) {
48                         if (pred.containsKey("jnetpred")) 
49                                 return pred.get("jnetpred");
50                 }
51                 return null;
52         }
53 }