Code to get NeuroLex id from DICOM id

9 views
Skip to first unread message

Stephen Larson

unread,
Sep 14, 2012, 8:55:10 AM9/14/12
to Satrajit Ghosh, Nolan Nichols, neur...@googlegroups.com
Hi Satra,

  You asked for a way to get a NeuroLex ID back from a DICOM ID.  Check out the following Python code:

from SPARQLWrapper import SPARQLWrapper, JSON 
dicomGroup = '0040'
dicomId = '8302'
sparql = SPARQLWrapper("http://rdf-stage.neuinfo.org/ds/query")
sparql.setQuery("""
prefix property: <http://neurolex.org/wiki/Special:URIResolver/Property-3A>
prefix xsd: <http://www.w3.org/2001/XMLSchema#>
select ?name ?id where { """ + 
'?s property:DICOMID "DICOM:' + dicomGroup + '"^^xsd:string .' + 
'?s property:DICOMID "' + dicomId + '"^^xsd:string . ' + 
"""
?s property:Label ?name .
?s property:Id ?id
} LIMIT 100
""")
sparql.setReturnFormat(JSON)
results = sparql.query().convert()
for result in results["results"]["bindings"]:
    print result["name"]['value']
    print result["id"]['value']

 Does this do what you were looking for?

Thanks,
  Stephen
Reply all
Reply to author
Forward
0 new messages