Search in sources :

Example 76 with RawDataFile

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

the class PeakComparisonRowFilterTask method filterPeakListRows.

/**
 * Filter the feature list rows by comparing peaks within a row.
 *
 * @param peakList feature list to filter.
 * @return a new feature list with rows of the original feature list that pass the filtering.
 */
private PeakList filterPeakListRows(final PeakList peakList) {
    // Create new feature list.
    final PeakList newPeakList = new SimplePeakList(peakList.getName() + ' ' + parameters.getParameter(PeakComparisonRowFilterParameters.SUFFIX).getValue(), peakList.getRawDataFiles());
    // Copy previous applied methods.
    for (final PeakListAppliedMethod method : peakList.getAppliedMethods()) {
        newPeakList.addDescriptionOfAppliedTask(method);
    }
    // Add task description to peakList.
    newPeakList.addDescriptionOfAppliedTask(new SimplePeakListAppliedMethod(getTaskDescription(), parameters));
    // Get parameters.
    final boolean evalutateFoldChange = parameters.getParameter(PeakComparisonRowFilterParameters.FOLD_CHANGE).getValue();
    final boolean evalutatePPMdiff = parameters.getParameter(PeakComparisonRowFilterParameters.MZ_PPM_DIFF).getValue();
    final boolean evalutateRTdiff = parameters.getParameter(PeakComparisonRowFilterParameters.RT_DIFF).getValue();
    final int columnIndex1 = parameters.getParameter(PeakComparisonRowFilterParameters.COLUMN_INDEX_1).getValue();
    final int columnIndex2 = parameters.getParameter(PeakComparisonRowFilterParameters.COLUMN_INDEX_2).getValue();
    final Range<Double> foldChangeRange = parameters.getParameter(PeakComparisonRowFilterParameters.FOLD_CHANGE).getEmbeddedParameter().getValue();
    final Range<Double> ppmDiffRange = parameters.getParameter(PeakComparisonRowFilterParameters.FOLD_CHANGE).getEmbeddedParameter().getValue();
    final Range<Double> rtDiffRange = parameters.getParameter(PeakComparisonRowFilterParameters.FOLD_CHANGE).getEmbeddedParameter().getValue();
    // Setup variables
    final PeakListRow[] rows = peakList.getRows();
    RawDataFile rawDataFile1;
    RawDataFile rawDataFile2;
    Feature peak1;
    Feature peak2;
    totalRows = rows.length;
    final RawDataFile[] rawDataFiles = peakList.getRawDataFiles();
    boolean allCriteriaMatched = true;
    // doesn't exist.
    if (columnIndex1 > rawDataFiles.length) {
        setErrorMessage("Column 1 set too large.");
        setStatus(TaskStatus.ERROR);
        return null;
    }
    if (columnIndex2 > rawDataFiles.length) {
        setErrorMessage("Column 2 set too large.");
        setStatus(TaskStatus.ERROR);
        return null;
    }
    // Loop over the rows & filter
    for (processedRows = 0; !isCanceled() && processedRows < totalRows; processedRows++) {
        if (isCanceled())
            return null;
        allCriteriaMatched = true;
        // Default value in case of null peak
        double peak1Area = 1.0;
        double peak2Area = 1.0;
        double peak1MZ = -1.0;
        double peak2MZ = -1.0;
        double peak1RT = -1.0;
        double peak2RT = -1.0;
        double foldChange = 0.0;
        double ppmDiff = 0.0;
        double rtDiff = 0.0;
        final PeakListRow row = rows[processedRows];
        rawDataFile1 = rawDataFiles[columnIndex1];
        rawDataFile2 = rawDataFiles[columnIndex2];
        peak1 = row.getPeak(rawDataFile1);
        peak2 = row.getPeak(rawDataFile2);
        if (peak1 != null) {
            peak1Area = peak1.getArea();
            peak1MZ = peak1.getMZ();
            peak1RT = peak1.getRT();
        }
        if (peak2 != null) {
            peak2Area = peak2.getArea();
            peak2MZ = peak2.getMZ();
            peak2RT = peak2.getRT();
        }
        // Fold change criteria checking.
        if (evalutateFoldChange) {
            foldChange = Math.log(peak1Area / peak2Area) / Math.log(2);
            if (!foldChangeRange.contains(foldChange))
                allCriteriaMatched = false;
            // PPM difference evaluation
            if (evalutatePPMdiff) {
                ppmDiff = (peak1MZ - peak2MZ) / peak1MZ * 1E6;
                if (!ppmDiffRange.contains(ppmDiff))
                    allCriteriaMatched = false;
            }
            // RT difference evaluation
            if (evalutateRTdiff) {
                rtDiff = peak1RT - peak2RT;
                if (!rtDiffRange.contains(rtDiff))
                    allCriteriaMatched = false;
            }
        }
        // Good row?
        if (allCriteriaMatched)
            newPeakList.addRow(copyPeakRow(row));
    }
    return newPeakList;
}
Also used : SimplePeakListAppliedMethod(net.sf.mzmine.datamodel.impl.SimplePeakListAppliedMethod) PeakListAppliedMethod(net.sf.mzmine.datamodel.PeakList.PeakListAppliedMethod) SimplePeakListAppliedMethod(net.sf.mzmine.datamodel.impl.SimplePeakListAppliedMethod) SimpleFeature(net.sf.mzmine.datamodel.impl.SimpleFeature) Feature(net.sf.mzmine.datamodel.Feature) SimplePeakListRow(net.sf.mzmine.datamodel.impl.SimplePeakListRow) PeakListRow(net.sf.mzmine.datamodel.PeakListRow) RawDataFile(net.sf.mzmine.datamodel.RawDataFile) SimplePeakList(net.sf.mzmine.datamodel.impl.SimplePeakList) SimplePeakList(net.sf.mzmine.datamodel.impl.SimplePeakList) PeakList(net.sf.mzmine.datamodel.PeakList)

