Search in sources :

Example 1 with CentroidMassDetector

use of net.sf.mzmine.modules.rawdatamethods.peakpicking.massdetection.centroid.CentroidMassDetector in project mzmine2 by mzmine.

the class SpectraIdentificationLipidSearchTask method run.

/**
 * @see java.lang.Runnable#run()
 */
@Override
public void run() {
    setStatus(TaskStatus.PROCESSING);
    // create mass list for scan
    DataPoint[] massList = null;
    ArrayList<DataPoint> massListAnnotated = new ArrayList<>();
    MassDetector massDetector = null;
    ArrayList<String> allCompoundIDs = new ArrayList<>();
    // Create a new mass list for MS/MS scan. Check if sprectrum is profile or centroid mode
    if (currentScan.getSpectrumType() == MassSpectrumType.CENTROIDED) {
        massDetector = new CentroidMassDetector();
        CentroidMassDetectorParameters parameters = new CentroidMassDetectorParameters();
        CentroidMassDetectorParameters.noiseLevel.setValue(noiseLevel);
        massList = massDetector.getMassValues(currentScan.getDataPoints(), parameters);
    } else {
        massDetector = new ExactMassDetector();
        ExactMassDetectorParameters parameters = new ExactMassDetectorParameters();
        ExactMassDetectorParameters.noiseLevel.setValue(noiseLevel);
        massList = massDetector.getMassValues(currentScan.getDataPoints(), parameters);
    }
    totalSteps = massList.length;
    // loop through every peak in mass list
    if (getStatus() != TaskStatus.PROCESSING) {
        return;
    }
    // Check if lipids should be modified
    if (searchForModifications == true) {
        lipidModificationMasses = getLipidModificationMasses(lipidModification);
    }
    // Calculate how many possible lipids we will try
    totalSteps = (((maxChainLength - minChainLength + 1) * (maxDoubleBonds - minDoubleBonds + 1)) * selectedLipids.length);
    // Combine Strings
    String annotation = "";
    // Try all combinations of fatty acid lengths and double bonds
    for (int j = 0; j < selectedLipids.length; j++) {
        int numberOfAcylChains = selectedLipids[j].getNumberOfAcylChains();
        int numberOfAlkylChains = selectedLipids[j].getNumberofAlkyChains();
        for (int chainLength = minChainLength; chainLength <= maxChainLength; chainLength++) {
            for (int chainDoubleBonds = minDoubleBonds; chainDoubleBonds <= maxDoubleBonds; chainDoubleBonds++) {
                for (int i = 0; i < massList.length; i++) {
                    searchedMass = massList[i].getMZ();
                    // Task canceled?
                    if (isCanceled())
                        return;
                    // than minimal length, skip this lipid
                    if (((chainLength > 0) && (chainLength < minChainLength))) {
                        continue;
                    }
                    // doesn't make sense, so let's skip such lipids
                    if (((chainDoubleBonds > 0) && (chainDoubleBonds > chainLength - 1))) {
                        continue;
                    }
                    // Prepare a lipid instance
                    LipidIdentity lipidChain = new LipidIdentity(selectedLipids[j], chainLength, chainDoubleBonds, numberOfAcylChains, numberOfAlkylChains);
                    annotation = findPossibleLipid(lipidChain, searchedMass);
                    if (annotation != "") {
                        allCompoundIDs.add(annotation);
                        massListAnnotated.add(massList[i]);
                    }
                    annotation = findPossibleLipidModification(lipidChain, searchedMass);
                    if (annotation != "") {
                        allCompoundIDs.add(annotation);
                        massListAnnotated.add(massList[i]);
                    }
                }
                finishedSteps++;
            }
        }
    }
    // new mass list
    DataPoint[] annotatedMassList = new DataPoint[massListAnnotated.size()];
    massListAnnotated.toArray(annotatedMassList);
    String[] annotations = new String[annotatedMassList.length];
    allCompoundIDs.toArray(annotations);
    DataPointsDataSet detectedCompoundsDataset = new DataPointsDataSet("Detected compounds", annotatedMassList);
    // Add label generator for the dataset
    SpectraDatabaseSearchLabelGenerator labelGenerator = new SpectraDatabaseSearchLabelGenerator(annotations, spectraPlot);
    spectraPlot.addDataSet(detectedCompoundsDataset, Color.orange, true, labelGenerator);
    spectraPlot.getXYPlot().getRenderer().setSeriesItemLabelGenerator(spectraPlot.getXYPlot().getSeriesCount(), labelGenerator);
    spectraPlot.getXYPlot().getRenderer().setDefaultPositiveItemLabelPosition(new ItemLabelPosition(ItemLabelAnchor.CENTER, TextAnchor.TOP_LEFT, TextAnchor.BOTTOM_CENTER, 0.0), true);
    setStatus(TaskStatus.FINISHED);
}
Also used : CentroidMassDetectorParameters(net.sf.mzmine.modules.rawdatamethods.peakpicking.massdetection.centroid.CentroidMassDetectorParameters) LipidIdentity(net.sf.mzmine.modules.peaklistmethods.identification.lipididentification.lipidutils.LipidIdentity) ArrayList(java.util.ArrayList) ExactMassDetector(net.sf.mzmine.modules.rawdatamethods.peakpicking.massdetection.exactmass.ExactMassDetector) DataPoint(net.sf.mzmine.datamodel.DataPoint) DataPoint(net.sf.mzmine.datamodel.DataPoint) ItemLabelPosition(org.jfree.chart.labels.ItemLabelPosition) CentroidMassDetector(net.sf.mzmine.modules.rawdatamethods.peakpicking.massdetection.centroid.CentroidMassDetector) CentroidMassDetector(net.sf.mzmine.modules.rawdatamethods.peakpicking.massdetection.centroid.CentroidMassDetector) ExactMassDetector(net.sf.mzmine.modules.rawdatamethods.peakpicking.massdetection.exactmass.ExactMassDetector) MassDetector(net.sf.mzmine.modules.rawdatamethods.peakpicking.massdetection.MassDetector) ExactMassDetectorParameters(net.sf.mzmine.modules.rawdatamethods.peakpicking.massdetection.exactmass.ExactMassDetectorParameters) DataPointsDataSet(net.sf.mzmine.modules.visualization.spectra.simplespectra.datasets.DataPointsDataSet) SpectraDatabaseSearchLabelGenerator(net.sf.mzmine.modules.visualization.spectra.simplespectra.spectraidentification.SpectraDatabaseSearchLabelGenerator)

