Ejemplo n.º 1
0
  @Override
  protected DataTile getRawData(String chr, int startLocation, int endLocation) {

    int queryLength = endLocation - startLocation;
    int longestFeature = getLongestFeature(chr);
    int adjustedStart = startLocation;
    int adjustedEnd = endLocation;
    if (queryLength < longestFeature) {
      int halfDiff = (longestFeature - queryLength) / 2;
      adjustedStart = startLocation - halfDiff - 1;
      adjustedEnd = endLocation + halfDiff;
    }

    try {
      Iterator<LocusScore> iter =
          pluginFeatureSource.getFeatures(chr, adjustedStart, adjustedEnd, -1);
      List<LocusScore> list = new ArrayList<LocusScore>(1000);
      LocusScore score;
      dataMin = Double.MAX_VALUE;
      dataMax = -Double.MAX_VALUE;

      while (iter.hasNext()) {
        score = iter.next();
        dataMin = Math.min(dataMin, score.getScore());
        dataMax = Math.max(dataMax, score.getScore());
        list.add(score);
        longestFeature = Math.max(longestFeature, score.getEnd() - score.getStart());
      }
      longestFeatureMap.put(chr, longestFeature);

      int length = list.size();
      int[] startLocations = new int[length];
      int[] endLocations = new int[length];
      float[] scores = new float[length];
      String[] names = new String[length];
      int idx = 0;
      for (LocusScore locusScore : list) {
        startLocations[idx] = locusScore.getStart();
        endLocations[idx] = locusScore.getEnd();
        scores[idx] = locusScore.getScore();
        names[idx] =
            Locus.getFormattedLocusString(
                locusScore.getChr(), locusScore.getStart(), locusScore.getEnd());
        idx++;
      }
      return new DataTile(startLocations, endLocations, scores, names);

    } catch (IOException e) {
      log.error(e.getMessage(), e);
      throw new RuntimeException(e);
    }
  }
Ejemplo n.º 2
0
  /**
   * Method description
   *
   * @param heading
   * @return
   */
  public List<LocusScore> getWholeGenomeScores(String heading) {

    List<LocusScore> wholeGenomeScores = wholeGenomeScoresCache.get(heading);
    if ((wholeGenomeScores == null) || wholeGenomeScores.isEmpty()) {
      int locationUnit = 1000;

      // Compute the smallest concievable feature that could be viewed on the
      // largest screen.  Be conservative.   The smallest feature is one at
      // the screen resolution scale in <chr units> / <pixel>
      int maxScreenSize = 4000;
      double minFeatureSize = 0; // ((double) genome.getLength()) / (maxScreenSize * locationUnit);

      long offset = 0;
      wholeGenomeScores = new ArrayList(1000);
      for (String chr : genome.getChromosomeNames()) {
        List<LocusScore> chrSegments = getSegments(heading, chr);
        if (chrSegments != null) {
          int lastgEnd = -1;
          for (LocusScore score : chrSegments) {
            Segment seg = (Segment) score;
            int gStart = (int) ((offset + score.getStart()) / locationUnit);
            int gEnd = (int) ((offset + score.getEnd()) / locationUnit);
            if ((gEnd - gStart) > minFeatureSize) {
              wholeGenomeScores.add(
                  new Segment(gStart, gStart, gEnd, gEnd, seg.getScore(), seg.getDescription()));
            }
          }
        }
        offset += genome.getChromosome(chr).getLength();
      }
      wholeGenomeScoresCache.put(heading, wholeGenomeScores);
    }
    return wholeGenomeScores;
  }
Ejemplo n.º 3
0
 public String encode(LocusScore score) {
   String[] tokens = new String[4];
   tokens[0] = score.getChr();
   tokens[1] = "" + score.getStart();
   tokens[2] = "" + score.getEnd();
   tokens[3] = "" + score.getScore();
   String out = StringUtils.join(tokens, delimiter);
   return out;
 }
