use of net.sf.mzmine.datamodel.PeakList.PeakListAppliedMethod in project mzmine2 by mzmine.
the class IsotopeGrouperTask method run.
/**
* @see Runnable#run()
*/
public void run() {
setStatus(TaskStatus.PROCESSING);
logger.info("Running isotopic peak grouper on " + peakList);
// We assume source peakList contains one datafile
RawDataFile dataFile = peakList.getRawDataFile(0);
// Create a new deisotoped peakList
deisotopedPeakList = new SimplePeakList(peakList + " " + suffix, peakList.getRawDataFiles());
// Collect all selected charge states
int[] charges = new int[maximumCharge];
for (int i = 0; i < maximumCharge; i++) charges[i] = i + 1;
// 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;
for (int ind = 0; ind < totalPeaks; ind++) {
if (isCanceled())
return;
Feature aPeak = sortedPeaks[ind];
// Check if peak was already deleted
if (aPeak == null) {
processedPeaks++;
continue;
}
// Check which charge state fits best around this peak
int bestFitCharge = 0;
int bestFitScore = -1;
Vector<Feature> bestFitPeaks = null;
for (int charge : charges) {
Vector<Feature> fittedPeaks = new Vector<Feature>();
fittedPeaks.add(aPeak);
fitPattern(fittedPeaks, aPeak, charge, sortedPeaks);
int score = fittedPeaks.size();
if ((score > bestFitScore) || ((score == bestFitScore) && (bestFitCharge > charge))) {
bestFitScore = score;
bestFitCharge = charge;
bestFitPeaks = fittedPeaks;
}
}
PeakListRow oldRow = peakList.getPeakRow(aPeak);
assert bestFitPeaks != null;
// isotope, we skip this left the original peak in the feature list.
if (bestFitPeaks.size() == 1) {
deisotopedPeakList.addRow(oldRow);
processedPeaks++;
continue;
}
// Convert the peak pattern to array
Feature[] originalPeaks = bestFitPeaks.toArray(new Feature[0]);
// Create a new SimpleIsotopePattern
DataPoint[] isotopes = new DataPoint[bestFitPeaks.size()];
for (int i = 0; i < isotopes.length; i++) {
Feature p = originalPeaks[i];
isotopes[i] = new SimpleDataPoint(p.getMZ(), p.getHeight());
}
SimpleIsotopePattern newPattern = new SimpleIsotopePattern(isotopes, IsotopePatternStatus.DETECTED, aPeak.toString());
// the lowest m/z peak
if (chooseMostIntense) {
Arrays.sort(originalPeaks, new PeakSorter(SortingProperty.Height, SortingDirection.Descending));
} else {
Arrays.sort(originalPeaks, new PeakSorter(SortingProperty.MZ, SortingDirection.Ascending));
}
Feature newPeak = new SimpleFeature(originalPeaks[0]);
newPeak.setIsotopePattern(newPattern);
newPeak.setCharge(bestFitCharge);
// Keep old ID
int oldID = oldRow.getID();
SimplePeakListRow newRow = new SimplePeakListRow(oldID);
PeakUtils.copyPeakListRowProperties(oldRow, newRow);
newRow.addPeak(dataFile, newPeak);
deisotopedPeakList.addRow(newRow);
// Remove all peaks already assigned to isotope pattern
for (int i = 0; i < sortedPeaks.length; i++) {
if (bestFitPeaks.contains(sortedPeaks[i]))
sortedPeaks[i] = null;
}
// Update completion rate
processedPeaks++;
}
// Add new peakList to the project
project.addPeakList(deisotopedPeakList);
// Load previous applied methods
for (PeakListAppliedMethod proc : peakList.getAppliedMethods()) {
deisotopedPeakList.addDescriptionOfAppliedTask(proc);
}
// Add task description to peakList
deisotopedPeakList.addDescriptionOfAppliedTask(new SimplePeakListAppliedMethod("Isotopic peaks grouper", parameters));
// Remove the original peakList if requested
if (removeOriginal)
project.removePeakList(peakList);
logger.info("Finished isotopic peak grouper on " + peakList);
setStatus(TaskStatus.FINISHED);
}
use of net.sf.mzmine.datamodel.PeakList.PeakListAppliedMethod in project mzmine2 by mzmine.
the class PeakListOpenHandler_2_5 method initializePeakList.
/**
* Initializes the feature list
*/
private void initializePeakList() {
RawDataFile[] dataFiles = currentPeakListDataFiles.toArray(new RawDataFile[0]);
buildingPeakList = new SimplePeakList(peakListName, dataFiles);
for (int i = 0; i < appliedMethods.size(); i++) {
String methodName = appliedMethods.elementAt(i);
String methodParams = appliedMethodParameters.elementAt(i);
PeakListAppliedMethod pam = new SimplePeakListAppliedMethod(methodName, methodParams);
buildingPeakList.addDescriptionOfAppliedTask(pam);
}
buildingPeakList.setDateCreated(dateCreated);
}
use of net.sf.mzmine.datamodel.PeakList.PeakListAppliedMethod in project mzmine2 by mzmine.
the class PeakListSaveHandler method savePeakList.
/**
* Create an XML document with the feature list information an save it into the project zip file
*
* @param peakList
* @param peakListSavedName name of the feature list
* @throws java.io.IOException
*/
public void savePeakList(PeakList peakList) throws IOException, TransformerConfigurationException, SAXException {
numberOfRows = peakList.getNumberOfRows();
finishedRows = 0;
StreamResult streamResult = new StreamResult(finalStream);
SAXTransformerFactory tf = (SAXTransformerFactory) SAXTransformerFactory.newInstance();
TransformerHandler hd = tf.newTransformerHandler();
Transformer serializer = hd.getTransformer();
serializer.setOutputProperty(OutputKeys.INDENT, "yes");
serializer.setOutputProperty(OutputKeys.ENCODING, "UTF-8");
hd.setResult(streamResult);
hd.startDocument();
AttributesImpl atts = new AttributesImpl();
hd.startElement("", "", PeakListElementName.PEAKLIST.getElementName(), atts);
atts.clear();
// <NAME>
hd.startElement("", "", PeakListElementName.PEAKLIST_NAME.getElementName(), atts);
hd.characters(peakList.getName().toCharArray(), 0, peakList.getName().length());
hd.endElement("", "", PeakListElementName.PEAKLIST_NAME.getElementName());
// <PEAKLIST_DATE>
String dateText = "";
if (((SimplePeakList) peakList).getDateCreated() == null) {
dateText = ((SimplePeakList) peakList).getDateCreated();
} else {
Date date = new Date();
dateText = dateFormat.format(date);
}
hd.startElement("", "", PeakListElementName.PEAKLIST_DATE.getElementName(), atts);
hd.characters(dateText.toCharArray(), 0, dateText.length());
hd.endElement("", "", PeakListElementName.PEAKLIST_DATE.getElementName());
// <QUANTITY>
hd.startElement("", "", PeakListElementName.QUANTITY.getElementName(), atts);
hd.characters(String.valueOf(numberOfRows).toCharArray(), 0, String.valueOf(numberOfRows).length());
hd.endElement("", "", PeakListElementName.QUANTITY.getElementName());
// <PROCESS>
PeakListAppliedMethod[] processes = peakList.getAppliedMethods();
for (PeakListAppliedMethod proc : processes) {
hd.startElement("", "", PeakListElementName.METHOD.getElementName(), atts);
hd.startElement("", "", PeakListElementName.METHOD_NAME.getElementName(), atts);
String methodName = proc.getDescription();
hd.characters(methodName.toCharArray(), 0, methodName.length());
hd.endElement("", "", PeakListElementName.METHOD_NAME.getElementName());
hd.startElement("", "", PeakListElementName.METHOD_PARAMETERS.getElementName(), atts);
String methodParameters = proc.getParameters();
hd.characters(methodParameters.toCharArray(), 0, methodParameters.length());
hd.endElement("", "", PeakListElementName.METHOD_PARAMETERS.getElementName());
hd.endElement("", "", PeakListElementName.METHOD.getElementName());
}
atts.clear();
// <RAWFILE>
RawDataFile[] dataFiles = peakList.getRawDataFiles();
for (int i = 0; i < dataFiles.length; i++) {
String ID = dataFilesIDMap.get(dataFiles[i]);
hd.startElement("", "", PeakListElementName.RAWFILE.getElementName(), atts);
char[] idChars = ID.toCharArray();
hd.characters(idChars, 0, idChars.length);
hd.endElement("", "", PeakListElementName.RAWFILE.getElementName());
}
// <ROW>
PeakListRow row;
for (int i = 0; i < numberOfRows; i++) {
if (canceled)
return;
atts.clear();
row = peakList.getRow(i);
atts.addAttribute("", "", PeakListElementName.ID.getElementName(), "CDATA", String.valueOf(row.getID()));
if (row.getComment() != null) {
atts.addAttribute("", "", PeakListElementName.COMMENT.getElementName(), "CDATA", row.getComment());
}
hd.startElement("", "", PeakListElementName.ROW.getElementName(), atts);
fillRowElement(row, hd);
hd.endElement("", "", PeakListElementName.ROW.getElementName());
finishedRows++;
}
hd.endElement("", "", PeakListElementName.PEAKLIST.getElementName());
hd.endDocument();
}
use of net.sf.mzmine.datamodel.PeakList.PeakListAppliedMethod in project mzmine2 by mzmine.
the class PeakListOpenHandler_2_0 method initializePeakList.
/**
* Initializes the feature list
*/
private void initializePeakList() {
RawDataFile[] dataFiles = currentPeakListDataFiles.toArray(new RawDataFile[0]);
buildingPeakList = new SimplePeakList(peakListName, dataFiles);
for (int i = 0; i < appliedMethods.size(); i++) {
String methodName = appliedMethods.elementAt(i);
String methodParams = appliedMethodParameters.elementAt(i);
PeakListAppliedMethod pam = new SimplePeakListAppliedMethod(methodName, methodParams);
buildingPeakList.addDescriptionOfAppliedTask(pam);
}
buildingPeakList.setDateCreated(dateCreated);
}
use of net.sf.mzmine.datamodel.PeakList.PeakListAppliedMethod in project mzmine2 by mzmine.
the class PeakListOpenHandler_2_3 method initializePeakList.
/**
* Initializes the feature list
*/
private void initializePeakList() {
RawDataFile[] dataFiles = currentPeakListDataFiles.toArray(new RawDataFile[0]);
buildingPeakList = new SimplePeakList(peakListName, dataFiles);
for (int i = 0; i < appliedMethods.size(); i++) {
String methodName = appliedMethods.elementAt(i);
String methodParams = appliedMethodParameters.elementAt(i);
PeakListAppliedMethod pam = new SimplePeakListAppliedMethod(methodName, methodParams);
buildingPeakList.addDescriptionOfAppliedTask(pam);
}
buildingPeakList.setDateCreated(dateCreated);
}
Aggregations