From: Sasha Sherstnev Date: Sat, 12 Oct 2013 12:56:45 +0000 (+0100) Subject: first nosql version X-Git-Url: http://source.jalview.org/gitweb/?a=commitdiff_plain;h=46548c37729c2642f58361cc373850d03fdabb65;p=jabaws.git first nosql version --- diff --git a/webservices/compbio/nosql/.classpath b/webservices/compbio/nosql/.classpath new file mode 100644 index 0000000..12511cb --- /dev/null +++ b/webservices/compbio/nosql/.classpath @@ -0,0 +1,16 @@ + + + + + + + + + + + + + + + + diff --git a/webservices/compbio/nosql/.gitignore b/webservices/compbio/nosql/.gitignore new file mode 100644 index 0000000..796b96d --- /dev/null +++ b/webservices/compbio/nosql/.gitignore @@ -0,0 +1 @@ +/build diff --git a/webservices/compbio/nosql/.project b/webservices/compbio/nosql/.project new file mode 100644 index 0000000..f2e4f29 --- /dev/null +++ b/webservices/compbio/nosql/.project @@ -0,0 +1,36 @@ + + + nosql + + + + + + org.eclipse.wst.jsdt.core.javascriptValidator + + + + + org.eclipse.jdt.core.javabuilder + + + + + org.eclipse.wst.common.project.facet.core.builder + + + + + org.eclipse.wst.validation.validationbuilder + + + + + + org.eclipse.jem.workbench.JavaEMFNature + org.eclipse.wst.common.modulecore.ModuleCoreNature + org.eclipse.wst.common.project.facet.core.nature + org.eclipse.jdt.core.javanature + org.eclipse.wst.jsdt.core.jsNature + + diff --git a/webservices/compbio/nosql/.settings/.jsdtscope b/webservices/compbio/nosql/.settings/.jsdtscope new file mode 100644 index 0000000..3a28de0 --- /dev/null +++ b/webservices/compbio/nosql/.settings/.jsdtscope @@ -0,0 +1,12 @@ + + + + + + + + + + + + diff --git a/webservices/compbio/nosql/.settings/org.eclipse.jdt.core.prefs b/webservices/compbio/nosql/.settings/org.eclipse.jdt.core.prefs new file mode 100644 index 0000000..f42de36 --- /dev/null +++ b/webservices/compbio/nosql/.settings/org.eclipse.jdt.core.prefs @@ -0,0 +1,7 @@ +eclipse.preferences.version=1 +org.eclipse.jdt.core.compiler.codegen.inlineJsrBytecode=enabled +org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.7 +org.eclipse.jdt.core.compiler.compliance=1.7 +org.eclipse.jdt.core.compiler.problem.assertIdentifier=error +org.eclipse.jdt.core.compiler.problem.enumIdentifier=error +org.eclipse.jdt.core.compiler.source=1.7 diff --git a/webservices/compbio/nosql/.settings/org.eclipse.wst.common.component b/webservices/compbio/nosql/.settings/org.eclipse.wst.common.component new file mode 100644 index 0000000..e76377e --- /dev/null +++ b/webservices/compbio/nosql/.settings/org.eclipse.wst.common.component @@ -0,0 +1,8 @@ + + + + + + + + diff --git a/webservices/compbio/nosql/.settings/org.eclipse.wst.common.project.facet.core.xml b/webservices/compbio/nosql/.settings/org.eclipse.wst.common.project.facet.core.xml new file mode 100644 index 0000000..b3f07fe --- /dev/null +++ b/webservices/compbio/nosql/.settings/org.eclipse.wst.common.project.facet.core.xml @@ -0,0 +1,10 @@ + + + + + + + + + + diff --git a/webservices/compbio/nosql/.settings/org.eclipse.wst.jsdt.ui.superType.container b/webservices/compbio/nosql/.settings/org.eclipse.wst.jsdt.ui.superType.container new file mode 100644 index 0000000..3bd5d0a --- /dev/null +++ b/webservices/compbio/nosql/.settings/org.eclipse.wst.jsdt.ui.superType.container @@ -0,0 +1 @@ +org.eclipse.wst.jsdt.launching.baseBrowserLibrary \ No newline at end of file diff --git a/webservices/compbio/nosql/.settings/org.eclipse.wst.jsdt.ui.superType.name b/webservices/compbio/nosql/.settings/org.eclipse.wst.jsdt.ui.superType.name new file mode 100644 index 0000000..05bd71b --- /dev/null +++ b/webservices/compbio/nosql/.settings/org.eclipse.wst.jsdt.ui.superType.name @@ -0,0 +1 @@ +Window \ No newline at end of file diff --git a/webservices/compbio/nosql/.settings/org.jboss.ide.eclipse.as.core.prefs b/webservices/compbio/nosql/.settings/org.jboss.ide.eclipse.as.core.prefs new file mode 100644 index 0000000..cf3aa3a --- /dev/null +++ b/webservices/compbio/nosql/.settings/org.jboss.ide.eclipse.as.core.prefs @@ -0,0 +1,2 @@ +eclipse.preferences.version=1 +org.jboss.ide.eclipse.as.core.singledeployable.deployableList= diff --git a/webservices/compbio/nosql/WebContent/AllReports.jsp b/webservices/compbio/nosql/WebContent/AllReports.jsp new file mode 100644 index 0000000..110bc3e --- /dev/null +++ b/webservices/compbio/nosql/WebContent/AllReports.jsp @@ -0,0 +1,9 @@ +<% + String query = request.getParameter("query"); + if (query.equals("date")) + response.sendRedirect("Sample.jsp"); + else if (query.equals("length")) + response.sendRedirect("JobLength.jsp"); + else if (query.equals("protein")) + response.sendRedirect("Sequence.jsp"); +%> \ No newline at end of file diff --git a/webservices/compbio/nosql/WebContent/Index.jsp b/webservices/compbio/nosql/WebContent/Index.jsp new file mode 100644 index 0000000..475b4a7 --- /dev/null +++ b/webservices/compbio/nosql/WebContent/Index.jsp @@ -0,0 +1,18 @@ +<%@ page language="java" contentType="text/html; charset=UTF-8" + pageEncoding="UTF-8"%> + + + + +Cassandra report + + +
+

