package compbio.controllers;
+import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map;
import java.util.regex.Pattern;
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;
+import compbio.beans.ProteinBean;
+import compbio.beans.TotalByCounterBean;
+import compbio.cassandra.readers.ReaderByCounter;
+import compbio.cassandra.readers.SequenceReader;
/**
- * Spring controller for sequence queries. This version works in the servlet
- * style.
+ * Spring controller for supporting sequence queries. This version works in the
+ * servlet style.
*
* @author Alexander Sherstnev
* @author Natasha Sherstneva
*/
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());
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());
return "query/SequenceCounts";
}
- @RequestMapping(value = "sequence/results", method = RequestMethod.GET)
+ /**
+ * 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 = "results", method = RequestMethod.GET)
public String findSequence(@RequestParam("sequence") String sequence, @RequestParam("searchtype") String searchtype,
Map<String, Object> model) {
model.put("username", getPrincipalName());
model.put("njobs", 0);
model.put("prot", trimmedsequence);
model.put("searchtype", searchtype);
-
+ StringBuilder csvline = new StringBuilder("");
if (0 < trimmedsequence.length()) {
- CassandraRequester cr = new CassandraRequester();
- List<ProteinBean> 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());
+ 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", result.get(0).getJobid().size());
+ } else {
+ model.put("njobs", result.size());
+ }
+ csvline.append("\'Job\',\'Annotation\',\'Sequence\'%0A");
+ for (ProteinBean entry : result) {
+ List<String> jobs = entry.getJobid();
+ String protein = entry.getSequence();
+ LinkedHashMap<String, String> predictions = entry.getPredictions();
+ StringBuilder jobline = new StringBuilder();
+ for (Map.Entry<String, String> pr : predictions.entrySet()) {
+ jobline.append("\'\',\'" + pr.getKey() + "\',\'" + pr.getValue() + "\'%0A");
+ }
+ for (String job : jobs) {
+ csvline.append("\'" + job + "\',\'Sequence\',\'" + protein + "\',\'%0A" + jobline.toString());
+ }
+ }
}
+ } else {
+ model.put("error", "The sequence after trimming is empty");
+ model.put("value", sequence);
+ return "query/Sequence";
}
+ model.put("csvfile", csvline.toString());
+
final long endTime = System.currentTimeMillis();
model.put("timeExecution", (endTime - startTime));
- return "reportProteinSequences";
+ return "reports/Sequences";
}
+ /**
+ * 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());
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);
+ StringBuilder csvline = new StringBuilder("");
if (null != r) {
model.put("njobs", r.size());
+ // form line for CSV file
+ csvline.append("\'Job%20 count\', \'Protein%20Sequence\'%0A");
+ for (TotalByCounterBean b : r) {
+ if (b.getName().equals("")) {
+ // fix problem with records without protein sequence
+ // (alignment jobs)
+ csvline.append("\'" + b.getTotaljobs() + "\',\'Alignment%20job\'%0A");
+ b.setName("Alignment job");
+ } else {
+ csvline.append("\'" + b.getTotaljobs() + "\',\'" + b.getName() + "\'%0A");
+ }
+ }
}
+ model.put("csvfile", csvline.toString());
+
+ model.put("results", r);
final long endTime = System.currentTimeMillis();
model.put("timeExecution", (endTime - startTime));
model.put("counter", realcounter);
- return "reportProteinSequencesCounter";
+ return "reports/SequencesStatistics";
}
}