Search in sources :

Example 21 with MassList

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

the class ProjectTreeMouseHandler method handlePopupTriggerEvent.

private void handlePopupTriggerEvent(MouseEvent e) {
    TreePath clickedPath = tree.getPathForLocation(e.getX(), e.getY());
    if (clickedPath == null)
        return;
    DefaultMutableTreeNode node = (DefaultMutableTreeNode) clickedPath.getLastPathComponent();
    Object clickedObject = node.getUserObject();
    if (clickedObject instanceof RawDataFile)
        dataFilePopupMenu.show(e.getComponent(), e.getX(), e.getY());
    if (clickedObject instanceof Scan)
        scanPopupMenu.show(e.getComponent(), e.getX(), e.getY());
    if (clickedObject instanceof MassList)
        massListPopupMenu.show(e.getComponent(), e.getX(), e.getY());
    if (clickedObject instanceof PeakList)
        peakListPopupMenu.show(e.getComponent(), e.getX(), e.getY());
    if (clickedObject instanceof PeakListRow)
        peakListRowPopupMenu.show(e.getComponent(), e.getX(), e.getY());
}
Also used : PeakListRow(net.sf.mzmine.datamodel.PeakListRow) TreePath(javax.swing.tree.TreePath) DefaultMutableTreeNode(javax.swing.tree.DefaultMutableTreeNode) RawDataFile(net.sf.mzmine.datamodel.RawDataFile) Scan(net.sf.mzmine.datamodel.Scan) PeakList(net.sf.mzmine.datamodel.PeakList) MassList(net.sf.mzmine.datamodel.MassList)

Example 22 with MassList

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

the class ProjectTreeRenderer method getTreeCellRendererComponent.

public Component getTreeCellRendererComponent(JTree tree, Object node, boolean sel, boolean expanded, boolean leaf, int row, boolean hasFocus) {
    JLabel label = (JLabel) super.getTreeCellRendererComponent(tree, node, sel, expanded, leaf, row, hasFocus);
    DefaultMutableTreeNode treeNode = (DefaultMutableTreeNode) node;
    Object embeddedObject = treeNode.getUserObject();
    if (embeddedObject instanceof MZmineProject) {
        label.setIcon(projectIcon);
        label.setFont(bigFont);
    }
    if (embeddedObject == RawDataTreeModel.dataFilesNodeName) {
        label.setIcon(dataFileIcon);
        label.setFont(bigFont);
    }
    if (embeddedObject == PeakListTreeModel.peakListsNodeName) {
        label.setFont(bigFont);
        label.setIcon(peakListsIcon);
    }
    if (embeddedObject instanceof RawDataFile) {
        label.setFont(smallerFont);
        boolean hasMassList = RawDataFileUtils.hasMassLists((RawDataFile) embeddedObject);
        if (hasMassList)
            label.setIcon(fileWithMassListIcon);
        else
            label.setIcon(fileIcon);
    }
    if (embeddedObject instanceof Scan) {
        Scan s = (Scan) embeddedObject;
        label.setIcon(spectrumIcon);
        label.setFont(smallFont);
        // could get blue text on blue background
        if (!sel) {
            if (s.getMSLevel() > 1)
                label.setForeground(Color.red);
            else
                label.setForeground(Color.blue);
        }
    }
    if (embeddedObject instanceof MassList) {
        label.setIcon(peakListIcon);
        label.setFont(smallFont);
    }
    if (embeddedObject instanceof PeakList) {
        PeakList p = (PeakList) embeddedObject;
        if (p.getNumberOfRawDataFiles() > 1) {
            label.setFont(smallerFont.deriveFont(Font.BOLD));
            label.setIcon(alignedPeaklistIcon);
        } else {
            label.setFont(smallerFont);
            label.setIcon(peakListIcon);
        }
    }
    if (embeddedObject instanceof PeakListRow) {
        PeakListRow r = (PeakListRow) embeddedObject;
        label.setIcon(peakIcon);
        label.setFont(smallFont);
        // Change the color only if the row is not selected
        if (!sel) {
            if (r.getPreferredPeakIdentity() != null) {
                label.setForeground(Color.red);
            }
        }
    }
    return label;
}
Also used : PeakListRow(net.sf.mzmine.datamodel.PeakListRow) DefaultMutableTreeNode(javax.swing.tree.DefaultMutableTreeNode) RawDataFile(net.sf.mzmine.datamodel.RawDataFile) JLabel(javax.swing.JLabel) MZmineProject(net.sf.mzmine.datamodel.MZmineProject) Scan(net.sf.mzmine.datamodel.Scan) PeakList(net.sf.mzmine.datamodel.PeakList) MassList(net.sf.mzmine.datamodel.MassList)

