Search in sources :

Example 81 with PeakListRow

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

the class ProjectTreeRenderer method getTreeCellRendererComponent.

public Component getTreeCellRendererComponent(JTree tree, Object node, boolean sel, boolean expanded, boolean leaf, int row, boolean hasFocus) {
    JLabel label = (JLabel) super.getTreeCellRendererComponent(tree, node, sel, expanded, leaf, row, hasFocus);
    DefaultMutableTreeNode treeNode = (DefaultMutableTreeNode) node;
    Object embeddedObject = treeNode.getUserObject();
    if (embeddedObject instanceof MZmineProject) {
        label.setIcon(projectIcon);
        label.setFont(bigFont);
    }
    if (embeddedObject == RawDataTreeModel.dataFilesNodeName) {
        label.setIcon(dataFileIcon);
        label.setFont(bigFont);
    }
    if (embeddedObject == PeakListTreeModel.peakListsNodeName) {
        label.setFont(bigFont);
        label.setIcon(peakListsIcon);
    }
    if (embeddedObject instanceof RawDataFile) {
        label.setFont(smallerFont);
        boolean hasMassList = RawDataFileUtils.hasMassLists((RawDataFile) embeddedObject);
        if (hasMassList)
            label.setIcon(fileWithMassListIcon);
        else
            label.setIcon(fileIcon);
    }
    if (embeddedObject instanceof Scan) {
        Scan s = (Scan) embeddedObject;
        label.setIcon(spectrumIcon);
        label.setFont(smallFont);
        // could get blue text on blue background
        if (!sel) {
            if (s.getMSLevel() > 1)
                label.setForeground(Color.red);
            else
                label.setForeground(Color.blue);
        }
    }
    if (embeddedObject instanceof MassList) {
        label.setIcon(peakListIcon);
        label.setFont(smallFont);
    }
    if (embeddedObject instanceof PeakList) {
        PeakList p = (PeakList) embeddedObject;
        if (p.getNumberOfRawDataFiles() > 1) {
            label.setFont(smallerFont.deriveFont(Font.BOLD));
            label.setIcon(alignedPeaklistIcon);
        } else {
            label.setFont(smallerFont);
            label.setIcon(peakListIcon);
        }
    }
    if (embeddedObject instanceof PeakListRow) {
        PeakListRow r = (PeakListRow) embeddedObject;
        label.setIcon(peakIcon);
        label.setFont(smallFont);
        // Change the color only if the row is not selected
        if (!sel) {
            if (r.getPreferredPeakIdentity() != null) {
                label.setForeground(Color.red);
            }
        }
    }
    return label;
}
Also used : PeakListRow(net.sf.mzmine.datamodel.PeakListRow) DefaultMutableTreeNode(javax.swing.tree.DefaultMutableTreeNode) RawDataFile(net.sf.mzmine.datamodel.RawDataFile) JLabel(javax.swing.JLabel) MZmineProject(net.sf.mzmine.datamodel.MZmineProject) Scan(net.sf.mzmine.datamodel.Scan) PeakList(net.sf.mzmine.datamodel.PeakList) MassList(net.sf.mzmine.datamodel.MassList)

Example 82 with PeakListRow

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

the class NeutralLossFilterTask method getRowFromCandidate.

/**
 * Extracts a feature list row from a Candidates array.
 *
 * @param candidates
 * @param peakIndex the index of the candidate peak, the feature list row should be extracted for.
 * @param plh
 * @return null if no peak with the given parameters exists, the specified feature list row
 *         otherwise.
 */
@Nullable
private PeakListRow getRowFromCandidate(@Nonnull Candidates candidates, int peakIndex, @Nonnull PeakListHandler plh) {
    if (peakIndex >= candidates.size())
        return null;
    Candidate cand = candidates.get(peakIndex);
    if (cand != null) {
        int id = cand.getCandID();
        PeakListRow original = plh.getRowByID(id);
        return original;
    }
    return null;
}
Also used : Candidate(net.sf.mzmine.modules.peaklistmethods.isotopes.isotopepeakscanner.Candidate) SimplePeakListRow(net.sf.mzmine.datamodel.impl.SimplePeakListRow) PeakListRow(net.sf.mzmine.datamodel.PeakListRow) Nullable(javax.annotation.Nullable)

