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;
}
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;
}
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);
}
}
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;
}
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;
}
Aggregations