Hi Marc,

Attached is a script that will get all DDIs from NDF-RT using a query to the Bioportal SPARQL endpoint. The data is output to as a dictionary to a Python pickle. wrt mapping, one thing I know about NDF-RT is it uses salt forms as the primary label for many of its drugs so mapping requires a bit of careful thought. If DPD is mapped to FDA UNII or RxNORM (active ingredients) than I would see if I can use queries to RxNorm (SQL) to complete the mapping because it appears to be complete as evidenced by RxNav.

kind regards,
-Rich

On 09/20/2013 10:11 AM, Marc Dumontier wrote:
Hi


Is anyone aware of any open work done on querying data out of NDF-RT, or some informative literature on anyone mapping Canadian drugs to it?

I've been asked to match as many Canadian drugs from the Health Canada Drug Product Database (DPD) to equivalent formulations in the NDF-RT

Once I have those mappings, I will need to query for the drug interactions within, and probably expose some of the other linkages, but the initial goal is is get the drug interactions.

I've loaded the OWL release in Apache Jena with no problem, and started writing some very basic SPARQL queries. I will need help stepping them up :)

Thanks
--
Marc Dumontier
519-584-5601
http://oscardevel.com/wordpress/
http://www.oscarmcmaster.org



--
Richard D Boyce, PhD
Assistant Professor of Biomedical Informatics
Faculty, Geriatric Pharmaceutical Outcomes and Gero-Informatics Research and 
Training Program
University of Pittsburgh
rd...@pitt.edu
Office: 412-648-9219
Twitter: @bhaapgh

## query-NDFRT-DDIs.py
## Simple Python script to query "http://sparql.bioontology.org/sparql/ for NDFRT DDIs"
## No extra libraries required.

# Authors: Richard D Boyce, Michel Dumontier
#
# July 2012
# 

## This library is free software; you can redistribute it and/or
## modify it under the terms of the GNU Library General Public
## License as published by the Free Software Foundation; either
## version 2 of the License, or (at your option) any later version.

## This library is distributed in the hope that it will be useful,
## but WITHOUT ANY WARRANTY; without even the implied warranty of
## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
## Library General Public License for more details.

## You should have received a copy of the GNU Library General Public
## License along with this library; if not, write to the
## Free Software Foundation, Inc., 59 Temple Place - Suite 330,
## Boston, MA 02111-1307, USA.

import json
import urllib2
import urllib
import traceback
import sys 
import pickle


def getPDDIDict():
    return {"source":"NDF-RT",
            "uri":None,
            "objectUri":None,
            "precipUri":None,
            "label":None,
            "severity":None
            }


def query(q,apikey,epr,f='application/json'):
    """Function that uses urllib/urllib2 to issue a SPARQL query.
       By default it requests json as data format for the SPARQL resultset"""

    try:
        params = {'query': q, 'apikey': apikey}
        params = urllib.urlencode(params)
        opener = urllib2.build_opener(urllib2.HTTPHandler)
        request = urllib2.Request(epr+'?'+params)
        request.add_header('Accept', f)
        request.get_method = lambda: 'GET'
        url = opener.open(request)
        return url.read()
    except Exception, e:
        traceback.print_exc(file=sys.stdout)
        raise e

if __name__ == "__main__":

    pddiDictL = []
    sparql_service = "http://sparql.bioontology.org/sparql/";

    #To get your API key register at http://bioportal.bioontology.org/accounts/new
    api_key = "74028721-e60e-4ece-989b-1d2c17d14e9c"

    query_string = """ 
PREFIX owl: <http://www.w3.org/2002/07/owl#>
PREFIX xsd: <http://www.w3.org/2001/XMLSchema#>
PREFIX rdfs:<http://www.w3.org/2000/01/rdf-schema#>
PREFIX skos:<http://www.w3.org/2004/02/skos/core#>
PREFIX ndfrt:<http://purl.bioontology.org/ontology/NDFRT/>
SELECT DISTINCT ?s ?label ?severity ?targetDrug
FROM <http://bioportal.bioontology.org/ontologies/NDFRT>
WHERE {
  ?s ndfrt:NDFRT_KIND ?o;
  skos:prefLabel ?label;
  ndfrt:SEVERITY ?severity. FILTER (regex(str(?o), "interaction", "i"))
  ?s ndfrt:has_participant ?targetDrug.
  ?s ndfrt:STATUS "Active"^^xsd:string.
}     
"""
    print "query_string: %s" % query_string
    json_string = query(query_string, api_key, sparql_service)
    resultset=json.loads(json_string)

    if len(resultset["results"]["bindings"]) == 0:
        print "INFO: No results"
    else:
        #print json.dumps(resultset,indent=1)
        cache = [None, None]
        for i in range(0, len(resultset["results"]["bindings"])):
            uri = resultset["results"]["bindings"][i]["s"]["value"]
            if uri == cache[0]:
                newPDDI = getPDDIDict()
                newPDDI["source"] = sparql_service
                newPDDI["uri"] = uri
                newPDDI["precipUri"] = cache[1]
                newPDDI["objectUri"] = resultset["results"]["bindings"][i]["targetDrug"]["value"]
                newPDDI["label"] = resultset["results"]["bindings"][i]["label"]["value"]
                newPDDI["severity"] = resultset["results"]["bindings"][i]["severity"]["value"]

                try:
                    (obj,precip) = newPDDI["label"].split("/")
                except ValueError:
                    print "ERROR: unable to split label into object and precipitant string parts: %s" % newPDDI["label"]
                    continue

                precip = precip.replace(" [VA Drug Interaction]","")
                (newPDDI["object"],newPDDI["precip"]) = (obj,precip)

                pddiDictL.append(newPDDI)
                cache = [None, None]
            else:
                cache[0] = uri
                cache[1] = resultset["results"]["bindings"][i]["targetDrug"]["value"]
                continue

    f = open("ndfrt-ddis.pickle","w")
    pickle.dump(pddiDictL, f)
    f.close()
        

Reply via email to