Example 23 with MassList

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

the class ADAPChromatogramBuilderTask method run.

/**
 * @see Runnable#run()
 */
public void run() {
    boolean writeChromCDF = true;
    setStatus(TaskStatus.PROCESSING);
    logger.info("Started chromatogram builder on " + dataFile);
    scans = scanSelection.getMatchingScans(dataFile);
    int[] allScanNumbers = scanSelection.getMatchingScanNumbers(dataFile);
    List<Double> rtListForChromCDF = new ArrayList<Double>();
    // Check if the scans are properly ordered by RT
    double prevRT = Double.NEGATIVE_INFINITY;
    for (Scan s : scans) {
        if (isCanceled()) {
            return;
        }
        if (writeChromCDF) {
            rtListForChromCDF.add(s.getRetentionTime());
        }
        if (s.getRetentionTime() < prevRT) {
            setStatus(TaskStatus.ERROR);
            final String msg = "Retention time of scan #" + s.getScanNumber() + " is smaller then the retention time of the previous scan." + " Please make sure you only use scans with increasing retention times." + " You can restrict the scan numbers in the parameters, or you can use the Crop filter module";
            setErrorMessage(msg);
            return;
        }
        prevRT = s.getRetentionTime();
    }
    // Check if the scans are MS1-only or MS2-only.
    int minMsLevel = Arrays.stream(scans).mapToInt(Scan::getMSLevel).min().orElseThrow(() -> new IllegalStateException("Cannot find the minimum MS level"));
    int maxMsLevel = Arrays.stream(scans).mapToInt(Scan::getMSLevel).max().orElseThrow(() -> new IllegalStateException("Cannot find the maximum MS level"));
    if (minMsLevel != maxMsLevel) {
        MZmineCore.getDesktop().displayMessage(null, "MZmine thinks that you are running ADAP Chromatogram builder on both MS1- and MS2-scans. " + "This will likely produce wrong results. " + "Please, set the scan filter parameter to a specific MS level");
    }
    // Create new feature list
    newPeakList = new SimplePeakList(dataFile + " " + suffix, dataFile);
    // make a list of all the data points
    // sort data points by intensity
    // loop through list
    // add data point to chromatogrm or make new one
    // update mz avg and other stuff
    // 
    // make a list of all the data points
    List<ExpandedDataPoint> allMzValues = new ArrayList<ExpandedDataPoint>();
    for (Scan scan : scans) {
        if (isCanceled())
            return;
        MassList massList = scan.getMassList(massListName);
        if (massList == null) {
            setStatus(TaskStatus.ERROR);
            setErrorMessage("Scan " + dataFile + " #" + scan.getScanNumber() + " does not have a mass list " + massListName);
            return;
        }
        DataPoint[] mzValues = massList.getDataPoints();
        if (mzValues == null) {
            setStatus(TaskStatus.ERROR);
            setErrorMessage("Mass list " + massListName + " does not contain m/z values for scan #" + scan.getScanNumber() + " of file " + dataFile);
            return;
        }
        for (DataPoint mzPeak : mzValues) {
            ExpandedDataPoint curDatP = new ExpandedDataPoint(mzPeak, scan.getScanNumber());
            allMzValues.add(curDatP);
        // corespondingScanNum.add(scan.getScanNumber());
        }
    }
    // Integer[] simpleCorespondingScanNums = new Integer[corespondingScanNum.size()];
    // corespondingScanNum.toArray(simpleCorespondingScanNums );
    ExpandedDataPoint[] simpleAllMzVals = new ExpandedDataPoint[allMzValues.size()];
    allMzValues.toArray(simpleAllMzVals);
    // sort data points by intensity
    Arrays.sort(simpleAllMzVals, new DataPointSorter(SortingProperty.Intensity, SortingDirection.Descending));
    // Exit if no peaks
    if (simpleAllMzVals.length == 0) {
        progress = 1.0;
        setStatus(TaskStatus.FINISHED);
        logger.info("Finished chromatogram builder with no peaks on " + dataFile);
        return;
    }
    double maxIntensity = simpleAllMzVals[0].getIntensity();
    // count starts at 1 since we already have added one with a single point.
    // Stopwatch stopwatch = Stopwatch.createUnstarted();
    // stopwatch2 = Stopwatch.createUnstarted();
    // Stopwatch stopwatch3 = Stopwatch.createUnstarted();
    progress = 0.0;
    double progressStep = (simpleAllMzVals.length > 0) ? 0.5 / simpleAllMzVals.length : 0.0;
    for (ExpandedDataPoint mzPeak : simpleAllMzVals) {
        progress += progressStep;
        if (isCanceled()) {
            return;
        }
        if (mzPeak == null || Double.isNaN(mzPeak.getMZ()) || Double.isNaN(mzPeak.getIntensity())) {
            continue;
        }
        // ////////////////////////////////////////////////
        Range<Double> containsPointRange = rangeSet.rangeContaining(mzPeak.getMZ());
        Range<Double> toleranceRange = mzTolerance.getToleranceRange(mzPeak.getMZ());
        if (containsPointRange == null) {
            // skip it entierly if the intensity is not high enough
            if (mzPeak.getIntensity() < minIntensityForStartChrom) {
                continue;
            }
            // look +- mz tolerance to see if ther is a range near by.
            // If there is use the proper boundry of that range for the
            // new range to insure than NON OF THE RANGES OVERLAP.
            Range<Double> plusRange = rangeSet.rangeContaining(toleranceRange.upperEndpoint());
            Range<Double> minusRange = rangeSet.rangeContaining(toleranceRange.lowerEndpoint());
            Double toBeLowerBound;
            Double toBeUpperBound;
            double cur_max_testing_mz = mzPeak.getMZ();
            // chromatogram so that none of the points are overlapping.
            if ((plusRange == null) && (minusRange == null)) {
                toBeLowerBound = toleranceRange.lowerEndpoint();
                toBeUpperBound = toleranceRange.upperEndpoint();
            } else if ((plusRange == null) && (minusRange != null)) {
                // the upper end point of the minus range will be the lower
                // range of the new one
                toBeLowerBound = minusRange.upperEndpoint();
                toBeUpperBound = toleranceRange.upperEndpoint();
            } else if ((minusRange == null) && (plusRange != null)) {
                toBeLowerBound = toleranceRange.lowerEndpoint();
                toBeUpperBound = plusRange.lowerEndpoint();
            // double tmp_this = plusRange.upperEndpoint();
            // System.out.println("tmp_this");
            } else if ((minusRange != null) && (plusRange != null)) {
                toBeLowerBound = minusRange.upperEndpoint();
                toBeUpperBound = plusRange.lowerEndpoint();
            } else {
                toBeLowerBound = 0.0;
                toBeUpperBound = 0.0;
            }
            if (toBeLowerBound < toBeUpperBound) {
                Range<Double> newRange = Range.open(toBeLowerBound, toBeUpperBound);
                ADAPChromatogram newChrom = new ADAPChromatogram(dataFile, allScanNumbers);
                newChrom.addMzPeak(mzPeak.getScanNumber(), mzPeak);
                newChrom.setHighPointMZ(mzPeak.getMZ());
                rangeToChromMap.put(newRange, newChrom);
                // also need to put it in the set -> this is where the range can be efficiently found.
                rangeSet.add(newRange);
            } else if (toBeLowerBound.equals(toBeUpperBound) && plusRange != null) {
                ADAPChromatogram curChrom = rangeToChromMap.get(plusRange);
                curChrom.addMzPeak(mzPeak.getScanNumber(), mzPeak);
            } else
                throw new IllegalStateException(String.format("Incorrect range [%f, %f] for m/z %f", toBeLowerBound, toBeUpperBound, mzPeak.getMZ()));
        } else {
            // In this case we do not need to update the rangeSet
            ADAPChromatogram curChrom = rangeToChromMap.get(containsPointRange);
            curChrom.addMzPeak(mzPeak.getScanNumber(), mzPeak);
            // update the entry in the map
            rangeToChromMap.put(containsPointRange, curChrom);
        }
    }
    // System.out.println("search chroms (ms): " + stopwatch.elapsed(TimeUnit.MILLISECONDS));
    // System.out.println("making new chrom (ms): " + stopwatch2.elapsed(TimeUnit.MILLISECONDS));
    // finish chromatograms
    Set<Range<Double>> ranges = rangeSet.asRanges();
    Iterator<Range<Double>> RangeIterator = ranges.iterator();
    List<ADAPChromatogram> buildingChromatograms = new ArrayList<ADAPChromatogram>();
    progressStep = (ranges.size() > 0) ? 0.5 / ranges.size() : 0.0;
    while (RangeIterator.hasNext()) {
        if (isCanceled()) {
            return;
        }
        progress += progressStep;
        Range<Double> curRangeKey = RangeIterator.next();
        ADAPChromatogram chromatogram = rangeToChromMap.get(curRangeKey);
        chromatogram.finishChromatogram();
        // And remove chromatograms who dont have a certian number of continous points above the
        // IntensityThresh2 level.
        double numberOfContinuousPointsAboveNoise = chromatogram.findNumberOfContinuousPointsAboveNoise(IntensityThresh2);
        if (numberOfContinuousPointsAboveNoise < minimumScanSpan) {
            // requirements");
            continue;
        } else {
            buildingChromatograms.add(chromatogram);
        }
    }
    ADAPChromatogram[] chromatograms = buildingChromatograms.toArray(new ADAPChromatogram[0]);
    // Sort the final chromatograms by m/z
    Arrays.sort(chromatograms, new PeakSorter(SortingProperty.MZ, SortingDirection.Ascending));
    // Add the chromatograms to the new feature list
    for (Feature finishedPeak : chromatograms) {
        SimplePeakListRow newRow = new SimplePeakListRow(newPeakID);
        newPeakID++;
        newRow.addPeak(dataFile, finishedPeak);
        newPeakList.addRow(newRow);
    // finishedPeak.outputChromToFile();
    }
    // Add new peaklist to the project
    project.addPeakList(newPeakList);
    // Add quality parameters to peaks
    QualityParameters.calculateQualityParameters(newPeakList);
    progress = 1.0;
    setStatus(TaskStatus.FINISHED);
    logger.info("Finished chromatogram builder on " + dataFile);
}
Also used : Feature(net.sf.mzmine.datamodel.Feature) SimplePeakListRow(net.sf.mzmine.datamodel.impl.SimplePeakListRow) DataPoint(net.sf.mzmine.datamodel.DataPoint) PeakSorter(net.sf.mzmine.util.PeakSorter) SimplePeakList(net.sf.mzmine.datamodel.impl.SimplePeakList) Range(com.google.common.collect.Range) DataPoint(net.sf.mzmine.datamodel.DataPoint) DataPointSorter(net.sf.mzmine.util.DataPointSorter) Scan(net.sf.mzmine.datamodel.Scan) MassList(net.sf.mzmine.datamodel.MassList)

