pythonsparqlvirtuososparqlwrapper

QueryBadFormed using Uniprot SPARQL endpoint


I am coding a SPARQL query from Python using SPARQLWrapper. The endpoint is Uniprot, but 50% of time, Iget an error when executing the code :

def getReviewProt(accession): 
    #print(accession)  
    mystring = '(uniprot:' + ') (uniprot:'.join(accession) + ')'
    #print(mystring)
    sparql = SPARQLWrapper("http://sparql.uniprot.org/sparql")

    sparql.setQuery("""
                    PREFIX  up_core: <http://purl.uniprot.org/core/>
                    PREFIX  up_taxonomy: <http://purl.uniprot.org/taxonomy/>
                    PREFIX  rdf:  <http://www.w3.org/1999/02/22-rdf-syntax-ns#>
                    PREFIX  owl:  <http://www.w3.org/2002/07/owl#>
                    PREFIX  apf:  <http://jena.hpl.hp.com/ARQ/property#>
                    PREFIX  xsd:  <http://www.w3.org/2001/XMLSchema#>
                    PREFIX  fn:   <http://www.w3.org/2005/xpath-functions#>
                    PREFIX  rdfs: <http://www.w3.org/2000/01/rdf-schema#>
                    PREFIX  uniprot: <http://purl.uniprot.org/uniprot/>
                    PREFIX  dc:   <http://purl.org/dc/elements/1.1/>
                    SELECT ?is_true
                    WHERE
                        {
                         VALUES (?ac) {"""+mystring+"""}
                         ?ac  up_core:reviewed  ?is_true   
                        }
                    """) 
    sparql.setReturnFormat(JSON)
    results = sparql.query().convert()
    return results

if __name__ == '__main__' :
    import sys
    #print(sys.path)
    accession = ["Q6GZX4","Q96375","B1XBG2"]
    res = getReviewProt(accession)
    for r in res['results']['bindings']:
       print(r['is_true']['value'])


So I get this error :

QueryBadFormed: a bad request has been sent to the endpoint, probably the sparql query is bad formed

When I try to see the exact error, here is what i get :

Exception:virtuoso.jdbc4.VirtuosoException: SQ156: Internal Optimized compiler error : sqlo table has no index in sqldf.c:3782.
Please report the statement compiled

The most strange is that when I try to execute it works, but like 50 % of the time. I get exactly the same error when making my query in the endpoint at this adress : http://sparql.uniprot.org/sparql . Sometimes it works perfectly, so I'm lost and of course, I want my program to work each time I execute it. They use the Virtuoso software in the endpoint, so I guess the problem comes from there, but I don't know how Virtuoso works. I'm new to SPARQL so it's quite hard for me to understand and resolve all errors, Can anyone help me ? Or if this problem has already been solved, I would be happy to have the link :) Thank you


Solution

  • The problem is not in your code, but in one of the two servers that run the sparql.uniprot.org endpoint. If you request went to the 'good' machine it worked, if it went to the 'broken' machine it failed. Both machines should be good now.