Example 77 with RawDataFile

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

the class DuplicateFilterTask method filterDuplicatePeakListRows.

/**
 * Filter our duplicate feature list rows.
 *
 * @param origPeakList the original feature list.
 * @param suffix the suffix to apply to the new feature list name.
 * @param mzTolerance m/z tolerance.
 * @param rtTolerance RT tolerance.
 * @param requireSameId must duplicate peaks have the same identities?
 * @return the filtered feature list.
 */
private PeakList filterDuplicatePeakListRows(final PeakList origPeakList, final String suffix, final MZTolerance mzTolerance, final RTTolerance rtTolerance, final boolean requireSameId, FilterMode mode) {
    final PeakListRow[] peakListRows = origPeakList.getRows();
    final int rowCount = peakListRows.length;
    RawDataFile[] rawFiles = origPeakList.getRawDataFiles();
    // Create the new feature list.
    final PeakList newPeakList = new SimplePeakList(origPeakList + " " + suffix, origPeakList.getRawDataFiles());
    // sort rows
    if (mode.equals(FilterMode.OLD_AVERAGE))
        Arrays.sort(peakListRows, new PeakListRowSorter(SortingProperty.Area, SortingDirection.Descending));
    else
        Arrays.sort(peakListRows, new PeakListRowSorter(SortingProperty.ID, SortingDirection.Ascending));
    // filter by average mz and rt
    boolean filterByAvgRTMZ = !mode.equals(FilterMode.SINGLE_FEATURE);
    // Loop through all feature list rows
    processedRows = 0;
    int n = 0;
    totalRows = rowCount;
    for (int firstRowIndex = 0; !isCanceled() && firstRowIndex < rowCount; firstRowIndex++) {
        final PeakListRow mainRow = peakListRows[firstRowIndex];
        if (mainRow != null) {
            // copy first row
            PeakListRow firstRow = copyRow(mainRow);
            for (int secondRowIndex = firstRowIndex + 1; !isCanceled() && secondRowIndex < rowCount; secondRowIndex++) {
                final PeakListRow secondRow = peakListRows[secondRowIndex];
                if (secondRow != null) {
                    // Compare identifications
                    final boolean sameID = !requireSameId || PeakUtils.compareIdentities(firstRow, secondRow);
                    boolean sameMZRT = // average or single feature
                    filterByAvgRTMZ ? checkSameAverageRTMZ(firstRow, secondRow, mzTolerance, rtTolerance) : checkSameSingleFeatureRTMZ(rawFiles, firstRow, secondRow, mzTolerance, rtTolerance);
                    // Duplicate peaks?
                    if (sameID && sameMZRT) {
                        // create consensus row in new filter
                        if (!mode.equals(FilterMode.OLD_AVERAGE)) {
                            // copy all detected features of row2 into row1
                            // to exchange gap-filled against detected features
                            createConsensusFirstRow(rawFiles, firstRow, secondRow);
                        }
                        // second row deleted
                        n++;
                        peakListRows[secondRowIndex] = null;
                    }
                }
            }
            // add to new list
            newPeakList.addRow(firstRow);
        }
        processedRows++;
    }
    // finalize
    if (!isCanceled()) {
        // Load previous applied methods.
        for (final PeakListAppliedMethod method : origPeakList.getAppliedMethods()) {
            newPeakList.addDescriptionOfAppliedTask(method);
        }
        // Add task description to peakList
        newPeakList.addDescriptionOfAppliedTask(new SimplePeakListAppliedMethod("Duplicate feature list rows filter", parameters));
        LOG.info("Removed " + n + " duplicate rows");
    }
    return newPeakList;
}
Also used : SimplePeakListRow(net.sf.mzmine.datamodel.impl.SimplePeakListRow) PeakListRow(net.sf.mzmine.datamodel.PeakListRow) RawDataFile(net.sf.mzmine.datamodel.RawDataFile) SimplePeakListAppliedMethod(net.sf.mzmine.datamodel.impl.SimplePeakListAppliedMethod) PeakListAppliedMethod(net.sf.mzmine.datamodel.PeakList.PeakListAppliedMethod) SimplePeakList(net.sf.mzmine.datamodel.impl.SimplePeakList) SimplePeakList(net.sf.mzmine.datamodel.impl.SimplePeakList) PeakList(net.sf.mzmine.datamodel.PeakList) SimplePeakListAppliedMethod(net.sf.mzmine.datamodel.impl.SimplePeakListAppliedMethod) PeakListRowSorter(net.sf.mzmine.util.PeakListRowSorter)

