use of net.sf.mzmine.datamodel.PeakList.PeakListAppliedMethod in project mzmine2 by mzmine.
the class ShapeModelerTask method run.
public void run() {
setStatus(TaskStatus.PROCESSING);
Class<?> shapeModelClass = shapeModelerType.getModelClass();
Constructor<?> shapeModelConstruct;
shapeModelConstruct = shapeModelClass.getConstructors()[0];
// Get data file information
RawDataFile dataFile = originalPeakList.getRawDataFile(0);
// Create new feature list
newPeakList = new SimplePeakList(originalPeakList + " " + suffix, dataFile);
totalRows = originalPeakList.getNumberOfRows();
int[] scanNumbers;
double[] retentionTimes, intensities;
SimplePeakListRow newRow;
for (PeakListRow row : originalPeakList.getRows()) {
if (isCanceled())
return;
newRow = new SimplePeakListRow(newPeakID);
try {
for (Feature peak : row.getPeaks()) {
// Load the intensities into array
dataFile = peak.getDataFile();
scanNumbers = peak.getScanNumbers();
retentionTimes = new double[scanNumbers.length];
for (int i = 0; i < scanNumbers.length; i++) retentionTimes[i] = dataFile.getScan(scanNumbers[i]).getRetentionTime();
intensities = new double[scanNumbers.length];
for (int i = 0; i < scanNumbers.length; i++) {
DataPoint dp = peak.getDataPoint(scanNumbers[i]);
if (dp != null)
intensities[i] = dp.getIntensity();
else
intensities[i] = 0;
}
Feature shapePeak = (Feature) shapeModelConstruct.newInstance(peak, scanNumbers, intensities, retentionTimes, resolution);
newRow.addPeak(shapePeak.getDataFile(), shapePeak);
}
} catch (Exception e) {
String message = "Error trying to make an instance of shape model class " + shapeModelClass;
MZmineCore.getDesktop().displayErrorMessage(MZmineCore.getDesktop().getMainWindow(), message);
logger.severe(message);
return;
}
newPeakList.addRow(newRow);
newPeakID++;
processedRows++;
}
// Add new peaklist to the project
project.addPeakList(newPeakList);
// Add quality parameters to peaks
QualityParameters.calculateQualityParameters(newPeakList);
// Remove the original peaklist if requested
if (removeOriginal)
project.removePeakList(originalPeakList);
// Load previous applied methods
for (PeakListAppliedMethod proc : originalPeakList.getAppliedMethods()) {
newPeakList.addDescriptionOfAppliedTask(proc);
}
// Add task description to peakList
newPeakList.addDescriptionOfAppliedTask(new SimplePeakListAppliedMethod("Peaks shaped by " + shapeModelerType + " function", parameters));
logger.finest("Finished peak shape modeler " + processedRows + " rows processed");
setStatus(TaskStatus.FINISHED);
}
use of net.sf.mzmine.datamodel.PeakList.PeakListAppliedMethod in project mzmine2 by mzmine.
the class PeakExtenderTask method run.
/**
* @see Runnable#run()
*/
public void run() {
setStatus(TaskStatus.PROCESSING);
logger.info("Running peak extender on " + peakList);
// We assume source peakList contains one datafile
RawDataFile dataFile = peakList.getRawDataFile(0);
// Create a new deisotoped peakList
extendedPeakList = new SimplePeakList(peakList + " " + suffix, peakList.getRawDataFiles());
// Sort peaks by descending height
Feature[] sortedPeaks = peakList.getPeaks(dataFile);
Arrays.sort(sortedPeaks, new PeakSorter(SortingProperty.Height, SortingDirection.Descending));
// Loop through all peaks
totalPeaks = sortedPeaks.length;
Feature oldPeak;
for (int ind = 0; ind < totalPeaks; ind++) {
if (isCanceled())
return;
oldPeak = sortedPeaks[ind];
if (oldPeak.getHeight() >= minimumHeight) {
Feature newPeak = this.getExtendedPeak(oldPeak);
// Get previous pekaListRow
PeakListRow oldRow = peakList.getPeakRow(oldPeak);
// keep old ID
int oldID = oldRow.getID();
SimplePeakListRow newRow = new SimplePeakListRow(oldID);
PeakUtils.copyPeakListRowProperties(oldRow, newRow);
newRow.addPeak(dataFile, newPeak);
extendedPeakList.addRow(newRow);
}
// Update completion rate
processedPeaks++;
}
// Add new peakList to the project
project.addPeakList(extendedPeakList);
// Add quality parameters to peaks
QualityParameters.calculateQualityParameters(extendedPeakList);
// Load previous applied methods
for (PeakListAppliedMethod proc : peakList.getAppliedMethods()) {
extendedPeakList.addDescriptionOfAppliedTask(proc);
}
// Add task description to peakList
extendedPeakList.addDescriptionOfAppliedTask(new SimplePeakListAppliedMethod("Peak extender", parameters));
// Remove the original peakList if requested
if (removeOriginal)
project.removePeakList(peakList);
logger.info("Finished peak extender on " + peakList);
setStatus(TaskStatus.FINISHED);
}
use of net.sf.mzmine.datamodel.PeakList.PeakListAppliedMethod in project mzmine2 by mzmine.
the class NeutralLossFilterTask method addResultToProject.
/**
* Add feature list to project, delete old if requested, add description to result
*/
public void addResultToProject() {
// Add new peakList to the project
project.addPeakList(resultPeakList);
// Load previous applied methods
for (PeakListAppliedMethod proc : peakList.getAppliedMethods()) {
resultPeakList.addDescriptionOfAppliedTask(proc);
}
// Add task description to peakList
resultPeakList.addDescriptionOfAppliedTask(new SimplePeakListAppliedMethod("NeutralLossFilter", parameters));
}
use of net.sf.mzmine.datamodel.PeakList.PeakListAppliedMethod 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.PeakListAppliedMethod 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;
}
Aggregations