Example 83 with PeakListRow

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

the class NeutralLossFilterTask method copyPeakRow.

/**
 * Create a copy of a feature list row.
 *
 * @param row the row to copy.
 * @return the newly created copy.
 */
private static PeakListRow copyPeakRow(final PeakListRow row) {
    // Copy the feature list row.
    final PeakListRow newRow = new SimplePeakListRow(row.getID());
    PeakUtils.copyPeakListRowProperties(row, newRow);
    // Copy the peaks.
    for (final Feature peak : row.getPeaks()) {
        final Feature newPeak = new SimpleFeature(peak);
        PeakUtils.copyPeakProperties(peak, newPeak);
        newRow.addPeak(peak.getDataFile(), newPeak);
    }
    return newRow;
}
Also used : SimplePeakListRow(net.sf.mzmine.datamodel.impl.SimplePeakListRow) PeakListRow(net.sf.mzmine.datamodel.PeakListRow) SimplePeakListRow(net.sf.mzmine.datamodel.impl.SimplePeakListRow) Feature(net.sf.mzmine.datamodel.Feature) SimpleFeature(net.sf.mzmine.datamodel.impl.SimpleFeature) SimpleFeature(net.sf.mzmine.datamodel.impl.SimpleFeature)

Example 84 with PeakListRow

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

the class PeakFilterTask method copyPeakRow.

/**
 * Create a copy of a feature list row.
 */
private static PeakListRow copyPeakRow(final PeakListRow row, final boolean[] keepPeak) {
    // Copy the feature list row.
    final PeakListRow newRow = new SimplePeakListRow(row.getID());
    PeakUtils.copyPeakListRowProperties(row, newRow);
    // Copy the peaks.
    int i = 0;
    for (final Feature peak : row.getPeaks()) {
        // Only keep peak if it fulfills the filter criteria
        if (keepPeak[i]) {
            final Feature newPeak = new SimpleFeature(peak);
            PeakUtils.copyPeakProperties(peak, newPeak);
            newRow.addPeak(peak.getDataFile(), newPeak);
        }
        i++;
    }
    return newRow;
}
Also used : SimplePeakListRow(net.sf.mzmine.datamodel.impl.SimplePeakListRow) PeakListRow(net.sf.mzmine.datamodel.PeakListRow) SimplePeakListRow(net.sf.mzmine.datamodel.impl.SimplePeakListRow) SimpleFeature(net.sf.mzmine.datamodel.impl.SimpleFeature) Feature(net.sf.mzmine.datamodel.Feature) SimpleFeature(net.sf.mzmine.datamodel.impl.SimpleFeature)

Example 85 with PeakListRow

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

the class RowsFilterTask method filterPeakListRows.

