Hello!

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

Note that updates take place every 10 minutes, commits may not be seen immediately.
Updates for web page compatibility.
authormiles <miles@localhost>
Thu, 9 Aug 2012 21:44:35 +0000 (21:44 +0000)
committermiles <miles@localhost>
Thu, 9 Aug 2012 21:44:35 +0000 (21:44 +0000)
svn path=/; revision=371

Personnel/miles/2/heatMap [new file with mode: 0644]
Personnel/miles/2/src/Heatmap.java
Personnel/miles/2/src/Species.java

diff --git a/Personnel/miles/2/heatMap b/Personnel/miles/2/heatMap
new file mode 100644 (file)
index 0000000..4caebd2
Binary files /dev/null and b/Personnel/miles/2/heatMap differ
index 2c587c255e22b6f87dbf5b16046dd1213d3c7a55..f7470032019ebf0a78fee46a22a12609083768bb 100644 (file)
@@ -6,12 +6,10 @@ import java.util.Scanner;
 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;
 
@@ -28,7 +26,7 @@ public class Heatmap {
        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")) {
@@ -41,31 +39,17 @@ public class Heatmap {
                }
                // 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;
        }
        
        
@@ -75,7 +59,7 @@ public class Heatmap {
        
        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();
@@ -133,56 +117,6 @@ public class Heatmap {
                } 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");
-        }
-        */
         
     }
        
@@ -200,29 +134,6 @@ public class Heatmap {
                }
                
                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++) {
@@ -255,9 +166,18 @@ public class Heatmap {
                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;
@@ -319,12 +239,11 @@ public class Heatmap {
                  
                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");
@@ -359,9 +278,9 @@ public class Heatmap {
                          System.err.println("SQLException: " + e.getMessage());
                  }
                  
-               rawSpecies = groupSpecies(rawSpecies);
+               Species[] finalSpecies = groupSpecies(rawSpecies);
                
-               return rawSpecies;
+               return finalSpecies;
                        
        }
        
@@ -380,12 +299,15 @@ public class Heatmap {
                                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];
@@ -414,17 +336,17 @@ public class Heatmap {
                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;
@@ -462,8 +384,8 @@ public class Heatmap {
                                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());
                        }
                }
                
index cf7bb31386b042270ff2302ece22a7a12949a442..98933cbc0bf33bac491d59220243a0a4eba253a1 100644 (file)
@@ -33,7 +33,7 @@ public class Species {
        public int findClusterFrequency(int clusterID) {
                int index = findClusterIndex(clusterID);
                if (index == -1) {
-                       return index;
+                       return 0;
                }
                return geneMap[index][1];
        }