Hello!

To see the file structure, click on "tree".

Note that updates take place every 10 minutes, commits may not be seen immediately.
Now able to handle more than one gene at a time.
authormiles <miles@localhost>
Tue, 17 Jul 2012 18:38:39 +0000 (18:38 +0000)
committermiles <miles@localhost>
Tue, 17 Jul 2012 18:38:39 +0000 (18:38 +0000)
svn path=/; revision=363

Personnel/miles/2/src/Main.java

index dd15395e52194bb3173de81cd4d4830b144f3414..4d21fc2dccd175547e977a6c77d314908495f35b 100644 (file)
@@ -2,10 +2,6 @@ import java.sql.*;
 import java.util.Properties;
 import java.awt.GradientPaint;
 
-//mysql> select super_id, species, count(species) from super_clust where super_id IN (1,2) group by species, super_id order by species;
-
-
-
 
 /**
  * @author miles
@@ -13,9 +9,10 @@ import java.awt.GradientPaint;
  */
 public class Main {
        String[] species;
+       static int[] allClusterIDs;
        
        public static void main(String[] args) {
-               String[] geneIDs = new String[] {"mgf009407m"};
+               String[] geneIDs = new String[] {"mgf009407m", "GRMZM2G457201_T02"};
                getHeatChartData(geneIDs);
        }
        
@@ -30,7 +27,8 @@ public class Main {
                connection = selectDatabase(statement, connection);
                
                clusterIDs = getAllClusters(geneIDs, connection);
-
+               allClusterIDs = clusterIDs;
+               
                Species[] species = findAllSpecies(clusterIDs, connection);
                // TODO find a way to sort the species
                //species.sort;
@@ -130,32 +128,58 @@ public class Main {
        
        // finds ALL clusters that the given geneID's fall into
        private static int[] getAllClusters(String[] geneIDs, Connection connection) {
-               ResultSet results = null;
-               int[] clusterIDs = {-1};
+               ResultSet rs = null;
+               int[] allClusters;
                
+               
+               String logicStatement = "gene = '";
                for (int i = 0; i < geneIDs.length; i ++) {
-                       // finds the cluster that the gene is in
-                       PreparedStatement findCluster;
-                       try {
-                               findCluster = connection.prepareStatement("SELECT DISTINCT super_id FROM super_clust WHERE gene = '" + geneIDs[i] + "'");
-                       } catch (SQLException e1) {
-                               System.out.println("Unexpected Error");
-                               findCluster = null;
+                       logicStatement = logicStatement + geneIDs[i];
+                       if(i+1 < geneIDs.length) {
+                               logicStatement = logicStatement + "' OR gene = '";
+                       } else {
+                               logicStatement = logicStatement + "'";
                        }
+               }
+               
+               // finds the clusters that the genes are in
+               PreparedStatement findCluster;
+               try {
+                       findCluster = connection.prepareStatement("SELECT DISTINCT super_id FROM super_clust WHERE "
+                                       + logicStatement);
+               } catch (SQLException e1) {
+                       System.out.println("Statment failed to prepare");
+                       findCluster = null;
+               }
+               
+               try {
+                       rs = findCluster.executeQuery();
+               } catch (SQLException e) {
+                       System.out.println("Unable to execute Query");
+               }
+               
+               int totalClusters = 0;
+               
+               try {
+                       rs.last();
+                       totalClusters = rs.getRow();
+                       rs.beforeFirst();
+               } catch (SQLException e) {
+                       System.out.println("Error in data, unable to parse");
+               }
+               
+               allClusters = new int[totalClusters];
+               
+               for (int i = 0; i < geneIDs.length; i ++) {
                        try {
-                               results = findCluster.executeQuery();
+                               rs.next();
+                               allClusters[i] = rs.getInt(1);
                        } catch (SQLException e) {
-                               System.out.println("Unable to execute Query");
-                       }
-                   try {
-                       results.next();
-                               clusterIDs[i] = (results.getInt(1));
-                               System.out.println(clusterIDs[i]);
-                       } catch (SQLException e) {
-                               System.out.println("Gene not found");
+                               System.out.println("Unexpected Error");
                        }
                }
-               return clusterIDs;
+               
+               return allClusters;
        }
 
        // selects the database to use