1 package compbio.controllers;
5 import java.util.regex.Pattern;
7 import org.springframework.stereotype.Controller;
8 import org.springframework.web.bind.annotation.RequestMapping;
9 import org.springframework.web.bind.annotation.RequestMethod;
10 import org.springframework.web.bind.annotation.RequestParam;
12 import compbio.cassandra.ProteinBean;
13 import compbio.cassandra.TotalByCounterBean;
14 import compbio.statistic.CassandraRequester;
17 * Spring controller for sequence queries. This version works in the servlet
20 * @author Alexander Sherstnev
21 * @author Natasha Sherstneva
24 * @version 1.0 December 2013
27 @RequestMapping("/sequence")
28 public class SequenceController extends BasicController {
31 * pattern for NON-protein alphabet symbols
33 private final Pattern NONPROTEIN = Pattern.compile("[^ARNDCQEGHILKMFPSTWYV]+", Pattern.CASE_INSENSITIVE);
35 @RequestMapping(value = "query", method = RequestMethod.GET)
36 public String formSequenceQuery(Map<String, Object> model) {
37 model.put("username", getPrincipalName());
38 model.put("value", "AAAAA");
39 return "query/Sequence";
42 @RequestMapping(value = "counts/query", method = RequestMethod.GET)
43 public String formCounterQuery(Map<String, Object> model) {
44 model.put("username", getPrincipalName());
45 model.put("value", 5);
46 return "query/SequenceCounts";
49 @RequestMapping(value = "sequence/results", method = RequestMethod.GET)
50 public String findSequence(@RequestParam("sequence") String sequence, @RequestParam("searchtype") String searchtype,
51 Map<String, Object> model) {
52 model.put("username", getPrincipalName());
53 final long startTime = System.currentTimeMillis();
56 String trimmedsequence = sequence.replaceAll("\\s", "");
57 if (trimmedsequence.equalsIgnoreCase("")) {
58 model.put("error", "The sequence cann't be empty");
59 model.put("value", sequence);
60 return "query/Sequence";
62 if (NONPROTEIN.matcher(trimmedsequence).find()) {
63 model.put("error", "The sequence contains symbols not from the standard protein alphabet");
64 model.put("value", sequence);
65 return "query/Sequence";
68 model.put("njobs", 0);
69 model.put("prot", trimmedsequence);
70 model.put("searchtype", searchtype);
72 if (0 < trimmedsequence.length()) {
73 CassandraRequester cr = new CassandraRequester();
74 List<ProteinBean> r = cr.readProteins(trimmedsequence, searchtype);
75 model.put("results", r);
77 if (searchtype.equals("whole"))
78 model.put("njobs", r.get(0).getJobid().size());
80 model.put("njobs", r.size());
83 final long endTime = System.currentTimeMillis();
84 model.put("timeExecution", (endTime - startTime));
85 return "reportProteinSequences";
88 @RequestMapping(value = "counts/results", method = RequestMethod.GET)
89 public String countSequences(@RequestParam("counterJob") String counter, Map<String, Object> model) {
90 model.put("username", getPrincipalName());
91 final long startTime = System.currentTimeMillis();
93 if (counter.equals("")) {
94 model.put("error", "The value must not be empty");
95 model.put("value", counter);
96 return "query/SequenceCounts";
101 realcounter = Integer.parseInt(counter.trim());
102 } catch (NumberFormatException e) {
103 model.put("error", "The value must be an integer number");
104 model.put("value", counter);
105 return "query/SequenceCounts";
108 if (realcounter < 1) {
109 model.put("error", "The value must be greater than 0");
110 model.put("value", counter);
111 return "query/SequenceCounts";
114 CassandraRequester cr = new CassandraRequester();
115 List<TotalByCounterBean> r = cr.readProteinByCounter(realcounter);
116 model.put("results", r);
117 model.put("njobs", 0);
119 model.put("njobs", r.size());
121 final long endTime = System.currentTimeMillis();
122 model.put("timeExecution", (endTime - startTime));
123 model.put("counter", realcounter);
124 return "reportProteinSequencesCounter";