Example 2 with CentroidMassDetector

use of net.sf.mzmine.modules.rawdatamethods.peakpicking.massdetection.centroid.CentroidMassDetector in project mzmine2 by mzmine.

the class SpectraIdentificationOnlineDatabaseTask method run.

/**
 * @see java.lang.Runnable#run()
 */
@Override
public void run() {
    setStatus(TaskStatus.PROCESSING);
    // create mass list for scan
    DataPoint[] massList = null;
    ArrayList<DataPoint> massListAnnotated = new ArrayList<>();
    MassDetector massDetector = null;
    ArrayList<String> allCompoundIDs = new ArrayList<>();
    // Create a new mass list for MS/MS scan. Check if sprectrum is profile or centroid mode
    if (currentScan.getSpectrumType() == MassSpectrumType.CENTROIDED) {
        massDetector = new CentroidMassDetector();
        CentroidMassDetectorParameters parameters = new CentroidMassDetectorParameters();
        CentroidMassDetectorParameters.noiseLevel.setValue(noiseLevel);
        massList = massDetector.getMassValues(currentScan.getDataPoints(), parameters);
    } else {
        massDetector = new ExactMassDetector();
        ExactMassDetectorParameters parameters = new ExactMassDetectorParameters();
        ExactMassDetectorParameters.noiseLevel.setValue(noiseLevel);
        massList = massDetector.getMassValues(currentScan.getDataPoints(), parameters);
    }
    numItems = massList.length;
    for (int i = 0; i < massList.length; i++) {
        // loop through every peak in mass list
        if (getStatus() != TaskStatus.PROCESSING) {
            return;
        }
        searchedMass = massList[i].getMZ() - ionType.getAddedMass();
        try {
            // find candidate compounds
            String[] compoundIDs = gateway.findCompounds(searchedMass, mzTolerance, 1, db.getParameterSet());
            // Combine strings
            String annotation = "";
            // max number of compounds to top three for visualization
            int counter = 0;
            for (int j = 0; !isCanceled() && j < compoundIDs.length; j++) {
                final DBCompound compound = gateway.getCompound(compoundIDs[j], db.getParameterSet());
                // In case we failed to retrieve data, skip this compound
                if (compound == null)
                    continue;
                if (counter < 3) {
                    int number = counter + 1;
                    annotation = annotation + " " + number + ". " + compound.getName();
                    counter++;
                }
            }
            if (annotation != "") {
                allCompoundIDs.add(annotation);
                massListAnnotated.add(massList[i]);
            }
        } catch (Exception e) {
            e.printStackTrace();
            logger.log(Level.WARNING, "Could not connect to " + db, e);
            setStatus(TaskStatus.ERROR);
            setErrorMessage("Could not connect to " + db + ": " + ExceptionUtils.exceptionToString(e));
            return;
        }
        finishedItems++;
    }
    // new mass list
    DataPoint[] annotatedMassList = new DataPoint[massListAnnotated.size()];
    massListAnnotated.toArray(annotatedMassList);
    String[] annotations = new String[annotatedMassList.length];
    allCompoundIDs.toArray(annotations);
    DataPointsDataSet detectedCompoundsDataset = new DataPointsDataSet("Detected compounds", annotatedMassList);
    // Add label generator for the dataset
    SpectraDatabaseSearchLabelGenerator labelGenerator = new SpectraDatabaseSearchLabelGenerator(annotations, spectraPlot);
    spectraPlot.addDataSet(detectedCompoundsDataset, Color.orange, true, labelGenerator);
    spectraPlot.getXYPlot().getRenderer().setSeriesItemLabelGenerator(spectraPlot.getXYPlot().getSeriesCount(), labelGenerator);
    spectraPlot.getXYPlot().getRenderer().setDefaultPositiveItemLabelPosition(new ItemLabelPosition(ItemLabelAnchor.CENTER, TextAnchor.TOP_LEFT, TextAnchor.BOTTOM_CENTER, 0.0), true);
    setStatus(TaskStatus.FINISHED);
}
Also used : CentroidMassDetectorParameters(net.sf.mzmine.modules.rawdatamethods.peakpicking.massdetection.centroid.CentroidMassDetectorParameters) ArrayList(java.util.ArrayList) ExactMassDetector(net.sf.mzmine.modules.rawdatamethods.peakpicking.massdetection.exactmass.ExactMassDetector) DataPoint(net.sf.mzmine.datamodel.DataPoint) DBCompound(net.sf.mzmine.modules.peaklistmethods.identification.onlinedbsearch.DBCompound) DataPoint(net.sf.mzmine.datamodel.DataPoint) ItemLabelPosition(org.jfree.chart.labels.ItemLabelPosition) CentroidMassDetector(net.sf.mzmine.modules.rawdatamethods.peakpicking.massdetection.centroid.CentroidMassDetector) CentroidMassDetector(net.sf.mzmine.modules.rawdatamethods.peakpicking.massdetection.centroid.CentroidMassDetector) ExactMassDetector(net.sf.mzmine.modules.rawdatamethods.peakpicking.massdetection.exactmass.ExactMassDetector) MassDetector(net.sf.mzmine.modules.rawdatamethods.peakpicking.massdetection.MassDetector) ExactMassDetectorParameters(net.sf.mzmine.modules.rawdatamethods.peakpicking.massdetection.exactmass.ExactMassDetectorParameters) DataPointsDataSet(net.sf.mzmine.modules.visualization.spectra.simplespectra.datasets.DataPointsDataSet) SpectraDatabaseSearchLabelGenerator(net.sf.mzmine.modules.visualization.spectra.simplespectra.spectraidentification.SpectraDatabaseSearchLabelGenerator)

