Search in sources :

Example 21 with ParameterSet

use of net.sf.mzmine.parameters.ParameterSet in project mzmine2 by mzmine.

the class TwoDVisualizerModule method show2DVisualizerSetupDialog.

public static void show2DVisualizerSetupDialog(RawDataFile dataFile, Range<Double> mzRange, Range<Double> rtRange) {
    ParameterSet parameters = MZmineCore.getConfiguration().getModuleParameters(TwoDVisualizerModule.class);
    parameters.getParameter(TwoDVisualizerParameters.dataFiles).setValue(RawDataFilesSelectionType.SPECIFIC_FILES, new RawDataFile[] { dataFile });
    if (rtRange != null)
        parameters.getParameter(TwoDVisualizerParameters.scanSelection).setValue(new ScanSelection(rtRange, 1));
    if (mzRange != null)
        parameters.getParameter(TwoDVisualizerParameters.mzRange).setValue(mzRange);
    ExitCode exitCode = parameters.showSetupDialog(MZmineCore.getDesktop().getMainWindow(), true);
    if (exitCode != ExitCode.OK)
        return;
    ScanSelection scanSel = parameters.getParameter(TwoDVisualizerParameters.scanSelection).getValue();
    Scan[] scans = scanSel.getMatchingScans(dataFile);
    rtRange = ScanUtils.findRtRange(scans);
    mzRange = parameters.getParameter(TwoDVisualizerParameters.mzRange).getValue();
    TwoDVisualizerWindow newWindow = new TwoDVisualizerWindow(dataFile, scans, rtRange, mzRange, parameters);
    newWindow.setVisible(true);
}
Also used : ParameterSet(net.sf.mzmine.parameters.ParameterSet) ScanSelection(net.sf.mzmine.parameters.parametertypes.selectors.ScanSelection) ExitCode(net.sf.mzmine.util.ExitCode) Scan(net.sf.mzmine.datamodel.Scan)

Example 22 with ParameterSet

use of net.sf.mzmine.parameters.ParameterSet in project mzmine2 by mzmine.

the class ModuleComboComponent method actionPerformed.

public void actionPerformed(ActionEvent event) {
    Object src = event.getSource();
    MZmineProcessingStep<?> selected = (MZmineProcessingStep<?>) comboBox.getSelectedItem();
    if (src == comboBox) {
        if (selected == null) {
            setButton.setEnabled(false);
            return;
        }
        ParameterSet parameterSet = selected.getParameterSet();
        int numOfParameters = parameterSet.getParameters().length;
        setButton.setEnabled(numOfParameters > 0);
    }
    if (src == setButton) {
        if (selected == null)
            return;
        ParameterSetupDialog dialog = (ParameterSetupDialog) SwingUtilities.getAncestorOfClass(ParameterSetupDialog.class, this);
        if (dialog == null)
            return;
        ParameterSet parameterSet = selected.getParameterSet();
        parameterSet.showSetupDialog(dialog, dialog.isValueCheckRequired());
    }
}
Also used : ParameterSet(net.sf.mzmine.parameters.ParameterSet) MZmineProcessingStep(net.sf.mzmine.modules.MZmineProcessingStep) ParameterSetupDialog(net.sf.mzmine.parameters.dialogs.ParameterSetupDialog)

Example 23 with ParameterSet

use of net.sf.mzmine.parameters.ParameterSet in project mzmine2 by mzmine.

the class ModuleComboParameter method loadValueFromXML.

@Override
public void loadValueFromXML(Element xmlElement) {
    NodeList items = xmlElement.getElementsByTagName("module");
    for (int i = 0; i < items.getLength(); i++) {
        Element moduleElement = (Element) items.item(i);
        String name = moduleElement.getAttribute("name");
        for (int j = 0; j < modulesWithParams.length; j++) {
            if (modulesWithParams[j].getModule().getName().equals(name)) {
                ParameterSet moduleParameters = modulesWithParams[j].getParameterSet();
                if (moduleParameters == null)
                    continue;
                moduleParameters.loadValuesFromXML((Element) items.item(i));
            }
        }
    }
    String selectedAttr = xmlElement.getAttribute("selected");
    for (int j = 0; j < modulesWithParams.length; j++) {
        if (modulesWithParams[j].getModule().getName().equals(selectedAttr)) {
            value = modulesWithParams[j];
        }
    }
}
Also used : ParameterSet(net.sf.mzmine.parameters.ParameterSet) NodeList(org.w3c.dom.NodeList) Element(org.w3c.dom.Element)

Example 24 with ParameterSet

use of net.sf.mzmine.parameters.ParameterSet in project mzmine2 by mzmine.

the class ModuleComboParameter method saveValueToXML.

