Search in sources :

Example 81 with Feature

use of net.sf.mzmine.datamodel.Feature in project mzmine2 by mzmine.

the class ResultWindow method actionPerformed.

public void actionPerformed(ActionEvent e) {
    String command = e.getActionCommand();
    if (command.equals("EXPORT")) {
        // Ask for filename
        JFileChooser fileChooser = new JFileChooser();
        fileChooser.setApproveButtonText("Export");
        int result = fileChooser.showSaveDialog(MZmineCore.getDesktop().getMainWindow());
        if (result != JFileChooser.APPROVE_OPTION)
            return;
        File outputFile = fileChooser.getSelectedFile();
        try {
            FileWriter fileWriter = new FileWriter(outputFile);
            BufferedWriter writer = new BufferedWriter(fileWriter);
            writer.write("Formula,Mass,RDBE,Isotope pattern score,MS/MS score");
            writer.newLine();
            for (int row = 0; row < resultsTable.getRowCount(); row++) {
                int modelRow = resultsTable.convertRowIndexToModel(row);
                ResultFormula formula = resultsTableModel.getFormula(modelRow);
                writer.write(formula.getFormulaAsString());
                writer.write(",");
                writer.write(String.valueOf(formula.getExactMass()));
                writer.write(",");
                if (formula.getRDBE() != null)
                    writer.write(String.valueOf(formula.getRDBE()));
                writer.write(",");
                if (formula.getIsotopeScore() != null)
                    writer.write(String.valueOf(formula.getIsotopeScore()));
                writer.write(",");
                if (formula.getMSMSScore() != null)
                    writer.write(String.valueOf(formula.getMSMSScore()));
                writer.newLine();
            }
            writer.close();
        } catch (Exception ex) {
            MZmineCore.getDesktop().displayErrorMessage(MZmineCore.getDesktop().getMainWindow(), "Error writing to file " + outputFile + ": " + ExceptionUtils.exceptionToString(ex));
        }
        return;
    }
    // The following actions require a single row to be selected
    int index = resultsTable.getSelectedRow();
    if (index < 0) {
        MZmineCore.getDesktop().displayMessage(MZmineCore.getDesktop().getMainWindow(), "Please select one result");
        return;
    }
    index = resultsTable.convertRowIndexToModel(index);
    ResultFormula formula = resultsTableModel.getFormula(index);
    if (command.equals("ADD")) {
        SimplePeakIdentity newIdentity = new SimplePeakIdentity(formula.getFormulaAsString());
        peakListRow.addPeakIdentity(newIdentity, false);
        // Notify the GUI about the change in the project
        MZmineCore.getProjectManager().getCurrentProject().notifyObjectChanged(peakListRow, false);
        // Repaint the window to reflect the change in the feature list
        MZmineCore.getDesktop().getMainWindow().repaint();
        dispose();
    }
    if (command.equals("COPY")) {
        String formulaString = formula.getFormulaAsString();
        StringSelection stringSelection = new StringSelection(formulaString);
        Clipboard clipboard = Toolkit.getDefaultToolkit().getSystemClipboard();
        clipboard.setContents(stringSelection, null);
    }
    if (command.equals("SHOW_ISOTOPES")) {
        logger.finest("Showing isotope pattern for formula " + formula.getFormulaAsString());
        IsotopePattern predictedPattern = formula.getPredictedIsotopes();
        if (predictedPattern == null)
            return;
        Feature peak = peakListRow.getBestPeak();
        RawDataFile dataFile = peak.getDataFile();
        int scanNumber = peak.getRepresentativeScanNumber();
        SpectraVisualizerModule.showNewSpectrumWindow(dataFile, scanNumber, null, peak.getIsotopePattern(), predictedPattern);
    }
    if (command.equals("SHOW_MSMS")) {
        Feature bestPeak = peakListRow.getBestPeak();
        RawDataFile dataFile = bestPeak.getDataFile();
        int msmsScanNumber = bestPeak.getMostIntenseFragmentScanNumber();
        if (msmsScanNumber < 1)
            return;
        SpectraVisualizerWindow msmsPlot = SpectraVisualizerModule.showNewSpectrumWindow(dataFile, msmsScanNumber);
        if (msmsPlot == null)
            return;
        Map<DataPoint, String> annotation = formula.getMSMSannotation();
        if (annotation == null)
            return;
        msmsPlot.addAnnotation(annotation);
    }
}
Also used : FileWriter(java.io.FileWriter) IsotopePattern(net.sf.mzmine.datamodel.IsotopePattern) SimplePeakIdentity(net.sf.mzmine.datamodel.impl.SimplePeakIdentity) Feature(net.sf.mzmine.datamodel.Feature) DataPoint(net.sf.mzmine.datamodel.DataPoint) BufferedWriter(java.io.BufferedWriter) StringSelection(java.awt.datatransfer.StringSelection) SpectraVisualizerWindow(net.sf.mzmine.modules.visualization.spectra.simplespectra.SpectraVisualizerWindow) JFileChooser(javax.swing.JFileChooser) RawDataFile(net.sf.mzmine.datamodel.RawDataFile) DataPoint(net.sf.mzmine.datamodel.DataPoint) Clipboard(java.awt.datatransfer.Clipboard) RawDataFile(net.sf.mzmine.datamodel.RawDataFile) File(java.io.File)

