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
*/
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);
}
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;
// 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