Search in sources :

Example 11 with Desktop

use of net.sf.mzmine.desktop.Desktop in project mzmine2 by mzmine.

the class Fx3DSamplingTask method run.

/**
 * @see java.lang.Runnable#run()
 */
public void run() {
    setStatus(TaskStatus.PROCESSING);
    logger.info("Started sampling 3D plot of " + dataFile);
    try {
        final double rtStep = (rtRange.upperEndpoint() - rtRange.lowerEndpoint()) / rtResolution;
        // create an array for all data points
        float[][] intensityValues = new float[1][mzResolution * rtResolution];
        boolean[] rtDataSet = new boolean[rtResolution];
        // load scans
        for (int scanIndex = 0; scanIndex < scans.length; scanIndex++) {
            if (isCanceled())
                return;
            Scan scan = scans[scanIndex];
            final Desktop desktop = MZmineCore.getDesktop();
            // Check scan numbers.
            if (scans.length == 0) {
                desktop.displayErrorMessage(MZmineCore.getDesktop().getMainWindow(), "No scans found");
                return;
            }
            DataPoint[] dataPoints = scan.getDataPoints();
            double[] scanMZValues = new double[dataPoints.length];
            double[] scanIntensityValues = new double[dataPoints.length];
            for (int dp = 0; dp < dataPoints.length; dp++) {
                scanMZValues[dp] = dataPoints[dp].getMZ();
                scanIntensityValues[dp] = dataPoints[dp].getIntensity();
            }
            double[] binnedIntensities = ScanUtils.binValues(scanMZValues, scanIntensityValues, mzRange, mzResolution, scan.getSpectrumType() != MassSpectrumType.CENTROIDED, BinningType.MAX);
            int scanBinIndex;
            double rt = scan.getRetentionTime();
            scanBinIndex = (int) ((rt - rtRange.lowerEndpoint()) / rtStep);
            // last scan falls into last bin
            if (scanBinIndex == rtResolution) {
                scanBinIndex--;
            }
            for (int mzIndex = 0; mzIndex < mzResolution; mzIndex++) {
                int intensityValuesIndex = (rtResolution * mzIndex) + scanBinIndex;
                if (binnedIntensities[mzIndex] > intensityValues[0][intensityValuesIndex]) {
                    intensityValues[0][intensityValuesIndex] = (float) binnedIntensities[mzIndex];
                }
                if (intensityValues[0][intensityValuesIndex] > maxBinnedIntensity)
                    maxBinnedIntensity = (double) binnedIntensities[mzIndex];
            }
            rtDataSet[scanBinIndex] = true;
            retrievedScans++;
        }
        // Interpolate missing values on the RT-axis
        for (int rtIndex = 1; rtIndex < rtResolution - 1; rtIndex++) {
            // If the data was set, go to next RT line
            if (rtDataSet[rtIndex])
                continue;
            int prevIndex, nextIndex;
            for (prevIndex = rtIndex - 1; prevIndex >= 0; prevIndex--) {
                if (rtDataSet[prevIndex])
                    break;
            }
            for (nextIndex = rtIndex + 1; nextIndex < rtResolution; nextIndex++) {
                if (rtDataSet[nextIndex])
                    break;
            }
            // If no neighboring data was found, give up
            if ((prevIndex < 0) || (nextIndex >= rtResolution))
                continue;
            for (int mzIndex = 0; mzIndex < mzResolution; mzIndex++) {
                int valueIndex = (rtResolution * mzIndex) + rtIndex;
                int nextValueIndex = (rtResolution * mzIndex) + nextIndex;
                int prevValueIndex = (rtResolution * mzIndex) + prevIndex;
                double prevValue = intensityValues[0][prevValueIndex];
                double nextValue = intensityValues[0][nextValueIndex];
                double slope = (nextValue - prevValue) / (nextIndex - prevIndex);
                intensityValues[0][valueIndex] = (float) (prevValue + (slope * (rtIndex - prevIndex)));
            }
        }
        float[][] finalIntensityValues = new float[rtResolution][mzResolution];
        for (int rtIndex = 0; rtIndex < rtResolution; rtIndex++) {
            for (int mzIndex = 0; mzIndex < mzResolution; mzIndex++) {
                int valueIndex = (rtResolution * mzIndex) + rtIndex;
                finalIntensityValues[rtIndex][mzIndex] = (float) (intensityValues[0][valueIndex] / maxBinnedIntensity);
            }
        }
        Fx3DRawDataFileDataset plotMesh = new Fx3DRawDataFileDataset(dataFile, finalIntensityValues, rtResolution, mzResolution, maxBinnedIntensity, dataFile.toString(), PEAK_COLORS[random.nextInt(14)]);
        Platform.runLater(() -> {
            controller.addDataset(plotMesh);
        });
    } catch (Throwable e) {
        setStatus(TaskStatus.ERROR);
        setErrorMessage("Error while sampling 3D data," + ExceptionUtils.exceptionToString(e));
        return;
    }
    logger.info("Finished sampling 3D plot of " + dataFile);
    setStatus(TaskStatus.FINISHED);
}
Also used : Desktop(net.sf.mzmine.desktop.Desktop) DataPoint(net.sf.mzmine.datamodel.DataPoint) Scan(net.sf.mzmine.datamodel.Scan) DataPoint(net.sf.mzmine.datamodel.DataPoint)