Example 78 with RawDataFile

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

the class KovatsIndexExtractionDialog method addDialogComponents.

@Override
protected void addDialogComponents() {
    super.addDialogComponents();
    mainPanel.removeAll();
    mainPanel.getParent().remove(mainPanel);
    ddlKovats = new DelayedDocumentListener(e -> updateKovatsList());
    DelayedDocumentListener ddlUpdateChart = new DelayedDocumentListener(e -> updateChart());
    newMainPanel = new JPanel(new MigLayout("fill", "[right][grow,fill]", ""));
    getContentPane().add(newMainPanel, BorderLayout.SOUTH);
    JPanel pnCenter = new JPanel(new BorderLayout());
    getContentPane().add(pnCenter, BorderLayout.CENTER);
    pnChart = new JPanel(new BorderLayout());
    pnCenter.add(pnChart, BorderLayout.CENTER);
    Box sizedummy = new Box(BoxLayout.X_AXIS);
    sizedummy.setMinimumSize(new Dimension(200, 450));
    sizedummy.setPreferredSize(new Dimension(200, 450));
    pnChart.add(sizedummy, BorderLayout.CENTER);
    // left: Kovats: min max and list
    JPanel west = new JPanel(new BorderLayout());
    newMainPanel.add(west);
    // add min max
    JPanel pnKovatsParam = new JPanel(new FlowLayout(FlowLayout.CENTER, 5, 5));
    west.add(pnKovatsParam, BorderLayout.NORTH);
    minc = (IntegerComponent) getComponentForParameter(KovatsIndexExtractionParameters.minKovats);
    maxc = (IntegerComponent) getComponentForParameter(KovatsIndexExtractionParameters.maxKovats);
    minc.addDocumentListener(ddlKovats);
    maxc.addDocumentListener(ddlKovats);
    pnKovatsParam.add(new JLabel("Min carbon:"));
    pnKovatsParam.add(minc);
    pnKovatsParam.add(new JLabel("Max carbon:"));
    pnKovatsParam.add(maxc);
    // kovats list
    JPanel pnKovatsSelect = new JPanel(new BorderLayout());
    west.add(pnKovatsSelect, BorderLayout.CENTER);
    comboKovats = (MultiChoiceComponent) getComponentForParameter(KovatsIndexExtractionParameters.kovats);
    comboKovats.addValueChangeListener(() -> handleKovatsSelectionChange());
    pnKovatsSelect.add(comboKovats, BorderLayout.CENTER);
    // center: Chart and parameters
    JPanel center = new JPanel(new BorderLayout());
    newMainPanel.add(center);
    // all parameters on peak pick panel
    JPanel pnSouth = new JPanel(new BorderLayout());
    center.add(pnSouth, BorderLayout.SOUTH);
    JPanel pnPeakPick = new JPanel(new MigLayout("", "[right][]", ""));
    pnSouth.add(pnPeakPick, BorderLayout.CENTER);
    valuesComponent = (StringComponent) getComponentForParameter(KovatsIndexExtractionParameters.pickedKovatsValues);
    MZRangeComponent mzc = (MZRangeComponent) getComponentForParameter(KovatsIndexExtractionParameters.mzRange);
    RTRangeComponent rtc = (RTRangeComponent) getComponentForParameter(KovatsIndexExtractionParameters.rtRange);
    DoubleComponent noisec = (DoubleComponent) getComponentForParameter(KovatsIndexExtractionParameters.noiseLevel);
    DoubleComponent edgeRatioC = (DoubleComponent) getComponentForParameter(KovatsIndexExtractionParameters.ratioTopEdge);
    valuesComponent.addDocumentListener(new DelayedDocumentListener(e -> kovatsValuesChanged()));
    valuesComponent.setLayout(new GridLayout(1, 1));
    pnCenter.add(valuesComponent, BorderLayout.SOUTH);
    JPanel pnButtonFlow = new JPanel();
    pnPeakPick.add(pnButtonFlow, "cell 0 0 2 1");
    JButton btnUpdateChart = new JButton("Update chart");
    btnUpdateChart.addActionListener(e -> updateChart());
    pnButtonFlow.add(btnUpdateChart);
    JButton btnPickRT = new JButton("Pick peaks");
    btnPickRT.addActionListener(e -> pickRetentionTimes());
    pnButtonFlow.add(btnPickRT);
    JButton btnSaveFile = new JButton("Save to file");
    btnSaveFile.setToolTipText("Save Kovats index file");
    btnSaveFile.addActionListener(e -> saveToFile());
    pnButtonFlow.add(btnSaveFile);
    JButton btnLoad = new JButton("Load");
    btnLoad.setToolTipText("Load Kovats index file");
    btnLoad.addActionListener(e -> loadFile());
    pnButtonFlow.add(btnLoad);
    JButton btnCombineFiles = new JButton("Combine files");
    btnCombineFiles.setToolTipText("Select multiple Kovats index files to be combined into one");
    btnCombineFiles.addActionListener(e -> combineFiles());
    pnButtonFlow.add(btnCombineFiles);
    // add combo for raw data file
    dataFiles = MZmineCore.getProjectManager().getCurrentProject().getDataFiles();
    comboDataFileName = new JComboBox<RawDataFile>(dataFiles);
    comboDataFileName2 = new JComboBox<RawDataFile>(dataFiles);
    cbSecondRaw = new JCheckBox();
    initRawDataFileSelection();
    pnPeakPick.add(new JLabel("Raw data file(s)"), "cell 0 1");
    pnPeakPick.add(comboDataFileName);
    cbSecondRaw.addItemListener(e -> useSecondDataFile(cbSecondRaw.isSelected()));
    pnPeakPick.add(cbSecondRaw, "cell 0 2");
    pnPeakPick.add(comboDataFileName2);
    // direct alkane selection < CxH2x+1 >
    JPanel pnAlkaneSelect = new JPanel();
    Dimension dim = new Dimension(SIZE, SIZE);
    JButton btnPrevAlkane = new JButton(iconPrev);
    btnPrevAlkane.addActionListener(e -> setMzRangeByAlkane(-1));
    btnPrevAlkane.setPreferredSize(dim);
    btnPrevAlkane.setMaximumSize(dim);
    JButton btnNextAlkane = new JButton(iconNext);
    btnNextAlkane.addActionListener(e -> setMzRangeByAlkane(1));
    btnNextAlkane.setPreferredSize(dim);
    btnNextAlkane.setMaximumSize(dim);
    lbCurrentAlkane = new JLabel("");
    cbCurrentAlkaneSubH = new JCheckBox("-H");
    cbCurrentAlkaneSubH.setSelected(true);
    cbCurrentAlkaneSubH.addItemListener(e -> setMzRangeByAlkane(0));
    pnAlkaneSelect.add(btnPrevAlkane);
    pnAlkaneSelect.add(lbCurrentAlkane);
    pnAlkaneSelect.add(btnNextAlkane);
    pnAlkaneSelect.add(cbCurrentAlkaneSubH);
    pnPeakPick.add(pnAlkaneSelect, "cell 1 3");
    pnPeakPick.add(new JLabel("m/z range"), "cell 0 4");
    pnPeakPick.add(mzc);
    pnPeakPick.add(new JLabel(KovatsIndexExtractionParameters.rtRange.getName()), "cell 0 5");
    pnPeakPick.add(rtc);
    pnPeakPick.add(new JLabel(KovatsIndexExtractionParameters.noiseLevel.getName()), "cell 0 6");
    pnPeakPick.add(noisec);
    pnPeakPick.add(new JLabel(KovatsIndexExtractionParameters.ratioTopEdge.getName()), "cell 0 7");
    pnPeakPick.add(edgeRatioC);
    // add listeners
    comboDataFileName.addItemListener(e -> updateChart());
    mzc.addDocumentListener(ddlUpdateChart);
    rtc.addDocumentListener(ddlUpdateChart);
    // show
    revalidate();
    updateMinimumSize();
    pack();
    updateChart();
}
Also used : Color(java.awt.Color) StringComponent(net.sf.mzmine.parameters.parametertypes.StringComponent) Arrays(java.util.Arrays) FileAndPathUtil(net.sf.mzmine.util.files.FileAndPathUtil) ChartGestureHandler(net.sf.mzmine.chartbasics.gestures.ChartGestureHandler) ValueMarker(org.jfree.chart.plot.ValueMarker) MultiChoiceComponent(net.sf.mzmine.parameters.parametertypes.MultiChoiceComponent) ParameterSet(net.sf.mzmine.parameters.ParameterSet) Event(net.sf.mzmine.chartbasics.gestures.ChartGesture.Event) JFileChooser(javax.swing.JFileChooser) BorderLayout(java.awt.BorderLayout) JComboBox(javax.swing.JComboBox) Image(java.awt.Image) Key(net.sf.mzmine.chartbasics.gestures.ChartGesture.Key) Font(java.awt.Font) Range(com.google.common.collect.Range) MZRangeComponent(net.sf.mzmine.parameters.parametertypes.ranges.MZRangeComponent) Icon(javax.swing.Icon) Logger(java.util.logging.Logger) StandardCharsets(java.nio.charset.StandardCharsets) Box(javax.swing.Box) ChartGestureDragDiffEvent(net.sf.mzmine.chartbasics.gestures.ChartGestureDragDiffEvent) Dimension(java.awt.Dimension) List(java.util.List) Stream(java.util.stream.Stream) XYDataset(org.jfree.data.xy.XYDataset) Entry(java.util.Map.Entry) JCheckBox(javax.swing.JCheckBox) Entity(net.sf.mzmine.chartbasics.gestures.ChartGesture.Entity) RTRangeComponent(net.sf.mzmine.parameters.parametertypes.ranges.RTRangeComponent) BasicStroke(java.awt.BasicStroke) JPanel(javax.swing.JPanel) MZmineCore(net.sf.mzmine.main.MZmineCore) ColorPalettes(net.sf.mzmine.util.ColorPalettes) JTextField(javax.swing.JTextField) FileNameExtensionFilter(javax.swing.filechooser.FileNameExtensionFilter) MzRangeFormulaCalculatorModule(net.sf.mzmine.modules.tools.mzrangecalculator.MzRangeFormulaCalculatorModule) RawDataFile(net.sf.mzmine.datamodel.RawDataFile) ArrayUtils(org.apache.commons.lang3.ArrayUtils) NumberFormat(java.text.NumberFormat) Button(net.sf.mzmine.chartbasics.gestures.ChartGesture.Button) ArrayList(java.util.ArrayList) Level(java.util.logging.Level) GridLayout(java.awt.GridLayout) IntegerComponent(net.sf.mzmine.parameters.parametertypes.IntegerComponent) FileNameComponent(net.sf.mzmine.parameters.parametertypes.filenames.FileNameComponent) DelayedDocumentListener(net.sf.mzmine.framework.listener.DelayedDocumentListener) Files(com.google.common.io.Files) ChartGesture(net.sf.mzmine.chartbasics.gestures.ChartGesture) TxtWriter(net.sf.mzmine.util.io.TxtWriter) ImageIcon(javax.swing.ImageIcon) TICPlot(net.sf.mzmine.modules.visualization.tic.TICPlot) ParameterSetupDialog(net.sf.mzmine.parameters.dialogs.ParameterSetupDialog) BoxLayout(javax.swing.BoxLayout) Stroke(java.awt.Stroke) FlowLayout(java.awt.FlowLayout) MZTolerance(net.sf.mzmine.parameters.parametertypes.tolerances.MZTolerance) JButton(javax.swing.JButton) KovatsIndex(net.sf.mzmine.modules.tools.kovats.KovatsValues.KovatsIndex) TICPlotType(net.sf.mzmine.modules.visualization.tic.TICPlotType) MigLayout(net.miginfocom.swing.MigLayout) Window(java.awt.Window) DecimalFormat(java.text.DecimalFormat) RawDataFilesSelection(net.sf.mzmine.parameters.parametertypes.selectors.RawDataFilesSelection) TICSumDataSet(net.sf.mzmine.modules.visualization.tic.TICSumDataSet) IOException(java.io.IOException) IonizationType(net.sf.mzmine.datamodel.IonizationType) File(java.io.File) Consumer(java.util.function.Consumer) RectangleInsets(org.jfree.chart.ui.RectangleInsets) TreeMap(java.util.TreeMap) ChartGestureDragDiffHandler(net.sf.mzmine.chartbasics.gestures.ChartGestureDragDiffHandler) JLabel(javax.swing.JLabel) RawDataFilesSelectionType(net.sf.mzmine.parameters.parametertypes.selectors.RawDataFilesSelectionType) DialogLoggerUtil(net.sf.mzmine.util.DialogLoggerUtil) DoubleComponent(net.sf.mzmine.parameters.parametertypes.DoubleComponent) DoubleComponent(net.sf.mzmine.parameters.parametertypes.DoubleComponent) JPanel(javax.swing.JPanel) FlowLayout(java.awt.FlowLayout) MigLayout(net.miginfocom.swing.MigLayout) JButton(javax.swing.JButton) JLabel(javax.swing.JLabel) JComboBox(javax.swing.JComboBox) Box(javax.swing.Box) JCheckBox(javax.swing.JCheckBox) Dimension(java.awt.Dimension) MZRangeComponent(net.sf.mzmine.parameters.parametertypes.ranges.MZRangeComponent) JCheckBox(javax.swing.JCheckBox) GridLayout(java.awt.GridLayout) BorderLayout(java.awt.BorderLayout) RawDataFile(net.sf.mzmine.datamodel.RawDataFile) DelayedDocumentListener(net.sf.mzmine.framework.listener.DelayedDocumentListener) RTRangeComponent(net.sf.mzmine.parameters.parametertypes.ranges.RTRangeComponent)

