Search in sources :

Example 1 with HistogramData

use of net.sf.mzmine.modules.visualization.mzhistogram.chart.HistogramData in project mzmine2 by mzmine.

the class MZDistributionHistoTask method run.

/**
 * @see Runnable#run()
 */
public void run() {
    setStatus(TaskStatus.PROCESSING);
    logger.info("Starting to build mz distribution histogram for " + dataFile);
    // all selected scans
    scans = scanSelection.getMatchingScans(dataFile);
    totalScans = scans.length;
    // histo data
    DoubleArrayList data = new DoubleArrayList();
    for (Scan scan : scans) {
        if (isCanceled())
            return;
        // retention time in range
        if (!useRTRange || rtRange.contains(scan.getRetentionTime())) {
            // go through all mass lists
            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();
            // insert all mz in order and count them
            Arrays.stream(mzValues).mapToDouble(dp -> dp.getMZ()).filter(mz -> mzRange.contains(mz)).forEach(mz -> data.add(mz));
            processedScans++;
        }
    }
    if (!data.isEmpty()) {
        // to array
        double[] histo = new double[data.size()];
        for (int i = 0; i < data.size(); i++) histo[i] = data.get(i);
        // create histogram dialog
        EHistogramDialog dialog = new EHistogramDialog("m/z distribution", "m/z", new HistogramData(histo), binWidth);
        dialog.setVisible(true);
    } else {
        throw new MSDKRuntimeException("Data was empty. Review your selected filters.");
    }
    setStatus(TaskStatus.FINISHED);
    logger.info("Finished mz distribution histogram on " + dataFile);
}
Also used : HistogramData(net.sf.mzmine.modules.visualization.mzhistogram.chart.HistogramData) Scan(net.sf.mzmine.datamodel.Scan) Arrays(java.util.Arrays) EHistogramDialog(net.sf.mzmine.modules.visualization.mzhistogram.chart.EHistogramDialog) TaskStatus(net.sf.mzmine.taskcontrol.TaskStatus) Range(com.google.common.collect.Range) RawDataFile(net.sf.mzmine.datamodel.RawDataFile) Logger(java.util.logging.Logger) DataPoint(net.sf.mzmine.datamodel.DataPoint) MassList(net.sf.mzmine.datamodel.MassList) DoubleArrayList(it.unimi.dsi.fastutil.doubles.DoubleArrayList) ParameterSet(net.sf.mzmine.parameters.ParameterSet) AbstractTask(net.sf.mzmine.taskcontrol.AbstractTask) MZmineProject(net.sf.mzmine.datamodel.MZmineProject) MSDKRuntimeException(io.github.msdk.MSDKRuntimeException) ScanSelection(net.sf.mzmine.parameters.parametertypes.selectors.ScanSelection) HistogramData(net.sf.mzmine.modules.visualization.mzhistogram.chart.HistogramData) DataPoint(net.sf.mzmine.datamodel.DataPoint) EHistogramDialog(net.sf.mzmine.modules.visualization.mzhistogram.chart.EHistogramDialog) MSDKRuntimeException(io.github.msdk.MSDKRuntimeException) Scan(net.sf.mzmine.datamodel.Scan) DoubleArrayList(it.unimi.dsi.fastutil.doubles.DoubleArrayList) MassList(net.sf.mzmine.datamodel.MassList) DataPoint(net.sf.mzmine.datamodel.DataPoint)

Aggregations

Range (com.google.common.collect.Range)1 MSDKRuntimeException (io.github.msdk.MSDKRuntimeException)1 DoubleArrayList (it.unimi.dsi.fastutil.doubles.DoubleArrayList)1 Arrays (java.util.Arrays)1 Logger (java.util.logging.Logger)1 DataPoint (net.sf.mzmine.datamodel.DataPoint)1 MZmineProject (net.sf.mzmine.datamodel.MZmineProject)1 MassList (net.sf.mzmine.datamodel.MassList)1 RawDataFile (net.sf.mzmine.datamodel.RawDataFile)1 Scan (net.sf.mzmine.datamodel.Scan)1 EHistogramDialog (net.sf.mzmine.modules.visualization.mzhistogram.chart.EHistogramDialog)1 HistogramData (net.sf.mzmine.modules.visualization.mzhistogram.chart.HistogramData)1 ParameterSet (net.sf.mzmine.parameters.ParameterSet)1 ScanSelection (net.sf.mzmine.parameters.parametertypes.selectors.ScanSelection)1 AbstractTask (net.sf.mzmine.taskcontrol.AbstractTask)1 TaskStatus (net.sf.mzmine.taskcontrol.TaskStatus)1