create ProteinBean
[proteocache.git] / server / compbio / statistic / CassandraRequester.java
index afba67b..c92b9bf 100755 (executable)
@@ -9,12 +9,12 @@ import java.util.Iterator;
 import java.util.List;
 import java.util.Map;
 
+import compbio.cassandra.ProteinBean;
 import compbio.cassandra.CassandraNativeConnector;
 import compbio.cassandra.CassandraReader;
 import compbio.cassandra.DataBase;
 import compbio.cassandra.Pair;
 import compbio.cassandra.StructureJobLog;
-import compbio.cassandra.StructureProteinPrediction;
 
 public class CassandraRequester {
        private CassandraReader db = new CassandraReader();
@@ -158,7 +158,7 @@ public class CassandraRequester {
                System.out.println("StatisticsProt.readLength: total number of dates = " + query.size());
                return query;
        }
-       
+
        /*
         * query: jobs and sequence at date
         */
@@ -190,34 +190,29 @@ public class CassandraRequester {
                System.out.println("StatisticsProt.readLength: total number of dates = " + query.size());
                return query;
        }
+
+
        /* 
         * query: protein sequence
         * */
-       public List<DataBase> readProteins(String protIn, String flag) {
-               if (protIn == null)
-                       return null;
-               System.out.println(protIn.length());
-               query = new ArrayList<DataBase>();
-               List<StructureProteinPrediction> res;
+       public List<ProteinBean> readProteins(String protIn, String flag) {
+               List<ProteinBean> result;
                if (flag.equals("whole")) 
-                       res = db.ReadWholeSequence(protIn);
+                       result = db.ReadWholeSequence(protIn);
                 else 
-                        res = (protIn.length() > 0) ? db.ReadPartOfSequence(protIn) : null;
-               if (res == null)
+                        result = db.ReadPartOfSequence(protIn);
+               if (result == null)
                        return null;
-               for (StructureProteinPrediction entry : res) {
-                               DataBase bean = new DataBase();
-                               bean.setProt(entry.getSequence());
-                               bean.setId(entry.getJobid());
-                               bean.setJpred(entry.getJnetpred());
-                               if (flag.equals("part"))
-                                       bean.setSubProt(CreateSubprot (entry.getSequence(), protIn));                           
-                               query.add(bean);
-                       
-               }
-               return query;
+               
+               if (flag.equals("part")) {
+                       for (ProteinBean entry : result) {
+                               entry.setSubProt(CreateSubprot(entry.getSequence(), protIn));
+                       }
+               }                                       
+               return result;
        }
        
+
        /* 
         * query protein sequences with number of jobs
         */
@@ -235,6 +230,26 @@ public class CassandraRequester {
                return query;
        }
        
+       /* 
+        * query ip with number of jobs
+        */
+       public List<DataBase> readIpByCounter(Integer minimalcounter) {
+               query = new ArrayList<DataBase>();
+               Map<String, Integer> map = db.ReadIpByCounter();
+               if (minimalcounter == null)
+                       minimalcounter = 0;
+               if (map == null)
+                       return null;
+               for (Map.Entry<String, Integer> entry : map.entrySet()) {
+                       if (entry.getValue() > minimalcounter) {
+                               DataBase bean = new DataBase();
+                               bean.setTotalId(entry.getValue());
+                               bean.setIp(entry.getKey());
+                               query.add(bean);
+                       }
+               }
+               return query;
+       }
        /*
         * query jobs log info
         */
@@ -249,6 +264,31 @@ public class CassandraRequester {
                return query;
        }
        
+       
+       /*
+        * query jobs by ipStructureJobLog
+        */
+       public List<DataBase> readIp(String ip) {
+               if (ip == null)
+                       return null;
+               List<Pair<String, String>> res = db.ReadIpWithJobs(ip);
+       //      System.out.println(res.size());
+               if (res == null) 
+                       return null;
+               query = new ArrayList<DataBase>();
+               for (Pair<String, String> entry : res) {        
+                       System.out.println("ip " + ip);
+                       System.out.println("id " + entry.getElement0());
+                       DataBase bean = new DataBase();
+                       bean.setIp(ip);
+                       bean.setId(entry.getElement0());
+                       bean.setProt(entry.getElement1());
+                       query.add(bean);
+               }
+               System.out.println(query.size());
+               return query;
+       }
+       
        /*
         * create list of parts of protein sequence;
         */