new readers for the queries
[proteocache.git] / datadb / compbio / cassandra / readers / PredictionReader.java
diff --git a/datadb/compbio/cassandra/readers/PredictionReader.java b/datadb/compbio/cassandra/readers/PredictionReader.java
new file mode 100644 (file)
index 0000000..b7613a3
--- /dev/null
@@ -0,0 +1,53 @@
+package compbio.cassandra.readers;
+
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+
+import com.datastax.driver.core.ResultSet;
+import com.datastax.driver.core.Row;
+
+public class PredictionReader extends CassandraReader {
+       
+       public PredictionReader() {
+               super();
+       }
+       
+       /**
+        * query: protein feature
+        * 
+        *  @param feature
+        *      a feature of secondary structure: Helix or Beta Sheet
+        *  
+        *  @param percent
+        *      fraction the feature in the protein
+        * 
+        * @return Map<String, String> to the controller SSFeaturesController
+        * 
+        **/
+       public Map<String, String> readProteinsPrediction(String feature, int percent) {
+               ResultSet results = CassandraQuery("SELECT * FROM ProteinRow;");
+               if (results.isExhausted())
+                       return null;
+               List<Row> rows = results.all();
+               Map<String, String> query = new HashMap<String, String>();
+               for (Row r : rows) {
+                       String prot = r.getString("Protein");
+                       String prediction = findJnetpred(r.getMap("Predictions", String.class, String.class));
+                       if (prot != null || prediction != null) {
+                               if (prediction.replaceAll("[^"+feature+"]", "").length() > prediction.length() * percent / 100) {
+                                       query.put(prot, prediction);
+                               }
+                       }
+               }
+               return query;
+       }
+
+       private String findJnetpred (Map<String,String> pred) {
+               if (pred != null) {
+                       if (pred.containsKey("jnetpred")) 
+                               return pred.get("jnetpred");
+               }
+               return null;
+       }
+}