use of net.sf.mzmine.datamodel.PeakList in project mzmine2 by mzmine.
the class PeakFilterModule method runModule.
@Override
@Nonnull
public ExitCode runModule(@Nonnull MZmineProject project, @Nonnull ParameterSet parameters, @Nonnull Collection<Task> tasks) {
final PeakList[] peakLists = parameters.getParameter(PeakFilterParameters.PEAK_LISTS).getValue().getMatchingPeakLists();
for (PeakList peakList : peakLists) {
Task newTask = new PeakFilterTask(project, peakList, parameters);
tasks.add(newTask);
}
return ExitCode.OK;
}
use of net.sf.mzmine.datamodel.PeakList in project mzmine2 by mzmine.
the class PeakFilterTask method filterPeakList.
/**
* Filter the feature list.
*
* @param peakList feature list to filter.
* @return a new feature list with entries of the original feature list that pass the filtering.
*/
private PeakList filterPeakList(final PeakList peakList) {
// Make a copy of the peakList
final PeakList newPeakList = new SimplePeakList(peakList.getName() + ' ' + parameters.getParameter(RowsFilterParameters.SUFFIX).getValue(), peakList.getRawDataFiles());
// Get parameters - which filters are active
final boolean filterByDuration = parameters.getParameter(PeakFilterParameters.PEAK_DURATION).getValue();
final boolean filterByArea = parameters.getParameter(PeakFilterParameters.PEAK_AREA).getValue();
final boolean filterByHeight = parameters.getParameter(PeakFilterParameters.PEAK_HEIGHT).getValue();
final boolean filterByDatapoints = parameters.getParameter(PeakFilterParameters.PEAK_DATAPOINTS).getValue();
final boolean filterByFWHM = parameters.getParameter(PeakFilterParameters.PEAK_FWHM).getValue();
final boolean filterByTailingFactor = parameters.getParameter(PeakFilterParameters.PEAK_TAILINGFACTOR).getValue();
final boolean filterByAsymmetryFactor = parameters.getParameter(PeakFilterParameters.PEAK_ASYMMETRYFACTOR).getValue();
final boolean filterByMS2 = parameters.getParameter(PeakFilterParameters.MS2_Filter).getValue();
// Loop through all rows in feature list
final PeakListRow[] rows = peakList.getRows();
totalRows = rows.length;
for (processedRows = 0; !isCanceled() && processedRows < totalRows; processedRows++) {
final PeakListRow row = rows[processedRows];
final RawDataFile[] rawdatafiles = row.getRawDataFiles();
int totalRawDataFiles = rawdatafiles.length;
boolean[] keepPeak = new boolean[totalRawDataFiles];
for (int i = 0; i < totalRawDataFiles; i++) {
// Peak values
keepPeak[i] = true;
final Feature peak = row.getPeak(rawdatafiles[i]);
final double peakDuration = peak.getRawDataPointsRTRange().upperEndpoint() - peak.getRawDataPointsRTRange().lowerEndpoint();
final double peakArea = peak.getArea();
final double peakHeight = peak.getHeight();
final int peakDatapoints = peak.getScanNumbers().length;
final int msmsScanNumber = peak.getMostIntenseFragmentScanNumber();
Double peakFWHM = peak.getFWHM();
Double peakTailingFactor = peak.getTailingFactor();
Double peakAsymmetryFactor = peak.getAsymmetryFactor();
if (peakFWHM == null) {
peakFWHM = -1.0;
}
if (peakTailingFactor == null) {
peakTailingFactor = -1.0;
}
if (peakAsymmetryFactor == null) {
peakAsymmetryFactor = -1.0;
}
// Check Duration
if (filterByDuration) {
final Range<Double> durationRange = parameters.getParameter(PeakFilterParameters.PEAK_DURATION).getEmbeddedParameter().getValue();
if (!durationRange.contains(peakDuration)) {
// Mark peak to be removed
keepPeak[i] = false;
}
}
// Check Area
if (filterByArea) {
final Range<Double> areaRange = parameters.getParameter(PeakFilterParameters.PEAK_AREA).getEmbeddedParameter().getValue();
if (!areaRange.contains(peakArea)) {
// Mark peak to be removed
keepPeak[i] = false;
}
}
// Check Height
if (filterByHeight) {
final Range<Double> heightRange = parameters.getParameter(PeakFilterParameters.PEAK_HEIGHT).getEmbeddedParameter().getValue();
if (!heightRange.contains(peakHeight)) {
// Mark peak to be removed
keepPeak[i] = false;
}
}
// Check # Data Points
if (filterByDatapoints) {
final Range<Integer> datapointsRange = parameters.getParameter(PeakFilterParameters.PEAK_DATAPOINTS).getEmbeddedParameter().getValue();
if (!datapointsRange.contains(peakDatapoints)) {
// Mark peak to be removed
keepPeak[i] = false;
}
}
// Check FWHM
if (filterByFWHM) {
final Range<Double> fwhmRange = parameters.getParameter(PeakFilterParameters.PEAK_FWHM).getEmbeddedParameter().getValue();
if (!fwhmRange.contains(peakFWHM)) {
// Mark peak to be removed
keepPeak[i] = false;
}
}
// Check Tailing Factor
if (filterByTailingFactor) {
final Range<Double> tailingRange = parameters.getParameter(PeakFilterParameters.PEAK_TAILINGFACTOR).getEmbeddedParameter().getValue();
if (!tailingRange.contains(peakTailingFactor)) {
// Mark peak to be removed
keepPeak[i] = false;
}
}
// Check height
if (filterByAsymmetryFactor) {
final Range<Double> asymmetryRange = parameters.getParameter(PeakFilterParameters.PEAK_ASYMMETRYFACTOR).getEmbeddedParameter().getValue();
if (!asymmetryRange.contains(peakAsymmetryFactor)) {
// Mark peak to be removed
keepPeak[i] = false;
}
}
// Check MS/MS filter
if (filterByMS2) {
if (msmsScanNumber < 1)
keepPeak[i] = false;
}
}
// empty row?
boolean isEmpty = Booleans.asList(keepPeak).stream().allMatch(keep -> !keep);
if (!isEmpty)
newPeakList.addRow(copyPeakRow(row, keepPeak));
}
return newPeakList;
}
use of net.sf.mzmine.datamodel.PeakList 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;
}
use of net.sf.mzmine.datamodel.PeakList 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;
}
use of net.sf.mzmine.datamodel.PeakList in project mzmine2 by mzmine.
the class CameraSearchModule method runModule.
@Override
@Nonnull
public ExitCode runModule(@Nonnull MZmineProject project, @Nonnull ParameterSet parameters, @Nonnull Collection<Task> tasks) {
PeakList[] peakLists = parameters.getParameter(CameraSearchParameters.PEAK_LISTS).getValue().getMatchingPeakLists();
for (PeakList peakList : peakLists) {
Task newTask = new CameraSearchTask(project, parameters, peakList);
tasks.add(newTask);
}
return ExitCode.OK;
}
Aggregations