Example 82 with Feature

use of net.sf.mzmine.datamodel.Feature in project mzmine2 by mzmine.

the class LinearNormalizerTask method run.

public void run() {
    setStatus(TaskStatus.PROCESSING);
    logger.info("Running linear normalizer");
    // This hashtable maps rows from original alignment result to rows of
    // the normalized alignment
    Hashtable<PeakListRow, SimplePeakListRow> rowMap = new Hashtable<PeakListRow, SimplePeakListRow>();
    // Create new feature list
    normalizedPeakList = new SimplePeakList(originalPeakList + " " + suffix, originalPeakList.getRawDataFiles());
    // Loop through all raw data files, and find the peak with biggest
    // height
    double maxOriginalHeight = 0.0;
    for (RawDataFile file : originalPeakList.getRawDataFiles()) {
        for (PeakListRow originalpeakListRow : originalPeakList.getRows()) {
            Feature p = originalpeakListRow.getPeak(file);
            if (p != null) {
                if (maxOriginalHeight <= p.getHeight())
                    maxOriginalHeight = p.getHeight();
            }
        }
    }
    // Loop through all raw data files, and normalize peak values
    for (RawDataFile file : originalPeakList.getRawDataFiles()) {
        // Cancel?
        if (isCanceled()) {
            return;
        }
        // Determine normalization type and calculate normalization factor
        double normalizationFactor = 1.0;
        // - normalization by average peak intensity
        if (normalizationType == NormalizationType.AverageIntensity) {
            double intensitySum = 0;
            int intensityCount = 0;
            for (PeakListRow peakListRow : originalPeakList.getRows()) {
                Feature p = peakListRow.getPeak(file);
                if (p != null) {
                    if (peakMeasurementType == PeakMeasurementType.HEIGHT) {
                        intensitySum += p.getHeight();
                    } else {
                        intensitySum += p.getArea();
                    }
                    intensityCount++;
                }
            }
            normalizationFactor = intensitySum / (double) intensityCount;
        }
        // - normalization by average squared peak intensity
        if (normalizationType == NormalizationType.AverageSquaredIntensity) {
            double intensitySum = 0.0;
            int intensityCount = 0;
            for (PeakListRow peakListRow : originalPeakList.getRows()) {
                Feature p = peakListRow.getPeak(file);
                if (p != null) {
                    if (peakMeasurementType == PeakMeasurementType.HEIGHT) {
                        intensitySum += (p.getHeight() * p.getHeight());
                    } else {
                        intensitySum += (p.getArea() * p.getArea());
                    }
                    intensityCount++;
                }
            }
            normalizationFactor = intensitySum / (double) intensityCount;
        }
        // - normalization by maximum peak intensity
        if (normalizationType == NormalizationType.MaximumPeakHeight) {
            double maximumIntensity = 0.0;
            for (PeakListRow peakListRow : originalPeakList.getRows()) {
                Feature p = peakListRow.getPeak(file);
                if (p != null) {
                    if (peakMeasurementType == PeakMeasurementType.HEIGHT) {
                        if (maximumIntensity < p.getHeight())
                            maximumIntensity = p.getHeight();
                    } else {
                        if (maximumIntensity < p.getArea())
                            maximumIntensity = p.getArea();
                    }
                }
            }
            normalizationFactor = maximumIntensity;
        }
        // - normalization by total raw signal
        if (normalizationType == NormalizationType.TotalRawSignal) {
            normalizationFactor = 0;
            for (int scanNumber : file.getScanNumbers(1)) {
                Scan scan = file.getScan(scanNumber);
                normalizationFactor += scan.getTIC();
            }
        }
        // Readjust normalization factor so that maximum height will be
        // equal to maximumOverallPeakHeightAfterNormalization after
        // normalization
        double maxNormalizedHeight = maxOriginalHeight / normalizationFactor;
        normalizationFactor = normalizationFactor * maxNormalizedHeight / maximumOverallPeakHeightAfterNormalization;
        // Normalize all peak intenisities using the normalization factor
        for (PeakListRow originalpeakListRow : originalPeakList.getRows()) {
            // Cancel?
            if (isCanceled()) {
                return;
            }
            Feature originalPeak = originalpeakListRow.getPeak(file);
            if (originalPeak != null) {
                SimpleFeature normalizedPeak = new SimpleFeature(originalPeak);
                PeakUtils.copyPeakProperties(originalPeak, normalizedPeak);
                double normalizedHeight = originalPeak.getHeight() / normalizationFactor;
                double normalizedArea = originalPeak.getArea() / normalizationFactor;
                normalizedPeak.setHeight(normalizedHeight);
                normalizedPeak.setArea(normalizedArea);
                SimplePeakListRow normalizedRow = rowMap.get(originalpeakListRow);
                if (normalizedRow == null) {
                    normalizedRow = new SimplePeakListRow(originalpeakListRow.getID());
                    PeakUtils.copyPeakListRowProperties(originalpeakListRow, normalizedRow);
                    rowMap.put(originalpeakListRow, normalizedRow);
                }
                normalizedRow.addPeak(file, normalizedPeak);
            }
        }
        // Progress
        processedDataFiles++;
    }
    // Finally add all normalized rows to normalized alignment result
    for (PeakListRow originalpeakListRow : originalPeakList.getRows()) {
        SimplePeakListRow normalizedRow = rowMap.get(originalpeakListRow);
        if (normalizedRow == null)
            continue;
        normalizedPeakList.addRow(normalizedRow);
    }
    // Add new peaklist to the project
    project.addPeakList(normalizedPeakList);
    // Load previous applied methods
    for (PeakListAppliedMethod proc : originalPeakList.getAppliedMethods()) {
        normalizedPeakList.addDescriptionOfAppliedTask(proc);
    }
    // Add task description to peakList
    normalizedPeakList.addDescriptionOfAppliedTask(new SimplePeakListAppliedMethod("Linear normalization of by " + normalizationType, parameters));
    // Remove the original peaklist if requested
    if (removeOriginal)
        project.removePeakList(originalPeakList);
    logger.info("Finished linear normalizer");
    setStatus(TaskStatus.FINISHED);
}
Also used : Hashtable(java.util.Hashtable) SimplePeakListAppliedMethod(net.sf.mzmine.datamodel.impl.SimplePeakListAppliedMethod) PeakListAppliedMethod(net.sf.mzmine.datamodel.PeakList.PeakListAppliedMethod) SimplePeakListAppliedMethod(net.sf.mzmine.datamodel.impl.SimplePeakListAppliedMethod) SimplePeakListRow(net.sf.mzmine.datamodel.impl.SimplePeakListRow) SimpleFeature(net.sf.mzmine.datamodel.impl.SimpleFeature) Feature(net.sf.mzmine.datamodel.Feature) SimpleFeature(net.sf.mzmine.datamodel.impl.SimpleFeature) SimplePeakListRow(net.sf.mzmine.datamodel.impl.SimplePeakListRow) PeakListRow(net.sf.mzmine.datamodel.PeakListRow) RawDataFile(net.sf.mzmine.datamodel.RawDataFile) Scan(net.sf.mzmine.datamodel.Scan) SimplePeakList(net.sf.mzmine.datamodel.impl.SimplePeakList)

