Search in sources :

Example 16 with MassList

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

the class SiriusExportTask method exportPeakListRow.

private void exportPeakListRow(PeakListRow row, BufferedWriter writer) throws IOException {
    // get row charge and polarity
    char polarity = 0;
    for (Feature f : row.getPeaks()) {
        char pol = f.getDataFile().getScan(f.getRepresentativeScanNumber()).getPolarity().asSingleChar().charAt(0);
        if (pol != polarity && polarity != 0) {
            setErrorMessage("Joined features have different polarity. This is most likely a bug. If not, please separate them as individual features and/or write a feature request on github.");
            setStatus(TaskStatus.ERROR);
            return;
        } else {
            polarity = pol;
        }
    }
    if (mergeEnabled) {
        MergeMode mergeMode = mergeParameters.getParameter(MsMsSpectraMergeParameters.MERGE_MODE).getValue();
        MsMsSpectraMergeModule merger = MZmineCore.getModuleInstance(MsMsSpectraMergeModule.class);
        if (mergeMode != MergeMode.ACROSS_SAMPLES) {
            for (Feature f : row.getPeaks()) {
                if (f.getFeatureStatus() == Feature.FeatureStatus.DETECTED && f.getMostIntenseFragmentScanNumber() >= 0) {
                    // write correlation spectrum
                    writeHeader(writer, row, f.getDataFile(), polarity, MsType.CORRELATED, -1);
                    writeCorrelationSpectrum(writer, f);
                    if (mergeMode == MergeMode.CONSECUTIVE_SCANS) {
                        // merge MS/MS
                        List<MergedSpectrum> spectra = merger.mergeConsecutiveScans(mergeParameters, f, massListName);
                        for (MergedSpectrum spectrum : spectra) {
                            writeHeader(writer, row, f.getDataFile(), polarity, MsType.MSMS, spectrum.filterByRelativeNumberOfScans(mergeParameters.getParameter(MsMsSpectraMergeParameters.PEAK_COUNT_PARAMETER).getValue()));
                            writeSpectrum(writer, spectrum.data);
                        }
                    } else {
                        MergedSpectrum spectrum = merger.mergeFromSameSample(mergeParameters, f, massListName).filterByRelativeNumberOfScans(mergeParameters.getParameter(MsMsSpectraMergeParameters.PEAK_COUNT_PARAMETER).getValue());
                        if (spectrum.data.length > 0) {
                            writeHeader(writer, row, f.getDataFile(), polarity, MsType.MSMS, spectrum);
                            writeSpectrum(writer, spectrum.data);
                        }
                    }
                }
            }
        } else {
            // write correlation spectrum
            writeHeader(writer, row, row.getBestPeak().getDataFile(), polarity, MsType.CORRELATED, -1);
            writeCorrelationSpectrum(writer, row.getBestPeak());
            // merge everything into one
            MergedSpectrum spectrum = merger.mergeAcrossSamples(mergeParameters, row, massListName).filterByRelativeNumberOfScans(mergeParameters.getParameter(MsMsSpectraMergeParameters.PEAK_COUNT_PARAMETER).getValue());
            if (spectrum.data.length > 0) {
                writeHeader(writer, row, row.getBestPeak().getDataFile(), polarity, MsType.MSMS, spectrum);
                writeSpectrum(writer, spectrum.data);
            }
        }
    } else {
        // No merging
        Feature bestPeak = row.getBestPeak();
        MassList ms1MassList = bestPeak.getRepresentativeScan().getMassList(massListName);
        if (ms1MassList != null) {
            writeHeader(writer, row, bestPeak.getDataFile(), polarity, MsType.MS, bestPeak.getRepresentativeScanNumber());
            writeSpectrum(writer, ms1MassList.getDataPoints());
        }
        for (Feature f : row.getPeaks()) {
            for (int ms2scan : f.getAllMS2FragmentScanNumbers()) {
                writeHeader(writer, row, f.getDataFile(), polarity, MsType.MSMS, ms2scan);
                MassList ms2MassList = f.getDataFile().getScan(ms2scan).getMassList(massListName);
                if (ms2MassList == null)
                    continue;
                writeSpectrum(writer, ms2MassList.getDataPoints());
            }
        }
    }
}
Also used : MergeMode(net.sf.mzmine.modules.tools.msmsspectramerge.MergeMode) MsMsSpectraMergeModule(net.sf.mzmine.modules.tools.msmsspectramerge.MsMsSpectraMergeModule) MergedSpectrum(net.sf.mzmine.modules.tools.msmsspectramerge.MergedSpectrum) Feature(net.sf.mzmine.datamodel.Feature) MassList(net.sf.mzmine.datamodel.MassList) DataPoint(net.sf.mzmine.datamodel.DataPoint)

Example 17 with MassList

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

the class MassListComponent method getMassListNames.

