private void writeSelf( String origTarget, GeneBranch currentParent, GeneBranch down, Writer writer1, Writer writer2) throws IOException { if (!down.isSelected()) return; String edgeTag; if (down.isLeaf() || travExp.getUpstream(down.gene).contains(currentParent)) { edgeTag = SIFEnum.CONTROLS_EXPRESSION_OF.getTag(); } else edgeTag = SIFEnum.CONTROLS_STATE_CHANGE_OF.getTag(); writer1.write(currentParent.gene + "\t" + edgeTag + "\t" + down.gene + "\n"); writeWeights(origTarget, currentParent, down, edgeTag, writer2); writeBranches(origTarget, down, writer1, writer2); }
public void generateInfluenceGraphs(List<String> result) { DownstreamTree tree = new DownstreamTree( travSt, travExp, new BranchDataProvider() { @Override public Color getColor(String gene, String root) { double pval = calcPVal(root, Collections.singleton(gene)); String colS = val2Color(pval, calcChangeDirection(root, gene) ? 1 : -1); String[] c = colS.split(" "); return new Color( Integer.parseInt(c[0]), Integer.parseInt(c[1]), Integer.parseInt(c[2])); } @Override public double getThickness(GeneBranch branch, String root) { Set<String> dwstr = branch.getAllGenes(); double cumPval = calcPVal(root, dwstr); return Math.min(-Math.log(cumPval), 5); } }); String dir = this.dir + dataset.name() + "/"; File d = new File(dir); if (!d.exists()) d.mkdirs(); assert d.isDirectory(); for (String mut : result) { GeneBranch g = tree.getTree(mut, downstream.get(mut), depth); g.trimToMajorPaths(downstream.get(mut)); if (g.selectLeaves(affectedDw.get(mut))) { if (!affectedDw.get(mut).isEmpty() && affectedDw.get(mut).size() < 6) RadialInfluenceTree.write(g.copy(true), false, dir + mut + ".svg"); writeTree(g, dir); } } }
private void writeWeights( String orig, GeneBranch from, GeneBranch to, String edgeType, Writer writer) throws IOException { Set<String> dwstr = to.getAllGenes(); dwstr.retainAll(downstream.get(orig)); assert !dwstr.isEmpty(); double cumPval = calcPVal(orig, dwstr); boolean upreg = calcChangeDirection(orig, to.gene); String key = from.gene + " " + edgeType + " " + to.gene; writer.write("edge\t" + key + "\tcolor\t" + val2Color(cumPval, 0) + "\n"); writer.write("edge\t" + key + "\twidth\t2\n"); if (affectedDw.get(orig).contains(to.gene)) { double pval = calcPVal(orig, Collections.singleton(to.gene)); writer.write("node\t" + to.gene + "\tcolor\t" + val2Color(pval, upreg ? 1 : -1) + "\n"); } else { writer.write("node\t" + to.gene + "\tcolor\t255 255 255\n"); } }