def insert_accession_sequence(core, plasmid, plasmid_seq): """ Given the SPARQL URIs for the core genome, the plasmid genome, and plasmid sequence, adds the plasmid sequence under the core genome and removes the connection to the plasmid genome. This is a cleanup routine, as core and plasmid genomes would share the same metadata, and it would not make sense to have both a plasmid and core genome instance containing the same metadata. Args: core (str): SPARQL URI based on the superphy ontology for the core genome instance plasmid (str): SPARQL URI based on the superphy ontology for the plasmid genome instance plasmid_seq (str): SPARQL URI based on the superphy ontology for the plasmid sequence instance \ Prints out the response from the server regarding the SPARQL Update query """ print _sparql_update( 'PREFIX rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#>\n' 'PREFIX : <https://github.com/superphy#>\n' 'INSERT DATA { :%s :has_accession "%s"^^xsd:string. ' ':%s :has_sequence :%s . :%s :is_sequence_of :%s . }\n' % (core, plasmid, core, plasmid_seq, plasmid_seq, core) )
def delete_blank_nodes(): """ Deletes all blank nodes on Blazegraph. This should only be ran when setting up the database, as blank nodes increase exponentially as triples get added and will cause a memory overflow error. Many of these blank nodes are from the interactions of the ontologies that superphy is built upon, but they do not significantly contribute to querying. Prints out the response from the server regarding the SPARQL Update query """ print _sparql_update( 'DELETE { ?x ?y ?z }' 'WHERE { ?x ?y ?z . FILTER ( isBlank(?x) || isBlank(?z) ) }' )
def delete_instance(name): """ Deletes an instance with a given SPARQL URI on the database by removing all triples with it (assumption:not a predicate, but then predicates aren't instances) Args: name: the SPARQL URI of the instance you want to delete Prints out the response from the server regarding the SPARQL Update query """ print _sparql_update( 'PREFIX rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#>\n' 'PREFIX : <https://github.com/superphy#>\n' 'DELETE { :%s ?property ?object . ?subject ?property :%s . }\n' 'WHERE {\n' '{ :%s ?property ?object }\n' 'UNION\n' '{ ?subject ?property :%s } }' % (name, name, name, name) )