Example 12 with Desktop

use of net.sf.mzmine.desktop.Desktop in project mzmine2 by mzmine.

the class SpectraIdentificationSpectralDatabaseTask method run.

/**
 * @see java.lang.Runnable#run()
 */
@Override
public void run() {
    setStatus(TaskStatus.PROCESSING);
    int count = 0;
    // add result frame
    resultWindow = new SpectraIdentificationResultsWindow();
    resultWindow.setVisible(true);
    try {
        tasks = parseFile(dataBaseFile);
        totalTasks = tasks.size();
        if (!tasks.isEmpty()) {
            // wait for the tasks to finish
            while (!isCanceled() && !tasks.isEmpty()) {
                for (int i = 0; i < tasks.size(); i++) {
                    if (tasks.get(i).isFinished() || tasks.get(i).isCanceled()) {
                        count += tasks.get(i).getCount();
                        tasks.remove(i);
                        i--;
                    }
                }
                // wait for all sub tasks to finish
                try {
                    Thread.sleep(100);
                } catch (Exception e) {
                    cancel();
                }
            }
            // cancelled
            if (isCanceled()) {
                tasks.stream().forEach(AbstractTask::cancel);
            }
        } else {
            setStatus(TaskStatus.ERROR);
            setErrorMessage("DB file was empty - or error while parsing " + dataBaseFile);
            return;
        }
    } catch (Exception e) {
        logger.log(Level.SEVERE, "Could not read file " + dataBaseFile, e);
        setStatus(TaskStatus.ERROR);
        setErrorMessage(e.toString());
    }
    logger.info("Added " + count + " spectral library matches");
    resultWindow.setTitle("Matched " + count + " compounds for scan#" + currentScan.getScanNumber());
    resultWindow.setMatchingFinished();
    resultWindow.revalidate();
    resultWindow.repaint();
    // Repaint the window
    Desktop desktop = MZmineCore.getDesktop();
    if (!(desktop instanceof HeadLessDesktop))
        desktop.getMainWindow().repaint();
    setStatus(TaskStatus.FINISHED);
}
Also used : AbstractTask(net.sf.mzmine.taskcontrol.AbstractTask) HeadLessDesktop(net.sf.mzmine.desktop.impl.HeadLessDesktop) Desktop(net.sf.mzmine.desktop.Desktop) SpectraIdentificationResultsWindow(net.sf.mzmine.modules.visualization.spectra.spectralmatchresults.SpectraIdentificationResultsWindow) IOException(java.io.IOException) UnsupportedFormatException(net.sf.mzmine.util.spectraldb.parser.UnsupportedFormatException) HeadLessDesktop(net.sf.mzmine.desktop.impl.HeadLessDesktop)

