use of net.sf.mzmine.datamodel.impl.SimplePeakList in project mzmine2 by mzmine.
the class RansacAlignerTask method run.
public void run() {
setStatus(TaskStatus.PROCESSING);
logger.info("Running Ransac aligner");
// twice, first for score calculation, second for actual alignment.
for (int i = 0; i < peakLists.length; i++) {
totalRows += peakLists[i].getNumberOfRows() * 2;
}
// Collect all data files
List<RawDataFile> allDataFiles = new ArrayList<RawDataFile>();
for (PeakList peakList : peakLists) {
for (RawDataFile dataFile : peakList.getRawDataFiles()) {
// Each data file can only have one column in aligned feature list
if (allDataFiles.contains(dataFile)) {
setStatus(TaskStatus.ERROR);
setErrorMessage("Cannot run alignment, because file " + dataFile + " is present in multiple feature lists");
return;
}
allDataFiles.add(dataFile);
}
}
// Create a new aligned feature list
alignedPeakList = new SimplePeakList(peakListName, allDataFiles.toArray(new RawDataFile[0]));
// Iterate source feature lists
for (PeakList peakList : peakLists) {
HashMap<PeakListRow, PeakListRow> alignmentMapping = this.getAlignmentMap(peakList);
PeakListRow[] allRows = peakList.getRows();
// Align all rows using mapping
for (PeakListRow row : allRows) {
PeakListRow targetRow = alignmentMapping.get(row);
// If we have no mapping for this row, add a new one
if (targetRow == null) {
targetRow = new SimplePeakListRow(newRowID);
newRowID++;
alignedPeakList.addRow(targetRow);
}
// Add all peaks from the original row to the aligned row
for (RawDataFile file : row.getRawDataFiles()) {
targetRow.addPeak(file, row.getPeak(file));
}
// Add all non-existing identities from the original row to the
// aligned row
PeakUtils.copyPeakListRowProperties(row, targetRow);
processedRows++;
}
}
// Next feature list
// Add new aligned feature list to the project
project.addPeakList(alignedPeakList);
// Edit by Aleksandr Smirnov
PeakListRow row = alignedPeakList.getRow(1);
double alignedRetTime = row.getAverageRT();
for (Feature peak : row.getPeaks()) {
double retTimeDelta = alignedRetTime - peak.getRT();
RawDataFile dataFile = peak.getDataFile();
SortedMap<Double, Double> chromatogram = new TreeMap<>();
for (int scan : peak.getScanNumbers()) {
DataPoint dataPoint = peak.getDataPoint(scan);
double retTime = dataFile.getScan(scan).getRetentionTime() + retTimeDelta;
if (dataPoint != null)
chromatogram.put(retTime, dataPoint.getIntensity());
}
}
// End of Edit
// Add task description to peakList
alignedPeakList.addDescriptionOfAppliedTask(new SimplePeakListAppliedMethod("Ransac aligner", parameters));
logger.info("Finished RANSAC aligner");
setStatus(TaskStatus.FINISHED);
}
use of net.sf.mzmine.datamodel.impl.SimplePeakList in project mzmine2 by mzmine.
the class MultiRawDataLearnerTask 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>
* - A RawDataFile holds a full chromatographic run with all ms scans<br>
* ---- Each Scan and the underlying raw data can be accessed <br>
* ---- Scans can be filtered by MS level, polarity, ...<br>
*/
// get all rows and sort by m/z
PeakListRow[] rows = peakList.getRows();
Arrays.sort(rows, new PeakListRowSorter(SortingProperty.MZ, SortingDirection.Ascending));
// number of rawFiles is 1 prior to peaklist alignment
RawDataFile[] rawFiles = peakList.getRawDataFiles();
boolean isAlignedPeakList = rawFiles.length > 1;
totalRows = rows.length;
// loop through all rows
for (PeakListRow row : rows) {
// loop through all raw data files
for (RawDataFile raw : rawFiles) {
// check for cancelled state and stop
if (isCanceled())
return;
// current peak
Feature peak = row.getPeak(raw);
// check for peak in row for specific raw file
if (peak != null) {
double mz = peak.getMZ();
double intensity = peak.getHeight();
double rt = peak.getRT();
// do stuff
// ...
}
}
// Update completion rate
processedRows++;
}
// add to project
addResultToProject();
logger.info("Finished on " + peakList);
setStatus(TaskStatus.FINISHED);
}
use of net.sf.mzmine.datamodel.impl.SimplePeakList in project mzmine2 by mzmine.
the class PeakLearnerTask 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>
* - A RawDataFile holds a full chromatographic run with all ms scans<br>
* ---- Each Scan and the underlying raw data can be accessed <br>
* ---- Scans can be filtered by MS level, polarity, ...<br>
*/
// is the data provided by peaklist enough for this task or
// do you want to work on one raw data file or on all files?
RawDataFile dataFile = peakList.getRawDataFile(0);
// get all peaks of a raw data file
// Sort peaks by ascending mz
Feature[] sortedPeaks = peakList.getPeaks(dataFile);
Arrays.sort(sortedPeaks, new PeakSorter(SortingProperty.MZ, SortingDirection.Ascending));
// Loop through all peaks
totalPeaks = sortedPeaks.length;
for (int i = 0; i < totalPeaks; i++) {
// check for cancelled state and stop
if (isCanceled())
return;
// current peak
Feature aPeak = sortedPeaks[i];
// do stuff
// ...
// add row to result feature list
PeakListRow row = peakList.getPeakRow(aPeak);
row = copyPeakRow(row);
resultPeakList.addRow(row);
// Update completion rate
processedPeaks++;
}
// add to project
addResultToProject();
logger.info("Finished on " + peakList);
setStatus(TaskStatus.FINISHED);
}
use of net.sf.mzmine.datamodel.impl.SimplePeakList in project mzmine2 by mzmine.
the class ChromatogramBuilderTask method run.
/**
* @see Runnable#run()
*/
public void run() {
setStatus(TaskStatus.PROCESSING);
logger.info("Started chromatogram builder on " + dataFile);
scans = scanSelection.getMatchingScans(dataFile);
int[] allScanNumbers = scanSelection.getMatchingScanNumbers(dataFile);
totalScans = scans.length;
// Check if the scans are properly ordered by RT
double prevRT = Double.NEGATIVE_INFINITY;
for (Scan s : scans) {
if (s.getRetentionTime() < prevRT) {
setStatus(TaskStatus.ERROR);
final String msg = "Retention time of scan #" + s.getScanNumber() + " is smaller then the retention time of the previous scan." + " Please make sure you only use scans with increasing retention times." + " You can restrict the scan numbers in the parameters, or you can use the Crop filter module";
setErrorMessage(msg);
return;
}
prevRT = s.getRetentionTime();
}
// Create new feature list
newPeakList = new SimplePeakList(dataFile + " " + suffix, dataFile);
Chromatogram[] chromatograms;
HighestDataPointConnector massConnector = new HighestDataPointConnector(dataFile, allScanNumbers, minimumTimeSpan, minimumHeight, mzTolerance);
for (Scan scan : scans) {
if (isCanceled())
return;
MassList massList = scan.getMassList(massListName);
if (massList == null) {
setStatus(TaskStatus.ERROR);
setErrorMessage("Scan " + dataFile + " #" + scan.getScanNumber() + " does not have a mass list " + massListName);
return;
}
DataPoint[] mzValues = massList.getDataPoints();
if (mzValues == null) {
setStatus(TaskStatus.ERROR);
setErrorMessage("Mass list " + massListName + " does not contain m/z values for scan #" + scan.getScanNumber() + " of file " + dataFile);
return;
}
massConnector.addScan(scan.getScanNumber(), mzValues);
processedScans++;
}
chromatograms = massConnector.finishChromatograms();
// Sort the final chromatograms by m/z
Arrays.sort(chromatograms, new PeakSorter(SortingProperty.MZ, SortingDirection.Ascending));
// Add the chromatograms to the new feature list
for (Feature finishedPeak : chromatograms) {
SimplePeakListRow newRow = new SimplePeakListRow(newPeakID);
newPeakID++;
newRow.addPeak(dataFile, finishedPeak);
newPeakList.addRow(newRow);
}
// Add new peaklist to the project
project.addPeakList(newPeakList);
// Add quality parameters to peaks
QualityParameters.calculateQualityParameters(newPeakList);
setStatus(TaskStatus.FINISHED);
logger.info("Finished chromatogram builder on " + dataFile);
}
use of net.sf.mzmine.datamodel.impl.SimplePeakList in project mzmine2 by mzmine.
the class PeakListOpenHandler_2_5 method initializePeakList.
/**
* Initializes the feature list
*/
private void initializePeakList() {
RawDataFile[] dataFiles = currentPeakListDataFiles.toArray(new RawDataFile[0]);
buildingPeakList = new SimplePeakList(peakListName, dataFiles);
for (int i = 0; i < appliedMethods.size(); i++) {
String methodName = appliedMethods.elementAt(i);
String methodParams = appliedMethodParameters.elementAt(i);
PeakListAppliedMethod pam = new SimplePeakListAppliedMethod(methodName, methodParams);
buildingPeakList.addDescriptionOfAppliedTask(pam);
}
buildingPeakList.setDateCreated(dateCreated);
}
Aggregations