Esempio n. 1
0
  /**
   * Render the site track (the top, summary view of the site).
   *
   * @param variant
   * @param bandRectangle
   * @param pX0
   * @param dX
   * @param context
   */
  public void renderSiteBand(
      Variant variant, Rectangle bandRectangle, int pX0, int dX, RenderContext context) {

    final boolean filtered = variant.isFiltered();
    final Color alleleColor;
    final Color refColor;
    double percent;
    if (track.getColorMode() == VariantTrack.ColorMode.METHYLATION_RATE) {
      alleleColor = this.convertMethylationRateToColor((float) variant.getMethlationRate() / 100);
      percent = variant.getCoveredSampleFraction();
      refColor = filtered ? colorAlleleRefAlpha : colorAlleleRef; // Gray
    } else {
      alleleColor = filtered ? colorAlleleBandAlpha : colorAlleleBand; // Red
      double af = variant.getAlleleFraction();
      if (af < 0) {
        double[] afreqs = variant.getAlleleFreqs();
        if (afreqs != null && afreqs.length > 0) {
          af = afreqs[0];
        }
      }
      percent = Math.min(1, af);
      if (percent <= 0) {
        percent = 0;
        refColor = filtered ? colorAlleleRefAlpha : colorAlleleRef; // Gray
      } else {
        refColor = filtered ? blueAlpha : blue; // Blue
      }
    }

    final int bottomY = bandRectangle.y + bandRectangle.height - BOTTOM_MARGIN;
    final int barHeight = bandRectangle.height - TOP_MARGIN - BOTTOM_MARGIN;
    final int alleleBarHeight = (int) (percent * barHeight);
    final int remainderHeight = barHeight - alleleBarHeight;

    if (remainderHeight > 0) {
      Graphics2D g = context.getGraphic2DForColor(refColor);
      g.fillRect(pX0, bottomY - alleleBarHeight - remainderHeight, dX, remainderHeight);
    }

    if (alleleBarHeight > 0) {
      Graphics2D g = context.getGraphic2DForColor(alleleColor);
      g.fillRect(pX0, bottomY - alleleBarHeight, dX, alleleBarHeight);
    }
  }
Esempio n. 2
0
  public void renderGenotypeBandSNP(
      Variant variant,
      RenderContext context,
      Rectangle bandRectangle,
      int pX0,
      int dX,
      String sampleName,
      VariantTrack.ColorMode coloring,
      boolean hideFiltered) {

    int pY = (int) bandRectangle.getY();
    int dY = (int) bandRectangle.getHeight();

    int tOffset = 6;
    int bOffset = 8;
    Graphics2D g = (Graphics2D) context.getGraphics().create();

    if (dX >= 10) {
      if (dY > 24) {
        Font f = FontManager.getFont(Font.BOLD, Math.min(dX, 12));
        g.setFont(f);
      } else if (dY > 18) {
        Font f = FontManager.getFont(Font.BOLD, Math.min(dX, 8));
        tOffset = 4;
        bOffset = 5;
        g.setFont(f);
      }
    }

    boolean isFiltered = variant.isFiltered() && hideFiltered;

    Genotype genotype = variant.getGenotype(sampleName);
    if (genotype == null) {
      log.error("Now what?");
    } else {
      Color b1Color = Color.gray;
      Color b2Color = Color.gray;
      char b1 = ' ';
      char b2 = ' ';
      // Assign proper coloring
      switch (coloring) {
        case GENOTYPE:
          b1Color = getGenotypeColor(genotype, isFiltered);
          b2Color = b1Color;
          break;

        case ALLELE:
          final List<Allele> alleleList = genotype.getAlleles();
          if (alleleList.size() > 0) {
            b1 = getFirstBase(alleleList.get(0));
            b1Color = nucleotideColors.get(b1);
          }
          if (alleleList.size() > 1) {
            b2 = getFirstBase(alleleList.get(1));
            b2Color = nucleotideColors.get(b2);
          }
          break;
        case METHYLATION_RATE:
          final double goodBaseCount = genotype.getAttributeAsDouble("GB");
          b1Color = colorNoCall;
          b2Color = b1Color;
          final double value = genotype.getAttributeAsDouble("MR");
          if (!Double.isNaN(goodBaseCount) && !Double.isNaN(value)) {
            if (goodBaseCount < VariantTrack.METHYLATION_MIN_BASE_COUNT || Double.isNaN(value)) {
              b1Color = colorNoCall;
              b2Color = b1Color;

            } else {
              float mr = (float) value;
              mr /= 100f;
              b1Color = convertMethylationRateToColor(mr);
              b2Color = b1Color;
            }
          } else {
            log.error(
                "GB and MR fields must be defined for all records in a VCF methylation file.");
          }
          break;

        default:
          b1Color = colorNoCall;
          b2Color = b1Color;
      }

      int y0 = track.getDisplayMode() == Track.DisplayMode.EXPANDED ? pY + 1 : pY;
      int h = Math.max(1, track.getDisplayMode() == Track.DisplayMode.EXPANDED ? dY - 2 : dY);

      if (coloring == VariantTrack.ColorMode.GENOTYPE) {

        g.setColor(b1Color);
        g.fillRect(pX0, y0, dX, h);
      } else {
        // Color by allele
        g.setColor(b1Color);
        g.fillRect(pX0, y0, (dX / 2), h);
        g.setColor(b2Color);
        g.fillRect(pX0 + (dX / 2), y0, (dX / 2), h);
      }

      if ((dX >= 10) && (dY >= 18)) {
        if (b1Color == Color.blue) {
          g.setColor(Color.white);
        } else {
          g.setColor(Color.black);
        }
        drawCenteredText(g, new char[] {b1}, pX0, pY - tOffset, dX, dY);
        drawCenteredText(g, new char[] {b2}, pX0, pY + (dY / 2) - bOffset, dX, dY);
      }
    }
    g.dispose();
  }