/**
 * Method returns the list of all identified MassList names in scans
 *
 * @return unique MassList names
 */
public static List<String> getMassListNames() {
    ArrayList<String> names = new ArrayList<>();
    RawDataFile[] dataFiles = MZmineCore.getProjectManager().getCurrentProject().getDataFiles();
    for (RawDataFile dataFile : dataFiles) {
        int[] scanNums = dataFile.getScanNumbers();
        for (int scanNum : scanNums) {
            Scan scan = dataFile.getScan(scanNum);
            MassList[] massLists = scan.getMassLists();
            for (MassList massList : massLists) {
                String name = massList.getName();
                if (!names.contains(name))
                    names.add(name);
            }
        }
    }
    return names;
}
Also used : RawDataFile(net.sf.mzmine.datamodel.RawDataFile) ArrayList(java.util.ArrayList) Scan(net.sf.mzmine.datamodel.Scan) MassList(net.sf.mzmine.datamodel.MassList)

Example 18 with MassList

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

the class ScanUtils method listAllScans.

/**
 * List of all scans with n signals >= noiseLevel in the specified or first massList, if none was
 * specified
 *
 * @param massListName the name or null/empty to always use the first masslist
 * @param noiseLevel
 * @param minNumberOfSignals
 * @return
 */
@Nonnull
public static List<Scan> listAllScans(Scan[] scans, @Nullable String massListName, double noiseLevel, int minNumberOfSignals) throws MissingMassListException {
    List<Scan> filtered = new ArrayList<>();
    for (Scan scan : scans) {
        // find mass list: with name or first
        final MassList massList = getMassListOrFirst(scan, massListName);
        if (massList == null)
            throw new MissingMassListException("", massListName);
        // minimum number of signals >= noiseLevel
        int signals = 0;
        for (DataPoint dp : massList.getDataPoints()) if (dp.getIntensity() >= noiseLevel)
            signals++;
        if (signals >= minNumberOfSignals)
            filtered.add(scan);
    }
    return filtered;
}
Also used : DataPoint(net.sf.mzmine.datamodel.DataPoint) SimpleDataPoint(net.sf.mzmine.datamodel.impl.SimpleDataPoint) ArrayList(java.util.ArrayList) Scan(net.sf.mzmine.datamodel.Scan) MassList(net.sf.mzmine.datamodel.MassList) MissingMassListException(net.sf.mzmine.util.exceptions.MissingMassListException) DataPoint(net.sf.mzmine.datamodel.DataPoint) SimpleDataPoint(net.sf.mzmine.datamodel.impl.SimpleDataPoint) Nonnull(javax.annotation.Nonnull)

Example 19 with MassList

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

the class PeakListTreeModel 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 PeakList) {
        int childCount = getChildCount(rootNode);
        insertNodeInto(newNode, rootNode, childCount);
        final PeakList peakList = (PeakList) object;
        PeakListRow[] rows = peakList.getRows();
        for (int i = 0; i < rows.length; i++) {
            DefaultMutableTreeNode rowNode = new DefaultMutableTreeNode(rows[i]);
            treeObjects.put(rows[i], rowNode);
            insertNodeInto(rowNode, newNode, i);
        }
    }
    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 : PeakListRow(net.sf.mzmine.datamodel.PeakListRow) DefaultMutableTreeNode(javax.swing.tree.DefaultMutableTreeNode) Scan(net.sf.mzmine.datamodel.Scan) PeakList(net.sf.mzmine.datamodel.PeakList) MassList(net.sf.mzmine.datamodel.MassList)

Example 20 with MassList

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

the class ProjectTreeMouseHandler method actionPerformed.

