use of net.sf.mzmine.datamodel.PeakListRow in project mzmine2 by mzmine.
the class PeakLearnerTask method copyPeakRow.
/**
* Create a copy of a feature list row.
*
* @param row the row to copy.
* @return the newly created copy.
*/
private static PeakListRow copyPeakRow(final PeakListRow row) {
// Copy the feature list row.
final PeakListRow newRow = new SimplePeakListRow(row.getID());
PeakUtils.copyPeakListRowProperties(row, newRow);
// Copy the peaks.
for (final Feature peak : row.getPeaks()) {
final Feature newPeak = new SimpleFeature(peak);
PeakUtils.copyPeakProperties(peak, newPeak);
newRow.addPeak(peak.getDataFile(), newPeak);
}
return newRow;
}
use of net.sf.mzmine.datamodel.PeakListRow in project mzmine2 by mzmine.
the class StreamPeakListRowLearnerTask 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>
*/
// use streams to filter, sort and create list
List<PeakListRow> rowList = Arrays.stream(peakList.getRows()).filter(r -> r.getAverageHeight() > 5000).sorted(new PeakListRowSorter(SortingProperty.MZ, SortingDirection.Ascending)).collect(Collectors.toList());
totalRows = rowList.size();
// ###########################################################
// OPTION 1: Streams
// either use stream to process all rows
rowList.stream().forEachOrdered(row -> {
// check for cancelled state and stop
if (isCanceled())
return;
// 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++;
});
// OPTION 2: For loop
for (PeakListRow row : rowList) {
// check for cancelled state and stop
if (isCanceled())
return;
// 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);
}
use of net.sf.mzmine.datamodel.PeakListRow in project mzmine2 by mzmine.
the class CDADataset method run.
@Override
public void run() {
status = TaskStatus.PROCESSING;
if (selectedRows.length == 0) {
this.status = TaskStatus.ERROR;
errorMessage = "No peaks selected for CDA plot";
return;
}
if (selectedRawDataFiles.length == 0) {
this.status = TaskStatus.ERROR;
errorMessage = "No raw data files selected for CDA plot";
return;
}
logger.info("Computing projection plot");
// Generate matrix of raw data (input to CDA)
boolean useArea = false;
if (parameters.getParameter(ProjectionPlotParameters.peakMeasurementType).getValue() == PeakMeasurementType.AREA)
useArea = true;
double[][] rawData = new double[selectedRawDataFiles.length][selectedRows.length];
for (int rowIndex = 0; rowIndex < selectedRows.length; rowIndex++) {
PeakListRow peakListRow = selectedRows[rowIndex];
for (int fileIndex = 0; fileIndex < selectedRawDataFiles.length; fileIndex++) {
RawDataFile rawDataFile = selectedRawDataFiles[fileIndex];
Feature p = peakListRow.getPeak(rawDataFile);
if (p != null) {
if (useArea)
rawData[fileIndex][rowIndex] = p.getArea();
else
rawData[fileIndex][rowIndex] = p.getHeight();
}
}
}
int numComponents = xAxisDimension;
if (yAxisDimension > numComponents)
numComponents = yAxisDimension;
// Scale data and do CDA
Preprocess.scaleToUnityVariance(rawData);
CDA cdaProj = new CDA(rawData);
cdaProj.iterate(100);
if (status == TaskStatus.CANCELED)
return;
double[][] result = cdaProj.getState();
if (status == TaskStatus.CANCELED)
return;
component1Coords = result[xAxisDimension - 1];
component2Coords = result[yAxisDimension - 1];
ProjectionPlotWindow newFrame = new ProjectionPlotWindow(peakList, this, parameters);
newFrame.setVisible(true);
status = TaskStatus.FINISHED;
logger.info("Finished computing projection plot.");
}
use of net.sf.mzmine.datamodel.PeakListRow in project mzmine2 by mzmine.
the class PCADataset method run.
@Override
public void run() {
status = TaskStatus.PROCESSING;
logger.info("Computing PCA projection plot");
// Generate matrix of raw data (input to PCA)
final boolean useArea = (parameters.getParameter(ProjectionPlotParameters.peakMeasurementType).getValue() == PeakMeasurementType.AREA);
if (selectedRows.length == 0) {
this.status = TaskStatus.ERROR;
errorMessage = "No peaks selected for PCA plot";
return;
}
if (selectedRawDataFiles.length == 0) {
this.status = TaskStatus.ERROR;
errorMessage = "No raw data files selected for PCA plot";
return;
}
double[][] rawData = new double[selectedRawDataFiles.length][selectedRows.length];
for (int rowIndex = 0; rowIndex < selectedRows.length; rowIndex++) {
PeakListRow peakListRow = selectedRows[rowIndex];
for (int fileIndex = 0; fileIndex < selectedRawDataFiles.length; fileIndex++) {
RawDataFile rawDataFile = selectedRawDataFiles[fileIndex];
Feature p = peakListRow.getPeak(rawDataFile);
if (p != null) {
if (useArea)
rawData[fileIndex][rowIndex] = p.getArea();
else
rawData[fileIndex][rowIndex] = p.getHeight();
}
}
}
int numComponents = xAxisPC;
if (yAxisPC > numComponents)
numComponents = yAxisPC;
// Scale data and do PCA
Preprocess.scaleToUnityVariance(rawData);
// Replace NaN values with 0.0
for (int i = 0; i < rawData.length; i++) {
for (int j = 0; j < rawData[i].length; j++) {
if (Double.isNaN(rawData[i][j]))
rawData[i][j] = 0.0;
}
}
PCA pcaProj = new PCA(rawData, numComponents);
projectionStatus = pcaProj.getProjectionStatus();
double[][] result = pcaProj.getState();
if (status == TaskStatus.CANCELED)
return;
component1Coords = result[xAxisPC - 1];
component2Coords = result[yAxisPC - 1];
ProjectionPlotWindow newFrame = new ProjectionPlotWindow(peakList, this, parameters);
newFrame.setVisible(true);
status = TaskStatus.FINISHED;
logger.info("Finished computing projection plot.");
}
use of net.sf.mzmine.datamodel.PeakListRow in project mzmine2 by mzmine.
the class RowVsRowDistanceProvider method getRankedDistance.
public double getRankedDistance(int i, int j, double mzMaxDiff, double rtMaxDiff, double minScore) {
// Itself
if (i == j)
return 0d;
// if (row_id > aligned_row_id) {
// int tmp = row_id;
// row_id = aligned_row_id;
// aligned_row_id = tmp;
// }
// if (row_id < aligned_row_id) {
// int tmp = row_id;
// row_id = aligned_row_id;
// aligned_row_id = tmp;
// }
PeakListRow row = full_rows_list.get(i);
PeakListRow k_row = full_rows_list.get(j);
// || (row_id >= 102 && aligned_row_id >= 102)) {
if (row.getRawDataFiles()[0] == k_row.getRawDataFiles()[0]) {
return 1000.0d;
} else // Not candidate
{
// k_row.getBestPeak().getMZ()) >= mzMaxDiff/2.0));
if ((Math.abs(row.getBestPeak().getRT() - k_row.getBestPeak().getRT()) >= rtMaxDiff / 2.0 || Math.abs(row.getBestPeak().getMZ() - k_row.getBestPeak().getMZ()) >= mzMaxDiff / 2.0)) {
return 100.0d;
}
}
double score = this.getScore(i, j, mzMaxDiff, rtMaxDiff).getScore();
// Score too low
if (score <= Math.max(HierarAlignerGCTask.MIN_SCORE_ABSOLUTE, minScore)) {
// System.out.println("(2) Final dist: " + 10.0f);
return 10.0d;
}
// Score OK
return this.maximumScore - score;
}
Aggregations