Choose query type

+ Search by date
+ Search by time interval
+ Search by protein sequence
+ +
+ + \ No newline at end of file diff --git a/webservices/compbio/nosql/WebContent/JobLength.jsp b/webservices/compbio/nosql/WebContent/JobLength.jsp new file mode 100644 index 0000000..65c7004 --- /dev/null +++ b/webservices/compbio/nosql/WebContent/JobLength.jsp @@ -0,0 +1,23 @@ +<%@ page language="java" contentType="text/html; charset=UTF-8" + pageEncoding="UTF-8"%> + <%@page import="java.util.Calendar"%> + + + + + +Date interval + + +
+

Enter time period

+ <% Calendar cal = Calendar.getInstance(); + String datecalBegin = cal.get(Calendar.YEAR) + "/" + cal.get(Calendar.MONTH) + "/1"; + String datecalEnd = cal.get(Calendar.YEAR) + "/" + cal.get(Calendar.MONTH) + "/" + cal.get(Calendar.DAY_OF_MONTH); + %> +

from style=" width : 145px;"/> + to style=" width : 145px;"/>

+ +
+ + \ No newline at end of file diff --git a/webservices/compbio/nosql/WebContent/META-INF/MANIFEST.MF b/webservices/compbio/nosql/WebContent/META-INF/MANIFEST.MF new file mode 100644 index 0000000..5e94951 --- /dev/null +++ b/webservices/compbio/nosql/WebContent/META-INF/MANIFEST.MF @@ -0,0 +1,3 @@ +Manifest-Version: 1.0 +Class-Path: + diff --git a/webservices/compbio/nosql/WebContent/PrintResult.jsp b/webservices/compbio/nosql/WebContent/PrintResult.jsp new file mode 100644 index 0000000..c2f2e81 --- /dev/null +++ b/webservices/compbio/nosql/WebContent/PrintResult.jsp @@ -0,0 +1,21 @@ +<%@ page language="java" contentType="text/html; charset=UTF-8" + pageEncoding="UTF-8"%> + + + + +Report + + +

Report Results

