Package net.sf.mzmine.data

Examples of net.sf.mzmine.data.PeakListRow


    } else {
      shownDataFiles = nonReferenceDataFiles;
    }

    for (int row = 0, rowIndex = 0; row < peakList.getNumberOfRows(); row++) {
      PeakListRow rowPeak = peakList.getRow(row);
      if (!onlyIdentified
          || (onlyIdentified && rowPeak.getPeakIdentities().length > 0)) {

        // Average area or height of the reference group
        double referenceAverage = 0;
        int referencePeakCount = 0;
        for (int column = 0; column < referenceDataFiles.size(); column++) {

          if (rowPeak.getPeak(referenceDataFiles.get(column)) != null) {

            if (area) {

              referenceAverage += rowPeak.getPeak(
                  referenceDataFiles.get(column)).getArea();
            } else {

              referenceAverage += rowPeak.getPeak(
                  referenceDataFiles.get(column)).getHeight();
            }
            referencePeakCount++;
          }
        }
        if (referencePeakCount > 0) {

          referenceAverage /= referencePeakCount;
        }

        // Divide the area or height of each peak by the average of the
        // area or height of the reference peaks in each row
        for (int column = 0; column < shownDataFiles.size(); column++) {
          double value = Double.NaN;
          if (rowPeak.getPeak(shownDataFiles.get(column)) != null) {

            ChromatographicPeak peak = rowPeak
                .getPeak(shownDataFiles.get(column));
            if (area) {

              value = peak.getArea() / referenceAverage;
            } else {
View Full Code Here


        ProjectionPlotParameters.peakMeasurementType).getValue() == PeakMeasurementType.AREA)
      useArea = true;

    double[][] rawData = new double[selectedRawDataFiles.length][selectedRows.length];
    for (int rowIndex = 0; rowIndex < selectedRows.length; rowIndex++) {
      PeakListRow peakListRow = selectedRows[rowIndex];
      for (int fileIndex = 0; fileIndex < selectedRawDataFiles.length; fileIndex++) {
        RawDataFile rawDataFile = selectedRawDataFiles[fileIndex];
        ChromatographicPeak p = peakListRow.getPeak(rawDataFile);
        if (p != null) {
          if (useArea)
            rawData[fileIndex][rowIndex] = p.getArea();
          else
            rawData[fileIndex][rowIndex] = p.getHeight();
View Full Code Here

    // data files that should be in the heat map
    List<RawDataFile> shownDataFiles = nonReferenceDataFiles;

    for (int row = 0, rowIndex = 0; row < peakList.getNumberOfRows(); row++) {
      PeakListRow rowPeak = peakList.getRow(row);
      if (!onlyIdentified
          || (onlyIdentified && rowPeak.getPeakIdentities().length > 0)) {
        // Average area or height of the reference group
        meanControlStats.clear();
        for (int column = 0; column < referenceDataFiles.size(); column++) {

          if (rowPeak.getPeak(referenceDataFiles.get(column)) != null) {

            if (area) {

              meanControlStats.addValue(rowPeak.getPeak(
                  referenceDataFiles.get(column)).getArea());
            } else {

              meanControlStats
                  .addValue(rowPeak.getPeak(
                      referenceDataFiles.get(column))
                      .getHeight());
            }

          }
        }

        // Divide the area or height of each peak by the average of the
        // area or height of the reference peaks in each row
        int columnIndex = 0;
        for (int column = 0; column < groups.size(); column++) {
          String group = groups.get(column);
          meanGroupStats.clear();
          if (!group.equals(referenceGroup)) {

            for (int dataColumn = 0; dataColumn < shownDataFiles
                .size(); dataColumn++) {

              Object paramValue = project.getParameterValue(
                  selectedParameter,
                  shownDataFiles.get(dataColumn));
              if (rowPeak.getPeak(shownDataFiles.get(dataColumn)) != null
                  && String.valueOf(paramValue).equals(group)) {

                ChromatographicPeak peak = rowPeak
                    .getPeak(shownDataFiles.get(dataColumn));

                if (!Double.isInfinite(peak.getArea())
                    && !Double.isNaN(peak.getArea())) {
View Full Code Here

    }
    double[][] rawData;
    if (isForSamples) {
      rawData = new double[selectedRawDataFiles.length][selectedRows.length];
      for (int rowIndex = 0; rowIndex < selectedRows.length; rowIndex++) {
        PeakListRow peakListRow = selectedRows[rowIndex];
        for (int fileIndex = 0; fileIndex < selectedRawDataFiles.length; fileIndex++) {
          RawDataFile rawDataFile = selectedRawDataFiles[fileIndex];
          ChromatographicPeak p = peakListRow.getPeak(rawDataFile);
          if (p != null) {
            if (useArea) {
              rawData[fileIndex][rowIndex] = p.getArea();
            } else {
              rawData[fileIndex][rowIndex] = p.getHeight();
            }
          }
        }
      }
    } else {
      rawData = new double[selectedRows.length][selectedRawDataFiles.length];
      for (int rowIndex = 0; rowIndex < selectedRows.length; rowIndex++) {
        PeakListRow peakListRow = selectedRows[rowIndex];
        for (int fileIndex = 0; fileIndex < selectedRawDataFiles.length; fileIndex++) {
          RawDataFile rawDataFile = selectedRawDataFiles[fileIndex];
          ChromatographicPeak p = peakListRow.getPeak(rawDataFile);
          if (p != null) {
            if (useArea) {
              rawData[rowIndex][fileIndex] = p.getArea();
            } else {
              rawData[rowIndex][fileIndex] = p.getHeight();
View Full Code Here

      dataFileChoices = selectedPeakList[0].getRawDataFiles();
    } else {
      dataFileChoices = new RawDataFile[0];
    }

    PeakListRow rowChoices[];
    if (selectedPeakList.length == 1) {
      rowChoices = selectedPeakList[0].getRows();
    } else {
      rowChoices = new PeakListRow[0];
    }
View Full Code Here

      for (ChromatographicPeak p : candidate.getPeaks()) {
        if (p.getHeight() < minHeight)
          continue standardIteration;
      }

      PeakListRow goodStandardCandidate[] = new PeakListRow[originalPeakLists.length];
      goodStandardCandidate[0] = candidate;

      double candidateMZ = candidate.getAverageMZ();
      double candidateRT = candidate.getAverageRT();

      // Find matching rows in remaining peaklists
      for (int i = 1; i < originalPeakLists.length; i++) {
        Range rtRange = rtTolerance.getToleranceRange(candidateRT);
        Range mzRange = mzTolerance.getToleranceRange(candidateMZ);
        PeakListRow matchingRows[] = originalPeakLists[i]
            .getRowsInsideScanAndMZRange(rtRange, mzRange);

        // If we have not found exactly 1 matching peak, move to next
        // standard candidate
        if (matchingRows.length != 1)
          continue standardIteration;

        // Check that all peaks of this row have proper height
        for (ChromatographicPeak p : matchingRows[0].getPeaks()) {
          if (p.getHeight() < minHeight)
            continue standardIteration;
        }

        // Save reference to matching peak in this peak list
        goodStandardCandidate[i] = matchingRows[0];

      }

      // If we found a match of same peak in all peaklists, mark it as a
      // good standard
      goodStandards.add(goodStandardCandidate);
      logger.finest("Found a good standard for RT normalization: "
          + candidate);

    }

    // Check if we have any standards
    if (goodStandards.size() == 0) {
      setStatus(TaskStatus.ERROR);
      errorMessage = "No good standard peak was found";
      return;
    }

    // Calculate average retention times of all standards
    double averagedRTs[] = new double[goodStandards.size()];
    for (int i = 0; i < goodStandards.size(); i++) {
      double rtAverage = 0;
      for (PeakListRow row : goodStandards.get(i))
        rtAverage += row.getAverageRT();
      rtAverage /= (double) originalPeakLists.length;
      averagedRTs[i] = rtAverage;
    }

    // Normalize each peak list
    for (int peakListIndex = 0; peakListIndex < originalPeakLists.length; peakListIndex++) {

      // Get standard rows for this peak list only
      PeakListRow standards[] = new PeakListRow[goodStandards.size()];
      for (int i = 0; i < goodStandards.size(); i++) {
        standards[i] = goodStandards.get(i)[peakListIndex];
      }

      normalizePeakList(originalPeakLists[peakListIndex],
View Full Code Here

   */
  private void normalizePeakList(PeakList originalPeakList,
      PeakList normalizedPeakList, PeakListRow standards[],
      double normalizedStdRTs[]) {

    PeakListRow originalRows[] = originalPeakList.getRows();

    // Iterate peak list rows
    for (PeakListRow originalRow : originalRows) {

      // Cancel?
      if (isCanceled()) {
        return;
      }

      // Normalize one row
      PeakListRow normalizedRow = normalizeRow(originalRow, standards,
          normalizedStdRTs);

      // Copy comment and identification
      normalizedRow.setComment(originalRow.getComment());
      for (PeakIdentity ident : originalRow.getPeakIdentities())
        normalizedRow.addPeakIdentity(ident, false);
      normalizedRow.setPreferredPeakIdentity(originalRow
          .getPreferredPeakIdentity());

      // Add the new row to normalized peak list
      normalizedPeakList.addRow(normalizedRow);

View Full Code Here

    Vector<Double> colorCoordsV = new Vector<Double>();
    Vector<PeakListRow> peakListRowsV = new Vector<PeakListRow>();

    for (int rowIndex = 0; rowIndex < numOfRows; rowIndex++) {

      PeakListRow row = alignedPeakList.getRow(rowIndex);

      // Collect available peak intensities for selected files
      Vector<Double> peakIntensities = new Vector<Double>();
      for (int fileIndex = 0; fileIndex < selectedFiles.length; fileIndex++) {
        ChromatographicPeak p = row.getPeak(selectedFiles[fileIndex]);
        if (p != null) {
          if (measurementType == PeakMeasurementType.AREA)
            peakIntensities.add(p.getArea());
          else
            peakIntensities.add(p.getHeight());
        }
      }

      // If there are at least two measurements available for this peak
      // then calc CV and include this peak in the plot
      if (peakIntensities.size() > 1) {
        double[] ints = CollectionUtils.toDoubleArray(peakIntensities);
        Double cv = MathUtils.calcCV(ints);

        Double rt = row.getAverageRT();
        Double mz = row.getAverageMZ();

        xCoordsV.add(rt);
        yCoordsV.add(mz);
        colorCoordsV.add(cv);
        peakListRowsV.add(row);
View Full Code Here

   * @return New peak list row with normalized retention time
   */
  private PeakListRow normalizeRow(PeakListRow originalRow,
      PeakListRow standards[], double normalizedStdRTs[]) {

    PeakListRow normalizedRow = new SimplePeakListRow(originalRow.getID());

    // Standard rows preceding and following this row
    int prevStdIndex = -1, nextStdIndex = -1;

    for (int stdIndex = 0; stdIndex < standards.length; stdIndex++) {

      // If this standard peak is actually originalRow
      if (standards[stdIndex] == originalRow) {
        prevStdIndex = stdIndex;
        nextStdIndex = stdIndex;
        break;
      }

      // If this standard peak is before our originalRow
      if (standards[stdIndex].getAverageRT() < originalRow.getAverageRT()) {
        if ((prevStdIndex == -1)
            || (standards[stdIndex].getAverageRT() > standards[prevStdIndex]
                .getAverageRT()))
          prevStdIndex = stdIndex;
      }

      // If this standard peak is after our originalRow
      if (standards[stdIndex].getAverageRT() > originalRow.getAverageRT()) {
        if ((nextStdIndex == -1)
            || (standards[stdIndex].getAverageRT() < standards[nextStdIndex]
                .getAverageRT()))
          nextStdIndex = stdIndex;
      }

    }

    // Calculate normalized retention time of this row
    double normalizedRT = -1;

    if ((prevStdIndex == -1) || (nextStdIndex == -1)) {
      normalizedRT = originalRow.getAverageRT();
    } else

    if (prevStdIndex == nextStdIndex) {
      normalizedRT = normalizedStdRTs[prevStdIndex];
    } else {
      double weight = (originalRow.getAverageRT() - standards[prevStdIndex]
          .getAverageRT())
          / (standards[nextStdIndex].getAverageRT() - standards[prevStdIndex]
              .getAverageRT());
      normalizedRT = normalizedStdRTs[prevStdIndex]
          + (weight * (normalizedStdRTs[nextStdIndex] - normalizedStdRTs[prevStdIndex]));
    }

    // Set normalized retention time to all peaks in this row
    for (RawDataFile file : originalRow.getRawDataFiles()) {
      ChromatographicPeak originalPeak = originalRow.getPeak(file);
      if (originalPeak != null) {
        SimpleChromatographicPeak normalizedPeak = new SimpleChromatographicPeak(
            originalPeak);
        PeakUtils.copyPeakProperties(originalPeak, normalizedPeak);
        normalizedPeak.setRT(normalizedRT);
        normalizedRow.addPeak(file, normalizedPeak);
      }
    }

    return normalizedRow;

View Full Code Here

    for (PeakList peakList : peakLists) {

      // Create a sorted set of scores matching
      TreeSet<RowVsRowScore> scoreSet = new TreeSet<RowVsRowScore>();

      PeakListRow allRows[] = peakList.getRows();

      // Calculate scores for all possible alignments of this row
      for (PeakListRow row : allRows) {

        if (isCanceled())
          return;

        // Calculate limits for a row with which the row can be aligned
        Range mzRange = mzTolerance.getToleranceRange(row
            .getAverageMZ());
        Range rtRange = rtTolerance.getToleranceRange(row
            .getAverageRT());

        // Get all rows of the aligned peaklist within parameter limits
        PeakListRow candidateRows[] = alignedPeakList
            .getRowsInsideScanAndMZRange(rtRange, mzRange);

        // Calculate scores and store them
        for (PeakListRow candidate : candidateRows) {

          if (sameChargeRequired) {
            if (!PeakUtils.compareChargeState(row, candidate))
              continue;
          }

          if (sameIDRequired) {
            if (!PeakUtils.compareIdentities(row, candidate))
              continue;
          }

          if (compareIsotopePattern) {
            IsotopePattern ip1 = row.getBestIsotopePattern();
            IsotopePattern ip2 = candidate.getBestIsotopePattern();

            if ((ip1 != null) && (ip2 != null)) {
              ParameterSet isotopeParams = parameters
                  .getParameter(
                      JoinAlignerParameters.compareIsotopePattern)
                  .getEmbeddedParameters();

              if (!IsotopePatternScoreCalculator.checkMatch(ip1,
                  ip2, isotopeParams)) {
                continue;
              }
            }
          }

          RowVsRowScore score = new RowVsRowScore(row, candidate,
              mzRange.getSize() / 2, mzWeight,
              rtRange.getSize() / 2, rtWeight);

          scoreSet.add(score);

        }

        processedRows++;

      }

      // Create a table of mappings for best scores
      Hashtable<PeakListRow, PeakListRow> alignmentMapping = new Hashtable<PeakListRow, PeakListRow>();

      // Iterate scores by descending order
      Iterator<RowVsRowScore> scoreIterator = scoreSet.iterator();
      while (scoreIterator.hasNext()) {

        RowVsRowScore score = scoreIterator.next();

        // Check if the row is already mapped
        if (alignmentMapping.containsKey(score.getPeakListRow()))
          continue;

        // Check if the aligned row is already filled
        if (alignmentMapping.containsValue(score.getAlignedRow()))
          continue;

        alignmentMapping.put(score.getPeakListRow(),
            score.getAlignedRow());

      }

      // Align all rows using mapping
      for (PeakListRow row : allRows) {

        PeakListRow targetRow = alignmentMapping.get(row);

        // If we have no mapping for this row, add a new one
        if (targetRow == null) {
          targetRow = new SimplePeakListRow(newRowID);
          newRowID++;
          alignedPeakList.addRow(targetRow);
        }

        // Add all peaks from the original row to the aligned row
        for (RawDataFile file : row.getRawDataFiles()) {
          targetRow.addPeak(file, row.getPeak(file));
        }

        // Add all non-existing identities from the original row to the
        // aligned row
        PeakUtils.copyPeakListRowProperties(row, targetRow);
View Full Code Here

TOP

Related Classes of net.sf.mzmine.data.PeakListRow

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.