Example 79 with RawDataFile

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

the class KovatsIndexExtractionDialog method initRawDataFileSelection.

/**
 * Init raw data selection to last used raw data file or "kovats" or "dro"
 */
private void initRawDataFileSelection() {
    if (dataFiles != null && dataFiles.length <= 0)
        return;
    RawDataFilesSelection select = parameterSet.getParameter(KovatsIndexExtractionParameters.dataFiles).getValue();
    RawDataFile[] raw = null;
    // set to parameters files - if they exist in this project
    if (select != null && select.getMatchingRawDataFiles().length > 0) {
        RawDataFile[] exists = Arrays.stream(select.getMatchingRawDataFiles()).filter(r -> Arrays.stream(dataFiles).anyMatch(d -> r.getName().equals(d.getName()))).toArray(RawDataFile[]::new);
        if (exists.length > 0)
            raw = exists;
    }
    if (raw == null) {
        // find kovats or dro file
        // first use all kovats named files and then dro (max 2)
        RawDataFile[] kovats = Arrays.stream(dataFiles).filter(d -> d.getName().toLowerCase().contains("kovats")).toArray(RawDataFile[]::new);
        RawDataFile[] dro = Arrays.stream(dataFiles).filter(d -> d.getName().toLowerCase().contains("dro")).toArray(RawDataFile[]::new);
        // maximum of two files are chosen (0,1,2)
        int size = Math.min(2, kovats.length + dro.length);
        raw = new RawDataFile[size];
        for (int i = 0; i < raw.length; i++) {
            if (i < kovats.length)
                raw[i] = kovats[i];
            else
                raw[i] = dro[i - kovats.length];
        }
    }
    if (raw.length > 0) {
        selectedDataFile = raw;
        comboDataFileName.setSelectedItem(selectedDataFile[0]);
        if (raw.length > 1) {
            comboDataFileName2.setSelectedItem(selectedDataFile[1]);
        }
    }
}
Also used : Color(java.awt.Color) StringComponent(net.sf.mzmine.parameters.parametertypes.StringComponent) Arrays(java.util.Arrays) FileAndPathUtil(net.sf.mzmine.util.files.FileAndPathUtil) ChartGestureHandler(net.sf.mzmine.chartbasics.gestures.ChartGestureHandler) ValueMarker(org.jfree.chart.plot.ValueMarker) MultiChoiceComponent(net.sf.mzmine.parameters.parametertypes.MultiChoiceComponent) ParameterSet(net.sf.mzmine.parameters.ParameterSet) Event(net.sf.mzmine.chartbasics.gestures.ChartGesture.Event) JFileChooser(javax.swing.JFileChooser) BorderLayout(java.awt.BorderLayout) JComboBox(javax.swing.JComboBox) Image(java.awt.Image) Key(net.sf.mzmine.chartbasics.gestures.ChartGesture.Key) Font(java.awt.Font) Range(com.google.common.collect.Range) MZRangeComponent(net.sf.mzmine.parameters.parametertypes.ranges.MZRangeComponent) Icon(javax.swing.Icon) Logger(java.util.logging.Logger) StandardCharsets(java.nio.charset.StandardCharsets) Box(javax.swing.Box) ChartGestureDragDiffEvent(net.sf.mzmine.chartbasics.gestures.ChartGestureDragDiffEvent) Dimension(java.awt.Dimension) List(java.util.List) Stream(java.util.stream.Stream) XYDataset(org.jfree.data.xy.XYDataset) Entry(java.util.Map.Entry) JCheckBox(javax.swing.JCheckBox) Entity(net.sf.mzmine.chartbasics.gestures.ChartGesture.Entity) RTRangeComponent(net.sf.mzmine.parameters.parametertypes.ranges.RTRangeComponent) BasicStroke(java.awt.BasicStroke) JPanel(javax.swing.JPanel) MZmineCore(net.sf.mzmine.main.MZmineCore) ColorPalettes(net.sf.mzmine.util.ColorPalettes) JTextField(javax.swing.JTextField) FileNameExtensionFilter(javax.swing.filechooser.FileNameExtensionFilter) MzRangeFormulaCalculatorModule(net.sf.mzmine.modules.tools.mzrangecalculator.MzRangeFormulaCalculatorModule) RawDataFile(net.sf.mzmine.datamodel.RawDataFile) ArrayUtils(org.apache.commons.lang3.ArrayUtils) NumberFormat(java.text.NumberFormat) Button(net.sf.mzmine.chartbasics.gestures.ChartGesture.Button) ArrayList(java.util.ArrayList) Level(java.util.logging.Level) GridLayout(java.awt.GridLayout) IntegerComponent(net.sf.mzmine.parameters.parametertypes.IntegerComponent) FileNameComponent(net.sf.mzmine.parameters.parametertypes.filenames.FileNameComponent) DelayedDocumentListener(net.sf.mzmine.framework.listener.DelayedDocumentListener) Files(com.google.common.io.Files) ChartGesture(net.sf.mzmine.chartbasics.gestures.ChartGesture) TxtWriter(net.sf.mzmine.util.io.TxtWriter) ImageIcon(javax.swing.ImageIcon) TICPlot(net.sf.mzmine.modules.visualization.tic.TICPlot) ParameterSetupDialog(net.sf.mzmine.parameters.dialogs.ParameterSetupDialog) BoxLayout(javax.swing.BoxLayout) Stroke(java.awt.Stroke) FlowLayout(java.awt.FlowLayout) MZTolerance(net.sf.mzmine.parameters.parametertypes.tolerances.MZTolerance) JButton(javax.swing.JButton) KovatsIndex(net.sf.mzmine.modules.tools.kovats.KovatsValues.KovatsIndex) TICPlotType(net.sf.mzmine.modules.visualization.tic.TICPlotType) MigLayout(net.miginfocom.swing.MigLayout) Window(java.awt.Window) DecimalFormat(java.text.DecimalFormat) RawDataFilesSelection(net.sf.mzmine.parameters.parametertypes.selectors.RawDataFilesSelection) TICSumDataSet(net.sf.mzmine.modules.visualization.tic.TICSumDataSet) IOException(java.io.IOException) IonizationType(net.sf.mzmine.datamodel.IonizationType) File(java.io.File) Consumer(java.util.function.Consumer) RectangleInsets(org.jfree.chart.ui.RectangleInsets) TreeMap(java.util.TreeMap) ChartGestureDragDiffHandler(net.sf.mzmine.chartbasics.gestures.ChartGestureDragDiffHandler) JLabel(javax.swing.JLabel) RawDataFilesSelectionType(net.sf.mzmine.parameters.parametertypes.selectors.RawDataFilesSelectionType) DialogLoggerUtil(net.sf.mzmine.util.DialogLoggerUtil) DoubleComponent(net.sf.mzmine.parameters.parametertypes.DoubleComponent) RawDataFilesSelection(net.sf.mzmine.parameters.parametertypes.selectors.RawDataFilesSelection) RawDataFile(net.sf.mzmine.datamodel.RawDataFile)

