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