Example 3 with CentroidMassDetector

use of net.sf.mzmine.modules.rawdatamethods.peakpicking.massdetection.centroid.CentroidMassDetector in project mzmine2 by mzmine.

the class SpectraIdentificationSumFormulaTask method run.

/**
 * @see java.lang.Runnable#run()
 */
@Override
public void run() {
    setStatus(TaskStatus.PROCESSING);
    logger.finest("Starting search for formulas for " + massRange + " Da");
    // create mass list for scan
    DataPoint[] massList = null;
    ArrayList<DataPoint> massListAnnotated = new ArrayList<>();
    MassDetector massDetector = null;
    ArrayList<String> allCompoundIDs = new ArrayList<>();
    // Create a new mass list for MS/MS scan. Check if sprectrum is profile or centroid mode
    if (currentScan.getSpectrumType() == MassSpectrumType.CENTROIDED) {
        massDetector = new CentroidMassDetector();
        CentroidMassDetectorParameters parameters = new CentroidMassDetectorParameters();
        CentroidMassDetectorParameters.noiseLevel.setValue(noiseLevel);
        massList = massDetector.getMassValues(currentScan.getDataPoints(), parameters);
    } else {
        massDetector = new ExactMassDetector();
        ExactMassDetectorParameters parameters = new ExactMassDetectorParameters();
        ExactMassDetectorParameters.noiseLevel.setValue(noiseLevel);
        massList = massDetector.getMassValues(currentScan.getDataPoints(), parameters);
    }
    numItems = massList.length;
    // loop through every peak in mass list
    if (getStatus() != TaskStatus.PROCESSING) {
        return;
    }
    IChemObjectBuilder builder = SilentChemObjectBuilder.getInstance();
    for (int i = 0; i < massList.length; i++) {
        massRange = mzTolerance.getToleranceRange((massList[i].getMZ() - ionType.getAddedMass()) / charge);
        generator = new MolecularFormulaGenerator(builder, massRange.lowerEndpoint(), massRange.upperEndpoint(), elementCounts);
        IMolecularFormula cdkFormula;
        String annotation = "";
        // create a map to store ResultFormula and relative mass deviation for sorting
        Map<Double, String> possibleFormulas = new TreeMap<>();
        while ((cdkFormula = generator.getNextFormula()) != null) {
            if (isCanceled())
                return;
            // Mass is ok, so test other constraints
            if (checkConstraints(cdkFormula) == true) {
                String formula = MolecularFormulaManipulator.getString(cdkFormula);
                // calc rel mass deviation
                Double relMassDev = ((((// 
                massList[i].getMZ() - ionType.getAddedMass()) / // 
                charge) - (// 
                FormulaUtils.calculateExactMass(MolecularFormulaManipulator.getString(cdkFormula))) / charge) / ((// 
                massList[i].getMZ() - ionType.getAddedMass()) / charge)) * 1000000;
                // write to map
                possibleFormulas.put(relMassDev, formula);
            }
        }
        Map<Double, String> treeMap = new TreeMap<>((Comparator<Double>) (o1, o2) -> Double.compare(Math.abs(o1), Math.abs(o2)));
        treeMap.putAll(possibleFormulas);
        // get top 3
        int ctr = 0;
        for (Map.Entry<Double, String> entry : treeMap.entrySet()) {
            int number = ctr + 1;
            if (ctr > 2)
                break;
            annotation = annotation + number + ". " + entry.getValue() + " Δ " + NumberFormat.getInstance().format(entry.getKey()) + " ppm; ";
            ctr++;
            if (isCanceled())
                return;
        }
        if (annotation != "") {
            allCompoundIDs.add(annotation);
            massListAnnotated.add(massList[i]);
        }
        logger.finest("Finished formula search for " + massRange + " m/z, found " + foundFormulas + " formulas");
    }
    // new mass list
    DataPoint[] annotatedMassList = new DataPoint[massListAnnotated.size()];
    massListAnnotated.toArray(annotatedMassList);
    String[] annotations = new String[annotatedMassList.length];
    allCompoundIDs.toArray(annotations);
    DataPointsDataSet detectedCompoundsDataset = new DataPointsDataSet("Detected compounds", annotatedMassList);
    // Add label generator for the dataset
    SpectraDatabaseSearchLabelGenerator labelGenerator = new SpectraDatabaseSearchLabelGenerator(annotations, spectraPlot);
    spectraPlot.addDataSet(detectedCompoundsDataset, Color.orange, true, labelGenerator);
    spectraPlot.getXYPlot().getRenderer().setSeriesItemLabelGenerator(spectraPlot.getXYPlot().getSeriesCount(), labelGenerator);
    spectraPlot.getXYPlot().getRenderer().setDefaultPositiveItemLabelPosition(new ItemLabelPosition(ItemLabelAnchor.CENTER, TextAnchor.TOP_LEFT, TextAnchor.BOTTOM_CENTER, 0.0), true);
    setStatus(TaskStatus.FINISHED);
}
Also used : Color(java.awt.Color) Scan(net.sf.mzmine.datamodel.Scan) MZmineCore(net.sf.mzmine.main.MZmineCore) CentroidMassDetector(net.sf.mzmine.modules.rawdatamethods.peakpicking.massdetection.centroid.CentroidMassDetector) CentroidMassDetectorParameters(net.sf.mzmine.modules.rawdatamethods.peakpicking.massdetection.centroid.CentroidMassDetectorParameters) TaskStatus(net.sf.mzmine.taskcontrol.TaskStatus) RDBERestrictionChecker(net.sf.mzmine.modules.peaklistmethods.identification.formulaprediction.restrictions.rdbe.RDBERestrictionChecker) TextAnchor(org.jfree.chart.ui.TextAnchor) MolecularFormulaManipulator(org.openscience.cdk.tools.manipulator.MolecularFormulaManipulator) MolecularFormulaGenerator(org.openscience.cdk.formula.MolecularFormulaGenerator) SpectraDatabaseSearchLabelGenerator(net.sf.mzmine.modules.visualization.spectra.simplespectra.spectraidentification.SpectraDatabaseSearchLabelGenerator) NumberFormat(java.text.NumberFormat) DataPoint(net.sf.mzmine.datamodel.DataPoint) ExactMassDetector(net.sf.mzmine.modules.rawdatamethods.peakpicking.massdetection.exactmass.ExactMassDetector) ArrayList(java.util.ArrayList) MassDetector(net.sf.mzmine.modules.rawdatamethods.peakpicking.massdetection.MassDetector) ParameterSet(net.sf.mzmine.parameters.ParameterSet) Map(java.util.Map) IChemObjectBuilder(org.openscience.cdk.interfaces.IChemObjectBuilder) FormulaUtils(net.sf.mzmine.util.FormulaUtils) MZTolerance(net.sf.mzmine.parameters.parametertypes.tolerances.MZTolerance) SilentChemObjectBuilder(org.openscience.cdk.silent.SilentChemObjectBuilder) Range(com.google.common.collect.Range) Logger(java.util.logging.Logger) IonizationType(net.sf.mzmine.datamodel.IonizationType) ElementalHeuristicChecker(net.sf.mzmine.modules.peaklistmethods.identification.formulaprediction.restrictions.elements.ElementalHeuristicChecker) MassSpectrumType(net.sf.mzmine.datamodel.MassSpectrumType) IMolecularFormula(org.openscience.cdk.interfaces.IMolecularFormula) ItemLabelPosition(org.jfree.chart.labels.ItemLabelPosition) AbstractTask(net.sf.mzmine.taskcontrol.AbstractTask) TreeMap(java.util.TreeMap) MolecularFormulaRange(org.openscience.cdk.formula.MolecularFormulaRange) Comparator(java.util.Comparator) ItemLabelAnchor(org.jfree.chart.labels.ItemLabelAnchor) ExactMassDetectorParameters(net.sf.mzmine.modules.rawdatamethods.peakpicking.massdetection.exactmass.ExactMassDetectorParameters) SpectraPlot(net.sf.mzmine.modules.visualization.spectra.simplespectra.SpectraPlot) DataPointsDataSet(net.sf.mzmine.modules.visualization.spectra.simplespectra.datasets.DataPointsDataSet) ArrayList(java.util.ArrayList) IMolecularFormula(org.openscience.cdk.interfaces.IMolecularFormula) ExactMassDetector(net.sf.mzmine.modules.rawdatamethods.peakpicking.massdetection.exactmass.ExactMassDetector) MolecularFormulaGenerator(org.openscience.cdk.formula.MolecularFormulaGenerator) DataPoint(net.sf.mzmine.datamodel.DataPoint) ItemLabelPosition(org.jfree.chart.labels.ItemLabelPosition) CentroidMassDetector(net.sf.mzmine.modules.rawdatamethods.peakpicking.massdetection.centroid.CentroidMassDetector) ExactMassDetector(net.sf.mzmine.modules.rawdatamethods.peakpicking.massdetection.exactmass.ExactMassDetector) MassDetector(net.sf.mzmine.modules.rawdatamethods.peakpicking.massdetection.MassDetector) DataPointsDataSet(net.sf.mzmine.modules.visualization.spectra.simplespectra.datasets.DataPointsDataSet) CentroidMassDetectorParameters(net.sf.mzmine.modules.rawdatamethods.peakpicking.massdetection.centroid.CentroidMassDetectorParameters) TreeMap(java.util.TreeMap) IChemObjectBuilder(org.openscience.cdk.interfaces.IChemObjectBuilder) DataPoint(net.sf.mzmine.datamodel.DataPoint) CentroidMassDetector(net.sf.mzmine.modules.rawdatamethods.peakpicking.massdetection.centroid.CentroidMassDetector) ExactMassDetectorParameters(net.sf.mzmine.modules.rawdatamethods.peakpicking.massdetection.exactmass.ExactMassDetectorParameters) Map(java.util.Map) TreeMap(java.util.TreeMap) SpectraDatabaseSearchLabelGenerator(net.sf.mzmine.modules.visualization.spectra.simplespectra.spectraidentification.SpectraDatabaseSearchLabelGenerator)

