Search in sources :

Example 1 with DBCompound

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

the class MassBankJapanGateway method getCompound.

/**
 * This method retrieves the details about the compound
 */
public DBCompound getCompound(String ID, ParameterSet parameters) throws IOException {
    URL entryURL = new URL(massBankEntryAddress + ID);
    // Retrieve data
    logger.finest("Querying URL " + entryURL);
    String massBankEntry = InetUtils.retrieveData(entryURL);
    String compoundName = null;
    String compoundFormula = null;
    URL structure2DURL = null;
    URL structure3DURL = null;
    URL databaseURL = entryURL;
    // Find compound name
    Pattern patName = Pattern.compile("RECORD_TITLE: (.*)");
    Matcher matcherName = patName.matcher(massBankEntry);
    if (matcherName.find()) {
        compoundName = matcherName.group(1);
    }
    // Find compound formula
    Pattern patFormula = Pattern.compile("CH\\$FORMULA: .*>(.+)</a>");
    Matcher matcherFormula = patFormula.matcher(massBankEntry);
    if (matcherFormula.find()) {
        compoundFormula = matcherFormula.group(1);
    }
    if (compoundName == null) {
        logger.warning("Could not parse compound name for compound " + ID + ", ignoring this compound");
        return null;
    }
    // new DBCompound(OnlineDatabases.MASSBANKJapan, ID, compoundName, compoundFormula, databaseURL, structure2DURL, structure3DURL);
    DBCompound newCompound = null;
    return newCompound;
}
Also used : Pattern(java.util.regex.Pattern) Matcher(java.util.regex.Matcher) URL(java.net.URL) DBCompound(net.sf.mzmine.modules.peaklistmethods.identification.onlinedbsearch.DBCompound)

Example 2 with DBCompound

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

the class YMDBGateway method getCompound.

/**
 * This method retrieves the details about YMDB compound
 */
public DBCompound getCompound(String ID, ParameterSet parameters) throws IOException {
    // We will parse the name and formula from the SDF file, it seems like
    // the easiest way
    URL sdfURL = new URL(ymdbSDFAddress + ID + ".sdf");
    logger.finest("Querying YMDB URL " + sdfURL);
    String sdfRecord = InetUtils.retrieveData(sdfURL);
    String[] lines = sdfRecord.split("\n");
    String compoundName = null;
    String compoundFormula = null;
    URL entryURL = new URL(ymdbEntryAddress + ID);
    URL structure2DURL = sdfURL;
    URL structure3DURL = new URL(ymdbSDFAddress + ID + ".sdf?dim=3d");
    for (int i = 0; i < lines.length - 1; i++) {
        if (lines[i].contains("> <GENERIC_NAME>")) {
            compoundName = lines[i + 1];
        }
        if (lines[i].contains("> <FORMULA>")) {
            compoundFormula = lines[i + 1];
        }
    }
    if (compoundName == null) {
        throw (new IOException("Could not parse compound name"));
    }
    DBCompound newCompound = new DBCompound(OnlineDatabases.YMDB, ID, compoundName, compoundFormula, entryURL, structure2DURL, structure3DURL);
    return newCompound;
}
Also used : IOException(java.io.IOException) URL(java.net.URL) DBCompound(net.sf.mzmine.modules.peaklistmethods.identification.onlinedbsearch.DBCompound)

Example 3 with DBCompound

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

the class ChemSpiderGateway method getCompound.

@Override
public DBCompound getCompound(final String ID, ParameterSet parameters) throws IOException {
    logger.finest("Fetching compound info for CSID #" + ID);
    // Get security token.
    final String apiKey = parameters.getParameter(ChemSpiderParameters.SECURITY_TOKEN).getValue();
    final List<String> fields = Arrays.asList("Formula", "CommonName", "MonoisotopicMass");
    try {
        RecordsApi apiInstance = new RecordsApi();
        apiInstance.getApiClient().setUserAgent("MZmine " + MZmineCore.getMZmineVersion());
        Integer recordId = Integer.valueOf(ID);
        RecordResponse response = apiInstance.recordsRecordIdDetailsGet(recordId, fields, apiKey);
        String name = response.getCommonName();
        if (Strings.isNullOrEmpty(name))
            name = UNKNOWN_NAME;
        String formula = response.getFormula();
        // Fix formula formatting
        if (!Strings.isNullOrEmpty(formula))
            formula = FORMULA_PATTERN.matcher(formula).replaceAll("");
        // Create and return the compound record.
        return new DBCompound(OnlineDatabases.CHEMSPIDER, ID, name, formula, new URL(STRUCTURE_URL_PATTERN.replaceFirst("CSID", ID)), new URL(STRUCTURE2D_URL_PATTERN.replaceFirst("CSID", ID)), new URL(STRUCTURE3D_URL_PATTERN.replaceFirst("CSID", ID)));
    } catch (ApiException e) {
        logger.log(Level.WARNING, "Failed to fetch compound info for CSID #" + ID, e);
        throw new IOException(e);
    }
}
Also used : RecordsApi(org.rsc.chemspider.api.RecordsApi) RecordResponse(org.rsc.chemspider.api.RecordResponse) IOException(java.io.IOException) DBCompound(net.sf.mzmine.modules.peaklistmethods.identification.onlinedbsearch.DBCompound) URL(java.net.URL) ApiException(org.rsc.chemspider.ApiException)

