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;
11 public class SequenceReader extends CassandraReader {
13 public SequenceReader() {
18 * query: protein sequence
21 * protein sequence or partial of protein sequence
23 * "whole" or "partial" of protein sequence
25 * @return List<ProteinBean> to the controller SequenceController
28 public List<ProteinBean> readProteins(String protIn, String searchtype) {
29 List<ProteinBean> query = new ArrayList<ProteinBean>();
30 if (searchtype.equals("whole")) {
31 ResultSet results = CassandraQuery("SELECT JobID, Predictions FROM ProteinRow WHERE Protein = '" + protIn + "';");
32 if (results.isExhausted())
34 List<Row> rows = results.all();
35 ProteinBean structure = new ProteinBean(protIn, rows.get(0).getMap("Predictions", String.class, String.class));
37 structure.setJobid(r.getString("JobID"));
41 ResultSet results = CassandraQuery("SELECT * FROM ProteinRow;");
42 if (results.isExhausted())
44 List<Row> rows = results.all();
46 String prot = r.getString("Protein");
47 if (prot.matches("(.*)" + protIn + "(.*)")) {
48 ProteinBean structure = new ProteinBean(prot, r.getMap("Predictions", String.class, String.class));
49 structure.setJobid(r.getString("JobID"));
54 if (searchtype.equals("partial")) {
55 for (ProteinBean entry : query) {
56 entry.setSubProt(CreateSubprotein(entry.getSequence(), protIn));
63 * create a list of parts of protein sequence for highlighting current value in report;
68 * partial of protein sequence
70 * @return List<String>
73 private static List<String> CreateSubprotein(String protein, String subprot) {
74 List<String> sub = new ArrayList<String>();
75 String subStr = protein;
76 while (subStr.length() > 0 && subStr.contains(subprot)) {
77 String first = subStr.substring(0, subStr.indexOf(subprot));
78 if (first.length() > 0)
81 subStr = subStr.substring(subStr.indexOf(subprot) + subprot.length(), subStr.length());
83 if (subStr.length() > 0)