use of net.sf.mzmine.datamodel.Feature 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);
}
use of net.sf.mzmine.datamodel.Feature in project mzmine2 by mzmine.
the class HeatMapTask method modifySimpleDataset.
private double[][] modifySimpleDataset(UserParameter<?, ?> selectedParameter, String referenceGroup) {
// Collect all data files
Vector<RawDataFile> allDataFiles = new Vector<RawDataFile>();
allDataFiles.addAll(Arrays.asList(peakList.getRawDataFiles()));
// Determine the reference group and non reference group (the rest of
// the samples) for raw data files
List<RawDataFile> referenceDataFiles = new ArrayList<RawDataFile>();
List<RawDataFile> nonReferenceDataFiles = new ArrayList<RawDataFile>();
for (RawDataFile rawDataFile : allDataFiles) {
Object paramValue = project.getParameterValue(selectedParameter, rawDataFile);
if (paramValue.equals(referenceGroup)) {
referenceDataFiles.add(rawDataFile);
} else {
nonReferenceDataFiles.add(rawDataFile);
}
}
int numRows = 0;
for (int row = 0; row < peakList.getNumberOfRows(); row++) {
if (!onlyIdentified || (onlyIdentified && peakList.getRow(row).getPeakIdentities().length > 0)) {
numRows++;
}
}
// Create a new aligned feature list with all the samples if the reference
// group has to be shown or with only
// the non reference group if not.
double[][] dataMatrix;
if (rcontrol) {
dataMatrix = new double[allDataFiles.size()][numRows];
} else {
dataMatrix = new double[nonReferenceDataFiles.size()][numRows];
}
// Data files that should be in the heat map
List<RawDataFile> shownDataFiles = null;
if (rcontrol) {
shownDataFiles = allDataFiles;
} else {
shownDataFiles = nonReferenceDataFiles;
}
for (int row = 0, rowIndex = 0; row < peakList.getNumberOfRows(); row++) {
PeakListRow rowPeak = peakList.getRow(row);
if (!onlyIdentified || (onlyIdentified && rowPeak.getPeakIdentities().length > 0)) {
// Average area or height of the reference group
double referenceAverage = 0;
int referencePeakCount = 0;
for (int column = 0; column < referenceDataFiles.size(); column++) {
if (rowPeak.getPeak(referenceDataFiles.get(column)) != null) {
if (area) {
referenceAverage += rowPeak.getPeak(referenceDataFiles.get(column)).getArea();
} else {
referenceAverage += rowPeak.getPeak(referenceDataFiles.get(column)).getHeight();
}
referencePeakCount++;
}
}
if (referencePeakCount > 0) {
referenceAverage /= referencePeakCount;
}
// area or height of the reference peaks in each row
for (int column = 0; column < shownDataFiles.size(); column++) {
double value = Double.NaN;
if (rowPeak.getPeak(shownDataFiles.get(column)) != null) {
Feature peak = rowPeak.getPeak(shownDataFiles.get(column));
if (area) {
value = peak.getArea() / referenceAverage;
} else {
value = peak.getHeight() / referenceAverage;
}
if (log) {
value = Math.log(value);
}
}
dataMatrix[column][rowIndex] = value;
}
rowIndex++;
}
}
// deviation of each column
if (scale) {
scale(dataMatrix);
}
// Create two arrays: row and column names
rowNames = new String[dataMatrix[0].length];
colNames = new String[shownDataFiles.size()];
for (int column = 0; column < shownDataFiles.size(); column++) {
colNames[column] = shownDataFiles.get(column).getName();
}
for (int row = 0, rowIndex = 0; row < peakList.getNumberOfRows(); row++) {
if (!onlyIdentified || (onlyIdentified && peakList.getRow(row).getPeakIdentities().length > 0)) {
if (peakList.getRow(row).getPeakIdentities() != null && peakList.getRow(row).getPeakIdentities().length > 0) {
rowNames[rowIndex++] = peakList.getRow(row).getPreferredPeakIdentity().getName();
} else {
rowNames[rowIndex++] = "Unknown";
}
}
}
return dataMatrix;
}
use of net.sf.mzmine.datamodel.Feature 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.Feature 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.Feature 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.");
}
Aggregations