fix data report, protein report
authorNatasha Sherstneva <n.shertneva@gmail.com>
Thu, 7 Nov 2013 13:32:02 +0000 (13:32 +0000)
committerNatasha Sherstneva <n.shertneva@gmail.com>
Thu, 7 Nov 2013 13:32:02 +0000 (13:32 +0000)
14 files changed:
.classpath
datadb/compbio/cassandra/CassandraNativeConnector.java
datadb/compbio/cassandra/DataBase.java
server/compbio/listeners/ServletJobsByDate.java [moved from server/compbio/listeners/QueryServlet.java with 81% similarity]
server/compbio/listeners/ServletSequenceProtein.java [moved from server/compbio/listeners/ProtServlet.java with 79% similarity]
server/compbio/listeners/ServletTimeExecution.java [moved from server/compbio/listeners/LengthServlet.java with 91% similarity]
server/compbio/statistic/CassandraRequester.java
website/AllReports.jsp
website/QueryJobsByDate.jsp [moved from website/Sample.jsp with 94% similarity]
website/QuerySequenceProtein.jsp [moved from website/Sequence.jsp with 78% similarity]
website/QueryTimeExecition.jsp [moved from website/JobLength.jsp with 95% similarity]
website/ReportJobsByDate.jsp [moved from website/ReportNew.jsp with 97% similarity]
website/ReportSequenceProtein.jsp [moved from website/ReportProt.jsp with 100% similarity]
website/ReportTimeExecution.jsp [moved from website/ReportLength.jsp with 100% similarity]

index 1e750dd..b03b998 100644 (file)
        <classpathentry kind="lib" path="WEB-INF/lib/jackson-core-asl-1.9.13.jar"/>
        <classpathentry kind="lib" path="WEB-INF/lib/jackson-mapper-asl-1.9.13.jar"/>
        <classpathentry kind="lib" path="WEB-INF/lib/displaytag-1.2.jar"/>
-       <classpathentry kind="con" path="org.eclipse.jst.server.core.container/org.eclipse.jst.server.tomcat.runtimeTarget/Apache Tomcat v7.0">
-               <attributes>
-                       <attribute name="owner.project.facets" value="jst.web"/>
-               </attributes>
-       </classpathentry>
        <classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/jdk1.7.0_45"/>
        <classpathentry kind="lib" path="WEB-INF/lib/jstl-1.2.jar"/>
+       <classpathentry kind="con" path="org.eclipse.jst.server.core.container/org.eclipse.jst.server.tomcat.runtimeTarget/Apache Tomcat v7.0"/>
        <classpathentry kind="output" path="WEB-INF/classes"/>
 </classpath>
index be90b05..b038457 100644 (file)
@@ -5,6 +5,7 @@ import java.util.Calendar;
 import java.util.HashMap;
 import java.util.List;
 import java.util.ArrayList;
+import java.util.Map;
 
 import com.datastax.driver.core.Cluster;
 import com.datastax.driver.core.Host;
@@ -135,17 +136,114 @@ public class CassandraNativeConnector {
                System.out.println (c + " rows analysed, execution time is " + (endTime - startTime) + " msec");
                return res;
        }
