Search in sources :

Example 6 with DBCompound

use of net.sf.mzmine.modules.peaklistmethods.identification.onlinedbsearch.DBCompound in project mzmine2 by mzmine.

the class PubChemGateway method getCompound.

/**
 * This method retrieves the details about a PubChem compound
 */
public DBCompound getCompound(String CID, ParameterSet parameters) throws IOException {
    try {
        Element docSumElement = compoundSummaryElements.get(CID);
        if (docSumElement == null)
            throw new IOException("Missing data of compound CID " + CID);
        XPathFactory factory = XPathFactory.newInstance();
        XPath xpath = factory.newXPath();
        /*
       * XPathExpression expr = xpath.compile("Item[@Name='MeSHHeadingList']/Item"); NodeList
       * nameElementNL = (NodeList) expr.evaluate(docSumElement, XPathConstants.NODESET); Element
       * nameElement = (Element) nameElementNL.item(0);
       */
        XPathExpression expr = xpath.compile("Item[@Name='SynonymList']/Item");
        NodeList nameElementNL = (NodeList) expr.evaluate(docSumElement, XPathConstants.NODESET);
        Element nameElement = (Element) nameElementNL.item(0);
        if (nameElement == null) {
            expr = xpath.compile("Item[@Name='IUPACName']");
            nameElementNL = (NodeList) expr.evaluate(docSumElement, XPathConstants.NODESET);
            nameElement = (Element) nameElementNL.item(0);
        }
        if (nameElement == null)
            throw new IOException("Could not parse compound name");
        expr = xpath.compile("Item[@Name='MolecularFormula']");
        NodeList formulaElementNL = (NodeList) expr.evaluate(docSumElement, XPathConstants.NODESET);
        Element formulaElement = (Element) formulaElementNL.item(0);
        String compoundName = nameElement.getTextContent();
        String compoundFormula = formulaElement.getTextContent();
        URL entryURL = new URL(pubchemEntryAddress + CID);
        URL structure2DURL = new URL(pubchem2DStructureAddress + CID);
        URL structure3DURL = new URL(pubchem3DStructureAddress + CID);
        DBCompound newCompound = new DBCompound(OnlineDatabases.PubChem, CID, compoundName, compoundFormula, entryURL, structure2DURL, structure3DURL);
        return newCompound;
    } catch (Exception e) {
        e.printStackTrace();
        throw new IOException(e);
    }
}
Also used : XPath(javax.xml.xpath.XPath) XPathExpression(javax.xml.xpath.XPathExpression) XPathFactory(javax.xml.xpath.XPathFactory) Element(org.w3c.dom.Element) NodeList(org.w3c.dom.NodeList) IOException(java.io.IOException) URL(java.net.URL) DBCompound(net.sf.mzmine.modules.peaklistmethods.identification.onlinedbsearch.DBCompound) IOException(java.io.IOException)

Example 7 with DBCompound

use of net.sf.mzmine.modules.peaklistmethods.identification.onlinedbsearch.DBCompound in project mzmine2 by mzmine.

the class HMDBGateway method getCompound.

/**
 * This method retrieves the details about HMDB compound
 */
public DBCompound getCompound(String ID, ParameterSet parameters) throws IOException {
    logger.finest("Obtaining information about HMDB compound id " + ID);
    Element nameElement, formulaElement;
    try {
        final String url = hmdbEntryAddress + ID + ".xml";
        logger.finest("Loading URL " + url);
        DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance();
        DocumentBuilder builder = dbf.newDocumentBuilder();
        Document parsedResult = builder.parse(url);
        XPathFactory factory = XPathFactory.newInstance();
        XPath xpath = factory.newXPath();
        XPathExpression expr = xpath.compile("//metabolite/name");
        NodeList nameElementNL = (NodeList) expr.evaluate(parsedResult, XPathConstants.NODESET);
        nameElement = (Element) nameElementNL.item(0);
        if (nameElement == null)
            throw new IOException("Could not parse compound name");
        expr = xpath.compile("//metabolite/chemical_formula");
        NodeList formulaElementNL = (NodeList) expr.evaluate(parsedResult, XPathConstants.NODESET);
        formulaElement = (Element) formulaElementNL.item(0);
        if (formulaElement == null)
            throw new IOException("Could not parse compound formula");
    } catch (Exception e) {
        throw new IOException(e);
    }
    final String compoundName = nameElement.getTextContent();
    final String compoundFormula = formulaElement.getTextContent();
    final URL structure2DURL = new URL(hmdbStructureAddress + ID + ".sdf");
    final URL structure3DURL = new URL(hmdbStructureAddress + ID + ".pdb");
    final URL entryURL = new URL(hmdbEntryAddress + ID);
    DBCompound newCompound = new DBCompound(OnlineDatabases.HMDB, ID, compoundName, compoundFormula, entryURL, structure2DURL, structure3DURL);
    return newCompound;
}
Also used : XPath(javax.xml.xpath.XPath) XPathExpression(javax.xml.xpath.XPathExpression) DocumentBuilderFactory(javax.xml.parsers.DocumentBuilderFactory) Element(org.w3c.dom.Element) NodeList(org.w3c.dom.NodeList) IOException(java.io.IOException) Document(org.w3c.dom.Document) IOException(java.io.IOException) URL(java.net.URL) DBCompound(net.sf.mzmine.modules.peaklistmethods.identification.onlinedbsearch.DBCompound) XPathFactory(javax.xml.xpath.XPathFactory) DocumentBuilder(javax.xml.parsers.DocumentBuilder)

Example 8 with DBCompound

use of net.sf.mzmine.modules.peaklistmethods.identification.onlinedbsearch.DBCompound in project mzmine2 by mzmine.

the class LipidMapsGateway method getCompound.