Example 80 with RawDataFile

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

the class SortDataFilesModule method runModule.

@Override
@Nonnull
public ExitCode runModule(@Nonnull MZmineProject project, @Nonnull ParameterSet parameters, @Nonnull Collection<Task> tasks) {
    List<RawDataFile> dataFiles = Arrays.asList(parameters.getParameter(SortDataFilesParameters.dataFiles).getValue().getMatchingRawDataFiles());
    RawDataTreeModel model = null;
    if (project instanceof MZmineProjectImpl) {
        model = ((MZmineProjectImpl) project).getRawDataTreeModel();
    } else if (MZmineCore.getDesktop() instanceof MainWindow) {
        ProjectTree tree = ((MainWindow) MZmineCore.getDesktop()).getMainPanel().getRawDataTree();
        model = (RawDataTreeModel) tree.getModel();
    }
    if (model == null)
        throw new MSDKRuntimeException("Cannot find raw data file tree model for sorting. Different MZmine project impl?");
    final DefaultMutableTreeNode rootNode = model.getRoot();
    // Get all tree nodes that represent selected data files, and remove
    // them from
    final ArrayList<DefaultMutableTreeNode> selectedNodes = new ArrayList<DefaultMutableTreeNode>();
    for (int row = 0; row < rootNode.getChildCount(); row++) {
        DefaultMutableTreeNode selectedNode = (DefaultMutableTreeNode) rootNode.getChildAt(row);
        Object selectedObject = selectedNode.getUserObject();
        if (dataFiles.contains(selectedObject)) {
            selectedNodes.add(selectedNode);
        }
    }
    // Get the index of the first selected item
    final ArrayList<Integer> positions = new ArrayList<Integer>();
    for (DefaultMutableTreeNode node : selectedNodes) {
        int nodeIndex = rootNode.getIndex(node);
        if (nodeIndex != -1)
            positions.add(nodeIndex);
    }
    if (positions.isEmpty())
        return ExitCode.ERROR;
    int insertPosition = Collections.min(positions);
    // Sort the data files by name
    Collections.sort(selectedNodes, new Comparator<DefaultMutableTreeNode>() {

        @Override
        public int compare(DefaultMutableTreeNode o1, DefaultMutableTreeNode o2) {
            return o1.getUserObject().toString().compareTo(o2.getUserObject().toString());
        }
    });
    // Reorder the nodes in the tree model
    for (DefaultMutableTreeNode node : selectedNodes) {
        model.removeNodeFromParent(node);
        model.insertNodeInto(node, rootNode, insertPosition);
        insertPosition++;
    }
    return ExitCode.OK;
}
Also used : DefaultMutableTreeNode(javax.swing.tree.DefaultMutableTreeNode) ArrayList(java.util.ArrayList) ProjectTree(net.sf.mzmine.desktop.impl.projecttree.ProjectTree) RawDataFile(net.sf.mzmine.datamodel.RawDataFile) MainWindow(net.sf.mzmine.desktop.impl.MainWindow) MSDKRuntimeException(io.github.msdk.MSDKRuntimeException) RawDataTreeModel(net.sf.mzmine.desktop.impl.projecttree.RawDataTreeModel) MZmineProjectImpl(net.sf.mzmine.project.impl.MZmineProjectImpl) Nonnull(javax.annotation.Nonnull)

