Ejemplo n.º 1
0
 def src_gen(self):
     retval = []
     for obj in self.graph.objects(
             predicate=self.PDBo.has_entity_src_genCategory):
         qres = rdf.RDFDataSourceBase(url=str(obj), cache=self.cache).query(
             """prefix PDBo: <http://rdf.wwpdb.org/schema/pdbx-v40.owl#>
             select ?entity_id ?scientific_name ?strain ?gene where
             {{
             ?s PDBo:has_entity_src_gen ?entity .
             ?entity
             PDBo:entity_src_gen.entity_id ?entity_id ;
             PDBo:entity_src_gen.pdbx_gene_src_scientific_name ?scientific_name ;
             PDBo:entity_src_gen.gene_src_strain ?strain ;
             PDBo:entity_src_gen.pdbx_gene_src_gene ?gene .
             }}
             """)
         for row in qres:
             entity_id, scientific_name, strain, gene = [
                 str(elem) for elem in row
             ]
             retval.append(
                 dict(entity_id=entity_id,
                      scientific_name=scientific_name,
                      strain=strain,
                      gene=gene))
     return retval
Ejemplo n.º 2
0
 def get_type(self):
     qres = self.query(
         """prefix rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#>
         prefix skos: <http://www.w3.org/2004/02/skos/core#>
         select ?type where
         {{
         ?s
         rdf:type ?type ;
         skos:prefLabel ?label .
         }}
         """)
     uri = [str(row[0]) for row in qres]
     assert len(uri) == 1
     label = [
         str(obj) for obj in rdf.RDFDataSourceBase(uri[0]).graph.objects(
             subject=URIRef(uri[0]), predicate=RDFS.label)
     ]
     assert len(label) == 1
     return label[0]
Ejemplo n.º 3
0
    def sequence_annotation(
            self, uri=UniProtDataSourceBase.UNIPROT.Sequence_Annotation):
        # http://www.uniprot.org/core/
        # http://www.uniprot.org/help/sequence_annotation
        qres = rdf.RDFDataSourceBase(str(self.UNIPROT)).query(
            """prefix rdfs: <http://www.w3.org/2000/01/rdf-schema#>
            prefix uniprot: <http://purl.uniprot.org/core/>
            select ?s ?label ?comment ?see_also where
            {{
            {{
            {{
            ?s
            rdfs:subClassOf+ <{uri}> ;
            rdfs:label ?label .
            }}
            union
            {{
            ?s rdfs:label ?label .
            filter( ?s = <{uri}> ).
            }}
            optional {{ ?s rdfs:comment ?comment }}
            optional {{ ?s rdfs:seeAlso ?see_also . }}
            }}
            }}
            """.format(uri=str(uri)))
        names = {}
        for row in qres:
            name, label = str(row[0]), str(row[1])
            value = dict(name=name, label=label)
            if row[2] is not None:
                value['comment'] = str(row[2])
            if row[3] is not None:
                value['see_also'] = str(row[3])
            names[name] = value

        qres = self.query(
            """prefix rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#>
            prefix rdfs: <http://www.w3.org/2000/01/rdf-schema#>
            prefix faldo: <http://biohackathon.org/resource/faldo#>
            prefix uniprot: <http://purl.uniprot.org/core/>
            select ?type ?begin ?end ?s ?comment ?substitution where
            {{
            ?s
            rdf:type ?type ;
            uniprot:range ?range .
            optional {{ ?s rdfs:comment ?comment }} .
            optional {{ ?s uniprot:substitution ?substitution }} .
            filter( ?type in ({}) ) .
            ?range faldo:begin ?begin_ ; faldo:end ?end_ .
            ?begin_ faldo:position ?begin .
            ?end_ faldo:position ?end .
            }}
            """.format(', '.join('<{}>'.format(name)
                                 for name in names.keys())))
        retval = []
        for row in qres:
            name, begin, end = str(row[0]), int(row[1]), int(row[2])
            value = dict(begin=begin, end=end, type=names[name])
            about = str(row[3])
            citation = self.citation(about)
            if len(citation) > 0:
                value['citation'] = citation
            if row[4] is not None:
                value['comment'] = str(row[4])
            if row[5] is not None:
                value['substitution'] = str(row[5])
            retval.append(value)
        return retval