use of net.sf.mzmine.datamodel.PeakList in project mzmine2 by mzmine.
the class RansacAlignerModule method runModule.
@Override
@Nonnull
public ExitCode runModule(@Nonnull MZmineProject project, @Nonnull ParameterSet parameters, @Nonnull Collection<Task> tasks) {
PeakList[] peakLists = parameters.getParameter(RansacAlignerParameters.peakLists).getValue().getMatchingPeakLists();
Task task = new RansacAlignerTask(project, peakLists, parameters);
tasks.add(task);
return ExitCode.OK;
}
use of net.sf.mzmine.datamodel.PeakList in project mzmine2 by mzmine.
the class RansacAlignerSetupDialog method updatePreview.
private void updatePreview() {
PeakList peakListX = (PeakList) peakListsComboX.getSelectedItem();
PeakList peakListY = (PeakList) peakListsComboY.getSelectedItem();
if ((peakListX == null) || (peakListY == null))
return;
// Select the rawDataFile which has more peaks in each peakList
int numPeaks = 0;
RawDataFile file = null;
RawDataFile file2 = null;
for (RawDataFile rfile : peakListX.getRawDataFiles()) {
if (peakListX.getPeaks(rfile).length > numPeaks) {
numPeaks = peakListX.getPeaks(rfile).length;
file = rfile;
}
}
numPeaks = 0;
for (RawDataFile rfile : peakListY.getRawDataFiles()) {
if (peakListY.getPeaks(rfile).length > numPeaks) {
numPeaks = peakListY.getPeaks(rfile).length;
file2 = rfile;
}
}
// Update the parameter set from dialog components
updateParameterSetFromComponents();
// Check the parameter values
ArrayList<String> errorMessages = new ArrayList<String>();
boolean parametersOK = super.parameterSet.checkParameterValues(errorMessages);
if (!parametersOK) {
StringBuilder message = new StringBuilder("Please check the parameter settings:\n\n");
for (String m : errorMessages) {
message.append(m);
message.append("\n");
}
MZmineCore.getDesktop().displayMessage(this, message.toString());
return;
}
// Ransac Alignment
Vector<AlignStructMol> list = this.getVectorAlignment(peakListX, peakListY, file, file2);
RANSAC ransac = new RANSAC(super.parameterSet);
ransac.alignment(list);
// Plot the result
this.chart.removeSeries();
this.chart.addSeries(list, peakListX.getName() + " vs " + peakListY.getName(), super.parameterSet.getParameter(RansacAlignerParameters.Linear).getValue());
this.chart.printAlignmentChart(peakListX.getName() + " RT", peakListY.getName() + " RT");
}
use of net.sf.mzmine.datamodel.PeakList 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.PeakList in project mzmine2 by mzmine.
the class LearnerModule method runModule.
@Override
@Nonnull
public ExitCode runModule(@Nonnull MZmineProject project, @Nonnull ParameterSet parameters, @Nonnull Collection<Task> tasks) {
// get parameters
PeakList[] peakLists = parameters.getParameter(LearnerParameters.peakLists).getValue().getMatchingPeakLists();
// create and start one task for each peaklist
for (final PeakList peakList : peakLists) {
Task newTask = new PeakListRowLearnerTask(project, peakList, parameters);
tasks.add(newTask);
}
return ExitCode.OK;
}
use of net.sf.mzmine.datamodel.PeakList in project mzmine2 by mzmine.
the class ADAP3AlignerTask method run.
@Override
public void run() {
if (isCanceled())
return;
String errorMsg = null;
setStatus(TaskStatus.PROCESSING);
LOG.info("Started ADAP Peak Alignment");
try {
PeakList peakList = alignPeaks();
if (!isCanceled()) {
project.addPeakList(peakList);
QualityParameters.calculateQualityParameters(peakList);
setStatus(TaskStatus.FINISHED);
LOG.info("Finished ADAP Peak Alignment");
}
} catch (IllegalArgumentException e) {
errorMsg = "Incorrect Feature Lists:\n" + e.getMessage();
} catch (Exception e) {
errorMsg = "'Unknown error' during alignment. \n" + e.getMessage();
} catch (Throwable t) {
setStatus(TaskStatus.ERROR);
setErrorMessage(t.getMessage());
LOG.log(Level.SEVERE, "ADAP Alignment error", t);
}
// Report error
if (errorMsg != null) {
setErrorMessage(errorMsg);
setStatus(TaskStatus.ERROR);
}
}
Aggregations