From: miles Date: Tue, 17 Jul 2012 18:38:39 +0000 (+0000) Subject: Now able to handle more than one gene at a time. X-Git-Url: http://gitweb.planteome.org/?a=commitdiff_plain;h=9b818376e2054c390a6c720d88fe649be62c0df4;p=old-jaiswallab-svn%2F.git Now able to handle more than one gene at a time. svn path=/; revision=363 --- diff --git a/Personnel/miles/2/src/Main.java b/Personnel/miles/2/src/Main.java index dd15395..4d21fc2 100644 --- a/Personnel/miles/2/src/Main.java +++ b/Personnel/miles/2/src/Main.java @@ -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