import java.awt.*;
import java.awt.geom.AffineTransform;
import java.awt.image.BufferedImage;
-import java.awt.image.BufferedImageOp;
import java.awt.image.ImageProducer;
import java.awt.image.RenderedImage;
import javax.imageio.ImageIO;
-import javax.swing.*;
//import org.tc33.jheatchart.HeatChart;
public static void main(String[] args) {
String[] geneIDs = new String[] {"mgf009407m", "GRMZM2G457201_T02", "LOC_Os03g53530.1", "Bradi3g44220.1"};
- Species[] species = getHeatChartData(geneIDs);
+ Species[] species = getHeatChartData(args);
// IF asked for table
if (option.equals("table")) {
}
// IF asked for webpage
if (option.equals("webpage")) {
- //return generateWebPageData(species);
- }
- //return null;
- }
-
- private static String[][] generateWebPageData(Species[] species) {
- String[][] heatChartData = new String[species.length + 1][];
- heatChartData[0] = new String[species.length];
- for(int s = 0; s < species.length; s ++) {
- heatChartData[0][s] = species[s].name;
- }
- for(int s = 1; s <= species.length; s ++) {
- heatChartData[s] = new String[allClusterIDs.length];
- for(int c = 0; c < allClusterIDs.length; c ++) {
- int frequency = species[s].findClusterFrequency(allClusterIDs[c]);
- // -1 means that species contains no genes in the specified cluster, but can't have negative color
- // ensure that frequency is never negative
- if (frequency == -1) {
- frequency = 0;
- }
- heatChartData[s][c] = Integer.toString(frequency);
+ for (int c = 0; c < allClusterIDs.length; c ++) {
+ String endChar = "";
+ if (c + 1 < allClusterIDs.length) {
+ endChar = ",";
+ }
+ System.out.print(allClusterIDs[c] + endChar);
}
+ System.out.println();
+ System.out.println(maxCount);
}
-
- return heatChartData;
+ //return null;
}
int heatMapHeight = 25*allClusterIDs.length;
int heatMapWidth = 25*species.length;
- int imageType = (false ? BufferedImage.TYPE_4BYTE_ABGR : BufferedImage.TYPE_3BYTE_BGR);
+ int imageType = (BufferedImage.TYPE_3BYTE_BGR);
BufferedImage heatMapImage = new BufferedImage(heatMapWidth, heatMapHeight, imageType);
Graphics2D heatMapGraphics = heatMapImage.createGraphics();
} catch (IOException e) {
System.out.println("Unable to write Heat Map Image");
}
-
-
-
- /*
- double[][] heatMapVals = new double[allClusterIDs.length][species.length];
- for (int s = 0; s < species.length; s ++) {
- for (int c = 0; c < allClusterIDs.length; c ++) {
- int frequency = species[s].findClusterFrequency(allClusterIDs[c]);
- // -1 means that species contains no genes in the specified cluster, but can't have negative color
- // ensure that frequency is never negative
- if (frequency == -1) {
- frequency = 0;
- }
- heatMapVals[c][s] = frequency;
- }
- }
- String[] names = new String[species.length];
- for (int s = 0; s < species.length; s ++) {
- names[s] = species[s].name;
- }
- HeatChart heatChart = new HeatChart(heatMapVals);
- Color axisColor = new Color(0, 0, 0);
- Color background = new Color(255, 255, 255);
- Dimension cellSize = new Dimension(20, 20);
- heatChart.setAxisColour(axisColor);
- heatChart.setBackgroundColour(background);
- heatChart.setCellSize(cellSize);
- heatChart.setXValues(names);
- heatChart.setTitle("Heat Map");
- heatChart.setYAxisLabel("Cluster ID");
- heatChart.setXAxisLabel("Species");
- heatChart.setHighValueColour(Color.red);
- heatChart.setLowValueColour(Color.blue);
- heatChart.setAxisThickness(1);
- heatChart.setColourScale(0.8);
- heatChart.setHighValueColour(Color.red);
- heatChart.setLowValueColour(Color.blue);
- heatChart.setAxisThickness(1);
- heatChart.setColourScale(0.8);
-
- Image heatMap = heatChart.getChartImage();
-
- File output = new File("heatMap.gif");
-
- try {
- ImageIO.write((RenderedImage) heatMap, "gif", output);
- } catch (IOException e) {
- System.out.println("Unable to write image to file");
- }
- */
}
}
PrintWriter printWriter = new PrintWriter(fileWriter);
- /*printWriter.print("Species \t");
- for (int clust = 0; clust < allClusterIDs.length; clust ++) {
- printWriter.print("Cluster " + clust + "\t");
- }
-
- printWriter.print("\n");
-
-
- for (int s = 0; s < species.length; s ++) {
- printWriter.print("\n" + species[s].name);
- for (int c = 0; c < allClusterIDs.length; c ++) {
- printWriter.print("\t");
- int frequency = species[s].findClusterFrequency(allClusterIDs[c]);
- // -1 means that species contains no genes in the specified cluster, but can't have negative color
- // ensure that frequency is never negative
- if (frequency == -1) {
- frequency = 0;
- }
- printWriter.print(frequency);
- }
- }
- printWriter.close();
- */
printWriter.print("Cluster id");
for (int s = 0; s< species.length; s++) {
allClusterIDs = clusterIDs;
Species[] species = findAllSpecies(clusterIDs, connection);
- System.out.println(species.length);
- for(int i = 0; i < species.length; i ++) {
- System.out.println(species[i].name + " " + species[i].geneMap[0][1]);
+ //System.out.println(species.length);
+ for(int s = 0; s < species.length; s ++) {
+ System.out.print(species[s].name + ",");
+ for (int c = 0; c < allClusterIDs.length; c ++) {
+ String endChar = "";
+ if (c + 1 < allClusterIDs.length) {
+ endChar = ",";
+ }
+ System.out.print(species[s].findClusterFrequency(allClusterIDs[c]) + endChar);
+ }
+ System.out.println("");
+
}
return species;
try {
rs.last();
- speciesCount = rs.getRow(); // remember that the query returns a distinct row for each species/super_id combo
- rs.beforeFirst(); // meaning that the number of rows = species * unique cluster ids
- rs.next(); // TODO must figure out how to ensure that ALL clusters for each species are grouped in ONE species object
- // WITHOUT causing errors. Above statement isn't quite true, for some reason some species aren't getting double counted, but others are.
+ speciesCount = rs.getRow();
+ rs.beforeFirst();
+ rs.next();
+
currentSpecies = rs.getString(2);
- System.out.println(allClusterIDs.length);
}
catch (SQLException e) {
System.out.println("Error in returned data - check database");
System.err.println("SQLException: " + e.getMessage());
}
- rawSpecies = groupSpecies(rawSpecies);
+ Species[] finalSpecies = groupSpecies(rawSpecies);
- return rawSpecies;
+ return finalSpecies;
}
cs ++;
lastSpecies = rawSpecies[count];
}
+ if (count + 1 == rawSpecies.length) {
+ species[cs] = lastSpecies;
+ }
}
int unique = 0;
for(int count = 0; (count < species.length && species[count] != null); count ++) {
unique = count + 1;
}
- System.out.println(unique + "unique");
+ //System.out.println(unique + "unique");
Species[] finalSpecies = new Species[unique];
for (int count = 0; count < unique; count ++) {
finalSpecies[count] = species[count];
int[] allClusters;
- String logicStatement = "gene = '";
+ String logicStatement = "gene LIKE '";
for (int i = 0; i < geneIDs.length; i ++) {
logicStatement = logicStatement + geneIDs[i];
if(i+1 < geneIDs.length) {
- logicStatement = logicStatement + "' OR gene = '";
+ logicStatement = logicStatement + "%' OR gene LIKE '";
} else {
- logicStatement = logicStatement + "'";
+ logicStatement = logicStatement + "%'";
}
}
- System.out.println(geneIDs.length);
- System.out.println(logicStatement);
+ //System.out.println(geneIDs.length);
+ //System.out.println(logicStatement);
// finds the clusters that the genes are in
PreparedStatement findCluster;
rs.next();
allClusters[i] = rs.getInt(1);
} catch (SQLException e) {
- System.out.println("Genes overlap");
- System.err.println("SQLException: " + e.getMessage());
+ //System.out.println("Genes overlap");
+ //System.err.println("SQLException: " + e.getMessage());
}
}