Ejemplo n.º 4
0
  @Test
  public void testLoadCombinedDataSourceSession() throws Exception {
    String sessionpath = TestUtils.DATA_DIR + "sessions/subtypes_wdiff.xml";
    rewriteRestoreSession(sessionpath);

    String combPart0 = "TRIBE_p_TCGAaffx_B1_2_GBM_Nsp_GenomeWideSNP_6_E11_155884";
    String combPart1 = "TRIGS_p_TCGAaffxB5_sty_GenomeWideSNP_6_D05_223156";

    DataTrack track0 =
        Iterables.find(IGV.getInstance().getDataTracks(), new ContIdPredicate(combPart0));
    DataTrack track1 =
        Iterables.find(IGV.getInstance().getDataTracks(), new ContIdPredicate(combPart1));

    DataSourceTrack combTrack =
        (DataSourceTrack)
            Iterables.find(
                IGV.getInstance().getDataTracks(),
                new ContIdPredicate(new String[] {combPart0, combPart1}));

    assertTrue(combTrack.getRenderer() instanceof BarChartRenderer);
    assertEquals("Difference", combTrack.getName());

    String chr = "chr1";
    int start = 0;
    int end = 1000;

    LocusScore sumScore0 = track0.getSummaryScores(chr, start, end, 0).get(0);
    LocusScore sumScore1 = track1.getSummaryScores(chr, start, end, 0).get(0);
    LocusScore sumScoreComb = combTrack.getSummaryScores(chr, start, end, 0).get(0);

    assertEquals(sumScore0.getStart(), sumScore1.getStart());
    assertEquals(sumScore0.getStart(), sumScoreComb.getStart());
    assertEquals(sumScore1.getEnd(), sumScoreComb.getEnd());

    assertEquals(sumScore0.getScore() - sumScore1.getScore(), sumScoreComb.getScore(), 1e-10);
  }
Ejemplo n.º 5
0
  /**
   * Render the track in the given rectangle.
   *
   * @param track
   * @param locusScores
   * @param context
   * @param arect
   */
  public synchronized void renderScores(
      Track track, List<LocusScore> locusScores, RenderContext context, Rectangle arect) {

    boolean showMissingData =
        PreferenceManager.getInstance().getAsBoolean(PreferenceManager.SHOW_MISSING_DATA_KEY);

    Graphics2D noDataGraphics = context.getGraphic2DForColor(UIConstants.NO_DATA_COLOR);
    Graphics2D tickGraphics = context.getGraphic2DForColor(Color.BLACK);

    Rectangle adjustedRect = calculateDrawingRect(arect);
    double origin = context.getOrigin();
    double locScale = context.getScale();

    Color posColor = track.getColor();
    Color negColor = track.getAltColor();

    // Get the Y axis definition, consisting of minimum, maximum, and base value.  Often
    // the base value is == min value which is == 0.

    DataRange dataRange = track.getDataRange();
    float maxValue = dataRange.getMaximum();
    float baseValue = dataRange.getBaseline();
    float minValue = dataRange.getMinimum();
    boolean isLog = dataRange.isLog();

    if (isLog) {
      minValue = (float) (minValue == 0 ? 0 : Math.log10(minValue));
      maxValue = (float) Math.log10(maxValue);
    }

    // Calculate the Y scale factor.

    double delta = (maxValue - minValue);
    double yScaleFactor = adjustedRect.getHeight() / delta;

    // Calculate the Y position in pixels of the base value.  Clip to bounds of rectangle
    double baseDelta = maxValue - baseValue;
    int baseY = (int) (adjustedRect.getY() + baseDelta * yScaleFactor);
    if (baseY < adjustedRect.y) {
      baseY = adjustedRect.y;
    } else if (baseY > adjustedRect.y + adjustedRect.height) {
      baseY = adjustedRect.y + adjustedRect.height;
    }

    int lastPx = 0;
    for (LocusScore score : locusScores) {

      // Note -- don't cast these to an int until the range is checked.
      // could get an overflow.
      double pX = ((score.getStart() - origin) / locScale);
      double dx = Math.ceil((Math.max(1, score.getEnd() - score.getStart())) / locScale) + 1;
      if ((pX + dx < 0)) {
        continue;
      } else if (pX > adjustedRect.getMaxX()) {
        break;
      }

      float dataY = score.getScore();
      if (isLog && dataY <= 0) {
        continue;
      }

      if (!Float.isNaN(dataY)) {

        // Compute the pixel y location.  Clip to bounds of rectangle.
        double dy = isLog ? Math.log10(dataY) - baseValue : (dataY - baseValue);
        int pY = baseY - (int) (dy * yScaleFactor);
        if (pY < adjustedRect.y) {
          pY = adjustedRect.y;
        } else if (pY > adjustedRect.y + adjustedRect.height) {
          pY = adjustedRect.y + adjustedRect.height;
        }

        Color color = (dataY >= baseValue) ? posColor : negColor;
        drawDataPoint(color, (int) dx, (int) pX, baseY, pY, context);
      }
      if (showMissingData) {

        // Draw from lastPx + 1  to pX - 1;
        int w = (int) pX - lastPx - 4;
        if (w > 0) {
          noDataGraphics.fillRect(lastPx + 2, (int) arect.getY(), w, (int) arect.getHeight());
        }
      }
      if (!Float.isNaN(dataY)) {

        lastPx = (int) pX + (int) dx;
      }
    }
    if (showMissingData) {
      int w = (int) arect.getMaxX() - lastPx - 4;
      if (w > 0) {
        noDataGraphics.fillRect(lastPx + 2, (int) arect.getY(), w, (int) arect.getHeight());
      }
    }
  }