Example 4 with CentroidMassDetector

use of net.sf.mzmine.modules.rawdatamethods.peakpicking.massdetection.centroid.CentroidMassDetector in project mzmine2 by mzmine.

the class SpectraIdentificationCustomDatabaseTask method run.

/**
 * @see java.lang.Runnable#run()
 */
@Override
public void run() {
    setStatus(TaskStatus.PROCESSING);
    // create mass list for scan
    DataPoint[] massList = null;
    ArrayList<DataPoint> massListAnnotated = new ArrayList<>();
    MassDetector massDetector = null;
    ArrayList<String> allCompoundIDs = new ArrayList<>();
    // Create a new mass list for MS/MS scan. Check if sprectrum is profile or centroid mode
    if (currentScan.getSpectrumType() == MassSpectrumType.CENTROIDED) {
        massDetector = new CentroidMassDetector();
        CentroidMassDetectorParameters parameters = new CentroidMassDetectorParameters();
        CentroidMassDetectorParameters.noiseLevel.setValue(noiseLevel);
        massList = massDetector.getMassValues(currentScan.getDataPoints(), parameters);
    } else {
        massDetector = new ExactMassDetector();
        ExactMassDetectorParameters parameters = new ExactMassDetectorParameters();
        ExactMassDetectorParameters.noiseLevel.setValue(noiseLevel);
        massList = massDetector.getMassValues(currentScan.getDataPoints(), parameters);
    }
    numItems = massList.length;
    // load custom database
    try {
        // read database contents in memory
        FileReader dbFileReader = new FileReader(dataBaseFile);
        databaseValues = CSVParser.parse(dbFileReader, fieldSeparator.charAt(0));
        if (ignoreFirstLine)
            finishedLines++;
        for (; finishedLines < databaseValues.length; finishedLines++) {
            if (isCanceled()) {
                dbFileReader.close();
                return;
            }
            int numOfColumns = Math.min(fieldOrder.length, databaseValues[finishedLines].length);
            String lineName = null;
            double lineMZ = 0;
            for (int i = 0; i < numOfColumns; i++) {
                if (fieldOrder[i] == FieldItem.FIELD_NAME)
                    lineName = databaseValues[finishedLines][i].toString();
                if (fieldOrder[i] == FieldItem.FIELD_MZ)
                    lineMZ = Double.parseDouble(databaseValues[finishedLines][i].toString());
            }
            for (int i = 0; i < massList.length; i++) {
                // loop through every peak in mass list
                if (getStatus() != TaskStatus.PROCESSING) {
                    return;
                }
                double searchedMass = massList[i].getMZ();
                Range<Double> mzRange = mzTolerance.getToleranceRange(searchedMass);
                boolean mzMatches = (lineMZ == 0d) || mzRange.contains(lineMZ);
                String annotation = "";
                if (mzMatches) {
                    // calc rel mass deviation
                    double relMassDev = ((searchedMass - lineMZ) / searchedMass) * 1000000;
                    logger.finest("Found compound " + lineName + " m/z " + NumberFormat.getInstance().format(searchedMass) + " Δ " + NumberFormat.getInstance().format(relMassDev) + " ppm");
                    annotation = lineName + " Δ " + NumberFormat.getInstance().format(relMassDev) + " ppm";
                }
                if (annotation != "") {
                    allCompoundIDs.add(annotation);
                    massListAnnotated.add(massList[i]);
                }
            }
            finishedLines++;
        }
        // close the file reader
        dbFileReader.close();
    } catch (Exception e) {
        logger.log(Level.WARNING, "Could not read file " + dataBaseFile, e);
        setStatus(TaskStatus.ERROR);
        setErrorMessage(e.toString());
        return;
    }
    // new mass list
    DataPoint[] annotatedMassList = new DataPoint[massListAnnotated.size()];
    massListAnnotated.toArray(annotatedMassList);
    String[] annotations = new String[annotatedMassList.length];
    allCompoundIDs.toArray(annotations);
    DataPointsDataSet detectedCompoundsDataset = new DataPointsDataSet("Detected compounds", annotatedMassList);
    // Add label generator for the dataset
    SpectraDatabaseSearchLabelGenerator labelGenerator = new SpectraDatabaseSearchLabelGenerator(annotations, spectraPlot);
    spectraPlot.addDataSet(detectedCompoundsDataset, Color.orange, true, labelGenerator);
    spectraPlot.getXYPlot().getRenderer().setSeriesItemLabelGenerator(spectraPlot.getXYPlot().getSeriesCount(), labelGenerator);
    spectraPlot.getXYPlot().getRenderer().setDefaultPositiveItemLabelPosition(new ItemLabelPosition(ItemLabelAnchor.CENTER, TextAnchor.TOP_LEFT, TextAnchor.BOTTOM_CENTER, 0.0), true);
    setStatus(TaskStatus.FINISHED);
}
Also used : CentroidMassDetectorParameters(net.sf.mzmine.modules.rawdatamethods.peakpicking.massdetection.centroid.CentroidMassDetectorParameters) ArrayList(java.util.ArrayList) ExactMassDetector(net.sf.mzmine.modules.rawdatamethods.peakpicking.massdetection.exactmass.ExactMassDetector) DataPoint(net.sf.mzmine.datamodel.DataPoint) DataPoint(net.sf.mzmine.datamodel.DataPoint) FileReader(java.io.FileReader) ItemLabelPosition(org.jfree.chart.labels.ItemLabelPosition) CentroidMassDetector(net.sf.mzmine.modules.rawdatamethods.peakpicking.massdetection.centroid.CentroidMassDetector) CentroidMassDetector(net.sf.mzmine.modules.rawdatamethods.peakpicking.massdetection.centroid.CentroidMassDetector) ExactMassDetector(net.sf.mzmine.modules.rawdatamethods.peakpicking.massdetection.exactmass.ExactMassDetector) MassDetector(net.sf.mzmine.modules.rawdatamethods.peakpicking.massdetection.MassDetector) ExactMassDetectorParameters(net.sf.mzmine.modules.rawdatamethods.peakpicking.massdetection.exactmass.ExactMassDetectorParameters) DataPointsDataSet(net.sf.mzmine.modules.visualization.spectra.simplespectra.datasets.DataPointsDataSet) SpectraDatabaseSearchLabelGenerator(net.sf.mzmine.modules.visualization.spectra.simplespectra.spectraidentification.SpectraDatabaseSearchLabelGenerator)

Example 5 with CentroidMassDetector

use of net.sf.mzmine.modules.rawdatamethods.peakpicking.massdetection.centroid.CentroidMassDetector in project mzmine2 by mzmine.

the class LipidSearchTask method searchMsmsFragments.

/**
 * This method searches for MS/MS fragments. A mass list for MS2 scans will be used if present. If
 * no mass list is present for MS2 scans it will create one using centroid or exact mass detection
 * algorithm
 */
private void searchMsmsFragments(PeakListRow row, double lipidIonMass, LipidIdentity lipid) {
    MassDetector massDetector = null;
    // Check if selected feature has MSMS spectra
    if (row.getAllMS2Fragmentations() != null) {
        Scan[] msmsScans = row.getAllMS2Fragmentations();
        for (Scan msmsScan : msmsScans) {
            DataPoint[] massList = null;
            // check if MS/MS scan already has a mass list
            if (msmsScan.getMassLists().length != 0) {
                massList = msmsScan.getMassLists()[0].getDataPoints();
            } else {
                // Create a new mass list for MS/MS scan. Check if sprectrum is profile or centroid mode
                if (msmsScan.getSpectrumType() == MassSpectrumType.CENTROIDED) {
                    massDetector = new CentroidMassDetector();
                    CentroidMassDetectorParameters parametersMSMS = new CentroidMassDetectorParameters();
                    CentroidMassDetectorParameters.noiseLevel.setValue(noiseLevelMSMS);
                    massList = massDetector.getMassValues(msmsScan, parametersMSMS);
                } else {
                    massDetector = new ExactMassDetector();
                    ExactMassDetectorParameters parametersMSMS = new ExactMassDetectorParameters();
                    ExactMassDetectorParameters.noiseLevel.setValue(noiseLevelMSMS);
                    massList = massDetector.getMassValues(msmsScan, parametersMSMS);
                }
            }
            MSMSLipidTools msmsLipidTools = new MSMSLipidTools();
            // check for negative polarity
            if (msmsScan.getPolarity() == PolarityType.NEGATIVE) {
                // check if lipid class has set negative fragments
                String[] fragments = lipid.getLipidClass().getMsmsFragmentsNegativeIonization();
                if (fragments.length > 0) {
                    ArrayList<String> listOfAnnotatedNegativeFragments = new ArrayList<String>();
                    for (int i = 0; i < massList.length; i++) {
                        Range<Double> mzTolRangeMSMS = mzToleranceMS2.getToleranceRange(massList[i].getMZ());
                        String annotatedNegativeFragment = msmsLipidTools.checkForNegativeClassSpecificFragment(mzTolRangeMSMS, row.getPreferredPeakIdentity(), lipidIonMass, fragments);
                        if (annotatedNegativeFragment.equals("") == false && row.getComment().contains(annotatedNegativeFragment) == false) {
                            listOfAnnotatedNegativeFragments.add(annotatedNegativeFragment);
                        }
                    }
                    if (listOfAnnotatedNegativeFragments.isEmpty() == false) {
                        // predict lipid fatty acid composition if possible
                        ArrayList<String> listOfPossibleFattyAcidCompositions = msmsLipidTools.predictFattyAcidComposition(listOfAnnotatedNegativeFragments, row.getPreferredPeakIdentity(), lipid.getLipidClass().getNumberOfAcylChains());
                        for (int i = 0; i < listOfPossibleFattyAcidCompositions.size(); i++) {
                            // Add possible composition to comment
                            if (row.getComment().equals(null)) {
                                row.setComment(" " + listOfPossibleFattyAcidCompositions.get(i) + " MS/MS scan " + msmsScan.getScanNumber() + ", RT " + MZmineCore.getConfiguration().getRTFormat().format(msmsScan.getRetentionTime()));
                            } else {
                                row.setComment(row.getComment() + ";" + " " + listOfPossibleFattyAcidCompositions.get(i) + " MS/MS scan " + msmsScan.getScanNumber() + ", RT " + MZmineCore.getConfiguration().getRTFormat().format(msmsScan.getRetentionTime()));
                            }
                        }
                        // add class specific fragments
                        for (int i = 0; i < listOfAnnotatedNegativeFragments.size(); i++) {
                            if (listOfAnnotatedNegativeFragments.get(i).contains("C") || listOfAnnotatedNegativeFragments.get(i).contains("H") || listOfAnnotatedNegativeFragments.get(i).contains("O")) {
                                // Add fragment to comment
                                if (row.getComment().equals(null)) {
                                    row.setComment(" " + listOfAnnotatedNegativeFragments.get(i) + " MS/MS scan " + msmsScan.getScanNumber() + ", RT " + MZmineCore.getConfiguration().getRTFormat().format(msmsScan.getRetentionTime()));
                                } else {
                                    row.setComment(row.getComment() + ";" + " " + listOfAnnotatedNegativeFragments.get(i) + " MS/MS scan " + msmsScan.getScanNumber() + ", RT " + MZmineCore.getConfiguration().getRTFormat().format(msmsScan.getRetentionTime()));
                                }
                            }
                        }
                    }
                }
            }
            // check if lipid class has positive fragments
            if (msmsScan.getPolarity() == PolarityType.POSITIVE) {
                // check if lipid class has set postiev fragments
                String[] fragments = lipid.getLipidClass().getMsmsFragmentsPositiveIonization();
                if (fragments.length > 0) {
                    ArrayList<String> listOfAnnotatedPositiveFragments = new ArrayList<String>();
                    for (int i = 0; i < massList.length; i++) {
                        Range<Double> mzTolRangeMSMS = mzToleranceMS2.getToleranceRange(massList[i].getMZ());
                        String annotatedPositiveFragment = msmsLipidTools.checkForPositiveClassSpecificFragment(mzTolRangeMSMS, row.getPreferredPeakIdentity(), lipidIonMass, fragments);
                        if (annotatedPositiveFragment.equals("") == false && row.getComment().contains(annotatedPositiveFragment) == false) {
                            listOfAnnotatedPositiveFragments.add(annotatedPositiveFragment);
                        }
                    }
                    // predict lipid fatty acid composition if possible
                    ArrayList<String> listOfPossibleFattyAcidCompositions = msmsLipidTools.predictFattyAcidComposition(listOfAnnotatedPositiveFragments, row.getPreferredPeakIdentity(), lipid.getLipidClass().getNumberOfAcylChains());
                    for (int i = 0; i < listOfPossibleFattyAcidCompositions.size(); i++) {
                        // Add possible composition to comment
                        if (row.getComment().equals(null)) {
                            row.setComment(" " + listOfPossibleFattyAcidCompositions.get(i) + " MS/MS scan " + msmsScan.getScanNumber() + ", RT " + MZmineCore.getConfiguration().getRTFormat().format(msmsScan.getRetentionTime()));
                        } else {
                            row.setComment(row.getComment() + ";" + " " + listOfPossibleFattyAcidCompositions.get(i) + " MS/MS scan " + msmsScan.getScanNumber() + ", RT " + MZmineCore.getConfiguration().getRTFormat().format(msmsScan.getRetentionTime()));
                        }
                    }
                    // add class specific fragments
                    for (int i = 0; i < listOfAnnotatedPositiveFragments.size(); i++) {
                        if (listOfAnnotatedPositiveFragments.get(i).contains("C")) {
                            // Add fragment to comment
                            if (row.getComment().equals(null)) {
                                row.setComment(" " + listOfAnnotatedPositiveFragments.get(i) + " MS/MS scan " + msmsScan.getScanNumber() + ", RT " + MZmineCore.getConfiguration().getRTFormat().format(msmsScan.getRetentionTime()));
                            } else {
                                row.setComment(row.getComment() + ";" + " " + listOfAnnotatedPositiveFragments.get(i) + " MS/MS scan " + msmsScan.getScanNumber() + ", RT " + MZmineCore.getConfiguration().getRTFormat().format(msmsScan.getRetentionTime()));
                            }
                        }
                    }
                }
            }
        }
    }
}
Also used : CentroidMassDetectorParameters(net.sf.mzmine.modules.rawdatamethods.peakpicking.massdetection.centroid.CentroidMassDetectorParameters) ArrayList(java.util.ArrayList) ExactMassDetector(net.sf.mzmine.modules.rawdatamethods.peakpicking.massdetection.exactmass.ExactMassDetector) DataPoint(net.sf.mzmine.datamodel.DataPoint) DataPoint(net.sf.mzmine.datamodel.DataPoint) MSMSLipidTools(net.sf.mzmine.modules.peaklistmethods.identification.lipididentification.lipididentificationtools.MSMSLipidTools) Scan(net.sf.mzmine.datamodel.Scan) CentroidMassDetector(net.sf.mzmine.modules.rawdatamethods.peakpicking.massdetection.centroid.CentroidMassDetector) CentroidMassDetector(net.sf.mzmine.modules.rawdatamethods.peakpicking.massdetection.centroid.CentroidMassDetector) ExactMassDetector(net.sf.mzmine.modules.rawdatamethods.peakpicking.massdetection.exactmass.ExactMassDetector) MassDetector(net.sf.mzmine.modules.rawdatamethods.peakpicking.massdetection.MassDetector) ExactMassDetectorParameters(net.sf.mzmine.modules.rawdatamethods.peakpicking.massdetection.exactmass.ExactMassDetectorParameters)

