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
69 * partial of protein sequence
71 * @return List<String>
74 private static List<String> CreateSubprotein(String protein, String subprot) {
75 List<String> sub = new ArrayList<String>();
76 String subStr = protein;
77 while (subStr.length() > 0 && subStr.contains(subprot)) {
78 String first = subStr.substring(0, subStr.indexOf(subprot));
79 if (first.length() > 0)
82 subStr = subStr.substring(subStr.indexOf(subprot) + subprot.length(), subStr.length());
84 if (subStr.length() > 0)