package compbio.controllers; import java.util.List; import java.util.Map; import java.util.regex.Pattern; import org.springframework.stereotype.Controller; 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.statistic.CassandraRequester; /** * Spring controller for sequence queries. This version works in the servlet * style. * * @author Alexander Sherstnev * @author Natasha Sherstneva * * @since 0.5 * @version 1.0 December 2013 */ @Controller @RequestMapping("/sequence") public class SequenceController extends BasicController { /** * pattern for NON-protein alphabet symbols */ private final Pattern NONPROTEIN = Pattern.compile("[^ARNDCQEGHILKMFPSTWYV]+", Pattern.CASE_INSENSITIVE); @RequestMapping(value = "query", method = RequestMethod.GET) public String formSequenceQuery(Map model) { model.put("username", getPrincipalName()); model.put("value", "AAAAA"); return "query/Sequence"; } @RequestMapping(value = "counts/query", method = RequestMethod.GET) public String formCounterQuery(Map model) { model.put("username", getPrincipalName()); model.put("value", 5); return "query/SequenceCounts"; } @RequestMapping(value = "sequence/results", method = RequestMethod.GET) public String findSequence(@RequestParam("sequence") String sequence, @RequestParam("searchtype") String searchtype, Map model) { model.put("username", getPrincipalName()); final long startTime = System.currentTimeMillis(); // input checks String trimmedsequence = sequence.replaceAll("\\s", ""); if (trimmedsequence.equalsIgnoreCase("")) { model.put("error", "The sequence cann't be empty"); model.put("value", sequence); return "query/Sequence"; } if (NONPROTEIN.matcher(trimmedsequence).find()) { model.put("error", "The sequence contains symbols not from the standard protein alphabet"); model.put("value", sequence); return "query/Sequence"; } model.put("njobs", 0); model.put("prot", trimmedsequence); model.put("searchtype", searchtype); if (0 < trimmedsequence.length()) { CassandraRequester cr = new CassandraRequester(); List r = cr.readProteins(trimmedsequence, searchtype); model.put("results", r); if (null != r) { if (searchtype.equals("whole")) model.put("njobs", r.get(0).getJobid().size()); else model.put("njobs", r.size()); } } final long endTime = System.currentTimeMillis(); model.put("timeExecution", (endTime - startTime)); return "reportProteinSequences"; } @RequestMapping(value = "counts/results", method = RequestMethod.GET) public String countSequences(@RequestParam("counterJob") String counter, Map model) { model.put("username", getPrincipalName()); final long startTime = System.currentTimeMillis(); if (counter.equals("")) { model.put("error", "The value must not be empty"); model.put("value", counter); return "query/SequenceCounts"; } int realcounter; try { realcounter = Integer.parseInt(counter.trim()); } catch (NumberFormatException e) { model.put("error", "The value must be an integer number"); model.put("value", counter); return "query/SequenceCounts"; } if (realcounter < 1) { model.put("error", "The value must be greater than 0"); model.put("value", counter); return "query/SequenceCounts"; } CassandraRequester cr = new CassandraRequester(); List r = cr.readProteinByCounter(realcounter); model.put("results", r); model.put("njobs", 0); if (null != r) { model.put("njobs", r.size()); } final long endTime = System.currentTimeMillis(); model.put("timeExecution", (endTime - startTime)); model.put("counter", realcounter); return "reportProteinSequencesCounter"; } }