Merge branch 'DAO'
[proteocache.git] / server / compbio / controllers / SequenceController.java
index 738e2d8..76903f8 100644 (file)
@@ -10,11 +10,10 @@ import org.springframework.web.bind.annotation.RequestMapping;
 import org.springframework.web.bind.annotation.RequestMethod;
 import org.springframework.web.bind.annotation.RequestParam;
 
-import compbio.cassandra.DataBase;
-import compbio.cassandra.ProteinBean;
-import compbio.cassandra.Total;
-import compbio.cassandra.TotalByCounterBean;
-import compbio.statistic.CassandraRequester;
+import compbio.beans.ProteinBean;
+import compbio.beans.TotalByCounterBean;
+import compbio.cassandra.readers.ReaderByCounter;
+import compbio.cassandra.readers.SequenceReader;
 
 /**
  * Spring controller for sequence queries. This version works in the servlet
@@ -35,6 +34,14 @@ public class SequenceController extends BasicController {
         */
        private final Pattern NONPROTEIN = Pattern.compile("[^ARNDCQEGHILKMFPSTWYV]+", Pattern.CASE_INSENSITIVE);
 
+       /**
+        * form a query page for search protein sequence. The servlet should be
+        * available for users and admins only. 
+        * 
+        * @param model
+        *            MVC model
+        * @return link to the JSP query page
+        */
        @RequestMapping(value = "query", method = RequestMethod.GET)
        public String formSequenceQuery(Map<String, Object> model) {
                model.put("username", getPrincipalName());
@@ -42,6 +49,14 @@ public class SequenceController extends BasicController {
                return "query/Sequence";
        }
 
+       /**
+        * form a query page for statistics: Protein by job count. The servlet should be
+        * available for users and admins only. 
+        * 
+        * @param model
+        *            MVC model
+        * @return link to the JSP query page
+        */
        @RequestMapping(value = "counts/query", method = RequestMethod.GET)
        public String formCounterQuery(Map<String, Object> model) {
                model.put("username", getPrincipalName());
@@ -49,6 +64,17 @@ public class SequenceController extends BasicController {
                return "query/SequenceCounts";
        }
 
+       /**
+        * form a report page for search protein sequence.
+        * 
+        * @param model
+        *            MVC model object
+        * @param sequence
+        *            protein sequence or part of sequence
+        * @param searchtype
+        *            defined whether the whole sequence or part of sequence would be searched
+        * @return link to the report JSP page
+        */
        @RequestMapping(value = "sequence/results", method = RequestMethod.GET)
        public String findSequence(@RequestParam("sequence") String sequence, @RequestParam("searchtype") String searchtype,
                        Map<String, Object> model) {
@@ -73,18 +99,18 @@ public class SequenceController extends BasicController {
                model.put("searchtype", searchtype);
                String csvline = "";
                if (0 < trimmedsequence.length()) {
-                       CassandraRequester cr = new CassandraRequester();
-                       List<ProteinBean> r = cr.readProteins(trimmedsequence, searchtype);
-                       model.put("results", r);
-                       if (null != r) {
+                       SequenceReader reader = new SequenceReader();
+                       List<ProteinBean> result = reader.readProteins(trimmedsequence, searchtype);
+                       model.put("results", result);
+                       if (null != result) {
                                if (searchtype.equals("whole"))
-                                       model.put("njobs", r.get(0).getJobid().size());
+                                       model.put("njobs", result.get(0).getJobid().size());
                                else
-                                       model.put("njobs", r.size());
+                                       model.put("njobs", result.size());
                                csvline = "\'Job\',\'Annotation\',\'Sequence\'%0A";
                        }
                        // form CSV file string
-                       for (ProteinBean entry : r) {
+                       for (ProteinBean entry : result) {
                                List<String> jobs = entry.getJobid();
                                String protein = entry.getSequence();
                                LinkedHashMap<String, String> predictions = entry.getPredictions();
@@ -103,6 +129,15 @@ public class SequenceController extends BasicController {
                return "reportProteinSequences";
        }
 
+       /**
+        * form a report page for statistics: Protein by job count.
+        * 
+        * @param model
+        *            MVC model object
+        * @param counter
+        *           
+        * @return link to the report JSP page
+        */
        @RequestMapping(value = "counts/results", method = RequestMethod.GET)
        public String countSequences(@RequestParam("counterJob") String counter, Map<String, Object> model) {
                model.put("username", getPrincipalName());
@@ -129,8 +164,10 @@ public class SequenceController extends BasicController {
                        return "query/SequenceCounts";
                }
 
-               CassandraRequester cr = new CassandraRequester();
-               List<TotalByCounterBean> r = cr.readProteinByCounter(realcounter);
+
+               ReaderByCounter reader = new ReaderByCounter();
+               List<TotalByCounterBean> r = reader.readProteinByCounter(realcounter);
+               model.put("results", r);
                model.put("njobs", 0);
                String csvline = "";
                if (null != r) {