use of net.sf.mzmine.datamodel.Feature in project mzmine2 by mzmine.
the class FeaturesSelectionDialog method actionPerformed.
/*
*
*
* @see
* java.awt.event.ActionListener#actionPerformed(java.awt.event.ActionEvent)
*/
@Override
public void actionPerformed(ActionEvent event) {
Object src = event.getSource();
if (src == btnOk) {
returnState = true;
this.dispose();
}
if (src == btnCancel) {
returnState = false;
this.dispose();
}
if (src == rawDataFileComboBox) {
panel12.removeAll();
RawDataFile dataFile = (RawDataFile) rawDataFileComboBox.getSelectedItem();
Feature[] features = allPeakLists[selectedIndex].getPeaks(dataFile);
featuresSelectionBox = new MultipleSelectionComponent<Feature>(features);
featuresSelectionBox.setToolTipText("Features Selection Box");
panel12.add(featuresSelectionBox, BorderLayout.CENTER);
panel12.revalidate();
}
if (src == peakListComboBox) {
PeakList peakList = (PeakList) peakListComboBox.getSelectedItem();
panel11.removeAll();
panel12.removeAll();
for (int j = 0; j < allPeakLists.length; j++) {
if (peakList.equals(allPeakLists[j])) {
RawDataFile[] rawDataFiles = allPeakLists[j].getRawDataFiles();
rawDataFileComboBox = new JComboBox<RawDataFile>(rawDataFiles);
rawDataFileComboBox.setToolTipText("Raw data files Selection Box");
rawDataFileComboBox.addActionListener(this);
panel11.add(rawDataFileComboBox, BorderLayout.CENTER);
this.setSize(670, 400);
LOG.finest("PeakListRowComboBox is Added");
selectedIndex = j;
RawDataFile datafile = allPeakLists[j].getRawDataFile(0);
Feature[] features = allPeakLists[j].getPeaks(datafile);
featuresSelectionBox = new MultipleSelectionComponent<Feature>(features);
featuresSelectionBox.setToolTipText("Features Selection Box");
panel12.add(featuresSelectionBox, BorderLayout.CENTER);
}
panel11.revalidate();
panel12.revalidate();
}
}
}
use of net.sf.mzmine.datamodel.Feature 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.Feature 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.Feature in project mzmine2 by mzmine.
the class PeakListRowLearnerTask 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 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;
}
Aggregations