
Hi, I'm sending you the adjusted module class (from my ENIGMA software), contains corrected code for module visualization (solved scrambling of data in separate leaves) as well as for eps figures, amongst others. The bayesian stuff is not in this class (results didn't make sense for my problem), so probably the best thing to do is to cut and paste relevant parts of the code in your code. Some other stuff that you might decide (not) to use: yellow-blue color scheme, condition labels, clustering of genes and/or conditions with cosine correlation coefficient, definition of extra leaf that groups all leaves with condition sets smaller than 3, which are excluded from the regulation program (too few datapoints to determine sensible regulators), prioritization of potential regulators based on whether their binding site is overrepresented in the module (provided you have chip data), extra visualization of overrepresented TFs, overrepresented GO categories and links to other modules. It is very possible that for some of this stuff to work, you need adjustments in other classes. Ask me to send them to you, or wait till the ENIGMA code is released (1 week). Don't trust the calculatePCCmap() function, there might be something wrong with it. Best, Steven -- ================================================================== Steven Maere, PhD Dept. of Plant Systems Biology Bioinformatics & Evolutionary Genomics research group VIB / Ghent University Technologiepark 927 B-9052 Gent BELGIUM tel: +32 9 331 3810 fax: +32 9 331 3809 email: stmae@psb.UGent.be http://www.psb.UGent.be http://bioinformatics.psb.ugent.be/ ================================================================== /* ENIGMA - Expression Network Inference and Gene Module Analysis Copyright (C) 2007 Flanders Interuniversitary Intsitute for Biotechnology (VIB) This source code is freely distributed under the terms of the GNU General Public License. See the files COPYRIGHT and LICENSE for details. Written by Steven Maere */ /* LeMoNe - a software to build module networks from expression data Copyright (C) 2005-2006 Flanders Interuniversitary Intsitute for Biotechnology (VIB) This source code is freely distributed under the terms of the GNU General Public License. See the files COPYRIGHT and LICENSE for details. Written by Eric Bonnet, Steven Maere, Tom Michoel, Yvan Saeys */ package enigma; import java.util.*; import java.util.List; import java.io.*; import java.awt.*; import java.awt.image.*; import java.awt.font.*; import java.awt.geom.*; import javax.imageio.*; import javax.swing.*; import net.sf.epsgraphics.*; import cern.jet.stat.*; import cern.colt.list.*; import cytoscape.data.annotation.OntologyTerm; public class Module extends JComponent { // FIELDS public ModuleNetwork moduleNetwork; public int number; public String name; public HashSet<Gene> Parents = new HashSet<Gene>(); public HashSet<Gene> Genes = new HashSet<Gene>(); public ArrayList<Gene> ordenedGenes = new ArrayList<Gene>(); public HashMap<Gene,Double> TFs = new HashMap<Gene,Double>(); public LinkedHashMap<OntologyTerm,Double> GO = new LinkedHashMap<OntologyTerm,Double>(); public HashMap<Condition,Double> Conditions = new HashMap<Condition,Double>(); public ArrayList<Condition> nonTreeConditions = new ArrayList<Condition>(); public HashMap<Integer,Condition> numberedConditions = new HashMap<Integer,Condition>(); public TreeNode regressionTree; // root node; this is the regulation program public TreeNode rightmostNode; // rightmost leaf node (for attaching gene labels in module picture) public LinkedHashSet<Module> modLinks = new LinkedHashSet<Module>(); public HashMap<Gene,HashMap<Gene,Double>> distMap; public HashMap<Condition,HashMap<Condition,Double>> condDistMap; public BingoResults bingoResults ; public boolean dist = true; //true to use distances to compare genes, false to use correlations // CONSTRUCTOR public Module() { } public Module(int number) { this.number = number; this.regressionTree = new TreeNode(); } public Module(String name, int number, HashSet Genes){ this.name = name; this.number = number; for(Object j: Genes){ this.Genes.add((Gene) j); this.ordenedGenes.add((Gene) j); } } // METHODS /* * This builds a full hierarchical clustering tree of the data in the * module, which can then be converted in a regulation program tree. * * Usage of TreeNode and LeafDistribution is somewhat different than for * regressionTree: - testGene and splitValue are not set on internal nodes - * internal nodes have a LeafDistribution as well, containing the statistics * of all leaves (=experiments) below it. The data given as input is the * full data matrix, but condSet may limit the set of experiments to be * clustered */ public void addGene(Gene g){ Genes.add(g); ordenedGenes.add(g); } public TreeNode avLinkHierarchicalClustering(TreeNode t) { if(!t.nodeStatus.equals("leaf")){ TreeNode bestTree = new TreeNode(); //calculateCondEuclDistMap(); calculateCondCosineCorMap(); // initialize treeList with the leaves of t ArrayList<TreeNode> treeList = new ArrayList<TreeNode>(); ArrayList<TreeNode> tmp = new ArrayList<TreeNode>(); t.gatherLeafList(treeList); t.gatherLeafList(tmp); //remove leafs with less than 3 conditions and put them aside... for(TreeNode tr: tmp){ if(tr.leafDistribution.condSet.size() < 3){ treeList.remove(tr); for(Integer c: tr.leafDistribution.condSet){ nonTreeConditions.add(numberedConditions.get(c)); } } } ArrayList<TreeNode> pairTreeList = new ArrayList<TreeNode>(); if(treeList.size() > 1){ // initialize list of pairwise merges for (int i = 0; i < treeList.size(); i++){ for (int j = 0; j < i; j++) { TreeNode tree = new TreeNode(); tree.nodeStatus = "internal"; tree.compareMeans = 2; tree.leftChild = treeList.get(i); tree.rightChild = treeList.get(j); tree.module = this; for (int s = 0; s < 3; s++){ tree.leafDistribution.statistics[s] = treeList.get(i).leafDistribution.statistics[s] + treeList.get(j).leafDistribution.statistics[s]; } for (int c : tree.leftChild.leafDistribution.condSet) tree.leafDistribution.condSet.add(c); for (int c : tree.rightChild.leafDistribution.condSet) tree.leafDistribution.condSet.add(c); pairTreeList.add(tree); } } // merge trees in treeList until one tree is left boolean keep; int cnt; bestTree = new TreeNode(); while (treeList.size() > 1) { // find the optimal pair tree bestTree = Collections.min(pairTreeList); // remove children of bestTree from treeList; bestTree will be added at the end treeList.remove(bestTree.leftChild); treeList.remove(bestTree.rightChild); // loop over the pair list and remove trees whose condSet intersects // with the condSet of the highest scoring tree, including the highest one // itself Iterator<TreeNode> it = pairTreeList.iterator(); while (it.hasNext()) { TreeNode tree = it.next(); keep = true; cnt = 0; while (keep & cnt < tree.leafDistribution.condSet.size()) { if (bestTree.leafDistribution.condSet.contains(tree.leafDistribution.condSet.get(cnt))){ keep = false; } cnt++; } if (!keep){ it.remove(); } } // add new trees which merge the bestTree with the other trees in // treeList; Iterator<TreeNode> it2 = treeList.iterator(); while (it2.hasNext()) { TreeNode ittree = it2.next(); TreeNode tree = new TreeNode(); tree.nodeStatus = "internal"; tree.compareMeans = 2; tree.leftChild = ittree; tree.rightChild = bestTree; tree.module = this; for (int s = 0; s < 3; s++){ tree.leafDistribution.statistics[s] = tree.leftChild.leafDistribution.statistics[s] + tree.rightChild.leafDistribution.statistics[s]; } for (Integer c : tree.leftChild.leafDistribution.condSet) tree.leafDistribution.condSet.add(c); for (Integer c : bestTree.leafDistribution.condSet) tree.leafDistribution.condSet.add(c); pairTreeList.add(tree); } // add bestTree again to treeList treeList.add(bestTree); // set bestTree as parent of its children bestTree.leftChild.parentNode = bestTree; bestTree.rightChild.parentNode = bestTree; } } else{ //no internal nodes, make one leaf node bestTree = new TreeNode(); for(TreeNode tr: treeList){ bestTree.leafDistribution.condSet.addAll(tr.leafDistribution.condSet); } for(Condition c: this.nonTreeConditions){ bestTree.leafDistribution.condSet.add(c.number); } bestTree.statistics(this.moduleNetwork.data,this.Genes); bestTree.module = this; } // 1 tree left, this is the one return bestTree; } else{ return t; } } //means-based average linkage hierachical clustering of conditions public TreeNode meansAvLinkHierarchicalClustering(TreeNode t) { if(!t.nodeStatus.equals("leaf")){ TreeNode bestTree = new TreeNode(); // initialize treeList with the leaves inferred from hierarchical clustering ArrayList<TreeNode> treeList = new ArrayList<TreeNode>(); ArrayList<TreeNode> tmp = new ArrayList<TreeNode>(); t.gatherLeafList(treeList); t.gatherLeafList(tmp); //remove leafs with less than 3 conditions and put them aside... for(TreeNode tr: tmp){ if(tr.leafDistribution.condSet.size() < 3){ treeList.remove(tr); for(Integer c: tr.leafDistribution.condSet){ nonTreeConditions.add(numberedConditions.get(c)); } } } ArrayList<TreeNode> pairTreeList = new ArrayList<TreeNode>(); if(treeList.size() > 1){ // initialize list of pairwise merges for (int i = 0; i < treeList.size(); i++){ for (int j = 0; j < i; j++) { TreeNode tree = new TreeNode(); tree.nodeStatus = "internal"; tree.compareMeans = 1; tree.leftChild = treeList.get(i); tree.rightChild = treeList.get(j); for (int s = 0; s < 3; s++){ tree.leafDistribution.statistics[s] = treeList.get(i).leafDistribution.statistics[s] + treeList.get(j).leafDistribution.statistics[s]; } //tree.leafDistribution.bayesianScore(); for (int c : tree.leftChild.leafDistribution.condSet) tree.leafDistribution.condSet.add(c); for (int c : tree.rightChild.leafDistribution.condSet) tree.leafDistribution.condSet.add(c); //tree.leafDistribution.bayesianScore(); pairTreeList.add(tree); } } // merge trees in treeList until one tree is left boolean keep; int cnt; while (treeList.size() > 1) { // find the pair tree with the smallest difference in mean expression (compareMeans = true) bestTree = Collections.min(pairTreeList); // remove children of bestTree from treeList; bestTree will be added at the end treeList.remove(bestTree.leftChild); treeList.remove(bestTree.rightChild); // loop over the pair list and remove trees whose condSet intersects // with the condSet of the highest scoring tree, including the highest one // itself Iterator<TreeNode> it = pairTreeList.iterator(); while (it.hasNext()) { TreeNode tree = it.next(); keep = true; cnt = 0; while (keep & cnt < tree.leafDistribution.condSet.size()) { if (bestTree.leafDistribution.condSet .contains(tree.leafDistribution.condSet.get(cnt))) keep = false; cnt++; } if (!keep) it.remove(); } // add new trees which merge the bestTree with the other trees in // treeList; Iterator<TreeNode> it2 = treeList.iterator(); while (it2.hasNext()) { TreeNode ittree = it2.next(); TreeNode tree = new TreeNode(); tree.nodeStatus = "internal"; tree.compareMeans = 1; tree.leftChild = ittree; tree.rightChild = bestTree; for (int s = 0; s < 3; s++){ tree.leafDistribution.statistics[s] = tree.leftChild.leafDistribution.statistics[s] + tree.rightChild.leafDistribution.statistics[s]; } //tree.leafDistribution.bayesianScore(); for (Integer c : tree.leftChild.leafDistribution.condSet) tree.leafDistribution.condSet.add(c); for (Integer c : bestTree.leafDistribution.condSet) tree.leafDistribution.condSet.add(c); //tree.leafDistribution.bayesianScore(); pairTreeList.add(tree); } // add bestTree again to treeList treeList.add(bestTree); // set bestTree as parent of its children bestTree.leftChild.parentNode = bestTree; bestTree.rightChild.parentNode = bestTree; // System.out.println(bestTree.postProb); } } else{ //no internal nodes, make one leaf node bestTree = new TreeNode(); for(TreeNode tr: treeList){ bestTree.leafDistribution.condSet.addAll(tr.leafDistribution.condSet); } for(Condition c: this.nonTreeConditions){ bestTree.leafDistribution.condSet.add(c.number); } bestTree.statistics(this.moduleNetwork.data,this.Genes); bestTree.module = this; } // 1 tree left, this is the one return bestTree; } else{ return t; } } public TreeNode avLinkHierarchicalClustering(ArrayList<Integer> condSet, double data[][]) { if(condSet.size() > 1){ //calculateCondEuclDistMap(); calculateCondCosineCorMap(); ArrayList<TreeNode> treeList = new ArrayList<TreeNode>(); // initialize treeList with just the bare leaves for (int i : condSet) { TreeNode tree = new TreeNode(); tree.nodeStatus = "leaf"; tree.module = this; tree.leafDistribution.condSet.add(i); for (Gene gene : this.Genes) if (!Double.isNaN(data[gene.number][i])) { tree.leafDistribution.statistics[0]++; tree.leafDistribution.statistics[1] += data[gene.number][i]; tree.leafDistribution.statistics[2] += Math.pow(data[gene.number][i], 2); } treeList.add(tree); } ArrayList<TreeNode> pairTreeList = new ArrayList<TreeNode>(); // initialize list of pairwise merges for (int i = 0; i < treeList.size(); i++){ for (int j = 0; j < i; j++) { TreeNode tree = new TreeNode(); tree.nodeStatus = "internal"; tree.compareMeans = 2; tree.leftChild = treeList.get(i); tree.rightChild = treeList.get(j); tree.module = this; for (int s = 0; s < 3; s++){ tree.leafDistribution.statistics[s] = treeList.get(i).leafDistribution.statistics[s] + treeList.get(j).leafDistribution.statistics[s]; } for (int c : tree.leftChild.leafDistribution.condSet) tree.leafDistribution.condSet.add(c); for (int c : tree.rightChild.leafDistribution.condSet) tree.leafDistribution.condSet.add(c); pairTreeList.add(tree); } } // merge trees in treeList until one tree is left boolean keep; int cnt; TreeNode bestTree = new TreeNode(); while (treeList.size() > 1) { // find the optimal pair tree bestTree = Collections.min(pairTreeList); // remove children of bestTree from treeList; bestTree will be added at the end treeList.remove(bestTree.leftChild); treeList.remove(bestTree.rightChild); // loop over the pair list and remove trees whose condSet intersects // with the condSet of the highest scoring tree, including the highest one // itself Iterator<TreeNode> it = pairTreeList.iterator(); while (it.hasNext()) { TreeNode tree = it.next(); keep = true; cnt = 0; while (keep & cnt < tree.leafDistribution.condSet.size()) { if (bestTree.leafDistribution.condSet.contains(tree.leafDistribution.condSet.get(cnt))){ keep = false; } cnt++; } if (!keep){ it.remove(); } } // add new trees which merge the bestTree with the other trees in // treeList; Iterator<TreeNode> it2 = treeList.iterator(); while (it2.hasNext()) { TreeNode ittree = it2.next(); TreeNode tree = new TreeNode(); tree.nodeStatus = "internal"; tree.compareMeans = 2; tree.leftChild = ittree; tree.rightChild = bestTree; tree.module = this; for (int s = 0; s < 3; s++){ tree.leafDistribution.statistics[s] = tree.leftChild.leafDistribution.statistics[s] + tree.rightChild.leafDistribution.statistics[s]; } for (Integer c : tree.leftChild.leafDistribution.condSet) tree.leafDistribution.condSet.add(c); for (Integer c : bestTree.leafDistribution.condSet) tree.leafDistribution.condSet.add(c); pairTreeList.add(tree); } // add bestTree again to treeList treeList.add(bestTree); // set bestTree as parent of its children bestTree.leftChild.parentNode = bestTree; bestTree.rightChild.parentNode = bestTree; } // 1 tree left, this is the one return bestTree; } else{ //tree with a single leaf TreeNode bestTree = new TreeNode() ; bestTree.nodeStatus = "leaf"; bestTree.module = this; for(Integer i:condSet){ bestTree.leafDistribution.condSet.add(i); for (Gene gene : this.Genes){ if (!Double.isNaN(data[gene.number][i])) { bestTree.leafDistribution.statistics[0]++; bestTree.leafDistribution.statistics[1] += data[gene.number][i]; bestTree.leafDistribution.statistics[2] += Math.pow(data[gene.number][i], 2); } } } return bestTree; } } public void calculatePCCmap(){ this.dist = false; distMap = new HashMap<Gene,HashMap<Gene,Double>>(); for(Gene t1:this.Genes){ for(Gene t2:this.Genes){ double[] exp1 = new double[this.Conditions.size()]; double[] exp2 = new double[this.Conditions.size()]; int count = 0 ; for(int i=0; i < this.moduleNetwork.data[t1.number].length;i++){ if (this.numberedConditions.keySet().contains(i)){ exp1[count] = this.moduleNetwork.data[t1.number][i]; exp2[count] = this.moduleNetwork.data[t2.number][i]; count++; } } DoubleArrayList a1 = new DoubleArrayList(exp1); DoubleArrayList a2 = new DoubleArrayList(exp2); double v1; double v2; if(a1.size() > 1){ v1 = cern.jet.stat.Descriptive.sampleStandardDeviation(a1.size(), cern.jet.stat.Descriptive.sampleVariance(a1,cern.jet.stat.Descriptive.mean(a1))); v2 = cern.jet.stat.Descriptive.sampleStandardDeviation(a2.size(), cern.jet.stat.Descriptive.sampleVariance(a2,cern.jet.stat.Descriptive.mean(a2))); double pcc = cern.jet.stat.Descriptive.correlation(a1,v1,a2,v2); if(!distMap.containsKey(t1)){ distMap.put(t1,new HashMap<Gene,Double>()); } distMap.get(t1).put(t2,new Double(pcc)); } else{ //correlation between genes for single exp doesn't make much sense if(!distMap.containsKey(t1)){ distMap.put(t1,new HashMap<Gene,Double>()); } distMap.get(t1).put(t2,new Double(0)); } } } } public void calculateEuclDistMap(){ this.dist = true; distMap = new HashMap<Gene,HashMap<Gene,Double>>(); for(Gene t1:this.Genes){ for(Gene t2:this.Genes){ double[] exp1 = new double[this.Conditions.size()]; double[] exp2 = new double[this.Conditions.size()]; int count = 0 ; for(int i=0; i < this.moduleNetwork.data[t1.number].length;i++){ if (this.numberedConditions.keySet().contains(i)){ exp1[count] = this.moduleNetwork.data[t1.number][i]; exp2[count] = this.moduleNetwork.data[t2.number][i]; count++; } } double dist = 0; for(int i = 0; i < exp1.length; i++){ if(!Double.isNaN(exp1[i]) && !Double.isNaN(exp2[i])){ dist += Math.pow(exp1[i]-exp2[i],2); } } dist = Math.sqrt(dist); if(!distMap.containsKey(t1)){ distMap.put(t1,new HashMap<Gene,Double>()); } distMap.get(t1).put(t2,new Double(dist)); } } } public void calculateCosineCorMap(){ this.dist = false; distMap = new HashMap<Gene,HashMap<Gene,Double>>(); for(Gene t1:this.Genes){ for(Gene t2:this.Genes){ double[] exp1 = new double[this.Conditions.size()]; double[] exp2 = new double[this.Conditions.size()]; int count = 0 ; for(int i=0; i < this.moduleNetwork.data[t1.number].length;i++){ if (this.numberedConditions.keySet().contains(i)){ exp1[count] = this.moduleNetwork.data[t1.number][i]; exp2[count] = this.moduleNetwork.data[t2.number][i]; count++; } } double corr = 0; double sum1 = 0; double sum2 = 0; for(int i = 0; i < exp1.length; i++){ if(!Double.isNaN(exp1[i]) && !Double.isNaN(exp2[i])){ corr += exp1[i]*exp2[i]; sum1 += Math.pow(exp1[i],2); sum2 += Math.pow(exp2[i],2); } } if((sum1 != 0) && (sum2 != 0) && (corr != Double.NaN)){ corr = corr / (Math.sqrt(sum1)*Math.sqrt(sum2)); } else{ System.out.println("Error in calculating cosine correlation for module " + this.name); } if(!distMap.containsKey(t1)){ distMap.put(t1,new HashMap<Gene,Double>()); } distMap.get(t1).put(t2,new Double(corr)); } } } public void calculateCondEuclDistMap(){ condDistMap = new HashMap<Condition,HashMap<Condition,Double>>(); HashMap<Integer,Gene> numberedGenes = new HashMap<Integer,Gene>(); for(Gene g: this.Genes){ numberedGenes.put(g.number,g); } for(Condition t1:this.Conditions.keySet()){ for(Condition t2:this.Conditions.keySet()){ double[] exp1 = new double[this.Genes.size()]; double[] exp2 = new double[this.Genes.size()]; int count = 0 ; for(int i=0; i < this.moduleNetwork.data.length;i++){ if (numberedGenes.keySet().contains(i)){ exp1[count] = this.moduleNetwork.data[i][t1.number]; exp2[count] = this.moduleNetwork.data[i][t2.number]; count++; } } double dist = 0; for(int i = 0; i < exp1.length; i++){ if(!Double.isNaN(exp1[i]) && !Double.isNaN(exp2[i])){ dist += Math.pow(exp1[i]-exp2[i],2); } } dist = Math.sqrt(dist); if(!condDistMap.containsKey(t1)){ condDistMap.put(t1,new HashMap<Condition,Double>()); } condDistMap.get(t1).put(t2,new Double(dist)); } } } public void calculateCondCosineCorMap(){ condDistMap = new HashMap<Condition,HashMap<Condition,Double>>(); HashMap<Integer,Gene> numberedGenes = new HashMap<Integer,Gene>(); for(Gene g: this.Genes){ numberedGenes.put(g.number,g); } for(Condition t1:this.Conditions.keySet()){ for(Condition t2:this.Conditions.keySet()){ double[] exp1 = new double[this.Genes.size()]; double[] exp2 = new double[this.Genes.size()]; int count = 0 ; for(int i=0; i < this.moduleNetwork.data.length;i++){ if (numberedGenes.keySet().contains(i)){ exp1[count] = this.moduleNetwork.data[i][t1.number]; exp2[count] = this.moduleNetwork.data[i][t2.number]; count++; } } double corr = 0; double sum1 = 0; double sum2 = 0; for(int i = 0; i < exp1.length; i++){ if(!Double.isNaN(exp1[i]) && !Double.isNaN(exp2[i])){ corr += exp1[i]*exp2[i]; sum1 += Math.pow(exp1[i],2); sum2 += Math.pow(exp2[i],2); } } if((sum1 != 0) && (sum2 != 0) && (corr != Double.NaN)){ corr = corr / (Math.sqrt(sum1)*Math.sqrt(sum2)); } else{ System.out.println("Error in calculating cosine correlation for module " + this.name); } if(!condDistMap.containsKey(t1)){ condDistMap.put(t1,new HashMap<Condition,Double>()); } condDistMap.get(t1).put(t2,new Double(corr)); } } } public void calculateMatchSimMap(double pThres){ this.dist = false; distMap = new HashMap<Gene,HashMap<Gene,Double>>(); for(Gene t1:this.Genes){ for(Gene t2:this.Genes){ double[] exp1 = new double[this.Conditions.size()]; double[] exp2 = new double[this.Conditions.size()]; double[] p1 = new double[this.Conditions.size()]; double[] p2 = new double[this.Conditions.size()]; int count = 0 ; for(int i=0; i < this.moduleNetwork.data[t1.number].length;i++){ if (this.numberedConditions.keySet().contains(i)){ exp1[count] = this.moduleNetwork.data[t1.number][i]; exp2[count] = this.moduleNetwork.data[t2.number][i]; p1[count] = this.moduleNetwork.pvals[t1.number][i]; p2[count] = this.moduleNetwork.pvals[t2.number][i]; count++; } } double match = 0; for(int i = 0; i < exp1.length; i++){ if((p1[i]<pThres)&&(p2[i]<pThres)&&(exp1[i]>0)&&(exp2[i]>0)){ match++; } else if((p1[i]<pThres)&&(p2[i]<pThres)&&(exp1[i]<0)&&(exp2[i]<0)){ match++; } } if(!distMap.containsKey(t1)){ distMap.put(t1,new HashMap<Gene,Double>()); } distMap.get(t1).put(t2,new Double(match)); } } } public GeneTree clusterGenes(){ // average linkage clustering of gene profiles // initialize list of pairwise merges //this.calculatePCCmap(); //this.calculateEuclDistMap(); //this.calculateMatchSimMap(0.01); this.calculateCosineCorMap(); ArrayList<GeneTree> treeList = new ArrayList<GeneTree>(); ArrayList<GeneTree> pairTreeList = new ArrayList<GeneTree>(); int ind = 0; for (Gene i: Genes){ treeList.add(ind,new GeneTree(i,this,dist)); ind++; } for (int i = 0; i < treeList.size(); i++){ for (int j = 0; j < i; j++) { HashSet<Gene> geneList = new HashSet<Gene>(); geneList.addAll(treeList.get(i).Genes); geneList.addAll(treeList.get(j).Genes); GeneTree tree = new GeneTree(geneList,this,treeList.get(i),treeList.get(j),dist); pairTreeList.add(tree); } } // merge trees in treeList until one tree is left boolean keep; int cnt; GeneTree bestTree = new GeneTree(); while (treeList.size() > 1) { // find the pair tree with the smallest difference in mean expression (compareMeans = true) bestTree = Collections.min(pairTreeList); // remove children of bestTree from treeList; bestTree will be added at the end treeList.remove(bestTree.leftChild); treeList.remove(bestTree.rightChild); // loop over the pair list and remove trees whose condSet intersects // with the condSet of the highest scoring tree, including the highest one // itself Iterator<GeneTree> it = pairTreeList.iterator(); while (it.hasNext()) { GeneTree tree = it.next(); keep = true; for(Gene g:tree.Genes) { if (bestTree.Genes.contains(g)){ keep = false; } } if (!keep){ it.remove(); } } // add new trees which merge the bestTree with the other trees in // treeList; Iterator<GeneTree> it2 = treeList.iterator(); while (it2.hasNext()) { GeneTree ittree = it2.next(); HashSet<Gene> geneList = new HashSet<Gene>(); geneList.addAll(bestTree.Genes); geneList.addAll(ittree.Genes); GeneTree tree = new GeneTree(geneList,this,ittree,bestTree,dist); pairTreeList.add(tree); } // add bestTree again to treeList treeList.add(bestTree); // set bestTree as parent of its children bestTree.leftChild.parentNode = bestTree; bestTree.rightChild.parentNode = bestTree; // System.out.println(bestTree.postProb); } // 1 tree left, this is the one // construct ordened gene list by depth-first search of bestTree this.ordenedGenes = new ArrayList<Gene>(); ArrayList<GeneTree> ordenedLeafs = new ArrayList<GeneTree>() ; bestTree.gatherLeafList(ordenedLeafs); for(int i = 0; i < ordenedLeafs.size(); i++){ this.ordenedGenes.addAll(ordenedLeafs.get(i).Genes); } return bestTree; } // draw module public void draw() { // scale factor int sc = 4; // coordinates of origin int x0 = 15; int y0 = 10; // tree step height int h = 18; // figure width String modName = "Module " + this.number + " : " + this.name; int width = Math.max(3 * x0 + 2*this.Conditions.size() + 5 + 2*this.TFs.keySet().size() + 2 + 2*this.GO.keySet().size() + 2 + 2*this.modLinks.size(),2*modName.length()+10); int height; int x = x0; int ybase = y0; //figure height //find largest GO term BufferedImage tmpIm = new BufferedImage(200, 200,BufferedImage.TYPE_INT_BGR); Graphics2D tmp = tmpIm.createGraphics(); tmp.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON); tmp.scale(sc, sc); FontRenderContext frc = tmp.getFontRenderContext(); int goHeight = 0; for(OntologyTerm go: GO.keySet()){ int a = Math.round((float) (new Font("SansSerif", Font.BOLD, 2).getStringBounds(go.getName(), frc).getWidth())); if(a > goHeight){ goHeight = a; } } //find largest Gene name int nameHeight = 0; for(Gene g : this.Genes){ //at 30 degree angle... int a = Math.round((float) (new Font("SansSerif", Font.BOLD, 2).getStringBounds(g.name, frc).getWidth() * Math.sqrt(3)/2.0)); if(a > goHeight){ nameHeight = a; } } int treeHeight = (h + 4) * (this.regressionTree.treeDepth() + 1); if(goHeight > treeHeight){ treeHeight = goHeight; } //set dimensions ybase = y0 + treeHeight; height = ybase + 2 * y0 + this.Genes.size()*2 + nameHeight; if (this.regressionTree.nodeStatus.equals("leaf")){ // no tree this.rightmostNode = this.regressionTree; } else { //find rightmost node to attach non-tree conditions and gene labels TreeNode tempNode = this.regressionTree ; while(tempNode.rightChild.nodeStatus.equals("internal")){tempNode = tempNode.rightChild;} this.rightmostNode = tempNode; // coordinates of root x = x0 + 2*this.regressionTree.leftChild.leafDistribution.condSet.size(); } BufferedImage image = new BufferedImage(sc * width, sc * height, BufferedImage.TYPE_INT_BGR); Graphics2D g2; g2 = image.createGraphics(); g2.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON); g2.scale(sc, sc); g2.setStroke(new BasicStroke(0.5F)); if (this.regressionTree.nodeStatus.equals("leaf")) { // no tree g2.setPaint(Color.white); g2.fillRect(0, 0, width, height); // draw data g2.setFont(new Font("SansSerif", Font.BOLD, 4)); g2.setPaint(Color.black); g2.drawString(modName , width/2 - 2*modName.length()/2, new Float(y0/2)); draw1leaf(x0, ybase, this.moduleNetwork.data, g2); } else { g2.setPaint(Color.white); g2.fillRect(0, 0, width, height); // draw regression tree g2.setFont(new Font("SansSerif", Font.BOLD, 4)); g2.setPaint(Color.black); g2.drawString(modName , width/2 - 2*modName.length()/2, new Float(y0/2)); drawnode(this.regressionTree, x, y0, h, ybase,this.moduleNetwork.data, g2); } String filename = "module" + this.number + ".png"; File outFile = new File(this.moduleNetwork.dataDir, filename); try { ImageIO.write(image, "png", outFile); } catch (IOException e) { return; } } // draw eps fig public void drawEps() { // scale factor int sc = 4; // coordinates of origin int x0 = 15; int y0 = 10; // tree step height int h = 18; // figure width int width = 3 * x0 + 2*this.Conditions.size() + 5 + 2*this.TFs.keySet().size()+ 2 + 2*this.GO.keySet().size() + 2 + 2*this.modLinks.size(); int height; int x = x0; int ybase = y0; String modName = "Module " + this.number + " : " + this.name; //figure height //find largest GO term BufferedImage tmpIm = new BufferedImage(200, 200,BufferedImage.TYPE_INT_BGR); Graphics2D tmp = tmpIm.createGraphics(); tmp.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON); tmp.scale(sc, sc); FontRenderContext frc = tmp.getFontRenderContext(); int goHeight = 0; for(OntologyTerm go: GO.keySet()){ int a = Math.round((float) (new Font("SansSerif", Font.BOLD, 2).getStringBounds(go.getName(), frc).getWidth())); if(a > goHeight){ goHeight = a; } } //find largest Gene name int nameHeight = 0; for(Gene g : this.Genes){ //at 30 degree angle... int a = Math.round((float) (new Font("SansSerif", Font.BOLD, 2).getStringBounds(g.name, frc).getWidth() * Math.sqrt(3)/2.0)); if(a > goHeight){ nameHeight = a; } } int treeHeight = (h + 4) * (this.regressionTree.treeDepth() + 1); if(goHeight > treeHeight){ treeHeight = goHeight; } //set dimensions ybase = y0 + treeHeight; height = ybase + 2 * y0 + this.Genes.size()*2 + nameHeight; if (this.regressionTree.nodeStatus.equals("leaf")){ // no tree this.rightmostNode = this.regressionTree; } else { //find rightmost node to attach non-tree conditions and gene labels TreeNode tempNode = this.regressionTree ; while(tempNode.rightChild.nodeStatus.equals("internal")){tempNode = tempNode.rightChild;} this.rightmostNode = tempNode; // coordinates of root x = x0 + 2*this.regressionTree.leftChild.leafDistribution.condSet.size(); } try{ EpsGraphics g2 = new EpsGraphics("module" + this.number + ".eps", new FileOutputStream(new File(this.moduleNetwork.dataDir,"module" + this.number + ".eps")),0,0,sc*width,sc*height,ColorMode.COLOR_CMYK); g2.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON); g2.scale(sc, sc); g2.setStroke(new BasicStroke(0.5F)); if (this.regressionTree.nodeStatus.equals("leaf")) { // no tree g2.setPaint(Color.white); g2.fillRect(0, 0, width, height); // draw data g2.setFont(new Font("SansSerif", Font.BOLD, 4)); g2.setPaint(Color.black); g2.drawString(modName , width/2 - 2*modName.length()/2, new Float(y0/2)); draw1leaf(x0, ybase, this.moduleNetwork.data, g2); } else { g2.setPaint(Color.white); g2.fillRect(0, 0, width, height); // draw regression tree g2.setFont(new Font("SansSerif", Font.BOLD, 4)); g2.setPaint(Color.black); g2.drawString(modName , width/2 - 2*modName.length()/2, new Float(y0/2)); drawnode(this.regressionTree, x, y0, h, ybase,this.moduleNetwork.data, g2); } g2.close(); } catch(Exception e){ System.out.println(e.toString()); } } // convert expression value to color public Color data2Color(Gene gene, double data) { Color col; float blueperc, yellowperc; blueperc = new Float(gene.upProb(data,this.moduleNetwork.dataMean,this.moduleNetwork.dataSigma)); yellowperc = new Float(gene.downProb(data,this.moduleNetwork.dataMean,this.moduleNetwork.dataSigma)); col = new Color(yellowperc, yellowperc, blueperc); return col; } // draw a node public void drawnode(TreeNode node, int x, int y, int h, int ybase, double[][] data, Graphics2D g) { // input: // (x,y): start coordinates, h: height of vertical node line, // ybase: baseline where leaves begin // data: expression data // g: graphics in which node is drawn if (node.nodeStatus.equals("internal")) { // where to start drawing regulator expression values int x1 = x - 2*node.leftChild.leafDistribution.condSet.size(); // draw regulator expression values left of split point for (int m = 0; m < node.leftChild.leafDistribution.condSet.size(); m++) { int exp = node.leftChild.leafDistribution.condSet.get(m); if (!Double.isNaN(data[node.testGene.number][exp])) { // convert data value to color Color col = data2Color(node.testGene,data[node.testGene.number][exp]); g.setPaint(col); } else // missing value g.setPaint(Color.white); g.fillRect(x1 + 2*m, y + h - 4, 2, 1); } // draw regulator expression values right of split point for (int m = 0; m < node.rightChild.leafDistribution.condSet.size(); m++) { int exp = node.rightChild.leafDistribution.condSet.get(m); if (!Double.isNaN(data[node.testGene.number][exp])) { // convert data value to color Color col = data2Color(node.testGene,data[node.testGene.number][exp]); g.setPaint(col); } else // missing value g.setPaint(Color.white); g.fillRect(x + 2*m, y + h - 4, 2, 1); } g.setPaint(Color.black); // draw vertical split line g.drawLine(x, y, x, y + h); // set font for writing regulator name g.setFont(new Font("SansSerif", Font.BOLD, 4)); FontRenderContext frc = g.getFontRenderContext(); // find dimensions of regulator name LineMetrics metrics = g.getFont().getLineMetrics(node.testGene.name, frc); float regwidth = (float) g.getFont().getStringBounds(node.testGene.name, frc).getWidth(); float regheight = (float) g.getFont().getStringBounds(node.testGene.name, frc).getHeight(); // draw ellipse around regulator name Shape r = new Ellipse2D.Double(x - 0.7 * regwidth, y + h - 11 - 1.4 * regheight + 1.5 * metrics.getDescent(), 1.4 * regwidth, 1.6 * regheight); if (this.TFs.keySet().contains(node.testGene)){ if (this.Genes.contains(node.testGene)){ g.setPaint(Color.orange); } else{ g.setPaint(Color.red); } } else if (this.Genes.contains(node.testGene)){ g.setPaint(Color.yellow); } else{ g.setPaint(Color.white); } g.fill(r); g.setPaint(Color.black); g.draw(r); // write regulator name g.drawString(node.testGene.name, new Float(x - 0.5 * regwidth), new Float(y + h - 11)); // annotate split with its regulator assignment entropy String quality = String.format("(%.2g)", node.entropy); g.setFont(new Font("SansSerif", Font.BOLD, 3)); g.drawString(quality, new Float(x - 2), new Float(y + h + 3)); // x-coordinate for leftChild int xl; if (node.leftChild.nodeStatus.equals("internal")) { // if child is also internal, start should be in the middle of // its own children xl = x - 2*node.leftChild.rightChild.leafDistribution.condSet.size(); } else { // if child is leaf, we draw a vertical to the middle of the // leaf as well as the leaf data point xl = x - 2*node.leftChild.leafDistribution.condSet.size() / 2; g.drawLine(xl, y + h, xl, ybase); int xl1 = x - 2*node.leftChild.leafDistribution.condSet.size(); //draw the condition labels for (int m = 0; m < node.leftChild.leafDistribution.condSet.size(); m++) { int exp = node.leftChild.leafDistribution.condSet.get(m); Condition c = numberedConditions.get(exp); g.setFont(new Font("SansSerif", Font.BOLD, 2)); g.setPaint(Color.black); g.rotate(Math.PI/3,new Float(xl1 + 2*m+1), new Float(ybase + 2*this.Genes.size()+2)); g.drawString(c.name, new Float(xl1 + 2*m+1), new Float(ybase + 2*this.Genes.size()+2)); g.rotate(-Math.PI/3,new Float(xl1 + 2*m+1), new Float(ybase + 2*this.Genes.size()+2)); } // draw the data points int gn = 0; g.setStroke(new BasicStroke(0.25F)); for (Gene gene : this.ordenedGenes) { for (int m = 0; m < node.leftChild.leafDistribution.condSet.size(); m++) { int exp = node.leftChild.leafDistribution.condSet.get(m); if (!Double.isNaN(data[gene.number][exp])) { // convert data to color Color col = data2Color(gene, data[gene.number][exp]); g.setPaint(col); } else // missing value g.setPaint(Color.white); g.fillRect(xl1 + 2*m, ybase + 2*gn, 2, 2); g.setPaint(Color.black); g.drawRect(xl1 + 2*m, ybase + 2*gn, 2, 2); } gn++; } g.setPaint(Color.black); // draw frame around expression values //g.drawRect(xl1, ybase, 2*node.leftChild.leafDistribution.condSet.size(), this.Genes.size()*2); g.setStroke(new BasicStroke(0.5F)); } // x-coordinate for rightChild int xr; if (node.rightChild.nodeStatus.equals("internal")) // if child is also internal, start should be in the middle of // its own children xr = x + 2*node.rightChild.leftChild.leafDistribution.condSet.size(); else { // if child is leaf, we draw a vertical to the middle of the // leaf as well as the leaf data point xr = x + 2*node.rightChild.leafDistribution.condSet.size() / 2; g.drawLine(xr, y + h, xr, ybase); //draw the condition labels for (int m = 0; m < node.rightChild.leafDistribution.condSet.size(); m++) { int exp = node.rightChild.leafDistribution.condSet.get(m); Condition c = numberedConditions.get(exp); g.setFont(new Font("SansSerif", Font.BOLD, 2)); g.setPaint(Color.black); g.rotate(Math.PI/3,new Float(x + 2*m+1), new Float(ybase + 2*this.Genes.size()+2)); g.drawString(c.name, new Float(x + 2*m+1), new Float(ybase + 2*this.Genes.size()+2)); g.rotate(-Math.PI/3,new Float(x + 2*m+1), new Float(ybase + 2*this.Genes.size()+2)); } if(node == this.rightmostNode){ //add labels of non-tree conditions int N = node.rightChild.leafDistribution.condSet.size(); for (int i = 0; i < this.nonTreeConditions.size(); i++) { g.setFont(new Font("SansSerif", Font.BOLD, 2)); g.setPaint(Color.black); g.rotate(Math.PI/3,new Float(x + 2*N +1 + 2*i), new Float(ybase + 2*this.Genes.size()+2)); g.drawString(this.nonTreeConditions.get(i).name, new Float(x + 2*N +1 + 2*i), new Float(ybase + 2*this.Genes.size()+2)); g.rotate(-Math.PI/3,new Float(x + 2*N +1 + 2*i), new Float(ybase + 2*this.Genes.size()+2)); } //add names of overrepresented TFs to plot g.setFont(new Font("SansSerif", Font.BOLD, 2)); g.setPaint(Color.black); int t=0; TreeSet<Gene> ordenedTFs = new TreeSet<Gene>((Set<Gene>) this.TFs.keySet()); for(Gene tf: ordenedTFs){ g.rotate(-Math.PI/2,new Float(x + 2*node.rightChild.leafDistribution.condSet.size() + 2*this.nonTreeConditions.size() +2 + 15 + 2*t), new Float(ybase -2)); g.drawString(tf.name, new Float(x + 2*node.rightChild.leafDistribution.condSet.size() + 2*this.nonTreeConditions.size()+2 + 15 + 2*t), new Float(ybase -2)); g.rotate(Math.PI/2,new Float(x + 2*node.rightChild.leafDistribution.condSet.size() + 2*this.nonTreeConditions.size()+2 + 15 + 2*t), new Float(ybase -2)); t++; } //add names of overrepresented GO cats to plot g.setFont(new Font("SansSerif", Font.BOLD, 2)); g.setPaint(Color.black); t=0; for(OntologyTerm go: GO.keySet()){ g.rotate(-Math.PI/2,new Float(x + 2*node.rightChild.leafDistribution.condSet.size() + 2*this.nonTreeConditions.size()+ 2*ordenedTFs.size() + 4 + 15 + 2*t), new Float(ybase -2)); g.drawString(go.getName(), new Float(x + 2*node.rightChild.leafDistribution.condSet.size() + 2*this.nonTreeConditions.size()+ 2*ordenedTFs.size() +4 + 15 + 2*t), new Float(ybase -2)); g.rotate(Math.PI/2,new Float(x + 2*node.rightChild.leafDistribution.condSet.size() + 2*this.nonTreeConditions.size()+ 2*ordenedTFs.size() +4 + 15 + 2*t), new Float(ybase -2)); t++; } //add names of module links to plot t = 0; g.setFont(new Font("SansSerif", Font.BOLD, 2)); g.setPaint(Color.black); for(Module m: modLinks){ g.rotate(-Math.PI/2,new Float(x + 2*node.rightChild.leafDistribution.condSet.size() + 2*this.nonTreeConditions.size()+ 2*ordenedTFs.size() + 4 + 2*GO.keySet().size() +2 + 15 + 2*t), new Float(ybase -2)); g.drawString(Integer.toString(m.number), new Float(x + 2*node.rightChild.leafDistribution.condSet.size() + 2*this.nonTreeConditions.size()+ 2*ordenedTFs.size() +4 + 2*GO.keySet().size() +2+ 15 + 2*t), new Float(ybase -2)); g.rotate(Math.PI/2,new Float(x + 2*node.rightChild.leafDistribution.condSet.size() + 2*this.nonTreeConditions.size()+ 2*ordenedTFs.size() +4 + 2*GO.keySet().size() +2+ 15 + 2*t), new Float(ybase -2)); t++; } } // draw the data points g.setStroke(new BasicStroke(0.25F)); int gn = 0; for (Gene gene : this.ordenedGenes) { for (int m = 0; m < node.rightChild.leafDistribution.condSet .size(); m++) { int exp = node.rightChild.leafDistribution.condSet.get(m); if (!Double.isNaN(data[gene.number][exp])) { // convert data to color Color col = data2Color(gene, data[gene.number][exp]); g.setPaint(col); } else // missing value g.setPaint(Color.white); g.fillRect(x + 2*m, ybase + 2*gn, 2, 2); g.setPaint(Color.black); g.drawRect(x + 2*m, ybase + 2*gn, 2, 2); } if(node == this.rightmostNode){ int N = node.rightChild.leafDistribution.condSet.size(); //draw non-tree condition data points for (int m = 0; m < this.nonTreeConditions.size(); m++) { int exp = this.nonTreeConditions.get(m).number; if (!Double.isNaN(data[gene.number][exp])) { // convert data to color Color col = data2Color(gene, data[gene.number][exp]); g.setPaint(col); } else // missing value g.setPaint(Color.white); g.fillRect(x + 2*N + 2*m, ybase + 2*gn, 2, 2); g.setPaint(Color.black); g.drawRect(x + 2*N + 2*m, ybase + 2*gn, 2, 2); } // draw line between rightmost leaf and extra conditions if(this.nonTreeConditions.size() > 0){ g.setStroke(new BasicStroke(0.5F)); g.setPaint(Color.white); g.drawLine(x + 2*N, ybase + 2*gn, x + 2*N, ybase + 2*gn + 2); g.setPaint(Color.black); g.setStroke(new BasicStroke(0.25F)); } //add names of genes to plot g.setFont(new Font("SansSerif", Font.BOLD, 2)); g.setPaint(Color.black); g.drawString(gene.name, new Float(x + 2*node.rightChild.leafDistribution.condSet.size() + 2*this.nonTreeConditions.size() +2), new Float(ybase + 2*gn+2)); //add yellow squares for overrepresented TFs int t = 0; TreeSet<Gene> ordenedTFs = new TreeSet<Gene>((Set<Gene>) this.TFs.keySet()); for(Gene tf: ordenedTFs){ if(this.moduleNetwork.getTFBinding().containsKey(tf) && this.moduleNetwork.getTFBinding().get(tf).containsKey(gene)){ g.setPaint(Color.yellow); g.fillRect(x + 2*node.rightChild.leafDistribution.condSet.size()+ 2*this.nonTreeConditions.size() + 15 + 2*t, ybase + 2*gn, 2, 2); } g.setPaint(Color.black); g.drawRect(x + 2*node.rightChild.leafDistribution.condSet.size()+ 2*this.nonTreeConditions.size() + 15 + 2*t, ybase + 2*gn, 2, 2); t++; } //add orange squares for overrepresented GO cats t = 0; for(OntologyTerm go: GO.keySet()){ boolean ok = false; for(OntologyTerm o: gene.GOannotations){ if(o.equals(go)){ ok = true; } } if(ok == true){ g.setPaint(Color.orange); g.fillRect(x + 2*node.rightChild.leafDistribution.condSet.size()+ 2*this.nonTreeConditions.size() + 2*ordenedTFs.size() +2 + 15 + 2*t, ybase + 2*gn, 2, 2); } g.setPaint(Color.black); g.drawRect(x + 2*node.rightChild.leafDistribution.condSet.size()+ 2*this.nonTreeConditions.size() + 2*ordenedTFs.size() +2 + 15 + 2*t, ybase + 2*gn, 2, 2); t++; } //add links to other modules t = 0; for(Module m: modLinks){ if(gene.modules.contains(m)){ g.setPaint(Color.blue); g.fillRect(x + 2*node.rightChild.leafDistribution.condSet.size()+ 2*this.nonTreeConditions.size() + 2*ordenedTFs.size() +2 + 2*GO.keySet().size() +2 + 15 + 2*t, ybase + 2*gn, 2, 2); } g.setPaint(Color.black); g.drawRect(x + 2*node.rightChild.leafDistribution.condSet.size()+ 2*this.nonTreeConditions.size() + 2*ordenedTFs.size() +2 + 2*GO.keySet().size() +2 + 15 + 2*t, ybase + 2*gn, 2, 2); t++; } } gn++; } g.setPaint(Color.black); // draw frame around expression values //g.drawRect(x, ybase, 2*node.rightChild.leafDistribution.condSet.size(), this.Genes.size()*2); g.setStroke(new BasicStroke(0.5F)); } // draw horizontal line between start coordinates for the children g.drawLine(xl, y + h, xr, y + h); // draw the children, right one is drawn lower than left one for clarity drawnode(node.leftChild, xl, y + h, h, ybase, data, g); drawnode(node.rightChild, xr, y + h, h + 4, ybase, data, g); // draw line between leaves g.setPaint(Color.white); g.drawLine(x, ybase, x, ybase + this.Genes.size()*2); g.setPaint(Color.black); } } // draw data as one big leaf (for module without parents) public void draw1leaf(int x, int y, double[][] data, Graphics2D g) { int numCond = this.regressionTree.leafDistribution.condSet.size(); if(numCond != this.Conditions.size()){ System.out.println("Error here"); } int gn = 0; for(int i = 0; i < this.regressionTree.leafDistribution.condSet.size();i++){ Condition c = this.numberedConditions.get(this.regressionTree.leafDistribution.condSet.get(i)); //add names of conditions g.setFont(new Font("SansSerif", Font.BOLD, 2)); g.setPaint(Color.black); g.rotate(Math.PI/3,new Float(x + 2*i+1), new Float(y + 2*this.Genes.size()+2)); g.drawString(c.name, new Float(x + 2*i+1), new Float(y + 2*this.Genes.size()+2)); g.rotate(-Math.PI/3,new Float(x + 2*i+1), new Float(y + 2*this.Genes.size()+2)); } //add names of overrepresented TFs to plot g.setFont(new Font("SansSerif", Font.BOLD, 2)); g.setPaint(Color.black); TreeSet<Gene> ordenedTFs = new TreeSet<Gene>((Set<Gene>) this.TFs.keySet()); int t=0; for(Gene tf: ordenedTFs){ g.rotate(-Math.PI/2,new Float(x + 2*(numCond+1) + 15 + 2*t), new Float(y -2)); g.drawString(tf.name, new Float(x + 2*(numCond+1) + 15 + 2*t), new Float(y -2)); g.rotate(Math.PI/2,new Float(x + 2*(numCond+1) + 15 + 2*t), new Float(y -2)); t++; } //add names of overrepresented GO cats to plot g.setFont(new Font("SansSerif", Font.BOLD, 2)); g.setPaint(Color.black); t=0; for(OntologyTerm go: GO.keySet()){ g.rotate(-Math.PI/2,new Float(x + 2*(numCond+1) + 2*ordenedTFs.size() + 2 + 15 + 2*t), new Float(y -2)); g.drawString(go.getName(), new Float(x + 2*(numCond+1) + 2*ordenedTFs.size() +2 + 15 + 2*t), new Float(y -2)); g.rotate(Math.PI/2,new Float(x + 2*(numCond+1) + 2*ordenedTFs.size() +2 + 15 + 2*t), new Float(y -2)); t++; } //add names of module links to plot t = 0; g.setFont(new Font("SansSerif", Font.BOLD, 2)); g.setPaint(Color.black); for(Module m: modLinks){ g.rotate(-Math.PI/2,new Float(x + 2*(numCond+1) + 2*ordenedTFs.size() + 2 + 2*GO.keySet().size() + 2 + 15 + 2*t), new Float(y -2)); g.drawString(Integer.toString(m.number), new Float(x + 2*(numCond+1) + 2*ordenedTFs.size() +2 + 2*GO.keySet().size() + 2 + 15 + 2*t), new Float(y -2)); g.rotate(Math.PI/2,new Float(x + 2*(numCond+1) + 2*ordenedTFs.size() +2 + 2*GO.keySet().size() + 2 + 15 + 2*t), new Float(y -2)); t++; } g.setStroke(new BasicStroke(0.25F)); for (Gene gene : this.ordenedGenes) { for (int i = 0; i < this.regressionTree.leafDistribution.condSet.size();i++) { int m = this.numberedConditions.get(this.regressionTree.leafDistribution.condSet.get(i)).number; if (!Double.isNaN(data[gene.number][m])) { // convert data to color Color col = data2Color(gene, data[gene.number][m]); g.setPaint(col); } else // missing value g.setPaint(Color.white); g.fillRect(x + 2*i, y + 2*gn, 2, 2); g.setPaint(Color.black); g.drawRect(x + 2*i, y + 2*gn, 2, 2); } //add name of gene g.setFont(new Font("SansSerif", Font.BOLD, 2)); g.setPaint(Color.black); g.drawString(gene.name, new Float(x + 2*(numCond+1)), new Float(y + 2*gn +2)); //add yellow squares for overrepresented TFs t=0; for(Gene tf: ordenedTFs){ if(this.moduleNetwork.getTFBinding().containsKey(tf) && this.moduleNetwork.getTFBinding().get(tf).containsKey(gene)){ g.setPaint(Color.yellow); g.fillRect(x + 2*(numCond) + 15 + 2*t, y + 2*gn, 2, 2); } g.setPaint(Color.black); g.drawRect(x + 2*(numCond) + 15 + 2*t, y + 2*gn, 2, 2); t++; } //add orange squares for overrepresented GO cats t = 0; for(OntologyTerm go: GO.keySet()){ //System.out.println(this.name + "\t" + go.getName()); boolean ok = false; for(OntologyTerm o: gene.GOannotations){ if(o.equals(go)){ //System.out.println(this.name + "\t" + go.getName() + "\t" + o.getName()); ok = true; } } if(ok == true){ g.setPaint(Color.orange); g.fillRect(x + 2*(numCond) + 2*ordenedTFs.size() +2 + 15 + 2*t, y + 2*gn, 2, 2); } g.setPaint(Color.black); g.drawRect(x + 2*(numCond) + 2*ordenedTFs.size() +2 + 15 + 2*t, y + 2*gn, 2, 2); t++; } //add links to other modules t = 0; for(Module m: modLinks){ if(gene.modules.contains(m)){ g.setPaint(Color.blue); g.fillRect(x + 2*(numCond) + 2*ordenedTFs.size() +2 + 2*GO.keySet().size() +2 + 15 + 2*t, y + 2*gn, 2, 2); } g.setPaint(Color.black); g.drawRect(x + 2*(numCond) + 2*ordenedTFs.size() +2 + 2*GO.keySet().size() +2 + 15 + 2*t, y + 2*gn, 2, 2); t++; } gn++; } g.setPaint(Color.black); // draw frame around expression values //g.drawRect(x, y, numCond*2, this.Genes.size()*2); g.setStroke(new BasicStroke(0.5F)); } public void setTFs(HashMap<Gene,Double> tfs){ TFs.putAll(tfs); } }
participants (1)
-
Steven Maere