/**
 * Filter the feature list rows.
 *
 * @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(RowsFilterParameters.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 onlyIdentified = parameters.getParameter(RowsFilterParameters.HAS_IDENTITIES).getValue();
    final boolean filterByIdentityText = parameters.getParameter(RowsFilterParameters.IDENTITY_TEXT).getValue();
    final boolean filterByCommentText = parameters.getParameter(RowsFilterParameters.COMMENT_TEXT).getValue();
    final String groupingParameter = (String) parameters.getParameter(RowsFilterParameters.GROUPSPARAMETER).getValue();
    final boolean filterByMinPeakCount = parameters.getParameter(RowsFilterParameters.MIN_PEAK_COUNT).getValue();
    final boolean filterByMinIsotopePatternSize = parameters.getParameter(RowsFilterParameters.MIN_ISOTOPE_PATTERN_COUNT).getValue();
    final boolean filterByMzRange = parameters.getParameter(RowsFilterParameters.MZ_RANGE).getValue();
    final boolean filterByRtRange = parameters.getParameter(RowsFilterParameters.RT_RANGE).getValue();
    final boolean filterByDuration = parameters.getParameter(RowsFilterParameters.PEAK_DURATION).getValue();
    final boolean filterByFWHM = parameters.getParameter(RowsFilterParameters.FWHM).getValue();
    final boolean filterByCharge = parameters.getParameter(RowsFilterParameters.CHARGE).getValue();
    final boolean filterByKMD = parameters.getParameter(RowsFilterParameters.KENDRICK_MASS_DEFECT).getValue();
    final boolean filterByMS2 = parameters.getParameter(RowsFilterParameters.MS2_Filter).getValue();
    final String removeRowString = parameters.getParameter(RowsFilterParameters.REMOVE_ROW).getValue();
    Double minCount = parameters.getParameter(RowsFilterParameters.MIN_PEAK_COUNT).getEmbeddedParameter().getValue();
    final boolean renumber = parameters.getParameter(RowsFilterParameters.Reset_ID).getValue();
    int rowsCount = 0;
    boolean removeRow = false;
    if (removeRowString.equals(RowsFilterParameters.removeRowChoices[0]))
        removeRow = false;
    else
        removeRow = true;
    // Keep rows that don't match any criteria. Keep by default.
    boolean filterRowCriteriaFailed = false;
    // Handle < 1 values for minPeakCount
    if ((minCount == null) || (minCount < 1))
        minCount = 1.0;
    // Round value down to nearest hole number
    int intMinCount = minCount.intValue();
    // Filter rows.
    final PeakListRow[] rows = peakList.getRows();
    totalRows = rows.length;
    for (processedRows = 0; !isCanceled() && processedRows < totalRows; processedRows++) {
        filterRowCriteriaFailed = false;
        final PeakListRow row = rows[processedRows];
        final int peakCount = getPeakCount(row, groupingParameter);
        // Check number of peaks.
        if (filterByMinPeakCount) {
            if (peakCount < intMinCount)
                filterRowCriteriaFailed = true;
        }
        // Check identities.
        if (onlyIdentified) {
            if (row.getPreferredPeakIdentity() == null)
                filterRowCriteriaFailed = true;
        }
        // Check average m/z.
        if (filterByMzRange) {
            final Range<Double> mzRange = parameters.getParameter(RowsFilterParameters.MZ_RANGE).getEmbeddedParameter().getValue();
            if (!mzRange.contains(row.getAverageMZ()))
                filterRowCriteriaFailed = true;
        }
        // Check average RT.
        if (filterByRtRange) {
            final Range<Double> rtRange = parameters.getParameter(RowsFilterParameters.RT_RANGE).getEmbeddedParameter().getValue();
            if (!rtRange.contains(row.getAverageRT()))
                filterRowCriteriaFailed = true;
        }
        // Search peak identity text.
        if (filterByIdentityText) {
            if (row.getPreferredPeakIdentity() == null)
                filterRowCriteriaFailed = true;
            if (row.getPreferredPeakIdentity() != null) {
                final String searchText = parameters.getParameter(RowsFilterParameters.IDENTITY_TEXT).getEmbeddedParameter().getValue().toLowerCase().trim();
                int numFailedIdentities = 0;
                PeakIdentity[] identities = row.getPeakIdentities();
                for (int index = 0; !isCanceled() && index < identities.length; index++) {
                    String rowText = identities[index].getName().toLowerCase().trim();
                    if (!rowText.contains(searchText))
                        numFailedIdentities += 1;
                }
                if (numFailedIdentities == identities.length)
                    filterRowCriteriaFailed = true;
            }
        }
        // Search peak comment text.
        if (filterByCommentText) {
            if (row.getComment() == null)
                filterRowCriteriaFailed = true;
            if (row.getComment() != null) {
                final String searchText = parameters.getParameter(RowsFilterParameters.COMMENT_TEXT).getEmbeddedParameter().getValue().toLowerCase().trim();
                final String rowText = row.getComment().toLowerCase().trim();
                if (!rowText.contains(searchText))
                    filterRowCriteriaFailed = true;
            }
        }
        // Calculate average duration and isotope pattern count.
        int maxIsotopePatternSizeOnRow = 1;
        double avgDuration = 0.0;
        final Feature[] peaks = row.getPeaks();
        for (final Feature p : peaks) {
            final IsotopePattern pattern = p.getIsotopePattern();
            if (pattern != null && maxIsotopePatternSizeOnRow < pattern.getNumberOfDataPoints()) {
                maxIsotopePatternSizeOnRow = pattern.getNumberOfDataPoints();
            }
            avgDuration += RangeUtils.rangeLength(p.getRawDataPointsRTRange());
        }
        // Check isotope pattern count.
        if (filterByMinIsotopePatternSize) {
            final int minIsotopePatternSize = parameters.getParameter(RowsFilterParameters.MIN_ISOTOPE_PATTERN_COUNT).getEmbeddedParameter().getValue();
            if (maxIsotopePatternSizeOnRow < minIsotopePatternSize)
                filterRowCriteriaFailed = true;
        }
        // Check average duration.
        avgDuration /= peakCount;
        if (filterByDuration) {
            final Range<Double> durationRange = parameters.getParameter(RowsFilterParameters.PEAK_DURATION).getEmbeddedParameter().getValue();
            if (!durationRange.contains(avgDuration))
                filterRowCriteriaFailed = true;
        }
        // Filter by FWHM range
        if (filterByFWHM) {
            final Range<Double> FWHMRange = parameters.getParameter(RowsFilterParameters.FWHM).getEmbeddedParameter().getValue();
            // If any of the peaks fail the FWHM criteria,
            Double FWHM_value = row.getBestPeak().getFWHM();
            if (FWHM_value != null && !FWHMRange.contains(FWHM_value))
                filterRowCriteriaFailed = true;
        }
        // Filter by charge range
        if (filterByCharge) {
            final Range<Integer> chargeRange = parameters.getParameter(RowsFilterParameters.CHARGE).getEmbeddedParameter().getValue();
            int charge = row.getBestPeak().getCharge();
            if (charge == 0 || !chargeRange.contains(charge))
                filterRowCriteriaFailed = true;
        }
        // Filter by KMD or RKM range
        if (filterByKMD) {
            // get embedded parameters
            final Range<Double> rangeKMD = parameters.getParameter(RowsFilterParameters.KENDRICK_MASS_DEFECT).getEmbeddedParameters().getParameter(KendrickMassDefectFilterParameters.kendrickMassDefectRange).getValue();
            final String kendrickMassBase = parameters.getParameter(RowsFilterParameters.KENDRICK_MASS_DEFECT).getEmbeddedParameters().getParameter(KendrickMassDefectFilterParameters.kendrickMassBase).getValue();
            final double shift = parameters.getParameter(RowsFilterParameters.KENDRICK_MASS_DEFECT).getEmbeddedParameters().getParameter(KendrickMassDefectFilterParameters.shift).getValue();
            final int charge = parameters.getParameter(RowsFilterParameters.KENDRICK_MASS_DEFECT).getEmbeddedParameters().getParameter(KendrickMassDefectFilterParameters.charge).getValue();
            final int divisor = parameters.getParameter(RowsFilterParameters.KENDRICK_MASS_DEFECT).getEmbeddedParameters().getParameter(KendrickMassDefectFilterParameters.divisor).getValue();
            final boolean useRemainderOfKendrickMass = parameters.getParameter(RowsFilterParameters.KENDRICK_MASS_DEFECT).getEmbeddedParameters().getParameter(KendrickMassDefectFilterParameters.useRemainderOfKendrickMass).getValue();
            // get m/z
            Double valueMZ = row.getBestPeak().getMZ();
            // calc exact mass of Kendrick mass base
            double exactMassFormula = FormulaUtils.calculateExactMass(kendrickMassBase);
            // calc exact mass of Kendrick mass factor
            double kendrickMassFactor = Math.round(exactMassFormula / divisor) / (exactMassFormula / divisor);
            double defectOrRemainder = 0.0;
            if (!useRemainderOfKendrickMass) {
                // calc Kendrick mass defect
                defectOrRemainder = Math.ceil(charge * (valueMZ * kendrickMassFactor)) - charge * (valueMZ * kendrickMassFactor);
            } else {
                // calc Kendrick mass remainder
                defectOrRemainder = (charge * (divisor - Math.round(FormulaUtils.calculateExactMass(kendrickMassBase))) * valueMZ) / // 
                FormulaUtils.calculateExactMass(kendrickMassBase) - Math.floor((charge * (divisor - Math.round(FormulaUtils.calculateExactMass(kendrickMassBase))) * valueMZ) / FormulaUtils.calculateExactMass(kendrickMassBase));
            }
            // shift Kendrick mass defect or remainder of Kendrick mass
            double kendrickMassDefectShifted = defectOrRemainder + shift - Math.floor(defectOrRemainder + shift);
            // check if shifted Kendrick mass defect or remainder of Kendrick mass is in range
            if (!rangeKMD.contains(kendrickMassDefectShifted))
                filterRowCriteriaFailed = true;
        }
        // Check ms2 filter .
        if (filterByMS2) {
            // iterates the peaks
            int failCounts = 0;
            for (int i = 0; i < peakCount; i++) {
                if (row.getPeaks()[i].getMostIntenseFragmentScanNumber() < 1) {
                    failCounts++;
                // filterRowCriteriaFailed = true;
                // break;
                }
            }
            if (failCounts == peakCount) {
                filterRowCriteriaFailed = true;
            }
        }
        if (!filterRowCriteriaFailed && !removeRow) {
            // Only add the row if none of the criteria have failed.
            rowsCount++;
            PeakListRow resetRow = copyPeakRow(row);
            if (renumber) {
                resetRow.setID(rowsCount);
            }
            newPeakList.addRow(resetRow);
        }
        if (filterRowCriteriaFailed && removeRow) {
            // Only remove rows that match *all* of the criteria, so add
            // rows that fail any of the criteria.
            rowsCount++;
            PeakListRow resetRow = copyPeakRow(row);
            if (renumber) {
                resetRow.setID(rowsCount);
            }
            newPeakList.addRow(resetRow);
        }
    }
    return newPeakList;
}
Also used : SimplePeakListAppliedMethod(net.sf.mzmine.datamodel.impl.SimplePeakListAppliedMethod) PeakListAppliedMethod(net.sf.mzmine.datamodel.PeakList.PeakListAppliedMethod) IsotopePattern(net.sf.mzmine.datamodel.IsotopePattern) SimplePeakListAppliedMethod(net.sf.mzmine.datamodel.impl.SimplePeakListAppliedMethod) Feature(net.sf.mzmine.datamodel.Feature) SimpleFeature(net.sf.mzmine.datamodel.impl.SimpleFeature) PeakIdentity(net.sf.mzmine.datamodel.PeakIdentity) SimplePeakListRow(net.sf.mzmine.datamodel.impl.SimplePeakListRow) PeakListRow(net.sf.mzmine.datamodel.PeakListRow) SimplePeakList(net.sf.mzmine.datamodel.impl.SimplePeakList) SimplePeakList(net.sf.mzmine.datamodel.impl.SimplePeakList) PeakList(net.sf.mzmine.datamodel.PeakList)

Aggregations

PeakListRow (net.sf.mzmine.datamodel.PeakListRow)148 Feature (net.sf.mzmine.datamodel.Feature)71 RawDataFile (net.sf.mzmine.datamodel.RawDataFile)55 SimplePeakListRow (net.sf.mzmine.datamodel.impl.SimplePeakListRow)54 PeakList (net.sf.mzmine.datamodel.PeakList)44 SimplePeakList (net.sf.mzmine.datamodel.impl.SimplePeakList)39 ArrayList (java.util.ArrayList)31 SimpleFeature (net.sf.mzmine.datamodel.impl.SimpleFeature)31 DataPoint (net.sf.mzmine.datamodel.DataPoint)29 SimplePeakListAppliedMethod (net.sf.mzmine.datamodel.impl.SimplePeakListAppliedMethod)26 Scan (net.sf.mzmine.datamodel.Scan)25 PeakIdentity (net.sf.mzmine.datamodel.PeakIdentity)20 PeakListRowSorter (net.sf.mzmine.util.PeakListRowSorter)17 SimpleDataPoint (net.sf.mzmine.datamodel.impl.SimpleDataPoint)13 PeakListAppliedMethod (net.sf.mzmine.datamodel.PeakList.PeakListAppliedMethod)12 HashMap (java.util.HashMap)11 Vector (java.util.Vector)11 ParameterSet (net.sf.mzmine.parameters.ParameterSet)11 IsotopePattern (net.sf.mzmine.datamodel.IsotopePattern)10 MassList (net.sf.mzmine.datamodel.MassList)10