new readers for the queries
[proteocache.git] / server / compbio / controllers / SequenceController.java
index df4c987..105ef2f 100644 (file)
@@ -9,8 +9,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.ProteinBean;
-import compbio.cassandra.TotalByCounterBean;
+import compbio.beans.ProteinBean;
+import compbio.beans.TotalByCounterBean;
+import compbio.cassandra.readers.ReaderByCounter;
+import compbio.cassandra.readers.SequenceReader;
 import compbio.statistic.CassandraRequester;
 
 /**
@@ -32,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());
@@ -39,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());
@@ -46,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) {
@@ -70,14 +99,14 @@ public class SequenceController extends BasicController {
                model.put("searchtype", searchtype);
 
                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());
                        }
                }
                final long endTime = System.currentTimeMillis();
@@ -85,6 +114,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());
@@ -111,8 +149,9 @@ 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);
                if (null != r) {