/**
 * This method retrieves the details about the compound
 */
public DBCompound getCompound(String ID, ParameterSet parameters) throws IOException {
    final URL entryURL = new URL(lipidMapsEntryAddress + ID);
    logger.finest("Loading data from LipidMaps via URL " + entryURL.toString());
    String lipidMapsEntry = InetUtils.retrieveData(entryURL);
    String[] fields = lipidMapsEntry.split("\t");
    if (fields.length < 4) {
        throw (new IOException("Could not parse compound " + ID));
    }
    // The columns are ID, common name, systematic name, formula, mass, etc.
    // Use common name by default for compoundName
    String compoundName = fields[1];
    // in that case we use the systematic name
    if (compoundName.equals("-"))
        compoundName = fields[2];
    String compoundFormula = fields[3];
    URL structure2DURL = new URL(lipidMapsStructureAddress + ID);
    URL structure3DURL = null;
    URL databaseURL = new URL(lipidMapsDetailsAddress + ID);
    DBCompound newCompound = new DBCompound(OnlineDatabases.LIPIDMAPS, ID, compoundName, compoundFormula, databaseURL, structure2DURL, structure3DURL);
    return newCompound;
}
Also used : IOException(java.io.IOException) URL(java.net.URL) DBCompound(net.sf.mzmine.modules.peaklistmethods.identification.onlinedbsearch.DBCompound)

Example 9 with DBCompound

use of net.sf.mzmine.modules.peaklistmethods.identification.onlinedbsearch.DBCompound in project mzmine2 by mzmine.

the class MetaCycGateway method getCompound.

/**
 * This method retrieves the details about PlantCyc compound
 */
public DBCompound getCompound(String ID, ParameterSet parameters) throws IOException {
    final String dataURL = metaCycObjectAddress + ID;
    try {
        DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance();
        DocumentBuilder builder = dbf.newDocumentBuilder();
        Document parsedResult = builder.parse(dataURL);
        XPathFactory factory = XPathFactory.newInstance();
        XPath xpath = factory.newXPath();
        XPathExpression expr = xpath.compile("//ptools-xml/Compound/common-name");
        NodeList nameElementNL = (NodeList) expr.evaluate(parsedResult, XPathConstants.NODESET);
        Element nameElement = (Element) nameElementNL.item(0);
        if (nameElement == null)
            throw new IOException("Could not parse compound name");
        String compoundName = nameElement.getTextContent();
        expr = xpath.compile("//ptools-xml/Compound/cml/molecule/formula");
        NodeList formulaElementNL = (NodeList) expr.evaluate(parsedResult, XPathConstants.NODESET);
        Element formulaElement = (Element) formulaElementNL.item(0);
        String compoundFormula = formulaElement.getAttribute("concise");
        compoundFormula = compoundFormula.replaceAll(" ", "");
        final URL entryURL = new URL(metaCycEntryAddress + ID);
        // Unfortunately MetaCyc does not contain structures in MOL format
        URL structure2DURL = null;
        URL structure3DURL = null;
        if (compoundName == null) {
            throw (new IOException("Invalid compound ID " + ID));
        }
        DBCompound newCompound = new DBCompound(OnlineDatabases.METACYC, ID, compoundName, compoundFormula, entryURL, structure2DURL, structure3DURL);
        return newCompound;
    } catch (Exception e) {
        e.printStackTrace();
        throw new IOException(e);
    }
}
Also used : XPath(javax.xml.xpath.XPath) XPathExpression(javax.xml.xpath.XPathExpression) DocumentBuilderFactory(javax.xml.parsers.DocumentBuilderFactory) NodeList(org.w3c.dom.NodeList) Element(org.w3c.dom.Element) IOException(java.io.IOException) Document(org.w3c.dom.Document) URL(java.net.URL) DBCompound(net.sf.mzmine.modules.peaklistmethods.identification.onlinedbsearch.DBCompound) IOException(java.io.IOException) XPathFactory(javax.xml.xpath.XPathFactory) DocumentBuilder(javax.xml.parsers.DocumentBuilder)

Example 10 with DBCompound

use of net.sf.mzmine.modules.peaklistmethods.identification.onlinedbsearch.DBCompound 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)

Aggregations

DBCompound (net.sf.mzmine.modules.peaklistmethods.identification.onlinedbsearch.DBCompound)10 URL (java.net.URL)9 IOException (java.io.IOException)7 XPath (javax.xml.xpath.XPath)3 XPathExpression (javax.xml.xpath.XPathExpression)3 XPathFactory (javax.xml.xpath.XPathFactory)3 Element (org.w3c.dom.Element)3 NodeList (org.w3c.dom.NodeList)3 Matcher (java.util.regex.Matcher)2 Pattern (java.util.regex.Pattern)2 DocumentBuilder (javax.xml.parsers.DocumentBuilder)2 DocumentBuilderFactory (javax.xml.parsers.DocumentBuilderFactory)2 Document (org.w3c.dom.Document)2 ArrayList (java.util.ArrayList)1 DataPoint (net.sf.mzmine.datamodel.DataPoint)1 MassDetector (net.sf.mzmine.modules.rawdatamethods.peakpicking.massdetection.MassDetector)1 CentroidMassDetector (net.sf.mzmine.modules.rawdatamethods.peakpicking.massdetection.centroid.CentroidMassDetector)1 CentroidMassDetectorParameters (net.sf.mzmine.modules.rawdatamethods.peakpicking.massdetection.centroid.CentroidMassDetectorParameters)1 ExactMassDetector (net.sf.mzmine.modules.rawdatamethods.peakpicking.massdetection.exactmass.ExactMassDetector)1 ExactMassDetectorParameters (net.sf.mzmine.modules.rawdatamethods.peakpicking.massdetection.exactmass.ExactMassDetectorParameters)1