Created
September 27, 2017 13:33
-
-
Save egonw/7178ae1d66673ab6dea5080a4743c0dd to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
bioclipse.requireVersion("2.7.0") | |
// download all GPML files for a species, and save those in /WikiPathways/data/ | |
// first, calculate m/z values for everything in Wikidata | |
referenceFile = "/WikiPathways/mz_smiles.tsv" | |
mzData = new java.util.HashMap() | |
new File(bioclipse.fullPath(referenceFile)).eachLine { line -> | |
tokens = line.tokenize( '\t' ) | |
if (tokens[0] != "compound") { | |
wkid = tokens[0].substring(31) | |
smiles = tokens[2].trim() | |
try { | |
mol = cdk.fromSMILES(smiles) | |
mzData.put(wkid, cdk.calculateMajorIsotopeMass(mol)) | |
} catch (Exception exception) { | |
println "Error while calculating mass for ${wkid}: " + exception.message | |
} | |
} | |
} | |
mapper = bridgedb.loadRelationalDatabase(bioclipse.fullPath("/WikiPathways/metabolites_20170826.bridge")) | |
dataMap = bioclipse.fullPath("/WikiPathways/data/human/") | |
gpmlFiles = new File(dataMap).listFiles() | |
outputFile = "/WikiPathways/mz_data.tsv" | |
renewFile(outputFile) | |
gpmlFiles.each { file -> | |
// println "File: " + file.name | |
def data = new XmlParser().parse(file) | |
def metabolites = data.DataNode.findAll{ | |
it.'@Type' | |
} | |
metabolites.each() { node -> | |
if (node.'@Type'.contains("Metabolite")) { | |
sourceFull = "" + (node.Xref.'@Database'.get(0)) | |
id = "" + (node.Xref.'@ID'.get(0)) | |
// println "$sourceFull .. $id" | |
if (sourceFull != null && sourceFull != "" && | |
id != null && id != "") { | |
source = bridgedb.getSourceFromName(sourceFull) | |
syscode = source.systemCode | |
xref = bridgedb.xref(id, syscode) | |
wkids = bridgedb.map(mapper, xref, "Wd") | |
if (wkids.size() > 0) { | |
// println "Wd items: " + wkids.size() | |
wkid = wkids.iterator().next().id | |
if (mzData.containsKey(wkid)) { | |
// println "Hit for $wkid" | |
// println " Value: " + mzData[wkid] | |
ui.append(outputFile, "" + wkid + "\t" + mzData[wkid] + "\n") | |
} else { | |
println "Got a Wikidata, but no m/z for " + xref | |
} | |
} else { | |
// println "No Wikidata item for " + xref | |
} | |
} | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment