Search in sources :

Example 1 with PeakListAppliedMethod

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);
}
Also used : SimplePeakListAppliedMethod(net.sf.mzmine.datamodel.impl.SimplePeakListAppliedMethod) PeakListAppliedMethod(net.sf.mzmine.datamodel.PeakList.PeakListAppliedMethod) SimplePeakListAppliedMethod(net.sf.mzmine.datamodel.impl.SimplePeakListAppliedMethod) Feature(net.sf.mzmine.datamodel.Feature) SimpleFeature(net.sf.mzmine.datamodel.impl.SimpleFeature) SimplePeakListRow(net.sf.mzmine.datamodel.impl.SimplePeakListRow) DataPoint(net.sf.mzmine.datamodel.DataPoint) SimpleDataPoint(net.sf.mzmine.datamodel.impl.SimpleDataPoint) SimpleFeature(net.sf.mzmine.datamodel.impl.SimpleFeature) SimpleDataPoint(net.sf.mzmine.datamodel.impl.SimpleDataPoint) SimplePeakListRow(net.sf.mzmine.datamodel.impl.SimplePeakListRow) PeakListRow(net.sf.mzmine.datamodel.PeakListRow) RawDataFile(net.sf.mzmine.datamodel.RawDataFile) DataPoint(net.sf.mzmine.datamodel.DataPoint) SimpleDataPoint(net.sf.mzmine.datamodel.impl.SimpleDataPoint) PeakSorter(net.sf.mzmine.util.PeakSorter) SimplePeakList(net.sf.mzmine.datamodel.impl.SimplePeakList) SimpleIsotopePattern(net.sf.mzmine.datamodel.impl.SimpleIsotopePattern) Vector(java.util.Vector)

Example 2 with PeakListAppliedMethod

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);
}
Also used : RawDataFile(net.sf.mzmine.datamodel.RawDataFile) SimplePeakListAppliedMethod(net.sf.mzmine.datamodel.impl.SimplePeakListAppliedMethod) PeakListAppliedMethod(net.sf.mzmine.datamodel.PeakList.PeakListAppliedMethod) SimplePeakList(net.sf.mzmine.datamodel.impl.SimplePeakList) SimplePeakListAppliedMethod(net.sf.mzmine.datamodel.impl.SimplePeakListAppliedMethod) DataPoint(net.sf.mzmine.datamodel.DataPoint) SimpleDataPoint(net.sf.mzmine.datamodel.impl.SimpleDataPoint)

Example 3 with PeakListAppliedMethod

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();
}
Also used : TransformerHandler(javax.xml.transform.sax.TransformerHandler) Transformer(javax.xml.transform.Transformer) StreamResult(javax.xml.transform.stream.StreamResult) SAXTransformerFactory(javax.xml.transform.sax.SAXTransformerFactory) PeakListAppliedMethod(net.sf.mzmine.datamodel.PeakList.PeakListAppliedMethod) Date(java.util.Date) DataPoint(net.sf.mzmine.datamodel.DataPoint) AttributesImpl(org.xml.sax.helpers.AttributesImpl) PeakListRow(net.sf.mzmine.datamodel.PeakListRow) RawDataFile(net.sf.mzmine.datamodel.RawDataFile)

Example 4 with PeakListAppliedMethod

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);
}
Also used : RawDataFile(net.sf.mzmine.datamodel.RawDataFile) SimplePeakListAppliedMethod(net.sf.mzmine.datamodel.impl.SimplePeakListAppliedMethod) PeakListAppliedMethod(net.sf.mzmine.datamodel.PeakList.PeakListAppliedMethod) SimplePeakList(net.sf.mzmine.datamodel.impl.SimplePeakList) SimplePeakListAppliedMethod(net.sf.mzmine.datamodel.impl.SimplePeakListAppliedMethod) DataPoint(net.sf.mzmine.datamodel.DataPoint) SimpleDataPoint(net.sf.mzmine.datamodel.impl.SimpleDataPoint)

Example 5 with PeakListAppliedMethod

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);
}
Also used : RawDataFile(net.sf.mzmine.datamodel.RawDataFile) SimplePeakListAppliedMethod(net.sf.mzmine.datamodel.impl.SimplePeakListAppliedMethod) PeakListAppliedMethod(net.sf.mzmine.datamodel.PeakList.PeakListAppliedMethod) SimplePeakList(net.sf.mzmine.datamodel.impl.SimplePeakList) SimplePeakListAppliedMethod(net.sf.mzmine.datamodel.impl.SimplePeakListAppliedMethod) DataPoint(net.sf.mzmine.datamodel.DataPoint) SimpleDataPoint(net.sf.mzmine.datamodel.impl.SimpleDataPoint)

Aggregations

PeakListAppliedMethod (net.sf.mzmine.datamodel.PeakList.PeakListAppliedMethod)21 SimplePeakListAppliedMethod (net.sf.mzmine.datamodel.impl.SimplePeakListAppliedMethod)20 SimplePeakList (net.sf.mzmine.datamodel.impl.SimplePeakList)14 RawDataFile (net.sf.mzmine.datamodel.RawDataFile)13 PeakListRow (net.sf.mzmine.datamodel.PeakListRow)12 SimplePeakListRow (net.sf.mzmine.datamodel.impl.SimplePeakListRow)11 Feature (net.sf.mzmine.datamodel.Feature)10 DataPoint (net.sf.mzmine.datamodel.DataPoint)8 SimpleFeature (net.sf.mzmine.datamodel.impl.SimpleFeature)7 SimpleDataPoint (net.sf.mzmine.datamodel.impl.SimpleDataPoint)5 PeakList (net.sf.mzmine.datamodel.PeakList)4 Vector (java.util.Vector)2 PeakSorter (net.sf.mzmine.util.PeakSorter)2 Range (com.google.common.collect.Range)1 Date (java.util.Date)1 Hashtable (java.util.Hashtable)1 Transformer (javax.xml.transform.Transformer)1 SAXTransformerFactory (javax.xml.transform.sax.SAXTransformerFactory)1 TransformerHandler (javax.xml.transform.sax.TransformerHandler)1 StreamResult (javax.xml.transform.stream.StreamResult)1