+<% String rez = request.getAttribute("result").toString(); + String[] rezLines = rez.split(";"); + for (int i = 0; i < rezLines.length; i++) { +%> +<%= rezLines[i]+"
" %> +<% +} +%> +Click here to go Back + + \ No newline at end of file diff --git a/webservices/compbio/nosql/WebContent/ReportLength.jsp b/webservices/compbio/nosql/WebContent/ReportLength.jsp new file mode 100644 index 0000000..0f20353 --- /dev/null +++ b/webservices/compbio/nosql/WebContent/ReportLength.jsp @@ -0,0 +1,28 @@ +<%@page import="java.util.ArrayList"%> +<%@ page trimDirectiveWhitespaces="true" %> +<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %> +<%@ taglib uri="http://java.sun.com/jsp/jstl/functions" prefix="fn" %> +<%@ taglib uri="http://java.sun.com/jsp/jstl/fmt" prefix="fmt" %> +<%@ taglib uri="http://displaytag.sf.net" prefix="dt" %> + +

Time execution for the interval: ${data1} - ${data2}

+ + + + + + + + + + + + + + + + + + + +
Dateless then 1sless then 10sless then 20smore then 20s
${res.date}${time}
diff --git a/webservices/compbio/nosql/WebContent/ReportNew.jsp b/webservices/compbio/nosql/WebContent/ReportNew.jsp new file mode 100644 index 0000000..c0715bd --- /dev/null +++ b/webservices/compbio/nosql/WebContent/ReportNew.jsp @@ -0,0 +1,43 @@ +<%@page import="java.util.ArrayList"%> +<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %> +<%@ taglib uri="http://java.sun.com/jsp/jstl/functions" prefix="fn" %> +<%@ taglib uri="http://java.sun.com/jsp/jstl/fmt" prefix="fmt" %> +<%@ taglib uri="http://displaytag.sf.net" prefix="dt" %> + +

Jobs statistics for the Period: + to

+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
DateNumber of Proteins
TotalFailedCancelledAbandoned
${res.date}000
Total:${sum}000
\ No newline at end of file diff --git a/webservices/compbio/nosql/WebContent/ReportProt.jsp b/webservices/compbio/nosql/WebContent/ReportProt.jsp new file mode 100644 index 0000000..e5bc3fa --- /dev/null +++ b/webservices/compbio/nosql/WebContent/ReportProt.jsp @@ -0,0 +1,39 @@ +<%@page import="java.util.ArrayList"%> +<%@ page trimDirectiveWhitespaces="true" %> +<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %> +<%@ taglib uri="http://java.sun.com/jsp/jstl/functions" prefix="fn" %> +<%@ taglib uri="http://java.sun.com/jsp/jstl/fmt" prefix="fmt" %> +<%@ taglib uri="http://displaytag.sf.net" prefix="dt" %> + +

Dundee ProteoCache query result

+ + + + + + + + + + + + + + + + + + + + + + + +
IDPrediction
${res.id} + + +${seq} +${seq} + + +
diff --git a/webservices/compbio/nosql/WebContent/Sample.jsp b/webservices/compbio/nosql/WebContent/Sample.jsp new file mode 100644 index 0000000..f080c3a --- /dev/null +++ b/webservices/compbio/nosql/WebContent/Sample.jsp @@ -0,0 +1,23 @@ +<%@ page language="java" contentType="text/html; charset=UTF-8" + pageEncoding="UTF-8"%> + <%@page import="java.util.Calendar"%> + + + + + +Date period + + +
+

Enter time period

+ <% Calendar cal = Calendar.getInstance(); + String datecalBegin = cal.get(Calendar.YEAR) + "/" + cal.get(Calendar.MONTH) + "/1"; + String datecalEnd = cal.get(Calendar.YEAR) + "/" + cal.get(Calendar.MONTH) + "/" + cal.get(Calendar.DAY_OF_MONTH); + %> +

from style=" width : 145px;"/> + to style=" width : 145px;"/>

+ +
+ + \ No newline at end of file diff --git a/webservices/compbio/nosql/WebContent/Sequence.jsp b/webservices/compbio/nosql/WebContent/Sequence.jsp new file mode 100644 index 0000000..29a033e --- /dev/null +++ b/webservices/compbio/nosql/WebContent/Sequence.jsp @@ -0,0 +1,20 @@ +<%@ page language="java" contentType="text/html; charset=UTF-8" + pageEncoding="UTF-8"%> + + + + + +Sequence of protein + + +
+
+

Enter protein sequence

+

+ search by the whole sequence + search by a part of sequence
+ +
+ + \ No newline at end of file diff --git a/webservices/compbio/nosql/WebContent/StatisticsProtein.jsp b/webservices/compbio/nosql/WebContent/StatisticsProtein.jsp new file mode 100644 index 0000000..06c7d72 --- /dev/null +++ b/webservices/compbio/nosql/WebContent/StatisticsProtein.jsp @@ -0,0 +1,41 @@ +<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %> +<%@ taglib uri="http://java.sun.com/jsp/jstl/functions" prefix="fn" %> +<%@ taglib uri="http://java.sun.com/jsp/jstl/fmt" prefix="fmt" %> +<%@ taglib uri="http://displaytag.sf.net" prefix="dt" %> + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
DateNumber of Proteins
TotalFailedCancelledAbandoned
${res.date}000
Total:${sum}000
diff --git a/webservices/compbio/nosql/WebContent/WEB-INF/lib/cassandra-all-1.2.4.jar b/webservices/compbio/nosql/WebContent/WEB-INF/lib/cassandra-all-1.2.4.jar new file mode 100644 index 0000000..ab244c5 Binary files /dev/null and b/webservices/compbio/nosql/WebContent/WEB-INF/lib/cassandra-all-1.2.4.jar differ diff --git a/webservices/compbio/nosql/WebContent/WEB-INF/lib/cassandra-clientutil-1.2.4.jar b/webservices/compbio/nosql/WebContent/WEB-INF/lib/cassandra-clientutil-1.2.4.jar new file mode 100644 index 0000000..1ac8df4 Binary files /dev/null and b/webservices/compbio/nosql/WebContent/WEB-INF/lib/cassandra-clientutil-1.2.4.jar differ diff --git a/webservices/compbio/nosql/WebContent/WEB-INF/lib/cassandra-thrift-1.2.4.jar b/webservices/compbio/nosql/WebContent/WEB-INF/lib/cassandra-thrift-1.2.4.jar new file mode 100644 index 0000000..ca72cf0 Binary files /dev/null and b/webservices/compbio/nosql/WebContent/WEB-INF/lib/cassandra-thrift-1.2.4.jar differ diff --git a/webservices/compbio/nosql/WebContent/WEB-INF/lib/commons-lang-2.4.jar b/webservices/compbio/nosql/WebContent/WEB-INF/lib/commons-lang-2.4.jar new file mode 100644 index 0000000..532939e Binary files /dev/null and b/webservices/compbio/nosql/WebContent/WEB-INF/lib/commons-lang-2.4.jar differ diff --git a/webservices/compbio/nosql/WebContent/WEB-INF/lib/displaytag-1.2.jar b/webservices/compbio/nosql/WebContent/WEB-INF/lib/displaytag-1.2.jar new file mode 100644 index 0000000..4f379bd Binary files /dev/null and b/webservices/compbio/nosql/WebContent/WEB-INF/lib/displaytag-1.2.jar differ diff --git a/webservices/compbio/nosql/WebContent/WEB-INF/lib/google-collections-0.8.jar b/webservices/compbio/nosql/WebContent/WEB-INF/lib/google-collections-0.8.jar new file mode 100644 index 0000000..01a54ef Binary files /dev/null and b/webservices/compbio/nosql/WebContent/WEB-INF/lib/google-collections-0.8.jar differ diff --git a/webservices/compbio/nosql/WebContent/WEB-INF/lib/hector-0.7.0-20-sources.jar b/webservices/compbio/nosql/WebContent/WEB-INF/lib/hector-0.7.0-20-sources.jar new file mode 100644 index 0000000..9a2fe11 Binary files /dev/null and b/webservices/compbio/nosql/WebContent/WEB-INF/lib/hector-0.7.0-20-sources.jar differ diff --git a/webservices/compbio/nosql/WebContent/WEB-INF/lib/hector-core-1.0-5.jar b/webservices/compbio/nosql/WebContent/WEB-INF/lib/hector-core-1.0-5.jar new file mode 100644 index 0000000..a325f08 Binary files /dev/null and b/webservices/compbio/nosql/WebContent/WEB-INF/lib/hector-core-1.0-5.jar differ diff --git a/webservices/compbio/nosql/WebContent/WEB-INF/lib/jamm-0.2.5.jar b/webservices/compbio/nosql/WebContent/WEB-INF/lib/jamm-0.2.5.jar new file mode 100644 index 0000000..e9baf75 Binary files /dev/null and b/webservices/compbio/nosql/WebContent/WEB-INF/lib/jamm-0.2.5.jar differ diff --git a/webservices/compbio/nosql/WebContent/WEB-INF/lib/jstl-1.2.jar b/webservices/compbio/nosql/WebContent/WEB-INF/lib/jstl-1.2.jar new file mode 100644 index 0000000..0fd275e Binary files /dev/null and b/webservices/compbio/nosql/WebContent/WEB-INF/lib/jstl-1.2.jar differ diff --git a/webservices/compbio/nosql/WebContent/WEB-INF/lib/libthrift-0.6.0.jar b/webservices/compbio/nosql/WebContent/WEB-INF/lib/libthrift-0.6.0.jar new file mode 100644 index 0000000..624e3ad Binary files /dev/null and b/webservices/compbio/nosql/WebContent/WEB-INF/lib/libthrift-0.6.0.jar differ diff --git a/webservices/compbio/nosql/WebContent/WEB-INF/lib/log4j-1.2.16.jar b/webservices/compbio/nosql/WebContent/WEB-INF/lib/log4j-1.2.16.jar new file mode 100644 index 0000000..5429a90 Binary files /dev/null and b/webservices/compbio/nosql/WebContent/WEB-INF/lib/log4j-1.2.16.jar differ diff --git a/webservices/compbio/nosql/WebContent/WEB-INF/lib/slf4j-1.7.5.tar.gz b/webservices/compbio/nosql/WebContent/WEB-INF/lib/slf4j-1.7.5.tar.gz new file mode 100644 index 0000000..3f3d799 Binary files /dev/null and b/webservices/compbio/nosql/WebContent/WEB-INF/lib/slf4j-1.7.5.tar.gz differ diff --git a/webservices/compbio/nosql/WebContent/WEB-INF/lib/slf4j-api-1.7.5.jar b/webservices/compbio/nosql/WebContent/WEB-INF/lib/slf4j-api-1.7.5.jar new file mode 100644 index 0000000..8766455 Binary files /dev/null and b/webservices/compbio/nosql/WebContent/WEB-INF/lib/slf4j-api-1.7.5.jar differ diff --git a/webservices/compbio/nosql/WebContent/WEB-INF/lib/slf4j-simple-1.7.5.jar b/webservices/compbio/nosql/WebContent/WEB-INF/lib/slf4j-simple-1.7.5.jar new file mode 100644 index 0000000..9dece31 Binary files /dev/null and b/webservices/compbio/nosql/WebContent/WEB-INF/lib/slf4j-simple-1.7.5.jar differ diff --git a/webservices/compbio/nosql/WebContent/WEB-INF/web.xml b/webservices/compbio/nosql/WebContent/WEB-INF/web.xml new file mode 100644 index 0000000..672606e --- /dev/null +++ b/webservices/compbio/nosql/WebContent/WEB-INF/web.xml @@ -0,0 +1,7 @@ + + + nosql + + combio.listeners.ContextListener + + \ No newline at end of file diff --git a/webservices/compbio/nosql/displaytag-1.2.jar b/webservices/compbio/nosql/displaytag-1.2.jar new file mode 100644 index 0000000..4f379bd Binary files /dev/null and b/webservices/compbio/nosql/displaytag-1.2.jar differ diff --git a/webservices/compbio/nosql/jstl-1.2.jar b/webservices/compbio/nosql/jstl-1.2.jar new file mode 100644 index 0000000..0fd275e Binary files /dev/null and b/webservices/compbio/nosql/jstl-1.2.jar differ diff --git a/webservices/compbio/nosql/src/combio/cassandra/CassandraCreate.java b/webservices/compbio/nosql/src/combio/cassandra/CassandraCreate.java new file mode 100644 index 0000000..376da4c --- /dev/null +++ b/webservices/compbio/nosql/src/combio/cassandra/CassandraCreate.java @@ -0,0 +1,103 @@ +package combio.cassandra; + +import java.util.Arrays; + +import me.prettyprint.cassandra.serializers.LongSerializer; +import me.prettyprint.cassandra.serializers.StringSerializer; +import me.prettyprint.cassandra.service.ThriftKsDef; +import me.prettyprint.hector.api.Cluster; +import me.prettyprint.hector.api.Keyspace; +import me.prettyprint.hector.api.beans.ColumnSlice; +import me.prettyprint.hector.api.ddl.ColumnFamilyDefinition; +import me.prettyprint.hector.api.ddl.ComparatorType; +import me.prettyprint.hector.api.ddl.KeyspaceDefinition; +import me.prettyprint.hector.api.factory.HFactory; +import me.prettyprint.hector.api.mutation.Mutator; +import me.prettyprint.hector.api.query.QueryResult; +import me.prettyprint.hector.api.query.SliceQuery; + +public class CassandraCreate { + private static Keyspace ksp; + private static Cluster cluster; + private static Mutator mutatorLong; + private static Mutator mutatorString; + private static Mutator mutatorLog; + StringSerializer ss = StringSerializer.get(); + LongSerializer ls = LongSerializer.get(); + + + // connect to cluster + public void Connection() { + cluster = HFactory.getOrCreateCluster("Protein Cluster", "127.0.0.1:9160"); + KeyspaceDefinition keyspaceDef = cluster.describeKeyspace("ProteinKeyspace"); + // If keyspace does not exist, the CFs don't exist either. => create them. +/* if (keyspaceDef != null) { + cluster.dropColumnFamily("ProteinKeyspace", "ProteinRow", true); + cluster.dropColumnFamily("ProteinKeyspace", "ProteinData", true); + cluster.dropKeyspace("ProteinKeyspace", true); + System.out.println("ProteinKeyspace has been dropped"); + } else*/ if (keyspaceDef == null) { // create column family + System.out.println("ProteinKeyspace has been null"); + ColumnFamilyDefinition cfProtein = HFactory.createColumnFamilyDefinition("ProteinKeyspace", "ProteinRow", ComparatorType.ASCIITYPE); + ColumnFamilyDefinition cfLog = HFactory.createColumnFamilyDefinition("ProteinKeyspace", "ProteinLog", ComparatorType.ASCIITYPE); + ColumnFamilyDefinition cfData = HFactory.createColumnFamilyDefinition("ProteinKeyspace", "ProteinData", ComparatorType.ASCIITYPE); + + KeyspaceDefinition newKeyspace = HFactory.createKeyspaceDefinition("ProteinKeyspace", + ThriftKsDef.DEF_STRATEGY_CLASS, 1, Arrays.asList(cfProtein, cfLog, cfData)); + //Add the schema to the cluster. + //"true" as the second param means that Hector will block until all nodes see the change. + cluster.addKeyspace(newKeyspace, true); + cluster.addColumnFamily(cfProtein, true); + cluster.addColumnFamily(cfLog, true); + cluster.addColumnFamily(cfData, true); + } + ksp = HFactory.createKeyspace("ProteinKeyspace", cluster); + System.out.println("Cassantra has been connected"); + } + + // parsing data from http://www.compbio.dundee.ac.uk/www-jpred/results/usage-new/alljobs.dat + public void Parsing() { + mutatorString = HFactory.createMutator(ksp, ss); // CF ProteinRow store protein and prediction + mutatorLog = HFactory.createMutator(ksp, ss); // CF ProteinLog store log informations (ip, id, dates start and dates of end) + mutatorLong = HFactory.createMutator(ksp, ls); // CF ProteinData store id and protein per data + System.out.println("Parsing......"); + String in = "http://www.compbio.dundee.ac.uk/www-jpred/results/usage-new/alljobs.dat"; + DataParsing datParsing = new DataParsing(); + datParsing.ParsingTest(in); + mutatorString.execute(); + mutatorLong.execute(); + mutatorLog.execute(); + System.out.println("Data Inserted"); + } + + public void Closing() { + cluster.getConnectionManager().shutdown(); + System.out.println("Cassantra has been closed"); + } + + // check whether this id exists in the cassandra DB + public boolean CheckIP(String ip) { + SliceQuery sliceQuery = HFactory.createSliceQuery(ksp, ss, ss, ss); + sliceQuery.setColumnFamily("ProteinLog").setKey(ip).setRange("", "", false, 100); + QueryResult> result = sliceQuery.execute(); + if (result.get().getColumns().size() > 0) + return true; + else + return false; + } + + public void InsertData(long dataWork, String dataBegin, String dataEnd, String ip, String id, String statusEx, String statusFinal, String protein, String jnetpred) { + mutatorLog.addInsertion(id, "ProteinLog", HFactory.createColumn("ip", ip, ss, ss)) + .addInsertion(id, "ProteinLog", HFactory.createColumn("DataBegin", dataBegin, ss, ss)) + .addInsertion(id, "ProteinLog", HFactory.createColumn("DataEnd", dataEnd, ss, ss)) + .addInsertion(id, "ProteinLog", HFactory.createColumn("Status ex", statusEx, ss, ss)) + .addInsertion(id, "ProteinLog", HFactory.createColumn("Status final", statusFinal, ss, ss)) + .addInsertion(id, "ProteinLog", HFactory.createColumn("Protein", protein, ss, ss)); + mutatorString.addInsertion(protein, "ProteinRow", HFactory.createColumn(id, jnetpred, ss, ss)); + mutatorLong.addInsertion(dataWork, "ProteinData", HFactory.createColumn(id, protein, ss, ss)); + } + + public Keyspace GetKeyspace() { + return ksp; + } +} diff --git a/webservices/compbio/nosql/src/combio/cassandra/DataBase.java b/webservices/compbio/nosql/src/combio/cassandra/DataBase.java new file mode 100644 index 0000000..036a48d --- /dev/null +++ b/webservices/compbio/nosql/src/combio/cassandra/DataBase.java @@ -0,0 +1,76 @@ +package combio.cassandra; + +import java.util.List; + +public class DataBase { + String date; + int total; + String id; + String prot; + String jpred; + List subProt; + List timeRez; + + + public DataBase() {} + + public DataBase(String dat, int total) { + this.date = dat; + this.total = total; + } + + public void setDate(String dat) { + this.date = dat; + } + + public String getDate() { + return date; + } + + public void setTotal(int tot) { + this.total = tot; + } + public int getTotal() { + return total; + } + + public void setProt(String prot) { + this.prot = prot; + } + + public String getProt() { + return prot; + } + + public void setJpred(String jpred) { + this.jpred = jpred; + } + + public String getJpred() { + return jpred; + } + + public void setId(String id) { + this.id = id; + } + + public String getId() { + return id; + } + + public void setSubProt(List subProt) { + this.subProt = subProt; + } + + public List getSubProt() { + return subProt; + } + + public void setTimeRez(List timeRez) { + this.timeRez = timeRez; + } + + public List getTimeRez() { + return timeRez; + } +} diff --git a/webservices/compbio/nosql/src/combio/cassandra/DataParsing.java b/webservices/compbio/nosql/src/combio/cassandra/DataParsing.java new file mode 100644 index 0000000..1a03ce4 --- /dev/null +++ b/webservices/compbio/nosql/src/combio/cassandra/DataParsing.java @@ -0,0 +1,98 @@ +package combio.cassandra; + +import java.io.BufferedReader; +import java.io.IOException; +import java.io.InputStreamReader; +import java.net.HttpURLConnection; +import java.net.MalformedURLException; +import java.net.URL; +import java.net.URLConnection; +import java.text.ParseException; +import java.text.SimpleDateFormat; +import java.util.Calendar; +import java.util.Date; + +public class DataParsing { + private CassandraCreate cc = new CassandraCreate(); + + public void ParsingTest(String input) { + System.out.println("Inserting....."); + URL url, urltable; +// int count = 0; +// int countNotM = 0; +// int countEr = 0; +// int countEmp = 0; + Calendar cal = Calendar.getInstance(); + String date = cal.get(Calendar.YEAR) + "/" + cal.get(Calendar.MONTH) + "/" + cal.get(Calendar.DAY_OF_MONTH); + try { + url = new URL(input); + URLConnection conn = url.openConnection(); + BufferedReader br = new BufferedReader(new InputStreamReader(conn.getInputStream())); + String line; + + while ((line = br.readLine()) != null) { + if (line.matches(date + "(.*)jp_[^\\s]+")) { + String[] table; + table = line.split("\\s+"); + // count++; + if (!cc.CheckIP(table[table.length - 1])) { + // countNotM++; + urltable = new URL("http://www.compbio.dundee.ac.uk/www-jpred/results/" +table[table.length - 1]+"/"+table[table.length - 1]+".concise.fasta"); + HttpURLConnection httpConnection = (HttpURLConnection) urltable.openConnection(); + if (httpConnection.getResponseCode() > 200) { +// countEr++; + continue; + } + try { + BufferedReader br1 = new BufferedReader(new InputStreamReader(httpConnection.getInputStream())); + String lineNext; + String newProt = ""; + String jnetpred = ""; + while ((lineNext = br1.readLine()) != null) { + if (lineNext.equals(">QUERY")) { + while (!(lineNext = br1.readLine()).matches(">[^\\s]+")) + newProt += lineNext; + } else if (lineNext.equals(">jnetpred")) { + while (!(lineNext = br1.readLine()).matches(">[^\\s]+")) + jnetpred += lineNext; + } + } + br1.close(); + if (newProt.length() <= 1) { + // countEmp++; + continue; + } + + SimpleDateFormat formatter = new SimpleDateFormat("yyyy/MM/dd"); + + String dateInString1 = table[0].substring(0, table[0].indexOf(":")); + + long dateWork1 = 0; + + try { + Date dat1 = formatter.parse(dateInString1); + dateWork1 = dat1.getTime(); + + } catch (ParseException e) { + e.printStackTrace(); + } + cc.InsertData(dateWork1, table[0], table[1], table[2], table[table.length - 1], "OK", "OK", newProt, jnetpred); + } catch (IOException e) { + // e.printStackTrace(); + } + // } + } + } + } + br.close(); +// System.out.println("Match " + count); +// System.out.println("Not Match " + countNotM); +// System.out.println("Error " + countEr); +// System.out.println("No protein " + countEmp); + } catch (MalformedURLException e) { + e.printStackTrace(); + } catch (IOException e) { + e.printStackTrace(); + } + } +} diff --git a/webservices/compbio/nosql/src/combio/listeners/ContextListener.java b/webservices/compbio/nosql/src/combio/listeners/ContextListener.java new file mode 100644 index 0000000..1b57283 --- /dev/null +++ b/webservices/compbio/nosql/src/combio/listeners/ContextListener.java @@ -0,0 +1,48 @@ +package combio.listeners; + +import java.util.concurrent.Executors; +import java.util.concurrent.ScheduledExecutorService; +import java.util.concurrent.TimeUnit; + +import javax.servlet.ServletContextEvent; +import javax.servlet.ServletContextListener; +import javax.servlet.annotation.WebListener; + +import combio.cassandra.CassandraCreate; + +/** + * Application Lifecycle Listener implementation class ContextListener + * + */ +@WebListener +public class ContextListener implements ServletContextListener { + private ScheduledExecutorService scheduler; + CassandraCreate cc = new CassandraCreate(); + /** + * @see ServletContextListener#contextInitialized(ServletContextEvent) + */ + public void contextInitialized(ServletContextEvent arg0) { + System.out.println("Session start ..........................................."); + cc.Connection(); + + + scheduler = Executors.newSingleThreadScheduledExecutor(); + scheduler.scheduleAtFixedRate(new Runnable() { + @Override + public void run() { cc.Parsing();}} + , 0, 30, TimeUnit.SECONDS); + } + + /** + * @see ServletContextListener#contextDestroyed(ServletContextEvent) + */ + public void contextDestroyed(ServletContextEvent arg0) { + cc.Closing(); + System.out.println("Shut down"); + scheduler.shutdownNow(); + } + + + + +} diff --git a/webservices/compbio/nosql/src/combio/listeners/DetailList.java b/webservices/compbio/nosql/src/combio/listeners/DetailList.java new file mode 100644 index 0000000..7d679f1 --- /dev/null +++ b/webservices/compbio/nosql/src/combio/listeners/DetailList.java @@ -0,0 +1,45 @@ +package combio.listeners; + +import java.io.IOException; +import java.util.ArrayList; +import java.util.List; + +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +import combio.cassandra.*; +import combio.statistic.StatisticsProt; + +/** + * Servlet implementation class DetailList + */ +@WebServlet("/DetailList") +public class DetailList extends HttpServlet { + private static final long serialVersionUID = 1L; + + /** + * @see HttpServlet#HttpServlet() + */ + + /** + * @see HttpServlet#doGet(HttpServletRequest request, HttpServletResponse response) + */ + protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { + List result; + String date1 = request.getParameter("data1"); + String date2 = request.getParameter("data2"); + StatisticsProt sp = new StatisticsProt(); +// result = sp.readDetail(date1, date2); + } + + /** + * @see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse response) + */ + protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { + // TODO Auto-generated method stub + } + +} diff --git a/webservices/compbio/nosql/src/combio/listeners/LengthServlet.java b/webservices/compbio/nosql/src/combio/listeners/LengthServlet.java new file mode 100644 index 0000000..6e4feee --- /dev/null +++ b/webservices/compbio/nosql/src/combio/listeners/LengthServlet.java @@ -0,0 +1,44 @@ +package combio.listeners; + +import java.io.IOException; +import java.util.List; + +import javax.servlet.RequestDispatcher; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +import combio.cassandra.DataBase; +import combio.statistic.StatisticsProt; + +/** + * Servlet implementation class LengthServlet + */ +@WebServlet("/LengthServlet") +public class LengthServlet extends HttpServlet { + private static final long serialVersionUID = 1L; + /** + * @see HttpServlet#doGet(HttpServletRequest request, HttpServletResponse response) + */ + protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { + List result; + String date1 = request.getParameter("data1"); + String date2 = request.getParameter("data2"); + StatisticsProt sp = new StatisticsProt(); + result = sp.readLength(date1, date2); + request.setAttribute("data1", date1); + request.setAttribute("data2", date2); + request.setAttribute("result", result); + RequestDispatcher rd = request.getRequestDispatcher("/ReportLength.jsp"); + rd.forward(request, response); + } + + /** + * @see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse response) + */ + protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { + doGet(request, response); + } +} diff --git a/webservices/compbio/nosql/src/combio/listeners/ProtServlet.java b/webservices/compbio/nosql/src/combio/listeners/ProtServlet.java new file mode 100644 index 0000000..7bef70d --- /dev/null +++ b/webservices/compbio/nosql/src/combio/listeners/ProtServlet.java @@ -0,0 +1,49 @@ +package combio.listeners; + +import java.io.IOException; +import java.util.List; + +import javax.servlet.RequestDispatcher; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +import combio.cassandra.DataBase; +import combio.statistic.StatisticsProt; + +/** + * Servlet implementation class ProtServlet + */ +@WebServlet("/ProtServlet") +public class ProtServlet extends HttpServlet { + private static final long serialVersionUID = 1L; + /** + * @see HttpServlet#doGet(HttpServletRequest request, HttpServletResponse response) + */ + protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { + List result; + String flag = request.getParameter("protein"); + String prot = request.getParameter("prot"); + StatisticsProt sp = new StatisticsProt(); + if (flag.equals("whole")) { + result = sp.readProt(prot); + } else { + result = sp.readPart(prot); + } + request.setAttribute("prot", prot); + request.setAttribute("flag", flag); + request.setAttribute("result", result); + RequestDispatcher rd = request.getRequestDispatcher("/ReportProt.jsp"); + rd.forward(request, response); + } + + /** + * @see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse response) + */ + protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { + doGet(request, response); + } + +} diff --git a/webservices/compbio/nosql/src/combio/listeners/QueryServlet.java b/webservices/compbio/nosql/src/combio/listeners/QueryServlet.java new file mode 100644 index 0000000..e9ab299 --- /dev/null +++ b/webservices/compbio/nosql/src/combio/listeners/QueryServlet.java @@ -0,0 +1,41 @@ +package combio.listeners; + +import java.io.IOException; +import java.util.List; + +import javax.servlet.RequestDispatcher; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +import combio.cassandra.*; +import combio.statistic.StatisticsProt; + + +@WebServlet("/QueryServlet") +public class QueryServlet extends HttpServlet { + private static final long serialVersionUID = 1L; + + /** + * @see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse response) + */ + protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { + List result; + String date1 = request.getParameter("data1"); + String date2 = request.getParameter("data2"); + StatisticsProt sp = new StatisticsProt(); + result = sp.readDetail(date1, date2); + request.setAttribute("data1", date1); + request.setAttribute("data2", date2); + request.setAttribute("result", result); + RequestDispatcher rd = request.getRequestDispatcher("/ReportNew.jsp"); + rd.forward(request, response); + } + + protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { + doGet(request, response); + } + +} diff --git a/webservices/compbio/nosql/src/combio/statistic/StatisticsProt.java b/webservices/compbio/nosql/src/combio/statistic/StatisticsProt.java new file mode 100644 index 0000000..72cad07 --- /dev/null +++ b/webservices/compbio/nosql/src/combio/statistic/StatisticsProt.java @@ -0,0 +1,204 @@ +package combio.statistic; + +import java.text.ParseException; +import java.text.SimpleDateFormat; +import java.util.ArrayList; +import java.util.Arrays; +import java.util.Collections; +import java.util.Date; +import java.util.Iterator; +import java.util.List; + +import me.prettyprint.cassandra.serializers.LongSerializer; +import me.prettyprint.cassandra.serializers.StringSerializer; +import me.prettyprint.hector.api.beans.ColumnSlice; +import me.prettyprint.hector.api.beans.HColumn; +import me.prettyprint.hector.api.beans.OrderedRows; +import me.prettyprint.hector.api.beans.Row; +import me.prettyprint.hector.api.factory.HFactory; +import me.prettyprint.hector.api.query.QueryResult; +import me.prettyprint.hector.api.query.RangeSlicesQuery; +import me.prettyprint.hector.api.query.SliceQuery; +import combio.cassandra.CassandraCreate; +import combio.cassandra.DataBase; + +public class StatisticsProt { + private final static long MILLISECONDS_PER_DAY = 1000L * 60 * 60 * 24; + private CassandraCreate cc = new CassandraCreate(); + private ArrayList query; + + // query for the period from date1 till date2 + public List readDetail(String dateInStringSt, String dateInStringEnd) { + long dateWorkSt = DateParsing(dateInStringSt); + long dateWorkEnd = DateParsing(dateInStringEnd); + query = new ArrayList(); + while (dateWorkSt <= dateWorkEnd) { + SliceQuery result = HFactory.createSliceQuery(cc.GetKeyspace(), LongSerializer.get(), StringSerializer.get(), StringSerializer.get()); + result.setColumnFamily("ProteinData"); + result.setKey(dateWorkSt); + result.setRange(null, null, false, Integer.MAX_VALUE); + QueryResult > columnSlice = result.execute(); + DataBase db = new DataBase(DateFormat(dateWorkSt), columnSlice.get().getColumns().size()); + query.add(db); + dateWorkSt += MILLISECONDS_PER_DAY ; + } + return query; + } + + // query jobs for the period from dateInStringSt till dateInStringEnd + public List readLength(String dateInStringSt, String dateInStringEnd) { + query = new ArrayList(); + long dateWorkSt = DateParsing(dateInStringSt); + long dateWorkEnd = DateParsing(dateInStringEnd); + while (dateWorkSt <= dateWorkEnd) { + List timeResult = new ArrayList(); + SliceQuery result = HFactory.createSliceQuery(cc.GetKeyspace(), LongSerializer.get(), StringSerializer.get(), StringSerializer.get()); + result.setColumnFamily("ProteinData"); + result.setKey(dateWorkSt); + result.setRange(null, null, false, Integer.MAX_VALUE); + QueryResult > columnSlice = result.execute(); + List> col = columnSlice.get().getColumns(); + Iterator> itCol = col.iterator(); + for (int i = 0; i < 4; i++) + timeResult.add(i, 0); + while (itCol.hasNext()) { + String id = itCol.next().getName(); + long lenResult = CountID(id); + if (lenResult <= 1) + timeResult.set(0, timeResult.get(0) + 1); + else if (lenResult > 1 && lenResult <= 10) + timeResult.set(1, timeResult.get(1) + 1); + else if (lenResult > 10 && lenResult <= 20) + timeResult.set(2, timeResult.get(2) + 1); + else + timeResult.set(3, timeResult.get(3) + 1); + } + DataBase db = new DataBase(); + db.setTimeRez(timeResult); + db.setDate(DateFormat(dateWorkSt)); + query.add(db); + List test = query.get(0).getTimeRez(); + dateWorkSt += MILLISECONDS_PER_DAY ; + } + return query; + } + + //query by a protein name + public List readProt(String protIn) { + query = new ArrayList(); + SliceQuery result = HFactory.createSliceQuery(cc.GetKeyspace(), StringSerializer.get(), StringSerializer.get(), StringSerializer.get()); + result.setColumnFamily("ProteinRow"); + result.setKey(protIn); + result.setRange(null, null, false, Integer.MAX_VALUE); + QueryResult > columnSlice = result.execute(); + Iterator > it = columnSlice.get().getColumns().iterator(); + while (it.hasNext()) { + HColumn col = it.next(); + DataBase db = new DataBase(); + db.setProt(protIn); + db.setId(col.getName()); + db.setJpred(col.getValue()); + query.add(db); + } + return query; + } + + + //query by a sequence (whether exists proteins contains this sequence in the name) + public List readPart(String protIn) { + int row_count = 10000; + query = new ArrayList(); + RangeSlicesQuery result = HFactory.createRangeSlicesQuery(cc.GetKeyspace(), StringSerializer.get(), StringSerializer.get(), StringSerializer.get()); + result.setColumnFamily("ProteinRow"); + result.setRange(null, null, false, Integer.MAX_VALUE); + result.setRowCount(row_count); + String last_key = null; + while (true) { + result.setKeys(last_key, null); + QueryResult > columnSlice = result.execute(); + OrderedRows rows = columnSlice.get(); + Iterator> rowsIterator = rows.iterator(); + while (rowsIterator.hasNext()) { + Row row = rowsIterator.next(); + last_key = row.getKey(); + if (last_key.matches("(.*)" + protIn + "(.*)")) { + Iterator > it = row.getColumnSlice().getColumns().iterator(); + while (it.hasNext()) { + HColumn col = it.next(); + List subProt = new ArrayList(); + String subStr = last_key; + while (subStr.length() > 0 && subStr.contains(protIn)) { + String first = subStr.substring(0, subStr.indexOf(protIn)); + if (first.length() > 0) + subProt.add(first); + subProt.add(protIn); + subStr = subStr.substring(subStr.indexOf(protIn) + protIn.length(), subStr.length()); + } + if (subStr.length() > 0) + subProt.add(subStr); + DataBase db = new DataBase(); + db.setProt(last_key); + db.setId(col.getName()); + db.setJpred(col.getValue()); + db.setSubProt(subProt); + query.add(db); + } + } + } + if (rows.getCount() < row_count) + break; + } + return query; + } + + // convert String to Date + private static long DateParsing(String datInput) { + long dateWorkSt = 0; + SimpleDateFormat formatter = new SimpleDateFormat("yyyy/MM/dd"); + try { + dateWorkSt = formatter.parse(datInput).getTime(); + } catch (ParseException e) { + e.printStackTrace(); + } + return dateWorkSt; + } + + // convert String to Date + private static long TimeConvert(String datInput) { + long dateWorkSt = 0; + SimpleDateFormat formatter = new SimpleDateFormat("yyyy/MM/dd:hh:mm:ss"); + try { + dateWorkSt = formatter.parse(datInput).getTime(); + } catch (ParseException e) { + e.printStackTrace(); + } + // System.out.println("start reverce" + DateFormat1(dateWorkSt)); + return dateWorkSt; + } + + // convert long to date in string format + private static String DateFormat(long inDate){ + SimpleDateFormat datformat = new SimpleDateFormat("dd/MM/yyyy"); + String dateString = datformat.format(new Date(inDate)); + return dateString; + } + + private static String DateFormat1(long inDate){ + SimpleDateFormat datformat = new SimpleDateFormat("dd/MM/yyyy:hh:mm:ss"); + String dateString = datformat.format(new Date(inDate)); + return dateString; + } + + public long CountID(String id) { + SliceQuery sliceQuery = HFactory.createSliceQuery(cc.GetKeyspace(), StringSerializer.get(), StringSerializer.get(), StringSerializer.get()); + sliceQuery.setColumnFamily("ProteinLog").setKey(id).setRange("", "", false, 100); + QueryResult> result = sliceQuery.execute(); + String datBegin = result.get().getColumnByName("DataBegin").getValue(); + String datEnd = result.get().getColumnByName("DataEnd").getValue(); + long datBeginLong = TimeConvert(datBegin); + long datEndLong = TimeConvert(datEnd); + return datEndLong-datBeginLong; + + } + +}