@Override
public void actionPerformed(ActionEvent e) {
    String command = e.getActionCommand();
    if (command.equals("SHOW_TIC")) {
        RawDataFile[] selectedFiles = tree.getSelectedObjects(RawDataFile.class);
        TICVisualizerModule.setupNewTICVisualizer(selectedFiles);
    }
    if (command.equals("SHOW_SPECTRUM")) {
        RawDataFile[] selectedFiles = tree.getSelectedObjects(RawDataFile.class);
        SpectraVisualizerModule module = MZmineCore.getModuleInstance(SpectraVisualizerModule.class);
        ParameterSet parameters = MZmineCore.getConfiguration().getModuleParameters(SpectraVisualizerModule.class);
        parameters.getParameter(SpectraVisualizerParameters.dataFiles).setValue(RawDataFilesSelectionType.SPECIFIC_FILES, selectedFiles);
        ExitCode exitCode = parameters.showSetupDialog(MZmineCore.getDesktop().getMainWindow(), true);
        MZmineProject project = MZmineCore.getProjectManager().getCurrentProject();
        if (exitCode == ExitCode.OK)
            module.runModule(project, parameters, new ArrayList<Task>());
    }
    if (command.equals("SHOW_IDA")) {
        RawDataFile[] selectedFiles = tree.getSelectedObjects(RawDataFile.class);
        if (selectedFiles.length == 0)
            return;
        MsMsVisualizerModule.showIDAVisualizerSetupDialog(selectedFiles[0]);
    }
    if (command.equals("SHOW_2D")) {
        RawDataFile[] selectedFiles = tree.getSelectedObjects(RawDataFile.class);
        if (selectedFiles.length == 0)
            return;
        TwoDVisualizerModule.show2DVisualizerSetupDialog(selectedFiles[0]);
    }
    if (command.equals("SHOW_3D")) {
        RawDataFile[] selectedFiles = tree.getSelectedObjects(RawDataFile.class);
        if (selectedFiles.length == 0)
            return;
        Fx3DVisualizerModule.setupNew3DVisualizer(selectedFiles[0]);
    }
    if (command.equals("SORT_FILES")) {
        // save current selection
        TreePath[] savedSelection = tree.getSelectionPaths();
        RawDataFile[] selectedFiles = tree.getSelectedObjects(RawDataFile.class);
        SortDataFilesModule module = MZmineCore.getModuleInstance(SortDataFilesModule.class);
        ParameterSet params = MZmineCore.getConfiguration().getModuleParameters(SortDataFilesModule.class);
        params.getParameter(SortDataFilesParameters.dataFiles).setValue(RawDataFilesSelectionType.SPECIFIC_FILES, selectedFiles);
        module.runModule(MZmineCore.getProjectManager().getCurrentProject(), params, new ArrayList<Task>());
        // restore selection
        tree.setSelectionPaths(savedSelection);
    }
    if (command.equals("REMOVE_EXTENSION")) {
        RawDataFile[] selectedFiles = tree.getSelectedObjects(RawDataFile.class);
        for (RawDataFile file : selectedFiles) {
            file.setName(FilenameUtils.removeExtension(file.toString()));
        }
        tree.updateUI();
    }
    if (command.equals("EXPORT_FILE")) {
        RawDataExportModule exportModule = MZmineCore.getModuleInstance(RawDataExportModule.class);
        ParameterSet params = MZmineCore.getConfiguration().getModuleParameters(RawDataExportModule.class);
        ExitCode ec = params.showSetupDialog(null, true);
        if (ec == ExitCode.OK) {
            ParameterSet parametersCopy = params.cloneParameterSet();
            ArrayList<Task> tasks = new ArrayList<>();
            MZmineProject project = MZmineCore.getProjectManager().getCurrentProject();
            exportModule.runModule(project, parametersCopy, tasks);
            MZmineCore.getTaskController().addTasks(tasks.toArray(new Task[0]));
        }
    }
    if (command.equals("RENAME_FILE")) {
        TreePath path = tree.getSelectionPath();
        if (path == null)
            return;
        else
            tree.startEditingAtPath(path);
    }
    if (command.equals("REMOVE_FILE")) {
        RawDataFile[] selectedFiles = tree.getSelectedObjects(RawDataFile.class);
        PeakList[] allPeakLists = MZmineCore.getProjectManager().getCurrentProject().getPeakLists();
        for (RawDataFile file : selectedFiles) {
            for (PeakList peakList : allPeakLists) {
                if (peakList.hasRawDataFile(file)) {
                    String msg = "Cannot remove file " + file.getName() + ", because it is present in the feature list " + peakList.getName();
                    MZmineCore.getDesktop().displayErrorMessage(MZmineCore.getDesktop().getMainWindow(), msg);
                    return;
                }
            }
            MZmineCore.getProjectManager().getCurrentProject().removeFile(file);
        }
    }
    if (command.equals("SHOW_SCAN")) {
        Scan[] selectedScans = tree.getSelectedObjects(Scan.class);
        for (Scan scan : selectedScans) {
            SpectraVisualizerModule.showNewSpectrumWindow(scan.getDataFile(), scan.getScanNumber());
        }
    }
    if (command.equals("EXPORT_SCAN")) {
        Scan[] selectedScans = tree.getSelectedObjects(Scan.class);
        ExportScansModule.showSetupDialog(selectedScans);
    }
    if (command.equals("SHOW_MASSLIST")) {
        MassList[] selectedMassLists = tree.getSelectedObjects(MassList.class);
        for (MassList massList : selectedMassLists) {
            Scan scan = massList.getScan();
            SpectraVisualizerWindow window = SpectraVisualizerModule.showNewSpectrumWindow(scan.getDataFile(), scan.getScanNumber());
            MassListDataSet dataset = new MassListDataSet(massList);
            window.addDataSet(dataset, Color.green);
        }
    }
    if (command.equals("REMOVE_MASSLIST")) {
        MassList[] selectedMassLists = tree.getSelectedObjects(MassList.class);
        for (MassList massList : selectedMassLists) {
            Scan scan = massList.getScan();
            scan.removeMassList(massList);
        }
    }
    if (command.equals("REMOVE_ALL_MASSLISTS")) {
        MassList[] selectedMassLists = tree.getSelectedObjects(MassList.class);
        for (MassList massList : selectedMassLists) {
            String massListName = massList.getName();
            RawDataFile[] dataFiles = MZmineCore.getProjectManager().getCurrentProject().getDataFiles();
            for (RawDataFile dataFile : dataFiles) {
                int[] scanNumbers = dataFile.getScanNumbers();
                for (int scanNum : scanNumbers) {
                    Scan scan = dataFile.getScan(scanNum);
                    MassList ml = scan.getMassList(massListName);
                    if (ml != null)
                        scan.removeMassList(ml);
                }
            }
        }
    }
    if (command.equals("SHOW_PEAKLIST_TABLES")) {
        PeakList[] selectedPeakLists = tree.getSelectedObjects(PeakList.class);
        for (PeakList peakList : selectedPeakLists) {
            PeakListTableModule.showNewPeakListVisualizerWindow(peakList);
        }
    }
    if (command.equals("SHOW_PEAKLIST_INFO")) {
        PeakList[] selectedPeakLists = tree.getSelectedObjects(PeakList.class);
        for (PeakList peakList : selectedPeakLists) {
            InfoVisualizerModule.showNewPeakListInfo(peakList);
        }
    }
    if (command.equals("SHOW_SCATTER_PLOT")) {
        PeakList[] selectedPeakLists = tree.getSelectedObjects(PeakList.class);
        for (PeakList peakList : selectedPeakLists) {
            ScatterPlotVisualizerModule.showNewScatterPlotWindow(peakList);
        }
    }
    if (command.equals("SORT_PEAKLISTS")) {
        // save current selection
        TreePath[] savedSelection = tree.getSelectionPaths();
        PeakList[] selectedPeakLists = tree.getSelectedObjects(PeakList.class);
        SortPeakListsModule module = MZmineCore.getModuleInstance(SortPeakListsModule.class);
        ParameterSet params = MZmineCore.getConfiguration().getModuleParameters(SortPeakListsModule.class);
        params.getParameter(SortPeakListsParameters.peakLists).setValue(PeakListsSelectionType.SPECIFIC_PEAKLISTS, selectedPeakLists);
        module.runModule(MZmineCore.getProjectManager().getCurrentProject(), params, new ArrayList<Task>());
        // restore selection
        tree.setSelectionPaths(savedSelection);
    }
    if (command.equals("RENAME_FEATURELIST")) {
        TreePath path = tree.getSelectionPath();
        if (path == null)
            return;
        else
            tree.startEditingAtPath(path);
    }
    if (command.equals("REMOVE_PEAKLIST")) {
        PeakList[] selectedPeakLists = tree.getSelectedObjects(PeakList.class);
        for (PeakList peakList : selectedPeakLists) MZmineCore.getProjectManager().getCurrentProject().removePeakList(peakList);
    }
    if (command.equals("SHOW_PEAK_SUMMARY")) {
        PeakListRow[] selectedRows = tree.getSelectedObjects(PeakListRow.class);
        for (PeakListRow row : selectedRows) {
            PeakSummaryVisualizerModule.showNewPeakSummaryWindow(row);
        }
    }
}
Also used : Task(net.sf.mzmine.taskcontrol.Task) ExitCode(net.sf.mzmine.util.ExitCode) ArrayList(java.util.ArrayList) SpectraVisualizerWindow(net.sf.mzmine.modules.visualization.spectra.simplespectra.SpectraVisualizerWindow) PeakListRow(net.sf.mzmine.datamodel.PeakListRow) SpectraVisualizerModule(net.sf.mzmine.modules.visualization.spectra.simplespectra.SpectraVisualizerModule) MZmineProject(net.sf.mzmine.datamodel.MZmineProject) MassListDataSet(net.sf.mzmine.modules.visualization.spectra.simplespectra.datasets.MassListDataSet) ParameterSet(net.sf.mzmine.parameters.ParameterSet) SortDataFilesModule(net.sf.mzmine.modules.rawdatamethods.sortdatafiles.SortDataFilesModule) RawDataExportModule(net.sf.mzmine.modules.rawdatamethods.rawdataexport.RawDataExportModule) TreePath(javax.swing.tree.TreePath) RawDataFile(net.sf.mzmine.datamodel.RawDataFile) Scan(net.sf.mzmine.datamodel.Scan) PeakList(net.sf.mzmine.datamodel.PeakList) MassList(net.sf.mzmine.datamodel.MassList) SortPeakListsModule(net.sf.mzmine.modules.peaklistmethods.sortpeaklists.SortPeakListsModule)

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