@Override
public void saveValueToXML(Element xmlElement) {
    if (value != null)
        xmlElement.setAttribute("selected", value.toString());
    Document parentDocument = xmlElement.getOwnerDocument();
    for (MZmineProcessingStep<?> item : modulesWithParams) {
        Element newElement = parentDocument.createElement("module");
        newElement.setAttribute("name", item.getModule().getName());
        ParameterSet moduleParameters = item.getParameterSet();
        if (moduleParameters != null)
            moduleParameters.saveValuesToXML(newElement);
        xmlElement.appendChild(newElement);
    }
}
Also used : ParameterSet(net.sf.mzmine.parameters.ParameterSet) Element(org.w3c.dom.Element) Document(org.w3c.dom.Document)

Example 25 with ParameterSet

use of net.sf.mzmine.parameters.ParameterSet in project mzmine2 by mzmine.

the class JoinAlignerTask method run.

/**
 * @see Runnable#run()
 */
@Override
public void run() {
    if ((mzWeight == 0) && (rtWeight == 0)) {
        setStatus(TaskStatus.ERROR);
        setErrorMessage("Cannot run alignment, all the weight parameters are zero");
        return;
    }
    setStatus(TaskStatus.PROCESSING);
    logger.info("Running join aligner");
    // twice, first for score calculation, second for actual alignment.
    for (int i = 0; i < peakLists.length; i++) {
        totalRows += peakLists[i].getNumberOfRows() * 2;
    }
    // Collect all data files
    Vector<RawDataFile> allDataFiles = new Vector<RawDataFile>();
    for (PeakList peakList : peakLists) {
        for (RawDataFile dataFile : peakList.getRawDataFiles()) {
            // Each data file can only have one column in aligned feature list
            if (allDataFiles.contains(dataFile)) {
                setStatus(TaskStatus.ERROR);
                setErrorMessage("Cannot run alignment, because file " + dataFile + " is present in multiple feature lists");
                return;
            }
            allDataFiles.add(dataFile);
        }
    }
    // Create a new aligned feature list
    alignedPeakList = new SimplePeakList(peakListName, allDataFiles.toArray(new RawDataFile[0]));
    // Iterate source feature lists
    for (PeakList peakList : peakLists) {
        // Create a sorted set of scores matching
        TreeSet<RowVsRowScore> scoreSet = new TreeSet<RowVsRowScore>();
        PeakListRow[] allRows = peakList.getRows();
        // Calculate scores for all possible alignments of this row
        for (PeakListRow row : allRows) {
            if (isCanceled())
                return;
            // Calculate limits for a row with which the row can be aligned
            Range<Double> mzRange = mzTolerance.getToleranceRange(row.getAverageMZ());
            Range<Double> rtRange = rtTolerance.getToleranceRange(row.getAverageRT());
            // Get all rows of the aligned peaklist within parameter limits
            PeakListRow[] candidateRows = alignedPeakList.getRowsInsideScanAndMZRange(rtRange, mzRange);
            // Calculate scores and store them
            for (PeakListRow candidate : candidateRows) {
                if (sameChargeRequired) {
                    if (!PeakUtils.compareChargeState(row, candidate))
                        continue;
                }
                if (sameIDRequired) {
                    if (!PeakUtils.compareIdentities(row, candidate))
                        continue;
                }
                if (compareIsotopePattern) {
                    IsotopePattern ip1 = row.getBestIsotopePattern();
                    IsotopePattern ip2 = candidate.getBestIsotopePattern();
                    if ((ip1 != null) && (ip2 != null)) {
                        ParameterSet isotopeParams = parameters.getParameter(JoinAlignerParameters.compareIsotopePattern).getEmbeddedParameters();
                        if (!IsotopePatternScoreCalculator.checkMatch(ip1, ip2, isotopeParams)) {
                            continue;
                        }
                    }
                }
                // compare the similarity of spectra mass lists on MS1 or MS2 level
                if (compareSpectraSimilarity) {
                    DataPoint[] rowDPs = null;
                    DataPoint[] candidateDPs = null;
                    SpectralSimilarity sim = null;
                    // get data points of mass list of the representative scans
                    if (msLevel == 1) {
                        rowDPs = row.getBestPeak().getRepresentativeScan().getMassList(massList).getDataPoints();
                        candidateDPs = candidate.getBestPeak().getRepresentativeScan().getMassList(massList).getDataPoints();
                    }
                    // get data points of mass list of the best fragmentation scans
                    if (msLevel == 2) {
                        if (row.getBestFragmentation() != null && candidate.getBestFragmentation() != null) {
                            rowDPs = row.getBestFragmentation().getMassList(massList).getDataPoints();
                            candidateDPs = candidate.getBestFragmentation().getMassList(massList).getDataPoints();
                        } else
                            continue;
                    }
                    // compare mass list data points of selected scans
                    if (rowDPs != null && candidateDPs != null) {
                        // calculate similarity using SimilarityFunction
                        sim = createSimilarity(rowDPs, candidateDPs);
                        // user set threshold
                        if (sim == null) {
                            continue;
                        }
                    }
                }
                RowVsRowScore score = new RowVsRowScore(row, candidate, RangeUtils.rangeLength(mzRange) / 2.0, mzWeight, RangeUtils.rangeLength(rtRange) / 2.0, rtWeight);
                scoreSet.add(score);
            }
            processedRows++;
        }
        // Create a table of mappings for best scores
        Hashtable<PeakListRow, PeakListRow> alignmentMapping = new Hashtable<PeakListRow, PeakListRow>();
        // Iterate scores by descending order
        Iterator<RowVsRowScore> scoreIterator = scoreSet.iterator();
        while (scoreIterator.hasNext()) {
            RowVsRowScore score = scoreIterator.next();
            // Check if the row is already mapped
            if (alignmentMapping.containsKey(score.getPeakListRow()))
                continue;
            // Check if the aligned row is already filled
            if (alignmentMapping.containsValue(score.getAlignedRow()))
                continue;
            alignmentMapping.put(score.getPeakListRow(), score.getAlignedRow());
        }
        // Align all rows using mapping
        for (PeakListRow row : allRows) {
            PeakListRow targetRow = alignmentMapping.get(row);
            // If we have no mapping for this row, add a new one
            if (targetRow == null) {
                targetRow = new SimplePeakListRow(newRowID);
                newRowID++;
                alignedPeakList.addRow(targetRow);
            }
            // Add all peaks from the original row to the aligned row
            for (RawDataFile file : row.getRawDataFiles()) {
                targetRow.addPeak(file, row.getPeak(file));
            }
            // Add all non-existing identities from the original row to the
            // aligned row
            PeakUtils.copyPeakListRowProperties(row, targetRow);
            processedRows++;
        }
    }
    // Next feature list
    // Add new aligned feature list to the project
    project.addPeakList(alignedPeakList);
    // Add task description to peakList
    alignedPeakList.addDescriptionOfAppliedTask(new SimplePeakListAppliedMethod("Join aligner", parameters));
    logger.info("Finished join aligner");
    setStatus(TaskStatus.FINISHED);
}
Also used : ParameterSet(net.sf.mzmine.parameters.ParameterSet) Hashtable(java.util.Hashtable) IsotopePattern(net.sf.mzmine.datamodel.IsotopePattern) SpectralSimilarity(net.sf.mzmine.util.scans.similarity.SpectralSimilarity) SimplePeakListAppliedMethod(net.sf.mzmine.datamodel.impl.SimplePeakListAppliedMethod) SimplePeakListRow(net.sf.mzmine.datamodel.impl.SimplePeakListRow) DataPoint(net.sf.mzmine.datamodel.DataPoint) SimplePeakListRow(net.sf.mzmine.datamodel.impl.SimplePeakListRow) PeakListRow(net.sf.mzmine.datamodel.PeakListRow) RawDataFile(net.sf.mzmine.datamodel.RawDataFile) DataPoint(net.sf.mzmine.datamodel.DataPoint) TreeSet(java.util.TreeSet) SimplePeakList(net.sf.mzmine.datamodel.impl.SimplePeakList) SimplePeakList(net.sf.mzmine.datamodel.impl.SimplePeakList) PeakList(net.sf.mzmine.datamodel.PeakList) Vector(java.util.Vector)

