use of net.sf.mzmine.datamodel.RawDataFile 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.RawDataFile in project mzmine2 by mzmine.
the class HeatMapTask method groupingDataset.
private double[][] groupingDataset(UserParameter<?, ?> selectedParameter, String referenceGroup) {
// Collect all data files
Vector<RawDataFile> allDataFiles = new Vector<RawDataFile>();
DescriptiveStatistics meanControlStats = new DescriptiveStatistics();
DescriptiveStatistics meanGroupStats = new DescriptiveStatistics();
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>();
List<String> groups = new ArrayList<String>();
for (RawDataFile rawDataFile : allDataFiles) {
Object paramValue = project.getParameterValue(selectedParameter, rawDataFile);
if (!groups.contains(String.valueOf(paramValue))) {
groups.add(String.valueOf(paramValue));
}
if (String.valueOf(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 = new double[groups.size() - 1][numRows];
pValueMatrix = new String[groups.size() - 1][numRows];
// data files that should be in the heat map
List<RawDataFile> 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
meanControlStats.clear();
for (int column = 0; column < referenceDataFiles.size(); column++) {
if (rowPeak.getPeak(referenceDataFiles.get(column)) != null) {
if (area) {
meanControlStats.addValue(rowPeak.getPeak(referenceDataFiles.get(column)).getArea());
} else {
meanControlStats.addValue(rowPeak.getPeak(referenceDataFiles.get(column)).getHeight());
}
}
}
// Divide the area or height of each peak by the average of the
// area or height of the reference peaks in each row
int columnIndex = 0;
for (int column = 0; column < groups.size(); column++) {
String group = groups.get(column);
meanGroupStats.clear();
if (!group.equals(referenceGroup)) {
for (int dataColumn = 0; dataColumn < shownDataFiles.size(); dataColumn++) {
Object paramValue = project.getParameterValue(selectedParameter, shownDataFiles.get(dataColumn));
if (rowPeak.getPeak(shownDataFiles.get(dataColumn)) != null && String.valueOf(paramValue).equals(group)) {
Feature peak = rowPeak.getPeak(shownDataFiles.get(dataColumn));
if (!Double.isInfinite(peak.getArea()) && !Double.isNaN(peak.getArea())) {
if (area) {
meanGroupStats.addValue(peak.getArea());
} else {
meanGroupStats.addValue(peak.getHeight());
}
}
}
}
double value = meanGroupStats.getMean() / meanControlStats.getMean();
if (meanGroupStats.getN() > 1 && meanControlStats.getN() > 1) {
pValueMatrix[columnIndex][rowIndex] = this.getPvalue(meanGroupStats, meanControlStats);
} else {
pValueMatrix[columnIndex][rowIndex] = "";
}
if (log) {
value = Math.log(value);
}
dataMatrix[columnIndex++][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[groups.size() - 1];
int columnIndex = 0;
for (String group : groups) {
if (!group.equals(referenceGroup)) {
colNames[columnIndex++] = group;
}
}
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.RawDataFile in project mzmine2 by mzmine.
the class SammonsDataset method run.
@Override
public void run() {
setStatus(TaskStatus.PROCESSING);
if (selectedRows.length == 0) {
this.status = TaskStatus.ERROR;
errorMessage = "No peaks selected for Sammons plot";
return;
}
if (selectedRawDataFiles.length == 0) {
this.status = TaskStatus.ERROR;
errorMessage = "No raw data files selected for Sammons plot";
return;
}
logger.info("Computing projection plot");
// Generate matrix of raw data (input to Sammon's projection)
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 Sammon's mapping
Preprocess.scaleToUnityVariance(rawData);
Sammons sammonsProj = new Sammons(rawData);
projectionStatus = sammonsProj.getProjectionStatus();
sammonsProj.iterate(100);
if (status == TaskStatus.CANCELED)
return;
double[][] result = sammonsProj.getState();
if (status == TaskStatus.CANCELED)
return;
component1Coords = result[xAxisDimension - 1];
component2Coords = result[yAxisDimension - 1];
ProjectionPlotWindow newFrame = new ProjectionPlotWindow(peakList, this, parameters);
newFrame.setVisible(true);
setStatus(TaskStatus.FINISHED);
logger.info("Finished computing projection plot.");
}
use of net.sf.mzmine.datamodel.RawDataFile 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.RawDataFile in project mzmine2 by mzmine.
the class ManualPeakPickerModule method runManualDetection.
public static ExitCode runManualDetection(RawDataFile[] dataFiles, PeakListRow peakListRow, PeakList peakList, PeakListTable table) {
Range<Double> mzRange = null, rtRange = null;
// Check the peaks for selected data files
for (RawDataFile dataFile : dataFiles) {
Feature peak = peakListRow.getPeak(dataFile);
if (peak == null)
continue;
if ((mzRange == null) || (rtRange == null)) {
mzRange = peak.getRawDataPointsMZRange();
rtRange = peak.getRawDataPointsRTRange();
} else {
mzRange = mzRange.span(peak.getRawDataPointsMZRange());
rtRange = rtRange.span(peak.getRawDataPointsRTRange());
}
}
// If none of the data files had a peak, check the whole row
if (mzRange == null) {
for (Feature peak : peakListRow.getPeaks()) {
if (peak == null)
continue;
if ((mzRange == null) || (rtRange == null)) {
mzRange = peak.getRawDataPointsMZRange();
rtRange = peak.getRawDataPointsRTRange();
} else {
mzRange = mzRange.span(peak.getRawDataPointsMZRange());
rtRange = rtRange.span(peak.getRawDataPointsRTRange());
}
}
}
ManualPickerParameters parameters = new ManualPickerParameters();
if (mzRange != null) {
parameters.getParameter(ManualPickerParameters.retentionTimeRange).setValue(rtRange);
parameters.getParameter(ManualPickerParameters.mzRange).setValue(mzRange);
}
ExitCode exitCode = parameters.showSetupDialog(MZmineCore.getDesktop().getMainWindow(), true);
if (exitCode != ExitCode.OK)
return exitCode;
ManualPickerTask task = new ManualPickerTask(MZmineCore.getProjectManager().getCurrentProject(), peakListRow, dataFiles, parameters, peakList, table);
MZmineCore.getTaskController().addTask(task);
return exitCode;
}
Aggregations