use of net.sf.mzmine.datamodel.Feature in project mzmine2 by mzmine.
the class PeakListSaveHandler method fillRowElement.
/**
* Add the row information into the XML document
*
* @param row
* @param element
* @throws IOException
*/
private void fillRowElement(PeakListRow row, TransformerHandler hd) throws SAXException, IOException {
// <PEAK_IDENTITY>
PeakIdentity preferredIdentity = row.getPreferredPeakIdentity();
PeakIdentity[] identities = row.getPeakIdentities();
AttributesImpl atts = new AttributesImpl();
for (int i = 0; i < identities.length; i++) {
if (canceled)
return;
atts.addAttribute("", "", PeakListElementName.ID.getElementName(), "CDATA", String.valueOf(i));
atts.addAttribute("", "", PeakListElementName.PREFERRED.getElementName(), "CDATA", String.valueOf(identities[i] == preferredIdentity));
hd.startElement("", "", PeakListElementName.PEAK_IDENTITY.getElementName(), atts);
fillIdentityElement(identities[i], hd);
hd.endElement("", "", PeakListElementName.PEAK_IDENTITY.getElementName());
}
if (canceled)
return;
// atts.addAttribute("", "", PeakListElementName.ID.getElementName(),
// "CDATA", "INFORMATION");
hd.startElement("", "", PeakListElementName.PEAK_INFORMATION.getElementName(), atts);
fillInformationElement(row.getPeakInformation(), hd);
hd.endElement("", "", PeakListElementName.PEAK_INFORMATION.getElementName());
// <PEAK>
Feature[] peaks = row.getPeaks();
for (Feature p : peaks) {
if (canceled)
return;
atts.clear();
String dataFileID = dataFilesIDMap.get(p.getDataFile());
atts.addAttribute("", "", PeakListElementName.COLUMN.getElementName(), "CDATA", dataFileID);
atts.addAttribute("", "", PeakListElementName.MZ.getElementName(), "CDATA", String.valueOf(p.getMZ()));
// In the project file, retention time is represented in seconds,
// for historical reasons
double rt = p.getRT() * 60d;
atts.addAttribute("", "", PeakListElementName.RT.getElementName(), "CDATA", String.valueOf(rt));
atts.addAttribute("", "", PeakListElementName.HEIGHT.getElementName(), "CDATA", String.valueOf(p.getHeight()));
atts.addAttribute("", "", PeakListElementName.AREA.getElementName(), "CDATA", String.valueOf(p.getArea()));
atts.addAttribute("", "", PeakListElementName.STATUS.getElementName(), "CDATA", p.getFeatureStatus().toString());
atts.addAttribute("", "", PeakListElementName.CHARGE.getElementName(), "CDATA", String.valueOf(p.getCharge()));
atts.addAttribute("", "", PeakListElementName.PARENT_CHROMATOGRAM_ROW_ID.getElementName(), "CDATA", p.getParentChromatogramRowID() != null ? String.valueOf(p.getParentChromatogramRowID()) : "");
hd.startElement("", "", PeakListElementName.PEAK.getElementName(), atts);
fillPeakElement(p, hd);
hd.endElement("", "", PeakListElementName.PEAK.getElementName());
}
}
use of net.sf.mzmine.datamodel.Feature in project mzmine2 by mzmine.
the class ChromatogramBuilderTask method run.
/**
* @see Runnable#run()
*/
public void run() {
setStatus(TaskStatus.PROCESSING);
logger.info("Started chromatogram builder on " + dataFile);
scans = scanSelection.getMatchingScans(dataFile);
int[] allScanNumbers = scanSelection.getMatchingScanNumbers(dataFile);
totalScans = scans.length;
// Check if the scans are properly ordered by RT
double prevRT = Double.NEGATIVE_INFINITY;
for (Scan s : scans) {
if (s.getRetentionTime() < prevRT) {
setStatus(TaskStatus.ERROR);
final String msg = "Retention time of scan #" + s.getScanNumber() + " is smaller then the retention time of the previous scan." + " Please make sure you only use scans with increasing retention times." + " You can restrict the scan numbers in the parameters, or you can use the Crop filter module";
setErrorMessage(msg);
return;
}
prevRT = s.getRetentionTime();
}
// Create new feature list
newPeakList = new SimplePeakList(dataFile + " " + suffix, dataFile);
Chromatogram[] chromatograms;
HighestDataPointConnector massConnector = new HighestDataPointConnector(dataFile, allScanNumbers, minimumTimeSpan, minimumHeight, mzTolerance);
for (Scan scan : scans) {
if (isCanceled())
return;
MassList massList = scan.getMassList(massListName);
if (massList == null) {
setStatus(TaskStatus.ERROR);
setErrorMessage("Scan " + dataFile + " #" + scan.getScanNumber() + " does not have a mass list " + massListName);
return;
}
DataPoint[] mzValues = massList.getDataPoints();
if (mzValues == null) {
setStatus(TaskStatus.ERROR);
setErrorMessage("Mass list " + massListName + " does not contain m/z values for scan #" + scan.getScanNumber() + " of file " + dataFile);
return;
}
massConnector.addScan(scan.getScanNumber(), mzValues);
processedScans++;
}
chromatograms = massConnector.finishChromatograms();
// Sort the final chromatograms by m/z
Arrays.sort(chromatograms, new PeakSorter(SortingProperty.MZ, SortingDirection.Ascending));
// Add the chromatograms to the new feature list
for (Feature finishedPeak : chromatograms) {
SimplePeakListRow newRow = new SimplePeakListRow(newPeakID);
newPeakID++;
newRow.addPeak(dataFile, finishedPeak);
newPeakList.addRow(newRow);
}
// Add new peaklist to the project
project.addPeakList(newPeakList);
// Add quality parameters to peaks
QualityParameters.calculateQualityParameters(newPeakList);
setStatus(TaskStatus.FINISHED);
logger.info("Finished chromatogram builder on " + dataFile);
}
use of net.sf.mzmine.datamodel.Feature in project mzmine2 by mzmine.
the class ShapeModelerTask method run.
public void run() {
setStatus(TaskStatus.PROCESSING);
Class<?> shapeModelClass = shapeModelerType.getModelClass();
Constructor<?> shapeModelConstruct;
shapeModelConstruct = shapeModelClass.getConstructors()[0];
// Get data file information
RawDataFile dataFile = originalPeakList.getRawDataFile(0);
// Create new feature list
newPeakList = new SimplePeakList(originalPeakList + " " + suffix, dataFile);
totalRows = originalPeakList.getNumberOfRows();
int[] scanNumbers;
double[] retentionTimes, intensities;
SimplePeakListRow newRow;
for (PeakListRow row : originalPeakList.getRows()) {
if (isCanceled())
return;
newRow = new SimplePeakListRow(newPeakID);
try {
for (Feature peak : row.getPeaks()) {
// Load the intensities into array
dataFile = peak.getDataFile();
scanNumbers = peak.getScanNumbers();
retentionTimes = new double[scanNumbers.length];
for (int i = 0; i < scanNumbers.length; i++) retentionTimes[i] = dataFile.getScan(scanNumbers[i]).getRetentionTime();
intensities = new double[scanNumbers.length];
for (int i = 0; i < scanNumbers.length; i++) {
DataPoint dp = peak.getDataPoint(scanNumbers[i]);
if (dp != null)
intensities[i] = dp.getIntensity();
else
intensities[i] = 0;
}
Feature shapePeak = (Feature) shapeModelConstruct.newInstance(peak, scanNumbers, intensities, retentionTimes, resolution);
newRow.addPeak(shapePeak.getDataFile(), shapePeak);
}
} catch (Exception e) {
String message = "Error trying to make an instance of shape model class " + shapeModelClass;
MZmineCore.getDesktop().displayErrorMessage(MZmineCore.getDesktop().getMainWindow(), message);
logger.severe(message);
return;
}
newPeakList.addRow(newRow);
newPeakID++;
processedRows++;
}
// Add new peaklist to the project
project.addPeakList(newPeakList);
// Add quality parameters to peaks
QualityParameters.calculateQualityParameters(newPeakList);
// Remove the original peaklist if requested
if (removeOriginal)
project.removePeakList(originalPeakList);
// Load previous applied methods
for (PeakListAppliedMethod proc : originalPeakList.getAppliedMethods()) {
newPeakList.addDescriptionOfAppliedTask(proc);
}
// Add task description to peakList
newPeakList.addDescriptionOfAppliedTask(new SimplePeakListAppliedMethod("Peaks shaped by " + shapeModelerType + " function", parameters));
logger.finest("Finished peak shape modeler " + processedRows + " rows processed");
setStatus(TaskStatus.FINISHED);
}
use of net.sf.mzmine.datamodel.Feature in project mzmine2 by mzmine.
the class PeakExtenderTask method run.
/**
* @see Runnable#run()
*/
public void run() {
setStatus(TaskStatus.PROCESSING);
logger.info("Running peak extender on " + peakList);
// We assume source peakList contains one datafile
RawDataFile dataFile = peakList.getRawDataFile(0);
// Create a new deisotoped peakList
extendedPeakList = new SimplePeakList(peakList + " " + suffix, peakList.getRawDataFiles());
// Sort peaks by descending height
Feature[] sortedPeaks = peakList.getPeaks(dataFile);
Arrays.sort(sortedPeaks, new PeakSorter(SortingProperty.Height, SortingDirection.Descending));
// Loop through all peaks
totalPeaks = sortedPeaks.length;
Feature oldPeak;
for (int ind = 0; ind < totalPeaks; ind++) {
if (isCanceled())
return;
oldPeak = sortedPeaks[ind];
if (oldPeak.getHeight() >= minimumHeight) {
Feature newPeak = this.getExtendedPeak(oldPeak);
// Get previous pekaListRow
PeakListRow oldRow = peakList.getPeakRow(oldPeak);
// keep old ID
int oldID = oldRow.getID();
SimplePeakListRow newRow = new SimplePeakListRow(oldID);
PeakUtils.copyPeakListRowProperties(oldRow, newRow);
newRow.addPeak(dataFile, newPeak);
extendedPeakList.addRow(newRow);
}
// Update completion rate
processedPeaks++;
}
// Add new peakList to the project
project.addPeakList(extendedPeakList);
// Add quality parameters to peaks
QualityParameters.calculateQualityParameters(extendedPeakList);
// Load previous applied methods
for (PeakListAppliedMethod proc : peakList.getAppliedMethods()) {
extendedPeakList.addDescriptionOfAppliedTask(proc);
}
// Add task description to peakList
extendedPeakList.addDescriptionOfAppliedTask(new SimplePeakListAppliedMethod("Peak extender", parameters));
// Remove the original peakList if requested
if (removeOriginal)
project.removePeakList(peakList);
logger.info("Finished peak extender on " + peakList);
setStatus(TaskStatus.FINISHED);
}
use of net.sf.mzmine.datamodel.Feature in project mzmine2 by mzmine.
the class ShapeModelerSetupDialog method loadPreviewPeak.
private void loadPreviewPeak() {
PeakListRow previewRow = (PeakListRow) comboPeak.getSelectedItem();
if (previewRow == null)
return;
logger.finest("Loading new preview peak " + previewRow);
Feature previewPeak = previewRow.getPeaks()[0];
ticPlot.removeAllTICDataSets();
// Load the intensities into array
RawDataFile dataFile = previewPeak.getDataFile();
int[] scanNumbers = previewPeak.getScanNumbers();
double[] retentionTimes = new double[scanNumbers.length];
for (int i = 0; i < scanNumbers.length; i++) retentionTimes[i] = dataFile.getScan(scanNumbers[i]).getRetentionTime();
double[] intensities = new double[scanNumbers.length];
for (int i = 0; i < scanNumbers.length; i++) {
DataPoint dp = previewPeak.getDataPoint(scanNumbers[i]);
if (dp != null)
intensities[i] = dp.getIntensity();
else
intensities[i] = 0;
}
// Create shape model
updateParameterSetFromComponents();
JComboBox<?> component = (JComboBox<?>) getComponentForParameter(ShapeModelerParameters.shapeModelerType);
ShapeModel model = (ShapeModel) component.getSelectedItem();
JFormattedTextField resolutionField = (JFormattedTextField) getComponentForParameter(ShapeModelerParameters.massResolution);
double resolution = ((Number) resolutionField.getValue()).doubleValue();
try {
Class<?> shapeModelClass = model.getModelClass();
Constructor<?> shapeModelConstruct = shapeModelClass.getConstructors()[0];
// shapePeakModel(ChromatographicPeak originalDetectedShape, int[]
// scanNumbers,
// double[] intensities, double[] retentionTimes, double resolution)
Feature shapePeak = (Feature) shapeModelConstruct.newInstance(previewPeak, scanNumbers, intensities, retentionTimes, resolution);
PeakDataSet peakDataSet = new PeakDataSet(shapePeak);
ticPlot.addPeakDataset(peakDataSet);
ticDataset = new ChromatogramTICDataSet(previewRow.getPeaks()[0]);
ticPlot.addTICDataset(ticDataset);
// Set auto range to axes
ticPlot.getXYPlot().getDomainAxis().setAutoRange(true);
ticPlot.getXYPlot().getDomainAxis().setAutoTickUnitSelection(true);
ticPlot.getXYPlot().getRangeAxis().setAutoRange(true);
ticPlot.getXYPlot().getRangeAxis().setAutoTickUnitSelection(true);
} catch (Exception e) {
String message = "Error trying to make an instance of Peak Builder " + model;
MZmineCore.getDesktop().displayErrorMessage(this, message);
logger.severe(message);
e.printStackTrace();
return;
}
}
Aggregations