Aggregations

ParameterSet (net.sf.mzmine.parameters.ParameterSet)53 ExitCode (net.sf.mzmine.util.ExitCode)19 RawDataFile (net.sf.mzmine.datamodel.RawDataFile)11 File (java.io.File)9 ArrayList (java.util.ArrayList)8 SimpleParameterSet (net.sf.mzmine.parameters.impl.SimpleParameterSet)8 Task (net.sf.mzmine.taskcontrol.Task)8 Element (org.w3c.dom.Element)8 PeakList (net.sf.mzmine.datamodel.PeakList)6 MZmineModule (net.sf.mzmine.modules.MZmineModule)6 Document (org.w3c.dom.Document)6 IOException (java.io.IOException)5 DataPoint (net.sf.mzmine.datamodel.DataPoint)5 PeakListRow (net.sf.mzmine.datamodel.PeakListRow)5 Scan (net.sf.mzmine.datamodel.Scan)5 MZmineProcessingModule (net.sf.mzmine.modules.MZmineProcessingModule)5 Nonnull (javax.annotation.Nonnull)4 Feature (net.sf.mzmine.datamodel.Feature)4 IsotopePattern (net.sf.mzmine.datamodel.IsotopePattern)4 PeakListsParameter (net.sf.mzmine.parameters.parametertypes.selectors.PeakListsParameter)4