Example 24 with MassList

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

the class RawDataTreeModel method addObject.

/**
 * This method must be called from Swing thread
 */
public void addObject(final Object object) {
    assert object != null;
    if (!SwingUtilities.isEventDispatchThread()) {
        throw new IllegalStateException("This method must be called from Swing thread");
    }
    // Create new node
    final DefaultMutableTreeNode newNode = new DefaultMutableTreeNode(object);
    treeObjects.put(object, newNode);
    if (object instanceof RawDataFile) {
        int childCount = getChildCount(rootNode);
        insertNodeInto(newNode, rootNode, childCount);
        RawDataFile dataFile = (RawDataFile) object;
        int[] scanNumbers = dataFile.getScanNumbers();
        for (int i = 0; i < scanNumbers.length; i++) {
            Scan scan = dataFile.getScan(scanNumbers[i]);
            DefaultMutableTreeNode scanNode = new DefaultMutableTreeNode(scan);
            treeObjects.put(scan, scanNode);
            insertNodeInto(scanNode, newNode, i);
            MassList[] massLists = scan.getMassLists();
            for (int j = 0; j < massLists.length; j++) {
                DefaultMutableTreeNode mlNode = new DefaultMutableTreeNode(massLists[j]);
                treeObjects.put(massLists[j], mlNode);
                insertNodeInto(mlNode, scanNode, j);
            }
        }
    }
    if (object instanceof MassList) {
        Scan scan = ((MassList) object).getScan();
        final DefaultMutableTreeNode scNode = treeObjects.get(scan);
        assert scNode != null;
        int index = scNode.getChildCount();
        insertNodeInto(newNode, scNode, index);
    }
}
Also used : DefaultMutableTreeNode(javax.swing.tree.DefaultMutableTreeNode) RawDataFile(net.sf.mzmine.datamodel.RawDataFile) Scan(net.sf.mzmine.datamodel.Scan) MassList(net.sf.mzmine.datamodel.MassList)