Aggregations

ArrayList (java.util.ArrayList)5 DataPoint (net.sf.mzmine.datamodel.DataPoint)5 MassDetector (net.sf.mzmine.modules.rawdatamethods.peakpicking.massdetection.MassDetector)5 CentroidMassDetector (net.sf.mzmine.modules.rawdatamethods.peakpicking.massdetection.centroid.CentroidMassDetector)5 CentroidMassDetectorParameters (net.sf.mzmine.modules.rawdatamethods.peakpicking.massdetection.centroid.CentroidMassDetectorParameters)5 ExactMassDetector (net.sf.mzmine.modules.rawdatamethods.peakpicking.massdetection.exactmass.ExactMassDetector)5 ExactMassDetectorParameters (net.sf.mzmine.modules.rawdatamethods.peakpicking.massdetection.exactmass.ExactMassDetectorParameters)5 DataPointsDataSet (net.sf.mzmine.modules.visualization.spectra.simplespectra.datasets.DataPointsDataSet)4 SpectraDatabaseSearchLabelGenerator (net.sf.mzmine.modules.visualization.spectra.simplespectra.spectraidentification.SpectraDatabaseSearchLabelGenerator)4 ItemLabelPosition (org.jfree.chart.labels.ItemLabelPosition)4 Scan (net.sf.mzmine.datamodel.Scan)2 Range (com.google.common.collect.Range)1 Color (java.awt.Color)1 FileReader (java.io.FileReader)1 NumberFormat (java.text.NumberFormat)1 Comparator (java.util.Comparator)1 Map (java.util.Map)1 TreeMap (java.util.TreeMap)1 Logger (java.util.logging.Logger)1 IonizationType (net.sf.mzmine.datamodel.IonizationType)1