Example 13 with Desktop

use of net.sf.mzmine.desktop.Desktop in project mzmine2 by mzmine.

the class CameraSearchTask method run.

@Override
public void run() {
    try {
        setStatus(TaskStatus.PROCESSING);
        // Check number of raw data files.
        if (peakList.getNumberOfRawDataFiles() != 1) {
            throw new IllegalStateException("CAMERA can only process feature lists for a single raw data file, i.e. non-aligned feature lists.");
        }
        // Run the search.
        cameraSearch(peakList.getRawDataFile(0));
        // Create new list with IsotopePattern information
        PeakList newPeakList = null;
        if (parameters.getParameter(CameraSearchParameters.CREATE_NEW_LIST).getValue()) {
            switch(groupBy) {
                case CameraSearchParameters.GROUP_BY_PCGROUP:
                    newPeakList = groupPeaksByPCGroup(peakList);
                    break;
                default:
                    newPeakList = groupPeaksByIsotope(peakList);
            }
        }
        if (!isCanceled()) {
            if (newPeakList != null) {
                project.addPeakList(newPeakList);
                QualityParameters.calculateQualityParameters(newPeakList);
            }
            // Finished.
            setStatus(TaskStatus.FINISHED);
            LOG.info("CAMERA Search completed");
        }
        // Repaint the window to reflect the change in the feature list
        Desktop desktop = MZmineCore.getDesktop();
        if (!(desktop instanceof HeadLessDesktop))
            desktop.getMainWindow().repaint();
    } catch (Throwable t) {
        LOG.log(Level.SEVERE, "CAMERA Search error", t);
        setErrorMessage(t.getMessage());
        setStatus(TaskStatus.ERROR);
    }
}
Also used : HeadLessDesktop(net.sf.mzmine.desktop.impl.HeadLessDesktop) Desktop(net.sf.mzmine.desktop.Desktop) SimplePeakList(net.sf.mzmine.datamodel.impl.SimplePeakList) PeakList(net.sf.mzmine.datamodel.PeakList) HeadLessDesktop(net.sf.mzmine.desktop.impl.HeadLessDesktop)

Example 14 with Desktop

use of net.sf.mzmine.desktop.Desktop in project mzmine2 by mzmine.

the class ComplexSearchTask method run.

/**
 * @see java.lang.Runnable#run()
 */
public void run() {
    setStatus(TaskStatus.PROCESSING);
    logger.info("Starting complex search in " + peakList);
    PeakListRow[] rows = peakList.getRows();
    totalRows = rows.length;
    // Sort the array by m/z so we start with biggest peak (possible
    // complex)
    Arrays.sort(rows, new PeakListRowSorter(SortingProperty.MZ, SortingDirection.Descending));
    // Compare each three rows against each other
    for (int i = 0; i < totalRows; i++) {
        Range<Double> testRTRange = rtTolerance.getToleranceRange(rows[i].getAverageRT());
        PeakListRow[] testRows = peakList.getRowsInsideScanRange(testRTRange);
        for (int j = 0; j < testRows.length; j++) {
            for (int k = j; k < testRows.length; k++) {
                // Task canceled?
                if (isCanceled())
                    return;
                // very small m/z peak
                if ((rows[i] == testRows[j]) || (rows[i] == testRows[k]))
                    continue;
                if (checkComplex(rows[i], testRows[j], testRows[k]))
                    addComplexInfo(rows[i], testRows[j], testRows[k]);
            }
        }
        finishedRows++;
    }
    // Add task description to peakList
    ((SimplePeakList) peakList).addDescriptionOfAppliedTask(new SimplePeakListAppliedMethod("Identification of complexes", parameters));
    // Repaint the window to reflect the change in the feature list
    Desktop desktop = MZmineCore.getDesktop();
    if (!(desktop instanceof HeadLessDesktop))
        desktop.getMainWindow().repaint();
    setStatus(TaskStatus.FINISHED);
    logger.info("Finished complexes search in " + peakList);
}
Also used : PeakListRow(net.sf.mzmine.datamodel.PeakListRow) HeadLessDesktop(net.sf.mzmine.desktop.impl.HeadLessDesktop) Desktop(net.sf.mzmine.desktop.Desktop) SimplePeakList(net.sf.mzmine.datamodel.impl.SimplePeakList) SimplePeakListAppliedMethod(net.sf.mzmine.datamodel.impl.SimplePeakListAppliedMethod) PeakListRowSorter(net.sf.mzmine.util.PeakListRowSorter) HeadLessDesktop(net.sf.mzmine.desktop.impl.HeadLessDesktop)