Example 25 with MassList

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

the class FormulaPredictionPeakListTask method checkConstraints.

private boolean checkConstraints(IMolecularFormula cdkFormula, PeakListRow peakListRow) {
    // Check elemental ratios
    if (checkRatios) {
        boolean check = ElementalHeuristicChecker.checkFormula(cdkFormula, ratiosParameters);
        if (!check) {
            return false;
        }
    }
    Double rdbeValue = RDBERestrictionChecker.calculateRDBE(cdkFormula);
    // Check RDBE condition
    if (checkRDBE && (rdbeValue != null)) {
        boolean check = RDBERestrictionChecker.checkRDBE(rdbeValue, rdbeParameters);
        if (!check) {
            return false;
        }
    }
    // Calculate isotope similarity score
    IsotopePattern detectedPattern = peakListRow.getBestIsotopePattern();
    IsotopePattern predictedIsotopePattern = null;
    Double isotopeScore = null;
    if ((checkIsotopes) && (detectedPattern != null)) {
        String stringFormula = MolecularFormulaManipulator.getString(cdkFormula);
        String adjustedFormula = FormulaUtils.ionizeFormula(stringFormula, ionType, charge);
        final double isotopeNoiseLevel = isotopeParameters.getParameter(IsotopePatternScoreParameters.isotopeNoiseLevel).getValue();
        final double detectedPatternHeight = detectedPattern.getHighestDataPoint().getIntensity();
        final double minPredictedAbundance = isotopeNoiseLevel / detectedPatternHeight;
        predictedIsotopePattern = IsotopePatternCalculator.calculateIsotopePattern(adjustedFormula, minPredictedAbundance, charge, ionType.getPolarity());
        isotopeScore = IsotopePatternScoreCalculator.getSimilarityScore(detectedPattern, predictedIsotopePattern, isotopeParameters);
        final double minScore = isotopeParameters.getParameter(IsotopePatternScoreParameters.isotopePatternScoreThreshold).getValue();
        if (isotopeScore < minScore) {
            return false;
        }
    }
    // MS/MS evaluation is slowest, so let's do it last
    Double msmsScore = null;
    Feature bestPeak = peakListRow.getBestPeak();
    RawDataFile dataFile = bestPeak.getDataFile();
    int msmsScanNumber = bestPeak.getMostIntenseFragmentScanNumber();
    if ((checkMSMS) && (msmsScanNumber > 0)) {
        Scan msmsScan = dataFile.getScan(msmsScanNumber);
        String massListName = msmsParameters.getParameter(MSMSScoreParameters.massList).getValue();
        MassList ms2MassList = msmsScan.getMassList(massListName);
        if (ms2MassList == null) {
            setStatus(TaskStatus.ERROR);
            setErrorMessage("The MS/MS scan #" + msmsScanNumber + " in file " + dataFile.getName() + " does not have a mass list called '" + massListName + "'");
            return false;
        }
        MSMSScore score = MSMSScoreCalculator.evaluateMSMS(cdkFormula, msmsScan, msmsParameters);
        double minMSMSScore = msmsParameters.getParameter(MSMSScoreParameters.msmsMinScore).getValue();
        if (score != null) {
            msmsScore = score.getScore();
            // Check the MS/MS condition
            if (msmsScore < minMSMSScore) {
                return false;
            }
        }
    }
    return true;
}
Also used : RawDataFile(net.sf.mzmine.datamodel.RawDataFile) IsotopePattern(net.sf.mzmine.datamodel.IsotopePattern) Scan(net.sf.mzmine.datamodel.Scan) Feature(net.sf.mzmine.datamodel.Feature) MassList(net.sf.mzmine.datamodel.MassList) MSMSScore(net.sf.mzmine.modules.peaklistmethods.msms.msmsscore.MSMSScore)