Example 83 with Feature

use of net.sf.mzmine.datamodel.Feature in project mzmine2 by mzmine.

the class RTCalibrationTask method run.

public void run() {
    setStatus(TaskStatus.PROCESSING);
    logger.info("Running retention time normalizer");
    // First we need to find standards by iterating through first feature list
    totalRows = originalPeakLists[0].getNumberOfRows();
    // Create new feature lists
    normalizedPeakLists = new SimplePeakList[originalPeakLists.length];
    for (int i = 0; i < originalPeakLists.length; i++) {
        normalizedPeakLists[i] = new SimplePeakList(originalPeakLists[i] + " " + suffix, originalPeakLists[i].getRawDataFiles());
        // Remember how many rows we need to normalize
        totalRows += originalPeakLists[i].getNumberOfRows();
    }
    // goodStandards Vector contains identified standard rows, represented
    // by arrays. Each array has same length as originalPeakLists array.
    // Array items represent particular standard peak in each PeakList
    Vector<PeakListRow[]> goodStandards = new Vector<PeakListRow[]>();
    // Iterate the first peaklist
    standardIteration: for (PeakListRow candidate : originalPeakLists[0].getRows()) {
        // Cancel?
        if (isCanceled()) {
            return;
        }
        processedRows++;
        // Check that all peaks of this row have proper height
        for (Feature 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<Double> rtRange = rtTolerance.getToleranceRange(candidateRT);
            Range<Double> mzRange = mzTolerance.getToleranceRange(candidateMZ);
            PeakListRow[] matchingRows = originalPeakLists[i].getRowsInsideScanAndMZRange(rtRange, mzRange);
            // standard candidate
            if (matchingRows.length != 1)
                continue standardIteration;
            // Check that all peaks of this row have proper height
            for (Feature p : matchingRows[0].getPeaks()) {
                if (p.getHeight() < minHeight)
                    continue standardIteration;
            }
            // Save reference to matching peak in this feature 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);
        setErrorMessage("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 feature list
    for (int peakListIndex = 0; peakListIndex < originalPeakLists.length; peakListIndex++) {
        // Get standard rows for this feature 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], normalizedPeakLists[peakListIndex], standards, averagedRTs);
    }
    // Cancel?
    if (isCanceled()) {
        return;
    }
    for (int i = 0; i < originalPeakLists.length; i++) {
        project.addPeakList(normalizedPeakLists[i]);
        // Load previous applied methods
        for (PeakListAppliedMethod proc : originalPeakLists[i].getAppliedMethods()) {
            normalizedPeakLists[i].addDescriptionOfAppliedTask(proc);
        }
        // Add task description to peakList
        normalizedPeakLists[i].addDescriptionOfAppliedTask(new SimplePeakListAppliedMethod("Retention time normalization", parameters));
        // Remove the original peaklists if requested
        if (removeOriginal)
            project.removePeakList(originalPeakLists[i]);
    }
    logger.info("Finished retention time normalizer");
    setStatus(TaskStatus.FINISHED);
}
Also used : SimplePeakListRow(net.sf.mzmine.datamodel.impl.SimplePeakListRow) PeakListRow(net.sf.mzmine.datamodel.PeakListRow) SimplePeakListAppliedMethod(net.sf.mzmine.datamodel.impl.SimplePeakListAppliedMethod) PeakListAppliedMethod(net.sf.mzmine.datamodel.PeakList.PeakListAppliedMethod) SimplePeakList(net.sf.mzmine.datamodel.impl.SimplePeakList) Range(com.google.common.collect.Range) SimplePeakListAppliedMethod(net.sf.mzmine.datamodel.impl.SimplePeakListAppliedMethod) Vector(java.util.Vector) SimpleFeature(net.sf.mzmine.datamodel.impl.SimpleFeature) Feature(net.sf.mzmine.datamodel.Feature)

Example 84 with Feature

use of net.sf.mzmine.datamodel.Feature in project mzmine2 by mzmine.

the class RTCalibrationTask method normalizeRow.

/**
 * Normalize retention time of given row using selected standards
 *
 * @param originalRow Feature list row to be normalized
 * @param standards Standard rows in same feature list
 * @param normalizedStdRTs Normalized retention times of standard rows
 * @return New feature 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()) {
        Feature originalPeak = originalRow.getPeak(file);
        if (originalPeak != null) {
            SimpleFeature normalizedPeak = new SimpleFeature(originalPeak);
            PeakUtils.copyPeakProperties(originalPeak, normalizedPeak);
            normalizedPeak.setRT(normalizedRT);
            normalizedRow.addPeak(file, normalizedPeak);
        }
    }
    return normalizedRow;
}
Also used : SimplePeakListRow(net.sf.mzmine.datamodel.impl.SimplePeakListRow) PeakListRow(net.sf.mzmine.datamodel.PeakListRow) RawDataFile(net.sf.mzmine.datamodel.RawDataFile) SimplePeakListRow(net.sf.mzmine.datamodel.impl.SimplePeakListRow) SimpleFeature(net.sf.mzmine.datamodel.impl.SimpleFeature) Feature(net.sf.mzmine.datamodel.Feature) SimpleFeature(net.sf.mzmine.datamodel.impl.SimpleFeature)

Example 85 with Feature

use of net.sf.mzmine.datamodel.Feature in project mzmine2 by mzmine.

the class StandardCompoundNormalizerTask method run.

public void run() {
    setStatus(TaskStatus.PROCESSING);
    logger.finest("Starting standard compound normalization of " + originalPeakList + " using " + normalizationType + " (total " + standardRows.length + " standard peaks)");
    // Check if we have standards
    if (standardRows.length == 0) {
        setErrorMessage("No internal standard peaks selected");
        setStatus(TaskStatus.ERROR);
        return;
    }
    // Initialize new alignment result for the normalized result
    normalizedPeakList = new SimplePeakList(originalPeakList + " " + suffix, originalPeakList.getRawDataFiles());
    // Copy raw data files from original alignment result to new alignment
    // result
    totalRows = originalPeakList.getNumberOfRows();
    // Loop through all rows
    rowIteration: for (PeakListRow row : originalPeakList.getRows()) {
        // Cancel ?
        if (isCanceled()) {
            return;
        }
        // Do not add the standard rows to the new peaklist
        for (int i = 0; i < standardRows.length; i++) {
            if (row == standardRows[i]) {
                processedRows++;
                continue rowIteration;
            }
        }
        // Copy comment and identification
        SimplePeakListRow normalizedRow = new SimplePeakListRow(row.getID());
        PeakUtils.copyPeakListRowProperties(row, normalizedRow);
        // Get m/z and RT of the current row
        double mz = row.getAverageMZ();
        double rt = row.getAverageRT();
        // Loop through all raw data files
        for (RawDataFile file : originalPeakList.getRawDataFiles()) {
            double[] normalizationFactors = null;
            double[] normalizationFactorWeights = null;
            if (normalizationType == StandardUsageType.Nearest) {
                // Search for nearest standard
                PeakListRow nearestStandardRow = null;
                double nearestStandardRowDistance = Double.MAX_VALUE;
                for (int standardRowIndex = 0; standardRowIndex < standardRows.length; standardRowIndex++) {
                    PeakListRow standardRow = standardRows[standardRowIndex];
                    double stdMZ = standardRow.getAverageMZ();
                    double stdRT = standardRow.getAverageRT();
                    double distance = MZvsRTBalance * Math.abs(mz - stdMZ) + Math.abs(rt - stdRT);
                    if (distance <= nearestStandardRowDistance) {
                        nearestStandardRow = standardRow;
                        nearestStandardRowDistance = distance;
                    }
                }
                assert nearestStandardRow != null;
                // Calc and store a single normalization factor
                normalizationFactors = new double[1];
                normalizationFactorWeights = new double[1];
                Feature standardPeak = nearestStandardRow.getPeak(file);
                if (standardPeak == null) {
                    // What to do if standard peak is not available?
                    normalizationFactors[0] = 1.0;
                } else {
                    if (peakMeasurementType == PeakMeasurementType.HEIGHT) {
                        normalizationFactors[0] = standardPeak.getHeight();
                    } else {
                        normalizationFactors[0] = standardPeak.getArea();
                    }
                }
                logger.finest("Normalizing row #" + row.getID() + " using standard peak " + standardPeak + ", factor " + normalizationFactors[0]);
                normalizationFactorWeights[0] = 1.0f;
            }
            if (normalizationType == StandardUsageType.Weighted) {
                // Add all standards as factors, and use distance as weight
                normalizationFactors = new double[standardRows.length];
                normalizationFactorWeights = new double[standardRows.length];
                for (int standardRowIndex = 0; standardRowIndex < standardRows.length; standardRowIndex++) {
                    PeakListRow standardRow = standardRows[standardRowIndex];
                    double stdMZ = standardRow.getAverageMZ();
                    double stdRT = standardRow.getAverageRT();
                    double distance = MZvsRTBalance * Math.abs(mz - stdMZ) + Math.abs(rt - stdRT);
                    Feature standardPeak = standardRow.getPeak(file);
                    if (standardPeak == null) {
                        // What to do if standard peak is not available?
                        normalizationFactors[standardRowIndex] = 1.0;
                        normalizationFactorWeights[standardRowIndex] = 0.0;
                    } else {
                        if (peakMeasurementType == PeakMeasurementType.HEIGHT) {
                            normalizationFactors[standardRowIndex] = standardPeak.getHeight();
                        } else {
                            normalizationFactors[standardRowIndex] = standardPeak.getArea();
                        }
                        normalizationFactorWeights[standardRowIndex] = 1 / distance;
                    }
                }
            }
            assert normalizationFactors != null;
            assert normalizationFactorWeights != null;
            // Calculate a single normalization factor as weighted average
            // of all factors
            double weightedSum = 0.0f;
            double sumOfWeights = 0.0f;
            for (int factorIndex = 0; factorIndex < normalizationFactors.length; factorIndex++) {
                weightedSum += normalizationFactors[factorIndex] * normalizationFactorWeights[factorIndex];
                sumOfWeights += normalizationFactorWeights[factorIndex];
            }
            double normalizationFactor = weightedSum / sumOfWeights;
            // For simple scaling of the normalized values
            normalizationFactor = normalizationFactor / 100.0f;
            logger.finest("Normalizing row #" + row.getID() + "[" + file + "] using factor " + normalizationFactor);
            // How to handle zero normalization factor?
            if (normalizationFactor == 0.0)
                normalizationFactor = Double.MIN_VALUE;
            // Normalize peak
            Feature originalPeak = row.getPeak(file);
            if (originalPeak != null) {
                SimpleFeature normalizedPeak = new SimpleFeature(originalPeak);
                PeakUtils.copyPeakProperties(originalPeak, normalizedPeak);
                double normalizedHeight = originalPeak.getHeight() / normalizationFactor;
                double normalizedArea = originalPeak.getArea() / normalizationFactor;
                normalizedPeak.setHeight(normalizedHeight);
                normalizedPeak.setArea(normalizedArea);
                normalizedRow.addPeak(file, normalizedPeak);
            }
        }
        normalizedPeakList.addRow(normalizedRow);
        processedRows++;
    }
    // Add new peaklist to the project
    project.addPeakList(normalizedPeakList);
    // Load previous applied methods
    for (PeakListAppliedMethod proc : originalPeakList.getAppliedMethods()) {
        normalizedPeakList.addDescriptionOfAppliedTask(proc);
    }
    // Add task description to peakList
    normalizedPeakList.addDescriptionOfAppliedTask(new SimplePeakListAppliedMethod("Standard compound normalization", parameters));
    // Remove the original peaklist if requested
    if (removeOriginal)
        project.removePeakList(originalPeakList);
    logger.info("Finished standard compound normalizer");
    setStatus(TaskStatus.FINISHED);
}
Also used : SimplePeakListRow(net.sf.mzmine.datamodel.impl.SimplePeakListRow) PeakListRow(net.sf.mzmine.datamodel.PeakListRow) RawDataFile(net.sf.mzmine.datamodel.RawDataFile) SimplePeakListAppliedMethod(net.sf.mzmine.datamodel.impl.SimplePeakListAppliedMethod) PeakListAppliedMethod(net.sf.mzmine.datamodel.PeakList.PeakListAppliedMethod) SimplePeakList(net.sf.mzmine.datamodel.impl.SimplePeakList) SimplePeakListAppliedMethod(net.sf.mzmine.datamodel.impl.SimplePeakListAppliedMethod) SimplePeakListRow(net.sf.mzmine.datamodel.impl.SimplePeakListRow) SimpleFeature(net.sf.mzmine.datamodel.impl.SimpleFeature) Feature(net.sf.mzmine.datamodel.Feature) SimpleFeature(net.sf.mzmine.datamodel.impl.SimpleFeature)

Aggregations

Feature (net.sf.mzmine.datamodel.Feature)115 PeakListRow (net.sf.mzmine.datamodel.PeakListRow)70 RawDataFile (net.sf.mzmine.datamodel.RawDataFile)60 SimplePeakListRow (net.sf.mzmine.datamodel.impl.SimplePeakListRow)41 DataPoint (net.sf.mzmine.datamodel.DataPoint)35 SimpleFeature (net.sf.mzmine.datamodel.impl.SimpleFeature)35 SimplePeakList (net.sf.mzmine.datamodel.impl.SimplePeakList)25 Scan (net.sf.mzmine.datamodel.Scan)22 PeakList (net.sf.mzmine.datamodel.PeakList)20 ArrayList (java.util.ArrayList)17 SimplePeakListAppliedMethod (net.sf.mzmine.datamodel.impl.SimplePeakListAppliedMethod)16 IsotopePattern (net.sf.mzmine.datamodel.IsotopePattern)15 PeakIdentity (net.sf.mzmine.datamodel.PeakIdentity)15 SimpleDataPoint (net.sf.mzmine.datamodel.impl.SimpleDataPoint)13 PeakListAppliedMethod (net.sf.mzmine.datamodel.PeakList.PeakListAppliedMethod)10 MassList (net.sf.mzmine.datamodel.MassList)9 HashMap (java.util.HashMap)8 Vector (java.util.Vector)8 ScanSelection (net.sf.mzmine.parameters.parametertypes.selectors.ScanSelection)7 TreeMap (java.util.TreeMap)6