use of net.sf.mzmine.util.PeakListRowSorter 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.util.PeakListRowSorter in project mzmine2 by mzmine.
the class AdductSearchTask method searchAdducts.
/**
* Search peak-list for adducts.
*/
private void searchAdducts() {
// Get rows.
final PeakListRow[] rows = peakList.getRows();
totalRows = rows.length;
// Start with the highest peaks.
Arrays.sort(rows, new PeakListRowSorter(SortingProperty.Height, SortingDirection.Descending));
// Compare each pair of rows against each other.
for (int i = 0; !isCanceled() && i < totalRows; i++) {
for (int j = 0; !isCanceled() && j < totalRows; j++) {
if (i == j)
continue;
findAdducts(rows[i], rows[j]);
}
finishedRows++;
}
}
use of net.sf.mzmine.util.PeakListRowSorter in project mzmine2 by mzmine.
the class VanKrevelenDiagramParameters method showSetupDialog.
@Override
public ExitCode showSetupDialog(Window parent, boolean valueCheckRequired) {
PeakList[] selectedPeakLists = getParameter(peakList).getValue().getMatchingPeakLists();
if (selectedPeakLists.length > 0) {
PeakListRow[] plRows = selectedPeakLists[0].getRows();
Arrays.sort(plRows, new PeakListRowSorter(SortingProperty.MZ, SortingDirection.Ascending));
}
return super.showSetupDialog(parent, valueCheckRequired);
}
use of net.sf.mzmine.util.PeakListRowSorter in project mzmine2 by mzmine.
the class FragmentSearchTask method run.
/**
* @see java.lang.Runnable#run()
*/
public void run() {
setStatus(TaskStatus.PROCESSING);
logger.info("Starting fragments search in " + peakList);
PeakListRow[] rows = peakList.getRows();
totalRows = rows.length;
// Start with the highest peaks
Arrays.sort(rows, new PeakListRowSorter(SortingProperty.Height, SortingDirection.Descending));
// Compare each two rows against each other
for (int i = 0; i < totalRows; i++) {
for (int j = i + 1; j < rows.length; j++) {
// Task canceled?
if (isCanceled())
return;
// smaller one may be a fragment
if (rows[i].getAverageMZ() > rows[j].getAverageMZ()) {
if (checkFragment(rows[i], rows[j]))
addFragmentInfo(rows[i], rows[j]);
} else {
if (checkFragment(rows[j], rows[i]))
addFragmentInfo(rows[j], rows[i]);
}
}
finishedRows++;
}
// Add task description to peakList
((SimplePeakList) peakList).addDescriptionOfAppliedTask(new SimplePeakListAppliedMethod("Identification of fragments", parameters));
// Repaint the window to reflect the change in the feature list
Desktop desktop = MZmineCore.getDesktop();
if (!(desktop instanceof HeadLessDesktop))
desktop.getMainWindow().repaint();
setStatus(TaskStatus.FINISHED);
logger.info("Finished fragments search in " + peakList);
}
use of net.sf.mzmine.util.PeakListRowSorter in project mzmine2 by mzmine.
the class PeakListRowLearnerTask method run.
/**
* @see Runnable#run()
*/
@Override
public void run() {
setStatus(TaskStatus.PROCESSING);
logger.info("Running learner task on " + peakList);
// Create a new results peakList which is added at the end
resultPeakList = new SimplePeakList(peakList + " " + suffix, peakList.getRawDataFiles());
/**
* - A PeakList is a list of Features (peak in retention time dimension with accurate m/z)<br>
* ---- contains one or multiple RawDataFiles <br>
* ---- access mean retention time, mean m/z, maximum intensity, ...<br>
*/
// get all rows and sort by m/z
PeakListRow[] rows = peakList.getRows();
Arrays.sort(rows, new PeakListRowSorter(SortingProperty.MZ, SortingDirection.Ascending));
totalRows = rows.length;
for (int i = 0; i < totalRows; i++) {
// check for cancelled state and stop
if (isCanceled())
return;
PeakListRow row = rows[i];
// access details
double mz = row.getAverageMZ();
double intensity = row.getAverageHeight();
double rt = row.getAverageRT();
Feature peak = row.getBestPeak();
// do stuff
// ...
// add row to peaklist result
PeakListRow copy = copyPeakRow(row);
resultPeakList.addRow(copy);
// Update completion rate
processedPeaks++;
}
// add to project
addResultToProject();
logger.info("Finished on " + peakList);
setStatus(TaskStatus.FINISHED);
}
Aggregations