Example 15 with Desktop

use of net.sf.mzmine.desktop.Desktop in project mzmine2 by mzmine.

the class SortSpectralDBIdentitiesTask method run.

/**
 * @see java.lang.Runnable#run()
 */
@Override
public void run() {
    setStatus(TaskStatus.PROCESSING);
    totalRows = peakList.getNumberOfRows();
    finishedRows = 0;
    for (PeakListRow row : peakList.getRows()) {
        if (isCanceled()) {
            return;
        }
        // sort identities of row
        sortIdentities(row, filterByMinScore, minScore);
        finishedRows++;
    }
    // Add task description to peakList
    peakList.addDescriptionOfAppliedTask(new SimplePeakListAppliedMethod("Sorted spectral database identities of DB search ", parameters));
    // Repaint the window to reflect the change in the feature list
    Desktop desktop = MZmineCore.getDesktop();
    if (!(desktop instanceof HeadLessDesktop))
        desktop.getMainWindow().repaint();
    setStatus(TaskStatus.FINISHED);
}
Also used : PeakListRow(net.sf.mzmine.datamodel.PeakListRow) HeadLessDesktop(net.sf.mzmine.desktop.impl.HeadLessDesktop) Desktop(net.sf.mzmine.desktop.Desktop) SimplePeakListAppliedMethod(net.sf.mzmine.datamodel.impl.SimplePeakListAppliedMethod) HeadLessDesktop(net.sf.mzmine.desktop.impl.HeadLessDesktop)

Aggregations

Desktop (net.sf.mzmine.desktop.Desktop)22 HeadLessDesktop (net.sf.mzmine.desktop.impl.HeadLessDesktop)17 SimplePeakListAppliedMethod (net.sf.mzmine.datamodel.impl.SimplePeakListAppliedMethod)10 SimplePeakList (net.sf.mzmine.datamodel.impl.SimplePeakList)6 IOException (java.io.IOException)5 PeakListRow (net.sf.mzmine.datamodel.PeakListRow)5 DataPoint (net.sf.mzmine.datamodel.DataPoint)4 AbstractTask (net.sf.mzmine.taskcontrol.AbstractTask)4 UnsupportedFormatException (net.sf.mzmine.util.spectraldb.parser.UnsupportedFormatException)4 Feature (net.sf.mzmine.datamodel.Feature)2 Scan (net.sf.mzmine.datamodel.Scan)2 SpectraIdentificationResultsWindow (net.sf.mzmine.modules.visualization.spectra.spectralmatchresults.SpectraIdentificationResultsWindow)2 ParameterSet (net.sf.mzmine.parameters.ParameterSet)2 PeakListRowSorter (net.sf.mzmine.util.PeakListRowSorter)2 BorderLayout (java.awt.BorderLayout)1 Color (java.awt.Color)1 File (java.io.File)1 FileReader (java.io.FileReader)1 URL (java.net.URL)1 Date (java.util.Date)1