Mercurial > repos > fabad > sparql_uniprot
comparison sparql_uniprot.py @ 23:478f5587f12a draft default tip
Uploaded
| author | fabad |
|---|---|
| date | Sun, 22 Oct 2017 15:57:18 -0400 |
| parents | 9bb153d42a1c |
| children |
comparison
equal
deleted
inserted
replaced
| 22:84c9f65ed7c6 | 23:478f5587f12a |
|---|---|
| 172 fileRes.close() | 172 fileRes.close() |
| 173 | 173 |
| 174 def sparqlwrap(proteinId, proteinName, geneName, organismName, diseaseAnnotation, domainName, similarityAnnotation, locationAnnotation, functionAnnotation, pharmaceuticalAnnotation, output): | 174 def sparqlwrap(proteinId, proteinName, geneName, organismName, diseaseAnnotation, domainName, similarityAnnotation, locationAnnotation, functionAnnotation, pharmaceuticalAnnotation, output): |
| 175 | 175 |
| 176 query = buildQuery(proteinId, proteinName, geneName, organismName, diseaseAnnotation, domainName, similarityAnnotation, locationAnnotation, functionAnnotation, pharmaceuticalAnnotation) | 176 query = buildQuery(proteinId, proteinName, geneName, organismName, diseaseAnnotation, domainName, similarityAnnotation, locationAnnotation, functionAnnotation, pharmaceuticalAnnotation) |
| 177 print query | 177 print (query) |
| 178 | 178 |
| 179 # Creamos un objeto del tipo SPARQLWrapper indicando en que | 179 # Creamos un objeto del tipo SPARQLWrapper indicando en que |
| 180 # direccion esta el servicio que recibe consultas en sparql | 180 # direccion esta el servicio que recibe consultas en sparql |
| 181 # y responde a estas. | 181 # y responde a estas. |
| 182 sparql = SPARQLWrapper('http://sparql.uniprot.org/sparql') | 182 sparql = SPARQLWrapper('http://sparql.uniprot.org/sparql') |
| 191 sparql.setReturnFormat(JSON) | 191 sparql.setReturnFormat(JSON) |
| 192 | 192 |
| 193 # Esta es la instruccion que realiza la consulta a | 193 # Esta es la instruccion que realiza la consulta a |
| 194 # uniprot. Devuelve un objeto de python que hay que | 194 # uniprot. Devuelve un objeto de python que hay que |
| 195 # tratar. | 195 # tratar. |
| 196 print "Ejecutando query" | 196 print ("Ejecutando query") |
| 197 results = sparql.query() | 197 results = sparql.query() |
| 198 | 198 |
| 199 # Con esto, convertimos el objeto devuelto por | 199 # Con esto, convertimos el objeto devuelto por |
| 200 # el servicio al formato que especificamos antes. | 200 # el servicio al formato que especificamos antes. |
| 201 # En este caso, json. | 201 # En este caso, json. |
| 202 print "Conviertiendo a json" | 202 print ("Conviertiendo a json") |
| 203 json = results.convert() | 203 json = results.convert() |
| 204 print "Fin conversion a json" | 204 print ("Fin conversion a json") |
| 205 | 205 |
| 206 # Dentro de la variable results tenemos informacion | 206 # Dentro de la variable results tenemos informacion |
| 207 # (metadatos) de lo que ha devuelto el servidor de | 207 # (metadatos) de lo que ha devuelto el servidor de |
| 208 # uniprot. | 208 # uniprot. |
| 209 print results.info() | 209 print (results.info()) |
| 210 | 210 |
| 211 # Imprimir resultados | 211 # Imprimir resultados |
| 212 printResults(json, output) | 212 printResults(json, output) |
| 213 | 213 |
| 214 | 214 |
