From efa31207c6ba71709270a30aa04145a59a659a4e Mon Sep 17 00:00:00 2001 From: Natasha Sherstneva Date: Thu, 7 Nov 2013 13:32:02 +0000 Subject: [PATCH] fix data report, protein report --- .classpath | 6 +- .../cassandra/CassandraNativeConnector.java | 102 +++++++++++++++++++- datadb/compbio/cassandra/DataBase.java | 10 ++ .../{QueryServlet.java => ServletJobsByDate.java} | 13 +-- ...rotServlet.java => ServletSequenceProtein.java} | 16 ++- ...engthServlet.java => ServletTimeExecution.java} | 6 +- server/compbio/statistic/CassandraRequester.java | 97 +++++++++++++++++++ website/AllReports.jsp | 6 +- website/{Sample.jsp => QueryJobsByDate.jsp} | 2 +- website/{Sequence.jsp => QuerySequenceProtein.jsp} | 5 +- website/{JobLength.jsp => QueryTimeExecition.jsp} | 2 +- website/{ReportNew.jsp => ReportJobsByDate.jsp} | 1 - .../{ReportProt.jsp => ReportSequenceProtein.jsp} | 0 .../{ReportLength.jsp => ReportTimeExecution.jsp} | 0 14 files changed, 233 insertions(+), 33 deletions(-) rename server/compbio/listeners/{QueryServlet.java => ServletJobsByDate.java} (81%) rename server/compbio/listeners/{ProtServlet.java => ServletSequenceProtein.java} (79%) rename server/compbio/listeners/{LengthServlet.java => ServletTimeExecution.java} (91%) rename website/{Sample.jsp => QueryJobsByDate.jsp} (94%) rename website/{Sequence.jsp => QuerySequenceProtein.jsp} (78%) rename website/{JobLength.jsp => QueryTimeExecition.jsp} (95%) rename website/{ReportNew.jsp => ReportJobsByDate.jsp} (97%) rename website/{ReportProt.jsp => ReportSequenceProtein.jsp} (100%) rename website/{ReportLength.jsp => ReportTimeExecution.jsp} (100%) diff --git a/.classpath b/.classpath index 1e750dd..b03b998 100644 --- a/.classpath +++ b/.classpath @@ -14,12 +14,8 @@ - - - - - + diff --git a/datadb/compbio/cassandra/CassandraNativeConnector.java b/datadb/compbio/cassandra/CassandraNativeConnector.java index be90b05..b038457 100644 --- a/datadb/compbio/cassandra/CassandraNativeConnector.java +++ b/datadb/compbio/cassandra/CassandraNativeConnector.java @@ -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 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 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 rows = results.all(); + System.out.println ("Query time is " + (queryTime - startTime) + " msec"); + System.out.println (" rows analysed, " + rows.size()); + List res = new ArrayList(); + 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 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 rows = results.all(); + System.out.println ("Query time is " + (queryTime - startTime) + " msec"); + System.out.println (" rows analysed, " + rows.size()); + List res = new ArrayList(); + 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> 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 rows = results.all(); + System.out.println ("Query time is " + (queryTime - startTime) + " msec"); + System.out.println (" rows analysed, " + rows.size()); + List> res = new ArrayList>(); + 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(); diff --git a/datadb/compbio/cassandra/DataBase.java b/datadb/compbio/cassandra/DataBase.java index 016a30a..cccf64b 100644 --- a/datadb/compbio/cassandra/DataBase.java +++ b/datadb/compbio/cassandra/DataBase.java @@ -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; } diff --git a/server/compbio/listeners/QueryServlet.java b/server/compbio/listeners/ServletJobsByDate.java similarity index 81% rename from server/compbio/listeners/QueryServlet.java rename to server/compbio/listeners/ServletJobsByDate.java index a69a18f..4aee8be 100644 --- a/server/compbio/listeners/QueryServlet.java +++ b/server/compbio/listeners/ServletJobsByDate.java @@ -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 res = sp.readDetails(date1, date2); + List 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); } diff --git a/server/compbio/listeners/ProtServlet.java b/server/compbio/listeners/ServletSequenceProtein.java similarity index 79% rename from server/compbio/listeners/ProtServlet.java rename to server/compbio/listeners/ServletSequenceProtein.java index d567106..6a10b94 100644 --- a/server/compbio/listeners/ProtServlet.java +++ b/server/compbio/listeners/ServletSequenceProtein.java @@ -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); } diff --git a/server/compbio/listeners/LengthServlet.java b/server/compbio/listeners/ServletTimeExecution.java similarity index 91% rename from server/compbio/listeners/LengthServlet.java rename to server/compbio/listeners/ServletTimeExecution.java index 76d0462..c380604 100644 --- a/server/compbio/listeners/LengthServlet.java +++ b/server/compbio/listeners/ServletTimeExecution.java @@ -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); } diff --git a/server/compbio/statistic/CassandraRequester.java b/server/compbio/statistic/CassandraRequester.java index 9885d64..b7f83a8 100755 --- a/server/compbio/statistic/CassandraRequester.java +++ b/server/compbio/statistic/CassandraRequester.java @@ -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 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(); + 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 readProteins(String protIn, String flag) { + query = new ArrayList(); + List res; + if (flag.equals("whole")) + res = DBInstance.ReadWholeSequence(protIn); + else + res = DBInstance.ReadPartOfSequence(protIn); + for (StructureProteinPrediction entry : res) { + Map 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 readProteinByCounter(int counter) { + query = new ArrayList(); + // List> res = DBInstance.ReadProteinDataByCounter(counter); + + return query; + } + + + private static List CreateSubprot (String protein, String subprot) { + List sub = new ArrayList(); + 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; } + } diff --git a/website/AllReports.jsp b/website/AllReports.jsp index 601c6b2..fabdf6d 100644 --- a/website/AllReports.jsp +++ b/website/AllReports.jsp @@ -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 diff --git a/website/Sample.jsp b/website/QueryJobsByDate.jsp similarity index 94% rename from website/Sample.jsp rename to website/QueryJobsByDate.jsp index 0116ba7..ae667fd 100644 --- a/website/Sample.jsp +++ b/website/QueryJobsByDate.jsp @@ -9,7 +9,7 @@ Date period -
+

Enter time period

<% Calendar cal = Calendar.getInstance(); String datecalBegin = cal.get(Calendar.YEAR) + "/" + (cal.get(Calendar.MONTH) + 1) + "/1"; diff --git a/website/Sequence.jsp b/website/QuerySequenceProtein.jsp similarity index 78% rename from website/Sequence.jsp rename to website/QuerySequenceProtein.jsp index 1cccbb2..3d86bd6 100644 --- a/website/Sequence.jsp +++ b/website/QuerySequenceProtein.jsp @@ -9,10 +9,11 @@
- +

Enter protein sequence

- search
+ search whole
+ search part


Enter minimum number of jobs per protein


diff --git a/website/JobLength.jsp b/website/QueryTimeExecition.jsp similarity index 95% rename from website/JobLength.jsp rename to website/QueryTimeExecition.jsp index c64ec3c..aaf925f 100644 --- a/website/JobLength.jsp +++ b/website/QueryTimeExecition.jsp @@ -9,7 +9,7 @@ Date interval - +

Enter time period

<% Calendar cal = Calendar.getInstance(); diff --git a/website/ReportNew.jsp b/website/ReportJobsByDate.jsp similarity index 97% rename from website/ReportNew.jsp rename to website/ReportJobsByDate.jsp index 969cad7..261a11b 100644 --- a/website/ReportNew.jsp +++ b/website/ReportJobsByDate.jsp @@ -48,7 +48,6 @@ 0 - ${res.date} diff --git a/website/ReportProt.jsp b/website/ReportSequenceProtein.jsp similarity index 100% rename from website/ReportProt.jsp rename to website/ReportSequenceProtein.jsp diff --git a/website/ReportLength.jsp b/website/ReportTimeExecution.jsp similarity index 100% rename from website/ReportLength.jsp rename to website/ReportTimeExecution.jsp -- 1.7.10.2