I'm currently using R to analyze some metabolomics data, and I'm using the hmdbQuery package to download HMDB entries for each metabolite in my dataset. I'm having some trouble working with the ontology data, though. For example, I would like to ask, "what are all the metabolites (which are in my dataset) which have the Lipid Transport annotation?" This is relatively straightforward with the Gene Ontology database, but with HMDB, I'm not sure how best to deal with the tree structure of the ontology data. Right now, I'm working on writing some elaborate code to dig into each branch of the tree, for each metabolite, and extract and store this information it in a table, but it doesn't seem very elegant. Have any of you dealt with this before?