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");
    }
  }
  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);
  }