Exemplo n.º 1
0
  private void run(VcfIterator in) {
    for (; ; ) {
      VariantContext ctx = null;
      if (in.hasNext()) ctx = in.next();

      if (ctx == null
          || this.genes.isEmpty()
          || (!this.genes.isEmpty() && !this.genes.get(0).getChr().equals(ctx.getChr()))
          || (!this.genes.isEmpty() && this.chromEnd <= ctx.getStart())) {
        this.print();
        if (System.out.checkError()) return;
        if (ctx == null) return;
        this.clear();

        if (chrom2knownGenes.containsKey(ctx.getChr())) {
          for (KnownGene g : chrom2knownGenes.get(ctx.getChr())) {
            if (this.genes.isEmpty()) {
              if (g.getTxEnd() <= ctx.getStart() || g.getTxStart() > ctx.getEnd()) {
                continue;
              }
              this.addGene(g);
            } else {
              if (!(g.getTxStart() > this.chromEnd || g.getTxEnd() <= this.chromStart)) {
                this.addGene(g);
              }
            }
          }
          if (genes.isEmpty()) {
            debug("no gene for " + ctx.getChr() + ":" + ctx.getStart());
          }
        } else {
          debug("not any gene for " + ctx.getChr());
        }
      }

      if (!genes.isEmpty()
          && ctx.getStart() - 1 >= this.chromStart
          && ctx.getStart() <= this.chromEnd) {
        this.addVariant(ctx);
      }
    }
  }
Exemplo n.º 2
0
  private void print() {
    if (this.positions.isEmpty()) {
      return;
    }
    ++count_pages_printed;

    final KnownGene first = genes.get(0);
    final double fHeight = 20;

    final Dimension localPage =
        new Dimension(
            (int) (this.pageDef.width),
            (int)
                (margin.top
                    + margin.bottom
                    + (this.genes.size() + 1) * fHeight
                    + this.sample2positions.size() * fHeight));

    System.out.println("\n%%Page: " + count_pages_printed + " " + count_pages_printed);
    System.out.println("gsave");
    System.out.println(
        1.0
            + " "
            + (localPage.height <= this.pageDef.height
                ? 1.0
                : 1.0 / (localPage.getHeight() / (float) this.pageDef.getHeight()))
            + " scale");

    // System.out.println( "%%BoundingBox: 0 0 "  + page.width +  " "  + page.height  );

    float midy = (float) (fHeight / 2.0f);

    double cdsHeight = fHeight * 0.4;
    double exonHeight = fHeight * 0.9;

    System.out.println(
        "2 "
            + (localPage.height - 10)
            + " moveto ("
            + first.getChromosome()
            + ":"
            + this.chromStart
            + "-"
            + this.chromEnd
            + ") show");

    System.out.println("1 0 0 setrgbcolor");
    System.out.println("0.3 setlinewidth");
    for (Integer r : this.positions) {
      System.out.print(
          "newpath "
              + (float) toPixel(r)
              + " 0 moveto 0 "
              + localPage.height
              + " rlineto stroke\n");
      System.out.print(
          (float) toPixel(r)
              + " "
              + (localPage.height - 5)
              + " moveto -90 rotate ("
              + (r)
              + ") show 90 rotate\n");
    }

    for (int i = 0; i < this.genes.size(); ++i) {
      KnownGene g = this.genes.get(i);
      System.out.println("gsave");
      System.out.println("0 " + (localPage.height - margin.top - (fHeight * i)) + " translate");

      double x1 = toPixel(g.getTxStart());
      double x2 = toPixel(g.getTxEnd());
      System.out.print("0 0 0 setrgbcolor\n");
      NEWPATH();
      MOVETO(x1, midy);
      LINETO(x2, midy);
      STROKE();
      // draw ticks

      System.out.print("0.2 setlinewidth\n");
      System.out.print("newpath\n");
      System.out.print(x1 + " " + midy + " moveto\n");
      System.out.print(x1 + " " + x2 + (g.isPositiveStrand() ? " forticksF" : " forticksR") + "\n");
      System.out.print("closepath stroke\n");

      System.out.print("0.5 setlinewidth\n");
      // draw txStart/txEnd
      System.out.print(
          "0.1 0.1 0.5 setrgbcolor\n"
              + "newpath\n"
              + +toPixel(g.getCdsStart())
              + " "
              + +(midy - cdsHeight / 2.0)
              + " "
              + (toPixel(g.getCdsEnd()) - toPixel(g.getCdsStart()))
              + " "
              + cdsHeight
              + " box closepath fill\n");
      // draw each exon
      for (int j = 0; j < g.getExonCount(); ++j) {
        System.out.print(
            toPixel(g.getExon(j).getStart())
                + " "
                + (midy - exonHeight / 2.0)
                + " "
                + (float) (toPixel(g.getExon(j).getEnd()) - toPixel(g.getExon(j).getStart()))
                + " "
                + exonHeight
                + " gradient\n");
      }
      // draw name
      System.out.print("0 0 0 setrgbcolor\n");
      System.out.print("10 " + midy + " moveto (" + g.getName() + ") show\n");
      System.out.println("grestore");
    }

    // samples
    {
      double y = localPage.height - margin.top - (fHeight * (this.genes.size() + 1));
      for (String sample : this.sample2positions.keySet()) {

        System.out.print("0.2 setlinewidth\n");
        System.out.print("0 0 0 setrgbcolor\n");
        System.out.print("10 " + (y - midy + 5) + " moveto (" + sample + ") show\n");
        System.out.print(
            "newpath "
                + margin.left
                + " "
                + y
                + " moveto\n"
                + pageDef.width
                + " "
                + 0
                + " rlineto stroke\n");
        for (Integer r2 : this.sample2positions.get(sample)) {

          System.out.print("0.8 setlinewidth\n");
          System.out.print("newpath " + toPixel(r2) + " " + y + " circle closepath stroke\n");
        }
        y -= fHeight;
      }
    }

    System.out.println("grestore");
    System.out.print("showpage\n");
  }
Exemplo n.º 3
0
 private void addGene(KnownGene g) {
   chromStart = Math.min(chromStart, g.getTxStart());
   chromEnd = Math.max(chromEnd, g.getTxEnd());
   genes.add(g);
 }