+       
+       /*
+        * getting data from the db ProteinData
+        */
+       public Integer ReadDateTable(long queryDate) {
+               final long startTime = System.currentTimeMillis();
+               String com = "SELECT jobtime, JobID FROM ProteinKeyspace.ProteinData WHERE jobtime = " + queryDate + ";";
+               System.out.println("Command: " + com);
+               ResultSet results = session.execute(com);
+               if (results.isExhausted())
+                       return null;
+               final long queryTime = System.currentTimeMillis();
+               List<Row> rows = results.all();
+               System.out.println ("Query time is " + (queryTime - startTime) + " msec");        
+               return rows.size();
+       }
 
        /*
+        * getting whole protein sequence from the db ProteinRow
+        */
+       public List<StructureProteinPrediction> ReadWholeSequence(String queryProtein) {
+               final long startTime = System.currentTimeMillis();
+               String com = "SELECT JobID, Predictions FROM ProteinKeyspace.ProteinRow WHERE Protein = '" + queryProtein + "';";
+               System.out.println("Command: " + com);
+               ResultSet results = session.execute(com);
+               if (results.isExhausted())
+                       return null;
+               final long queryTime = System.currentTimeMillis();
+               List<Row> rows = results.all();
+               System.out.println ("Query time is " + (queryTime - startTime) + " msec");   
+               System.out.println (" rows analysed,  " + rows.size());
+               List<StructureProteinPrediction> res = new ArrayList<StructureProteinPrediction>();
+               int c = 0;
+               for (Row r : rows) {
+                       StructureProteinPrediction structure = new StructureProteinPrediction(queryProtein, r.getString("JobID"), r.getMap("Predictions", String.class, String.class));         
+                       res.add(structure);
+                       ++c;
+               }
+               final long endTime = System.currentTimeMillis();
+               System.out.println (c + " rows analysed, execution time is " + (endTime - startTime) + " msec");
+               return res;
+       }
+       
+       /*
+        * getting part of protein sequence from the db ProteinRow
+        */
+       public List<StructureProteinPrediction>  ReadPartOfSequence(String queryProtein) {
+               final long startTime = System.currentTimeMillis();
+               String com = "SELECT * FROM ProteinKeyspace.ProteinRow;";
+               System.out.println("Command: " + com);
+               ResultSet results = session.execute(com);
+               if (results.isExhausted())
+                       return null;
+               final long queryTime = System.currentTimeMillis();
+               List<Row> rows = results.all();
+               System.out.println ("Query time is " + (queryTime - startTime) + " msec");   
+               System.out.println (" rows analysed,  " + rows.size());
+               List<StructureProteinPrediction>  res = new ArrayList<StructureProteinPrediction>();
+               int c = 0;
+               for (Row r : rows) {
+                       String prot = r.getString("Protein");
+                       if (prot.matches("(.*)" + queryProtein + "(.*)")) {
+                       //      System.out.println(prot);
+                               StructureProteinPrediction structure = new StructureProteinPrediction(prot, r.getString("JobID"), r.getMap("Predictions", String.class, String.class));         
+                               res.add(structure);
+                               ++c;
+                       }
+               }
+               final long endTime = System.currentTimeMillis();
+               System.out.println (c + " rows analysed, execution time is " + (endTime - startTime) + " msec");
+               return res;
+       }
+       
+       /*
+        * getting protein sequences by counter
+        */
+       public List<Pair<String, Integer>>  ReadProteinDataByCounter(int counter) {
+               final long startTime = System.currentTimeMillis();
+               String com = "SELECT DISTINCT Protein FROM ProteinKeyspace.ProteinRow;";
+               System.out.println("Command: " + com);
+               ResultSet results = session.execute(com);
+               if (results.isExhausted())
+                       return null;
+               final long queryTime = System.currentTimeMillis();
+               List<Row> rows = results.all();
+               System.out.println ("Query time is " + (queryTime - startTime) + " msec");   
+               System.out.println (" rows analysed,  " + rows.size());
+               List<Pair<String, Integer>>  res = new ArrayList<Pair<String, Integer>>();
+               int c = 0;
+               for (Row r : rows) {
+                       String prot = r.getString("Protein");
+                       
+               }
+               final long endTime = System.currentTimeMillis();
+               System.out.println (c + " rows analysed, execution time is " + (endTime - startTime) + " msec");
+               return res;
+       }
+       
+       /*
         * getting earlest date of jobs from the db
         */
        public long getEarliestDateInDB() {
                final long startTime = System.currentTimeMillis();
-               String com = "SELECT jobtime FROM ProteinKeyspace.ProteinData;";
+               String com = "SELECT jobtime,JobID FROM ProteinKeyspace.ProteinData;";
                System.out.println("Command: " + com);
                ResultSet results = session.execute(com);
                final long queryTime = System.currentTimeMillis();
-               System.out.println ("Query time is " + (queryTime - startTime) + " msec");
+               System.out.println ("Query time is  " + (queryTime - startTime) + " msec");
 
                Calendar cal = Calendar.getInstance();
                long res = cal.getTimeInMillis();
index 016a30a..cccf64b 100644 (file)
@@ -7,6 +7,7 @@ import java.util.Collections;
 public class DataBase {
        private String date;
        private int total;
+       private int totalJobs;
        private int totalId;
        private String id;
        private String prot;
@@ -39,6 +40,15 @@ public class DataBase {
                return total;
        }
 
+       
+       public void setTotalJobs(int totalJobs) {
+               this.totalJobs = totalJobs;
+       }
+
+       public int getTotalJobs() {
+               return totalJobs;
+       }
+
        public void setTotalId(int totId) {
                this.totalId = totId;
        }
similarity index 81%
rename from server/compbio/listeners/QueryServlet.java
rename to server/compbio/listeners/ServletJobsByDate.java
index a69a18f..4aee8be 100644 (file)
@@ -12,10 +12,11 @@ import javax.servlet.http.HttpServletRequest;
 import javax.servlet.http.HttpServletResponse;
 
 import compbio.cassandra.DataBase;
+import compbio.statistic.CassandraRequester;
 import compbio.statistic.StatisticsProt;
 
-@WebServlet("/QueryServlet")
-public class QueryServlet extends HttpServlet {
+@WebServlet("/ServletJobsByDate")
+public class ServletJobsByDate extends HttpServlet {
        private static final long serialVersionUID = 1L;
 
        /**
@@ -26,21 +27,21 @@ public class QueryServlet extends HttpServlet {
                final long startTime = System.currentTimeMillis();
                String date1 = request.getParameter("data1");
                String date2 = request.getParameter("data2");
-               StatisticsProt sp = new StatisticsProt();
+               CassandraRequester cr = new CassandraRequester();
                if (null != request.getParameter("option")) {
                        Calendar cal = Calendar.getInstance();
-                       date1 = StatisticsProt.DateFormatYYMMDD(sp.earliestDate());
+                       date1 = StatisticsProt.DateFormatYYMMDD(cr.earliestDate());
                        date2 = cal.get(Calendar.YEAR) + "/" + (cal.get(Calendar.MONTH) + 1) + "/" + cal.get(Calendar.DAY_OF_MONTH);
                }
                request.setAttribute("data1", date1);
                request.setAttribute("data2", date2);
-               List<DataBase> res = sp.readDetails(date1, date2);
+               List<DataBase> res = cr.countJobs(date1, date2);
                request.setAttribute("result", res);
                final long endTime = System.currentTimeMillis();
                request.setAttribute("timeExecution", (endTime - startTime));
                System.out.println ("QueryServlet.doGet: total number of dates = " + res.size());
                request.setAttribute("flag", request.getParameter("option"));
-               RequestDispatcher rd = request.getRequestDispatcher("/ReportNew.jsp");
+               RequestDispatcher rd = request.getRequestDispatcher("/ReportJobsByDate.jsp");
                rd.forward(request, response);
        }
 
@@ -9,13 +9,14 @@ import javax.servlet.http.HttpServlet;
 import javax.servlet.http.HttpServletRequest;
 import javax.servlet.http.HttpServletResponse;
 
+import compbio.statistic.CassandraRequester;
 import compbio.statistic.StatisticsProt;
 
 /**
  * Servlet implementation class ProtServlet
  */
-@WebServlet("/ProtServlet")
-public class ProtServlet extends HttpServlet {
+@WebServlet("/ServletSequenceProtein")
+public class ServletSequenceProtein extends HttpServlet {
        private static final long serialVersionUID = 1L;
 
        /**
@@ -28,14 +29,11 @@ public class ProtServlet extends HttpServlet {
                String prot = request.getParameter("prot");
                String search = request.getParameter("Search");
                int counter = Integer.parseInt(request.getParameter("counterJob"));
-               StatisticsProt sp = new StatisticsProt();
+               CassandraRequester cr = new CassandraRequester();
                if (search.equals("Search counter")) {
-                       request.setAttribute("result", sp.readProtID(counter));
+       //              request.setAttribute("result", sp.readProtID(counter));
                } else {
-                       if (flag.equals("whole"))
-                               request.setAttribute("result", sp.readProteins(prot));
-                       else
-                               request.setAttribute("result", sp.readPart(prot));
+                               request.setAttribute("result", cr.readProteins(prot, flag));
                }
                final long endTime = System.currentTimeMillis();
                request.setAttribute("timeExecution", (endTime - startTime));
@@ -43,7 +41,7 @@ public class ProtServlet extends HttpServlet {
                request.setAttribute("flag", flag);
                request.setAttribute("search", search);
                request.setAttribute("counter", counter);
-               RequestDispatcher rd = request.getRequestDispatcher("/ReportProt.jsp");
+               RequestDispatcher rd = request.getRequestDispatcher("/ReportSequenceProtein.jsp");
                rd.forward(request, response);
        }
 
@@ -16,8 +16,8 @@ import compbio.statistic.CassandraRequester;
 /**
  * Servlet implementation class LengthServlet
  */
-@WebServlet("/LengthServlet")
-public class LengthServlet extends HttpServlet {
+@WebServlet("/ServletTimeExecution")
+public class ServletTimeExecution extends HttpServlet {
        private static final long serialVersionUID = 1L;
 
        /**
@@ -40,7 +40,7 @@ public class LengthServlet extends HttpServlet {
                request.setAttribute("flag", request.getParameter("option"));
                final long endTime = System.currentTimeMillis();
                request.setAttribute("timeExecution", (endTime - startTime));
-               RequestDispatcher rd = request.getRequestDispatcher("/ReportLength.jsp");
+               RequestDispatcher rd = request.getRequestDispatcher("/ReportTimeExecution.jsp");
                rd.forward(request, response);
        }
 
index 9885d64..b7f83a8 100755 (executable)
@@ -5,11 +5,14 @@ import java.text.SimpleDateFormat;
 import java.util.ArrayList;
 import java.util.Calendar;
 import java.util.Date;
+import java.util.Iterator;
 import java.util.List;
+import java.util.Map;
 
 import compbio.cassandra.CassandraNativeConnector;
 import compbio.cassandra.DataBase;
 import compbio.cassandra.Pair;
+import compbio.cassandra.StructureProteinPrediction;
 
 public class CassandraRequester {
        private CassandraNativeConnector DBInstance = new CassandraNativeConnector();
@@ -105,7 +108,100 @@ public class CassandraRequester {
                System.out.println("StatisticsProt.readLength: total number of dates = " + query.size());
                return query;
        }
+       
+       /*
+        * query: total number of jobs  for the period from date1 till date2
+        */
+       public List<DataBase> countJobs(String date1, String date2) {
+               if (null == date1) {
+                       date1 = "1970/1/1";
+               }
+               if (null == date2) {
+                       date1 = "2100/1/1";
+               }
+               if (!isThisDateValid(date1) || !isThisDateValid(date2)) {
+                       System.out.println("Wrong date: point 3");
+                       return null;
+               }
+               SetDateRange();
+               long dateStart = DateParsing(date1);
+               long dateEnd = DateParsing(date2);
+               if (dateEnd < earlestDate || dateStart > currentDate || dateStart > dateEnd)
+                       return null;
+               if (dateStart < earlestDate)
+                       dateStart = earlestDate;
+               if (dateEnd > currentDate)
+                       dateStart = currentDate;
 
+               Calendar start = Calendar.getInstance();
+               start.setTime(new Date(dateStart));
+               Calendar end = Calendar.getInstance();
+               end.setTime(new Date(dateEnd));
+               query = new ArrayList<DataBase>();
+               for (Date date = start.getTime(); !start.after(end); start.add(Calendar.DATE, 1), date = start.getTime()) {
+                       Integer res = DBInstance.ReadDateTable(date.getTime());
+                       if (res == null)
+                               continue;
+                       DataBase db = new DataBase();
+                       db.setTotal(res);
+                       db.setDate(DateFormat(date.getTime()));
+                       query.add(db);
+               }                       
+               System.out.println("StatisticsProt.readLength: total number of dates = " + query.size());
+               return query;
+       }
+       /* 
+        * query: protein sequence
+        * */
+       public List<DataBase> readProteins(String protIn, String flag) {
+               query = new ArrayList<DataBase>();
+               List<StructureProteinPrediction> res;
+               if (flag.equals("whole")) 
+                       res = DBInstance.ReadWholeSequence(protIn);
+                else 
+                       res = DBInstance.ReadPartOfSequence(protIn);
+               for (StructureProteinPrediction entry : res) {
+                       Map<String,String> pred = entry.getPrediction();
+                       Iterator it = pred.entrySet().iterator();
+                       while (it.hasNext()) {
+                               DataBase db = new DataBase();
+                               db.setProt(entry.getSequence());
+                               Map.Entry pairs = (Map.Entry)it.next();
+                               db.setId(entry.getJobid());
+                               db.setJpred(pairs.getValue().toString());
+                               if (flag.equals("part"))
+                                       db.setSubProt(CreateSubprot (entry.getSequence(), protIn));                             
+                               query.add(db);
+                       }
+               }
+               return query;
+       }
+       
+       /* 
+        * query  protein sequences with number of jobs
+        * */
+       public List<DataBase> readProteinByCounter(int counter) {
+               query = new ArrayList<DataBase>();
+       //      List<Pair<String, String>> res = DBInstance.ReadProteinDataByCounter(counter);
+               
+               return query;
+       }
+       
+       
+       private static List<String> CreateSubprot (String protein, String subprot) {
+               List<String> sub = new ArrayList<String>();
+               String subStr = protein;
+               while (subStr.length() > 0 && subStr.contains(subprot)) {
+                       String first = subStr.substring(0, subStr.indexOf(subprot));
+                       if (first.length() > 0)
+                               sub.add(first);
+                       sub.add(subprot);
+                       subStr = subStr.substring(subStr.indexOf(subprot) + subprot.length(), subStr.length());
+               }
+               if (subStr.length() > 0)
+                       sub.add(subStr);
+               return sub;
+       }
        /*
         * convert String date into long date (miliseconds since the epoch start)
         */
@@ -167,4 +263,5 @@ public class CassandraRequester {
                earlestDate =  DBInstance.getEarliestDateInDB();
                return earlestDate;
        }
+       
 }
index 601c6b2..fabdf6d 100644 (file)
@@ -1,11 +1,11 @@
 <%
        String query = request.getParameter("query");
        if (query.equals("date"))
-               response.sendRedirect("Sample.jsp");
+               response.sendRedirect("QueryJobsByDate.jsp");
        else if (query.equals("length"))
-               response.sendRedirect("JobLength.jsp");
+               response.sendRedirect("QueryTimeExecition.jsp");
        else if (query.equals("protein"))
-               response.sendRedirect("Sequence.jsp");
+               response.sendRedirect("QuerySequenceProtein.jsp");
        else if (query.equals("log"))
                response.sendRedirect("LogQuery.jsp");
 %>
\ No newline at end of file
similarity index 94%
rename from website/Sample.jsp
rename to website/QueryJobsByDate.jsp
index 0116ba7..ae667fd 100644 (file)
@@ -9,7 +9,7 @@
 <title>Date period</title>
 </head>
 <body>
-       <form method="post" action="QueryServlet">
+       <form method="post" action="ServletJobsByDate">
                <h3>Enter time period</h3>      
                 <% Calendar cal = Calendar.getInstance();
                        String datecalBegin = cal.get(Calendar.YEAR) + "/" + (cal.get(Calendar.MONTH) + 1) + "/1";
similarity index 78%
rename from website/Sequence.jsp
rename to website/QuerySequenceProtein.jsp
index 1cccbb2..3d86bd6 100644 (file)
@@ -9,10 +9,11 @@
 </head>
 <body>
        <br/>
-       <form method="get" action="ProtServlet">
+       <form method="get" action="ServletSequenceProtein">
                <h3>Enter protein sequence</h3> 
                <p><textarea rows="14" cols="80" name="prot">ABCDE</textarea></p>
-               <input type="radio" name="protein" value="part" Checked>search<br/>
+               <input type="radio" name="protein" value="whole" Checked>search whole<br/>
+               <input type="radio" name="protein" value="part">search part<br/>
                <input type="submit" name="Search" value="Search sequence"/><br/><br/>
                <h3>Enter minimum number of jobs per protein</h3>
                <input type="text" name="counterJob" value = 3><br/>
similarity index 95%
rename from website/JobLength.jsp
rename to website/QueryTimeExecition.jsp
index c64ec3c..aaf925f 100644 (file)
@@ -9,7 +9,7 @@
 <title>Date interval</title>
 </head>
 <body>
-       <form method="post" action="LengthServlet">
+       <form method="post" action="ServletTimeExecution">
                <h3>Enter time period</h3>
                <%
                        Calendar cal = Calendar.getInstance();
similarity index 97%
rename from website/ReportNew.jsp
rename to website/ReportJobsByDate.jsp
index 969cad7..261a11b 100644 (file)
@@ -48,7 +48,6 @@
                        <td style="text-align: right">0</td>
                </tr>
 
-               <c:set var="sum" value="0" />
                <c:forEach items="${result}" var="res">
                        <tr>
                                <td>${res.date}</td>