package compbio.controllers;
-import java.util.List;
import java.util.Map;
import org.springframework.stereotype.Controller;
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.
+ * Spring controller for protein secondary structure features. This version
+ * works in the servlet style.
*
* @author Alexander Sherstnev
* @author Natasha Sherstneva
@RequestMapping("/features")
public class SSFeaturesController extends BasicController {
- @RequestMapping(value = "query", method = RequestMethod.GET)
- public String formCounterQuery(Map<String, Object> model) {
- model.put("username", getPrincipalName());
- model.put("type", 'E');
- model.put("value", 80);
+ /**
+ * form a query page for protein secondary structure feaatures: Proteins
+ * with given fraction of H/E (helix/beta sheets)
+ *
+ * @param model
+ * MVC model object
+ *
+ * @return link to the report JSP page
+ */
+ @RequestMapping(value = "query", method = RequestMethod.GET)
+ public String formCounterQuery(Map<String, Object> model) {
+ model.put("username", getPrincipalName());
+ model.put("type", 'E');
+ model.put("value", 50);
+ return "query/SSFeatures";
+ }
+
+ /**
+ * form a results page for protein secondary structure features: Proteins
+ * with given fraction of H/E (helix/beta sheets) All proteins with E/H
+ * higher than a given percent of the length are returned
+ *
+ * @param model
+ * MVC model object
+ * @param typeFeature
+ * type of SS: H/E (helix/beta sheets)
+ * @param percent
+ * fraction of the protein length predicted as H/E (helix/beta
+ * sheets)
+ *
+ * @return link to the report JSP page
+ */
+ @RequestMapping(value = "results", method = RequestMethod.GET)
+ public String countSequences(@RequestParam("TypeFeatures") String typeFeature, @RequestParam("Percent") String percent,
+ Map<String, Object> model) {
+ model.put("username", getPrincipalName());
+ final long startTime = System.currentTimeMillis();
+
+ if (percent.equals("")) {
+ model.put("error", "The value must not be empty");
+ model.put("type", typeFeature);
+ model.put("value", percent);
return "query/SSFeatures";
}
-
- @RequestMapping(value = "features/results", method = RequestMethod.GET)
- public String countSequences(@RequestParam("TypeFeatures") String typeFeature, @RequestParam("Percent") String percent,Map<String, Object> model) {
- model.put("username", getPrincipalName());
- final long startTime = System.currentTimeMillis();
- if (percent.equals("")) {
- model.put("error", "The value must not be empty");
- model.put("type", typeFeature);
- model.put("value", percent);
- return "query/SSFeatures";
- }
+ int realpercent;
+ try {
+ realpercent = Integer.parseInt(percent.trim());
+ } catch (NumberFormatException e) {
+ model.put("error", "The value must be an integer number");
+ model.put("value", percent);
+ return "query/SSFeatures";
+ }
- int realpercent;
- try {
- realpercent = Integer.parseInt(percent.trim());
- } catch (NumberFormatException e) {
- model.put("error", "The value must be an integer number");
- model.put("value", percent);
- return "query/SSFeatures";
- }
+ if (realpercent < 1) {
+ model.put("error", "The value must be greater than 0");
+ model.put("value", percent);
+ return "query/SSFeatures";
+ }
- if (realpercent < 1) {
- model.put("error", "The value must be greater than 0");
- model.put("value", percent);
- return "query/SSFeatures";
- }
-
- if (realpercent > 100) {
- model.put("error", "The value must be less than 100");
- model.put("value", percent);
- return "query/SSFeatures";
- }
+ if (realpercent > 100) {
+ model.put("error", "The value must be less than 100");
+ model.put("value", percent);
+ return "query/SSFeatures";
+ }
+
+ CassandraRequester cr = new CassandraRequester();
+ Map<String, String> r = cr.readProteinsPrediction(typeFeature, realpercent);
+ model.put("results", r);
+ model.put("njobs", 0);
+ StringBuilder csvline = new StringBuilder("");
+ if (null != r) {
+ model.put("njobs", r.size());
+ csvline.append("\'Prediction%20number\',\'Protein%20Sequence\', \'Secondary%20Structure%20Prediction\'%0A");
- CassandraRequester cr = new CassandraRequester();
- Map<String, String> r = cr.readProteinsPrediction(typeFeature, realpercent);
- model.put("results", r);
- model.put("njobs", 0);
- if (null != r) {
- model.put("njobs", r.size());
+ // form line for CSV file
+ int counter = 1;
+ for (Map.Entry<String, String> entry : r.entrySet()) {
+ csvline.append("\'" + counter + "\',\'" + entry.getKey() + "\',\'" + entry.getValue() + "\'%0A");
+ ++counter;
}
- final long endTime = System.currentTimeMillis();
- model.put("timeExecution", (endTime - startTime));
- model.put("feature", typeFeature);
- model.put("percent", realpercent);
- return "reportSSFeatures";
}
+ model.put("csvfile", csvline.toString());
-
+ final long endTime = System.currentTimeMillis();
+ model.put("timeExecution", (endTime - startTime));
+ model.put("feature", typeFeature);
+ model.put("percent", realpercent);
+ return "reports/SSFeatures";
+ }
}