Aggregations

RawDataFile (net.sf.mzmine.datamodel.RawDataFile)185 Feature (net.sf.mzmine.datamodel.Feature)59 PeakListRow (net.sf.mzmine.datamodel.PeakListRow)52 DataPoint (net.sf.mzmine.datamodel.DataPoint)51 Scan (net.sf.mzmine.datamodel.Scan)40 ArrayList (java.util.ArrayList)33 PeakList (net.sf.mzmine.datamodel.PeakList)33 Nonnull (javax.annotation.Nonnull)24 SimpleDataPoint (net.sf.mzmine.datamodel.impl.SimpleDataPoint)24 SimplePeakList (net.sf.mzmine.datamodel.impl.SimplePeakList)24 SimplePeakListRow (net.sf.mzmine.datamodel.impl.SimplePeakListRow)22 Task (net.sf.mzmine.taskcontrol.Task)20 SimplePeakListAppliedMethod (net.sf.mzmine.datamodel.impl.SimplePeakListAppliedMethod)19 SimpleFeature (net.sf.mzmine.datamodel.impl.SimpleFeature)17 IOException (java.io.IOException)14 ParameterSet (net.sf.mzmine.parameters.ParameterSet)14 File (java.io.File)13 MassList (net.sf.mzmine.datamodel.MassList)13 PeakListAppliedMethod (net.sf.mzmine.datamodel.PeakList.PeakListAppliedMethod)13 TreeMap (java.util.TreeMap)10