Aggregations

MassList (net.sf.mzmine.datamodel.MassList)36 Scan (net.sf.mzmine.datamodel.Scan)25 DataPoint (net.sf.mzmine.datamodel.DataPoint)24 RawDataFile (net.sf.mzmine.datamodel.RawDataFile)14 Feature (net.sf.mzmine.datamodel.Feature)9 PeakListRow (net.sf.mzmine.datamodel.PeakListRow)9 ArrayList (java.util.ArrayList)6 DefaultMutableTreeNode (javax.swing.tree.DefaultMutableTreeNode)5 PeakList (net.sf.mzmine.datamodel.PeakList)5 SimpleDataPoint (net.sf.mzmine.datamodel.impl.SimpleDataPoint)4 SimplePeakListRow (net.sf.mzmine.datamodel.impl.SimplePeakListRow)4 Range (com.google.common.collect.Range)3 FileWriter (java.io.FileWriter)3 IOException (java.io.IOException)3 TreePath (javax.swing.tree.TreePath)3 IsotopePattern (net.sf.mzmine.datamodel.IsotopePattern)3 MZmineProject (net.sf.mzmine.datamodel.MZmineProject)3 MergedSpectrum (net.sf.mzmine.modules.tools.msmsspectramerge.MergedSpectrum)3 MsMsSpectraMergeModule (net.sf.mzmine.modules.tools.msmsspectramerge.MsMsSpectraMergeModule)3 BufferedWriter (java.io.BufferedWriter)2