Add the "Reload" and "CSV" buttons
[proteocache.git] / server / compbio / controllers / SequenceController.java
index df4c987..738e2d8 100644 (file)
@@ -1,5 +1,6 @@
 package compbio.controllers;
 
+import java.util.LinkedHashMap;
 import java.util.List;
 import java.util.Map;
 import java.util.regex.Pattern;
@@ -9,7 +10,9 @@ import org.springframework.web.bind.annotation.RequestMapping;
 import org.springframework.web.bind.annotation.RequestMethod;
 import org.springframework.web.bind.annotation.RequestParam;
 
+import compbio.cassandra.DataBase;
 import compbio.cassandra.ProteinBean;
+import compbio.cassandra.Total;
 import compbio.cassandra.TotalByCounterBean;
 import compbio.statistic.CassandraRequester;
 
@@ -68,7 +71,7 @@ public class SequenceController extends BasicController {
                model.put("njobs", 0);
                model.put("prot", trimmedsequence);
                model.put("searchtype", searchtype);
-
+               String csvline = "";
                if (0 < trimmedsequence.length()) {
                        CassandraRequester cr = new CassandraRequester();
                        List<ProteinBean> r = cr.readProteins(trimmedsequence, searchtype);
@@ -78,8 +81,23 @@ public class SequenceController extends BasicController {
                                        model.put("njobs", r.get(0).getJobid().size());
                                else
                                        model.put("njobs", r.size());
+                               csvline = "\'Job\',\'Annotation\',\'Sequence\'%0A";
+                       }
+                       // form CSV file string
+                       for (ProteinBean entry : r) {
+                               List<String> jobs = entry.getJobid();
+                               String protein = entry.getSequence();
+                               LinkedHashMap<String, String> predictions = entry.getPredictions();
+                               for (String job : jobs) {
+                                       csvline += "\'" + job + "\',\'Sequence\',\'" + protein + "\',\'%0A";
+                                       for (Map.Entry<String, String> pr : predictions.entrySet()) {
+                                               csvline += "\'\',\'" + pr.getKey() + "\',\'" + pr.getValue() + "\'%0A";
+                                       }
+                               }
                        }
                }
+               model.put("csvfile", csvline);
+
                final long endTime = System.currentTimeMillis();
                model.put("timeExecution", (endTime - startTime));
                return "reportProteinSequences";
@@ -113,11 +131,27 @@ public class SequenceController extends BasicController {
 
                CassandraRequester cr = new CassandraRequester();
                List<TotalByCounterBean> r = cr.readProteinByCounter(realcounter);
-               model.put("results", r);
                model.put("njobs", 0);
+               String csvline = "";
                if (null != r) {
                        model.put("njobs", r.size());
+                       csvline = "\'Job%20 count\', \'Protein%20Sequence\'%0A";
                }
+               // form line for CSV file
+
+               for (TotalByCounterBean b : r) {
+                       if (b.getName().equals("")) {
+                               csvline += "\'" + b.getTotaljobs() + "\',\'Alignment%20job\'%0A";
+                               // fix problem with records without protein sequence (alignment
+                               // jobs)
+                               b.setName("Alignment job");
+                       } else {
+                               csvline += "\'" + b.getTotaljobs() + "\',\'" + b.getName() + "\'%0A";
+                       }
+               }
+               model.put("csvfile", csvline);
+
+               model.put("results", r);
                final long endTime = System.currentTimeMillis();
                model.put("timeExecution", (endTime - startTime));
                model.put("counter", realcounter);