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 to the controller SSFeaturesController * **/ public Map readProteinsPrediction(String feature, int percent) { ResultSet results = CassandraQuery("SELECT * FROM ProteinRow;"); if (results.isExhausted()) return null; List rows = results.all(); Map query = new HashMap(); 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 pred) { if (pred != null) { if (pred.containsKey("jnetpred")) return pred.get("jnetpred"); } return null; } }