Next changeset 1:c76273c080a1 (2016-05-02) |
Commit message:
Uploaded |
added:
sparql_uniprot |
b |
diff -r 000000000000 -r 1586018e9661 sparql_uniprot --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/sparql_uniprot Mon May 02 16:43:25 2016 -0400 |
[ |
b'@@ -0,0 +1,296 @@\n+<?xml version="1.0"?>\n+<tool_dependency>\n+ <package name="sparql_uniprot" version="0.1">\n+ <readme>\n+ Install SPARQLWrapper via virtualenv.\n+ </readme>\n+ <install version="1.0">\n+ <actions>\n+ <action type="setup_virtualenv">SPARQLWrapper==1.7.6</action>\n+ </actions>\n+ </install>\n+ </package>\n+</tool_dependency>\n+from SPARQLWrapper import SPARQLWrapper, JSON\n+import sys\n+\n+# Constante con los prefijos comunes a usar en queries\n+COMMON_PREFIXES = """\n+\tPREFIX up:<http://purl.uniprot.org/core/>\n+\tPREFIX keywords:<http://purl.uniprot.org/keywords/>\n+\tPREFIX uniprotkb:<http://purl.uniprot.org/uniprot/>\n+\tPREFIX taxon:<http://purl.uniprot.org/taxonomy/>\n+\tPREFIX ec:<http://purl.uniprot.org/enzyme/>\n+\tPREFIX rdf:<http://www.w3.org/1999/02/22-rdf-syntax-ns#>\n+\tPREFIX rdfs:<http://www.w3.org/2000/01/rdf-schema#>\n+\tPREFIX skos:<http://www.w3.org/2004/02/skos/core#>\n+\tPREFIX owl:<http://www.w3.org/2002/07/owl#>\n+\tPREFIX bibo:<http://purl.org/ontology/bibo/>\n+\tPREFIX dc:<http://purl.org/dc/terms/>\n+\tPREFIX xsd:<http://www.w3.org/2001/XMLSchema#>\n+\tPREFIX faldo:<http://biohackathon.org/resource/faldo#>\n+"""\n+\n+# Lista con los nombres de las variables que obtenemos de la base de datos.\n+paramList = [\'protein\', \'proteinFullName\', \'geneName\', \'organismName\', \'diseaseAnnotationText\', \'domainFullName\', \'similarityAnnotationText\', \'locationAnnotationText\', \'functionAnnotationText\', \'pharmaceuticalAnnotationText\'];\n+\n+def buildQuery(proteinId, proteinName, geneName, organismName, diseaseAnnotation, domainName, similarityAnnotation, locationAnnotation, functionAnnotation, pharmaceuticalAnnotation):\n+\tquery = COMMON_PREFIXES\n+\tquery += "select distinct \\n"\n+\tquery += "\t?protein\\n"\n+\tquery += "\t?proteinFullName\\n"\n+\tquery += "\t?geneName\\n"\n+\tquery += "\t?organismName\\n"\n+\tquery += "\t?diseaseAnnotationText\\n"\n+\tquery += "\t?domainFullName\\n"\n+\tquery += "\t?similarityAnnotationText\\n"\n+\tquery += "\t?locationAnnotationText\\n"\n+\tquery += "\t?functionAnnotationText\\n"\n+\tquery += "\t?pharmaceuticalAnnotationText\\n"\n+\tquery += "where{\\n"\n+\n+\tquery += "\t?protein a up:Protein .\\n"\n+\n+\tif (proteinId != \'\'):\n+\t\tquery += "\tVALUES ?protein {uniprotkb:"+ proteinId + "}\\n"\n+\n+\tquery += "\\n"\n+\n+\tif (proteinName == \'\'):\n+\t\tquery += "\tOPTIONAL {\\n"\n+\tquery += "\t?protein up:recommendedName ?proteinName .\\n"\n+\tquery += "\t?proteinName up:fullName ?proteinFullName . \\n"\n+\tif (proteinName !=\'\'):\n+\t\tquery += "\tfilter( regex(str(?proteinFullName), " + \'"\' + proteinName + \'"\' + ",\\"i\\" )) .\\n"\n+\tif (proteinName == \'\'):\n+\t\tquery += "\t}\\n"\n+\tquery += "\\n"\n+\n+\tif (geneName == \'\'):\n+\t\tquery += "\tOPTIONAL {\\n"\n+\tquery += "\t?protein up:encodedBy ?gene .\\n"\n+\tquery += "\t?gene skos:prefLabel ?geneName .\\n"\n+\tif (geneName != \'\'):\n+\t\tquery += "\tfilter( regex(str(?geneName), " + \'"\' + geneName + \'"\' + ",\\"i\\" )) .\\n"\n+\tif (geneName == \'\'):\n+\t\tquery += "\t}\\n"\n+\n+\tquery += "\\n"\n+\n+\tif (organismName == \'\'):\n+\t\tquery += "\tOPTIONAL {\\n"\n+\tquery += "\t?protein up:organism ?organism .\\n"\n+\tquery += "\t?organism up:scientificName ?organismName .\\n"\n+\tif (organismName != \'\'):\n+\t\tquery += "\tfilter( regex(str(?organismName), " + \'"\' + organismName + \'"\' + ",\\"i\\" )) .\\n"\n+\tif (organismName == \'\'):\n+\t\tquery += "\t}\\n"\n+\n+\tquery += "\\n"\n+\n+\tif (diseaseAnnotation == \'\'):\n+\t\tquery += "\tOPTIONAL {\\n"\n+\tquery += "\t?protein up:annotation ?diseaseAnnotation .\\n"\n+\tquery += "\t?diseaseAnnotation a up:Disease_Annotation .\\n"\n+\tquery += "\t?diseaseAnnotation up:disease ?disease .\\n"\n+\tquery += "\t?disease rdfs:comment ?diseaseAnnotationText\\n"\n+\tif (diseaseAnnotation != \'\'):\n+\t\tquery += "\tfilter( regex(str(?diseaseAnnotationText), " + \'"\' + diseaseAnnotation + \'"\' + ",\\"i\\" )) .\\n"\n+\tif (diseaseAnnotation == \'\'):\n+\t\tquery += "\t}\\n"\n+\n+\tquery += "\\n"\n+\n+\tif (domainName == \'\'):\n+\t\tquery += "\tOPTIONAL {\\n"\n+\tquery += "\t?protein up:domain ?domain .\\n"\n+\tquery += "\t?domain up:recommendedName ?domainName .\\n"\n+\tquery += "\t?'..b'o que recibe consultas en sparql\n+\t# y responde a estas.\n+\tsparql = SPARQLWrapper(\'http://sparql.uniprot.org/sparql\')\n+\n+\t# Especificamos la consulta que queremos hacer en sparql.\n+\tsparql.setQuery(query)\n+\n+\t# Indicamos en que formato queremos que nos devuelva\n+\t# los resultados de la consulta. Puede ser json, xml,\n+\t# rfd, turtle... Simplemente son distintos formatos\n+\t# para representar los datos en ficheros de texto.\n+\tsparql.setReturnFormat(JSON)\n+\n+\t# Esta es la instruccion que realiza la consulta a\n+\t# uniprot. Devuelve un objeto de python que hay que\n+\t# tratar.\n+\tprint "Ejecutando query"\n+\tresults = sparql.query()\n+\n+\t# Con esto, convertimos el objeto devuelto por\n+\t# el servicio al formato que especificamos antes.\n+\t# En este caso, json.\n+\tprint "Conviertiendo a json"\n+\tjson = results.convert()\n+\tprint "Fin conversion a json"\n+\n+\t# Dentro de la variable results tenemos informacion\n+\t# (metadatos) de lo que ha devuelto el servidor de\n+\t# uniprot.\n+\tprint results.info()\n+\n+\t# Imprimir resultados\n+\tprintResults(json, output)\n+\n+\n+# Obtener parametros de la linea de comandos.\n+proteinId = sys.argv[1]\n+proteinName = sys.argv[2]\n+geneName = sys.argv[3]\n+organismName = sys.argv[4]\n+diseaseAnnotation = sys.argv[5]\n+domainName =sys.argv[6]\n+similarityAnnotation = sys.argv[7]\n+locationAnnotation = sys.argv[8]\n+functionAnnotation = sys.argv[9]\n+pharmaceuticalAnnotation = sys.argv[10]\n+output = sys.argv[11]\n+\n+# Llamada a la funcion que realiza la consulta.\n+sparqlwrap(proteinId, proteinName, geneName, organismName, diseaseAnnotation, domainName, similarityAnnotation, locationAnnotation, functionAnnotation, pharmaceuticalAnnotation, output)\n+\n+<tool id="sparql_uniprot" name="Uniprot Sparql" version="0.1.0">\n+ <description>Perform a search into uniprot database using its sparql interface.</description>\n+ <command interpreter="python">sparql_uniprot.py "${protein}" "${proteinName}" "${geneName}" "${organismName}" "${diseaseAnnotation}" "${domainName}" "${similarityAnnotation}" "${locationAnnotation}" "${functionAnnotation}" "${pharmaceuticalAnnotation}" "${output}"</command>\n+ <inputs>\n+ <param name="protein" type="text" label="Uniprot Identifier"/>\n+\n+ <param name="proteinName" type="text" label="Protein Name">\n+\t<!-- sanitizer para que nos deje usar el caracter $ -->\n+\t<sanitizer sanitize="False"/>\n+ </param>\n+\n+ <param name="geneName" type="text" label="Gene Name">\n+\t<sanitizer sanitize="False"/>\n+ </param>\n+\n+ <param name="organismName" type="text" label="Organism">\n+\t<sanitizer sanitize="False"/>\n+ </param>\n+\n+ <param name="diseaseAnnotation" type="text" label="Disease Annotation">\n+\t<sanitizer sanitize="False"/>\n+ </param>\n+\n+ <param name="domainName" type="text" label="Domain">\n+\t<sanitizer sanitize="False"/>\n+ </param>\n+\n+ <param name="similarityAnnotation" type="text" label="Similarity Annotation">\n+\t<sanitizer sanitize="False"/>\n+ </param>\n+\n+ <param name="locationAnnotation" type="text" label="Location Annotation">\n+\t<sanitizer sanitize="False"/>\n+ </param>\n+\n+ <param name="functionAnnotation" type="text" label="Function Annotation">\n+\t<sanitizer sanitize="False"/>\n+ </param>\n+\n+ <param name="pharmaceuticalAnnotation" type="text" label="Pharmaceutical Annotation">\n+\t<sanitizer sanitize="False"/>\n+ </param>\n+ </inputs>\n+\n+ <outputs>\n+ <data format="tabular" name="output" />\n+ </outputs>\n+\n+ <help>\n+\tWith this tool you can search proteins using regular expressions by the following fields: uniprot identifier, protein name, gene name , organism name, disease annotation, domain name, similarity annotation, location annotation, function annotation or pharmaceutical annotationText. You can fill the fields you want and the tool will return all the data found in uniprot by filling the other fields. Results will be stored in a tabular format. If you want to search the exact match of a field you should use ^parameter$, for example ^insulin$.\n+ </help>\n+\n+</tool>\n' |