1 package compbio.cassandra.readers;
3 import java.util.ArrayList;
6 import com.datastax.driver.core.ResultSet;
7 import com.datastax.driver.core.Row;
9 import compbio.beans.ProteinBean;
12 * Reader class for making requests on protein sequences to cassandra.
14 * @author Alexander Sherstnev
15 * @author Natasha Sherstneva
19 * @since December 2013
21 public class SequenceReader extends CassandraReader {
23 public SequenceReader() {
28 * query: protein sequence
31 * protein sequence or partial of protein sequence
33 * "whole" or "partial" of protein sequence
35 * @return List<ProteinBean> to the controller SequenceController
38 public List<ProteinBean> readProteins(String sequence, String searchtype) {
39 List<ProteinBean> query = new ArrayList<ProteinBean>();
40 if (searchtype.equals("whole")) {
41 ResultSet results = CassandraQuery("SELECT JobID, Predictions FROM ProteinRow WHERE Protein = '" + sequence + "';");
42 if (results.isExhausted())
44 List<Row> rows = results.all();
45 ProteinBean structure = new ProteinBean(sequence, rows.get(0).getMap("Predictions", String.class, String.class));
47 structure.setJobid(r.getString("JobID"));
51 ResultSet results = CassandraQuery("SELECT * FROM ProteinRow;");
52 if (results.isExhausted())
54 List<Row> rows = results.all();
56 String protein = r.getString("Protein");
57 if (protein.matches("(.*)" + sequence + "(.*)")) {
58 ProteinBean foundsequence = new ProteinBean(protein, r.getMap("Predictions", String.class, String.class));
59 foundsequence.setJobid(r.getString("JobID"));
60 query.add(foundsequence);
63 for (ProteinBean entry : query) {
64 entry.setSubProt(CreateSubprotein(entry.getSequence(), sequence));
71 * create a list of parts of protein sequence for highlighting current value
77 * partial of protein sequence
79 * @return List<String>
82 private static List<String> CreateSubprotein(String protein, String subprot) {
83 List<String> sub = new ArrayList<String>();
84 String subStr = protein;
85 while (subStr.length() > 0 && subStr.contains(subprot)) {
86 String first = subStr.substring(0, subStr.indexOf(subprot));
87 if (first.length() > 0)
90 subStr = subStr.substring(subStr.indexOf(subprot) + subprot.length(), subStr.length());
92 if (subStr.length() > 0)