Example 4 with DBCompound

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

the class KEGGGateway method getCompound.

/**
 * This method retrieves the details about a KEGG compound
 */
public DBCompound getCompound(String ID, ParameterSet parameters) throws IOException {
    String queryAddress = keggGetAddress + ID;
    URL queryURL = new URL(queryAddress);
    String compoundData = InetUtils.retrieveData(queryURL);
    String[] dataLines = compoundData.split("\n");
    String compoundName = null, compoundFormula = null, ID3DMet = null;
    for (String line : dataLines) {
        if (line.startsWith("NAME")) {
            compoundName = line.substring(12);
            if (compoundName.endsWith(";")) {
                compoundName = compoundName.substring(0, compoundName.length() - 1);
            }
        }
        if (line.startsWith("FORMULA")) {
            compoundFormula = line.substring(12);
        }
        // 3DMET id is last 6 characters on the line
        if (line.contains("3DMET")) {
            ID3DMet = line.substring(line.length() - 6);
        }
    }
    if ((compoundName == null) || (compoundFormula == null)) {
        throw (new IOException("Could not obtain compound name and formula"));
    }
    URL entryURL = new URL(keggEntryAddress + ID);
    URL structure2DURL = new URL(kegg2DStructureAddress + ID);
    URL structure3DURL = null;
    if (ID3DMet != null) {
        structure3DURL = new URL(met3DStructureAddress1 + ID3DMet + met3DStructureAddress2);
    }
    DBCompound newCompound = new DBCompound(OnlineDatabases.KEGG, ID, compoundName, compoundFormula, entryURL, structure2DURL, structure3DURL);
    return newCompound;
}
Also used : IOException(java.io.IOException) URL(java.net.URL) DBCompound(net.sf.mzmine.modules.peaklistmethods.identification.onlinedbsearch.DBCompound)

Example 5 with DBCompound

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

the class MassBankEuropeGateway method getCompound.

/**
 * This method retrieves the details about the compound
 */
public DBCompound getCompound(String ID, ParameterSet parameters) throws IOException {
    URL entryURL = new URL(massBankEntryAddress + ID);
    // Retrieve data
    logger.finest("Querying MassBank.eu URL " + entryURL);
    String massBankEntry = InetUtils.retrieveData(entryURL);
    String compoundName = null;
    String compoundFormula = null;
    URL structure2DURL = null;
    URL structure3DURL = null;
    URL databaseURL = entryURL;
    // Find compound name
    Pattern patName = Pattern.compile("RECORD_TITLE: (.*)");
    Matcher matcherName = patName.matcher(massBankEntry);
    if (matcherName.find()) {
        compoundName = matcherName.group(1).replaceAll("\\<[^>]*>", "");
    }
    // Find compound formula
    Pattern patFormula = Pattern.compile("CH\\$FORMULA: .*>(.*)</a>");
    Matcher matcherFormula = patFormula.matcher(massBankEntry);
    if (matcherFormula.find()) {
        compoundFormula = matcherFormula.group(1).replaceAll("\\<[^>]*>", "");
    }
    if (compoundName == null) {
        logger.warning("Could not parse compound name for compound " + ID);
        return null;
    }
    DBCompound newCompound = new DBCompound(OnlineDatabases.MASSBANKEurope, ID, compoundName, compoundFormula, databaseURL, structure2DURL, structure3DURL);
    return newCompound;
}
Also used : Pattern(java.util.regex.Pattern) Matcher(java.util.regex.Matcher) URL(java.net.URL) DBCompound(net.sf.mzmine.modules.peaklistmethods.identification.onlinedbsearch.DBCompound)

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