コード例 #1
0
  /**
   * Draws a rectangle symbolizing a variant
   *
   * @param g graphics object
   * @param height height of the graphics
   * @param variantDisplay the variant
   * @param color the color of the stripe
   * @param genomeWindow the displayed genome window
   */
  private void drawVariant(
      Graphics g,
      int height,
      VariantDisplay variantDisplay,
      Color color,
      GenomeWindow genomeWindow) {
    Variant variant = variantDisplay.getVariant();

    // Get start and stop position
    int start = variant.getStart();
    int stop = variant.getStop();

    // Fits the start and stop position to the screen
    if ((start < genomeWindow.getStart())
        && (stop
            > genomeWindow
                .getStart())) { // if the variant starts before the left edge of the track but stop
                                // after
      start = genomeWindow.getStart(); // the drawing must start from the left edge of the track
    }
    if ((start < genomeWindow.getStop())
        && (stop
            > genomeWindow
                .getStop())) { // if the variant start before the right edge of the track and ends
                               // up further,
      stop = genomeWindow.getStop(); // the drawing must stop at the right edge of the track
    }

    // Transform the start and stop position to screen coordinates
    int x =
        projectWindow.genomeToScreenPosition(start); // get the position where the variant starts
    int width =
        projectWindow.genomeToScreenWidth(
            stop - start); // get the width of the variant on the screen

    if (width == 0) { // if the width is 0 pixel,
      width = 1; // we set it to 1 in order to be seen
    }

    // Get the height of the clip and of the stripe
    int variantHeight =
        getVariantHeight(variant, height); // Instantiate the int for the height of the variant

    // Sets the stripe color
    Color newColor;
    if ((drawer.getVariantUnderMouse() != null)
        && drawer.getVariantUnderMouse().equals(variant)) { // if there is a variant under the mouse
      newColor = Colors.stripeFilter(color); // we change the color of the variant
    } else { // if not
      newColor =
          new Color(
              color.getRed(),
              color.getGreen(),
              color.getBlue(),
              variantOpacity); // we use the defined color taking into account the opacity
    }
    g.setColor(newColor); // we set the graphic object color

    // if it is not a blank of synchronization
    int y =
        height
            - variantHeight; // y represents the top left corner of the stripes, the axis goes down
                             // to the bottom

    // Draws the variant
    int nucleotideNumber;
    if (variant
        instanceof
        ReferenceVariant) { // drawing a reference stripe requires a different method (shorter and
                            // more simple)
      if (color != null) { // if color is null, it means we don't want to draw the reference
        drawReference(g, x, width, height);
      }
    } else {
      g.fillRect(x, y, width, variantHeight); // draw the stripe

      // Draws the edge line of stripes
      if (variant.getType()
          == VariantType.INSERTION) { // the edge of an insertion and a deletion are different
        drawInsertion(g, x, y, width, variantHeight);
      } else if (variant.getType() == VariantType.DELETION) {
        drawDeletion(g, x, y, width, variantHeight);
      }
    }

    if (variantDisplay.getDisplay() == VariantDisplayList.SHOW_FILTER) {
      drawFilterPattern(g, x, y, width, variantHeight);
    }
    nucleotideNumber = stop - start;
    if (nucleotideNumber == 0) {
      nucleotideNumber = 1;
    }

    // Draw the variant letters
    if (variant.getType() != VariantType.MIX) {
      drawLetters(
          g,
          height,
          x,
          width,
          variantHeight,
          variantDisplay,
          nucleotideNumber); // draw the letters (nucleotides) over the stripe
    }
  }
コード例 #2
0
  /**
   * Draws the letters (nucleotides) over the stripe.
   *
   * @param g graphics object
   * @param graphicsHeigth height of the graphics object
   * @param x x coordinate
   * @param width width of the stripe
   * @param height height of the stripe
   * @param variantDisplay variant
   * @param nucleotideNumber number of nucleotide to display
   */
  private void drawLetters(
      Graphics g,
      int graphicsHeigth,
      int x,
      int width,
      int height,
      VariantDisplay variantDisplay,
      int nucleotideNumber) {
    Variant variant = variantDisplay.getVariant();
    VariantType variantType = variant.getType(); // gets the variant type
    if (((variantType == VariantType.INSERTION)
            && (MGDisplaySettings.DRAW_INSERTION_LETTERS == MGDisplaySettings.YES_MG_OPTION))
        || // checks all options in order to determine if the letters must be drawn
        ((variantType == VariantType.DELETION)
            && (MGDisplaySettings.DRAW_DELETION_LETTERS == MGDisplaySettings.YES_MG_OPTION))
        || ((variantType == VariantType.SNPS)
            && (MGDisplaySettings.DRAW_SNP_LETTERS == MGDisplaySettings.YES_MG_OPTION))
        || ((variant instanceof ReferenceVariant)
            && (MGDisplaySettings.DRAW_REFERENCE_LETTERS == MGDisplaySettings.YES_MG_OPTION))) {

      // if the letters must be drawn
      double windowWidth =
          width
              / nucleotideNumber; // calculate the size of window (here, the window is the width of
                                  // a nucleotide on the screen)
      FontMetrics fm = g.getFontMetrics(); // get the font metrics
      if ((fm.getHeight() < height)
          && (fm.stringWidth("A")
              < windowWidth)) { // verifies if the height of the font is smaller than the height of
                                // the stripe AND if the width of a reference letter (A) is smaller
                                // than a window size
        String letters = variantDisplay.getVariantSequence();
        g.setColor(Colors.BLACK); // set the color of the letters
        int letterY =
            (int)
                (graphicsHeigth - (height / 2d)); // define where the draw will start on the Y axis
        Graphics2D g2d =
            (Graphics2D)
                g.create(); // we reverse all coordinates to display the letter on the right way
        if (currentDrawingAllele == AlleleType.ALLELE02) {
          g2d.scale(1, -1);
          letterY *= -1;
          // letterY -= fm.getHeight() / 2d;	// commented because it was buggy on windows
        } else {
          // letterY += fm.getHeight() / 2d;	// commented because it was buggy on windows
        }

        int firstNucleotide =
            projectWindow.screenToGenomePosition(x)
                - variant
                    .getStart(); // retrieve the position of the first displayed nucleotide in the
                                 // variant
        firstNucleotide = Math.max(0, firstNucleotide);

        for (int i = 0;
            i < nucleotideNumber;
            i++) { // for all the nucleotide that are supposed to be displayed
          String letter = "-"; // the default letter is the question mark
          if ((letters != "-")
              && ((i + firstNucleotide)
                  < letters
                      .length())) { // if the letters are different to the question mark and if the
                                    // current index is smaller than the string length
            letter = letters.charAt(i + firstNucleotide) + ""; // we get the current character
          }
          // int xC = (int) Math.round(x + (i * windowWidth) + ((windowWidth -
          // fm.stringWidth(letter)) * 0.5));	// the horizontal position from where the draw starts:
          // x (of the stripe) + size of a window * current window number + (windows width - letter
          // width) / 2 (for the middle)
          int xC = projectWindow.genomeToScreenPosition(variant.getStart() + i + firstNucleotide);
          g2d.drawString(letter, xC, letterY); // we draw the letter
        }
      }
    }
  }