1 package compbio.controllers;
5 import org.springframework.stereotype.Controller;
6 import org.springframework.web.bind.annotation.RequestMapping;
7 import org.springframework.web.bind.annotation.RequestMethod;
8 import org.springframework.web.bind.annotation.RequestParam;
10 import compbio.cassandra.readers.FeaturesReader;
13 * Spring controller for protein secondary structure features. This version
14 * works in the servlet style.
16 * @author Alexander Sherstnev
17 * @author Natasha Sherstneva
20 * @version 1.0 December 2013
23 @RequestMapping("/features")
24 public class SSFeaturesController extends BasicController {
27 * form a query page for protein secondary structure feaatures: Proteins
28 * with given fraction of H/E (helix/beta sheets)
33 * @return link to the report JSP page
35 @RequestMapping(value = "query", method = RequestMethod.GET)
36 public String formCounterQuery(Map<String, Object> model) {
37 model.put("username", getPrincipalName());
38 model.put("type", 'E');
39 model.put("value", 50);
40 return "query/SSFeatures";
44 * form a results page for protein secondary structure features: Proteins
45 * with given fraction of H/E (helix/beta sheets) All proteins with E/H
46 * higher than a given percent of the length are returned
51 * type of SS: H/E (helix/beta sheets)
53 * fraction of the protein length predicted as H/E (helix/beta
56 * @return link to the report JSP page
58 @RequestMapping(value = "results", method = RequestMethod.GET)
59 public String countSequences(@RequestParam("TypeFeatures") String typeFeature, @RequestParam("Percent") String percent,
60 Map<String, Object> model) {
61 model.put("username", getPrincipalName());
62 final long startTime = System.currentTimeMillis();
64 if (percent.equals("")) {
65 model.put("error", "The value must not be empty");
66 model.put("type", typeFeature);
67 model.put("value", percent);
68 return "query/SSFeatures";
73 realpercent = Integer.parseInt(percent.trim());
74 } catch (NumberFormatException e) {
75 model.put("error", "The value must be an integer number");
76 model.put("value", percent);
77 return "query/SSFeatures";
80 if (realpercent < 1) {
81 model.put("error", "The value must be greater than 0");
82 model.put("value", percent);
83 return "query/SSFeatures";
86 if (realpercent > 100) {
87 model.put("error", "The value must be less than 100");
88 model.put("value", percent);
89 return "query/SSFeatures";
92 FeaturesReader reader = new FeaturesReader();
93 Map<String, String> r = reader.readProteinsPrediction(typeFeature, realpercent);
94 model.put("results", r);
95 model.put("njobs", 0);
96 StringBuilder csvline = new StringBuilder("");
98 model.put("njobs", r.size());
99 csvline.append("\'Prediction%20number\',\'Protein%20Sequence\', \'Secondary%20Structure%20Prediction\'%0A");
101 // form line for CSV file
103 for (Map.Entry<String, String> entry : r.entrySet()) {
104 csvline.append("\'" + counter + "\',\'" + entry.getKey() + "\',\'" + entry.getValue() + "\'%0A");
108 model.put("csvfile", csvline.toString());
110 final long endTime = System.currentTimeMillis();
111 model.put("timeExecution", (endTime - startTime));
112 model.put("feature", typeFeature);
113 model.put("percent", realpercent);
114 return "reports/SSFeatures";