Merge branch 'DAO' of https://source.jalview.org/git/proteocache into DAO
[proteocache.git] / datadb / compbio / cassandra / readers / SequenceReader.java
index 244902f..7e77126 100644 (file)
@@ -8,66 +8,77 @@ import com.datastax.driver.core.Row;
 
 import compbio.beans.ProteinBean;
 
+/**
+ * Reader class for making requests on protein sequences to cassandra.
+ * 
+ * @author Alexander Sherstnev
+ * @author Natasha Sherstneva
+ * 
+ * @since 0.5
+ * @version 1.0 
+ * @since December 2013
+ */
 public class SequenceReader extends CassandraReader {
 
        public SequenceReader() {
                super();
        }
-       
+
        /**
         * query: protein sequence
-        *  
-        * @param protIn
-        *           protein sequence or partial of protein sequence
+        * 
+        * @param sequence
+        *            protein sequence or partial of protein sequence
         * @param searchtype
-        *           "whole" or "partial" of protein sequence
+        *            "whole" or "partial" of protein sequence
         * 
         * @return List<ProteinBean> to the controller SequenceController
         * 
         **/
-       public List<ProteinBean> readProteins(String protIn, String searchtype) {
+       public List<ProteinBean> readProteins(String sequence, String searchtype) {
                List<ProteinBean> query = new ArrayList<ProteinBean>();
                if (searchtype.equals("whole")) {
-                       ResultSet results = CassandraQuery("SELECT  JobID, Predictions FROM ProteinRow WHERE Protein = '" + protIn + "';");
+                       ResultSet results = CassandraQuery("SELECT JobID, Predictions FROM ProteinRow WHERE Protein = '" + sequence + "';");
                        if (results.isExhausted())
                                return null;
                        List<Row> rows = results.all();
-                       ProteinBean structure = new ProteinBean(protIn, rows.get(0).getMap("Predictions", String.class, String.class));
+                       ProteinBean structure = new ProteinBean(sequence, rows.get(0).getMap("Predictions", String.class, String.class));
                        for (Row r : rows) {
                                structure.setJobid(r.getString("JobID"));
                        }
                        query.add(structure);
                } else {
-                       ResultSet results = CassandraQuery("SELECT  * FROM ProteinRow;");
+                       ResultSet results = CassandraQuery("SELECT * FROM ProteinRow;");
                        if (results.isExhausted())
                                return null;
                        List<Row> rows = results.all();
                        for (Row r : rows) {
-                               String prot = r.getString("Protein");
-                               if (prot.matches("(.*)" + protIn + "(.*)")) {
-                                       ProteinBean structure = new ProteinBean(prot, r.getMap("Predictions", String.class, String.class));
-                                       structure.setJobid(r.getString("JobID"));
-                                       query.add(structure);
+                               String protein = r.getString("Protein");
+                               if (protein.matches("(.*)" + sequence + "(.*)")) {
+                                       ProteinBean foundsequence = new ProteinBean(protein, r.getMap("Predictions", String.class, String.class));
+                                       foundsequence.setJobid(r.getString("JobID"));
+                                       query.add(foundsequence);
                                }
                        }
                }
                if (searchtype.equals("partial")) {
                        for (ProteinBean entry : query) {
-                               entry.setSubProt(CreateSubprotein(entry.getSequence(), protIn));
+                               entry.setSubProt(CreateSubprotein(entry.getSequence(), sequence));
                        }
                }
                return query;
        }
-       
+
        /**
-        * create a list of parts of protein sequence for highlighting current value in report;
-        *  
+        * create a list of parts of protein sequence for highlighting current value
+        * in report;
+        * 
         * @param protein
-        *           protein sequence 
+        *            protein sequence
         * @param subprot
-        *           partial of protein sequence
+        *            partial of protein sequence
         * 
-        * @return List<String> 
+        * @return List<String>
         * 
         **/
        private static List<String> CreateSubprotein(String protein, String subprot) {