import java.sql.*;
+
import java.io.*;
import java.util.Properties;
import java.util.Scanner;
import java.awt.*;
+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;
/**
* @author miles
public class Heatmap {
String[] species;
static int[] allClusterIDs;
+ static int maxCount = 0;
public static void main(String[] args) {
String[] geneIDs = new String[] {"mgf009407m", "GRMZM2G457201_T02", "LOC_Os03g53530.1", "Bradi3g44220.1"};
generateDelimitedTable(species);
// IF asked for image
- // generateHeatMapImage(species)
+ generateHeatMapImage(species);
// IF asked for webpage
//displayHeatChart(species);
}
+ private static void generateHeatMapImage(Species[] species) {
+ /*
+ File output = new File("heatMap");
+
+ int heatMapHeight = 25*allClusterIDs.length;
+ int heatMapWidth = 25*species.length;
+ int imageType = (false ? BufferedImage.TYPE_4BYTE_ABGR : BufferedImage.TYPE_3BYTE_BGR);
+
+ BufferedImage heatMapImage = new BufferedImage(heatMapWidth, heatMapHeight, imageType);
+ Graphics2D heatMapGraphics = heatMapImage.createGraphics();
+
+ 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;
+ }
+ Color cellColor = new Color((255/maxCount) * frequency, 0, 0);
+ heatMapGraphics.setColor(cellColor);
+ heatMapGraphics.fillRect(s*25, c*25, 25, 25);
+ }
+ }
+
+
+ int chartWidth = heatMapWidth + 50;
+ int chartHeight = heatMapHeight + 300;
+ BufferedImage chartImage = new BufferedImage(chartWidth, chartHeight, imageType);
+ Graphics2D chartGraphics = chartImage.createGraphics();
+ Color background = new Color(255, 255, 255);
+ chartGraphics.setColor(background);
+ chartGraphics.fillRect(0, 0, chartWidth, chartHeight);
+ chartGraphics.drawImage(heatMapImage, 50, 300, null);
+ chartGraphics.setColor(Color.black);
+ chartGraphics.drawString("Heat Map", 25, 25);
+
+ for (int c = 0; c < allClusterIDs.length; c ++) {
+ String clusterID = Integer.toString(allClusterIDs[c]);
+ chartGraphics.drawString(clusterID, 5, (315 + c*25));
+ }
+
+ try {
+ ImageIO.write((RenderedImage) chartImage, "gif", output);
+ } 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");
+
+ Image heatMap = heatChart.getChartImage();
+
+ File output = new File("heatMap");
+
+ try {
+ ImageIO.write((RenderedImage) heatMap, "gif", output);
+ } catch (IOException e) {
+ System.out.println("Unable to write image to file");
+ }
+
+ }
+
private static void generateDelimitedTable(Species[] species) {
System.out.println("About to create a new tab delimited file with data requested." + "\n" + "Please name new file:");
Scanner in = new Scanner(System.in);
}
printWriter.print("\t" + frequency);
}
-
- }
}
+ printWriter.close();
+ }
// creates a connection, distributes work and information to the various helper functions
// gathers the final list of species and their geneMaps in one place
rawSpecies[speciesCount].setName(currentSpecies);
rawSpecies[speciesCount].addCluster(rs.getInt(1), rs.getInt(3));
while(rs.next()) {
+ if(rs.getInt(3) > maxCount) {
+ maxCount = rs.getInt(3);
+ }
String name = rs.getString(2);
if (name == currentSpecies) {
rawSpecies[speciesCount].addCluster(rs.getInt(1), rs.getInt(3));
-Species Cluster 0 Cluster 1 Cluster 2
-
-Arabidopsis_lyrata 1 1 1
-Arabidopsis_thaliana 0 1 1
-Batrachochytrium_distachyon 0 0 1
-Brachypodium_distachyon 1 2 1
-Caenorhabditis_elegans 0 0 1
-Carica_papaya 0 0 1
-Chlamydomonas_reinhardtii 0 0 1
-Cucumis_sativus 0 1 2
-Danio_rerio 0 0 1
-Drosophila_melanogaster 0 0 1
-Ectocarpus_siliculosus 0 1 1
-Fragaria_vesca 0 1 1
-Glycine_max 0 4 2
-Homo_sapiens 0 0 2
-Laccaria_bicolor 0 0 1
-Magnaporthe_grissa 0 0 1
-Manihot_esculenta 0 1 1
-Mimulus_guttatus 0 1 1
-Neurospora_crassa 0 0 1
-Oryza_sativa 2 1 1
-Pediculus_humanus 1 0 1
-Physcomitrella_patens 0 0 1
-Populus_trichocarpa 0 2 1
-Prunus_persica 0 1 1
-Rattus_norvegicus 0 1 1
-Ricinus_communis 0 1 1
-Saccharomyces_cerevisiae 0 0 1
-Selaginella_moellendorffii 0 1 1
-Sorghum_bicolor 0 1 1
-Vitis_vinifera 0 1 1
\ No newline at end of file
+Cluster id Arabidopsis_lyrata Arabidopsis_thaliana Batrachochytrium_distachyon Brachypodium_distachyon Caenorhabditis_elegans Carica_papaya Chlamydomonas_reinhardtii Cucumis_sativus Danio_rerio Drosophila_melanogaster Ectocarpus_siliculosus Fragaria_vesca Glycine_max Homo_sapiens Laccaria_bicolor Magnaporthe_grissa Manihot_esculenta Mimulus_guttatus Neurospora_crassa Oryza_sativa Pediculus_humanus Physcomitrella_patens Populus_trichocarpa Prunus_persica Rattus_norvegicus Ricinus_communis Saccharomyces_cerevisiae Selaginella_moellendorffii Sorghum_bicolor Vitis_vinifera
+0 1 0 0 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 2 1 0 0 0 0 0 0 0 0 0
+1 1 1 0 2 0 0 0 1 0 0 1 1 4 0 0 0 1 1 0 1 0 0 2 1 1 1 0 1 1 1
+2 1 1 1 1 1 1 1 2 1 1 1 1 2 2 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1
\ No newline at end of file