本文整理汇总了Python中dipper.utils.GraphUtils.GraphUtils.getNode方法的典型用法代码示例。如果您正苦于以下问题:Python GraphUtils.getNode方法的具体用法?Python GraphUtils.getNode怎么用?Python GraphUtils.getNode使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类dipper.utils.GraphUtils.GraphUtils
的用法示例。
在下文中一共展示了GraphUtils.getNode方法的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: _get_gene2pubmed
# 需要导入模块: from dipper.utils.GraphUtils import GraphUtils [as 别名]
# 或者: from dipper.utils.GraphUtils.GraphUtils import getNode [as 别名]
def _get_gene2pubmed(self, limit):
"""
Loops through the gene2pubmed file and adds a simple triple to say that a given publication
is_about a gene. Publications are added as NamedIndividuals.
:param limit:
:return:
"""
gu = GraphUtils(curie_map.get())
if self.testMode:
g = self.testgraph
else:
g = self.graph
is_about = gu.getNode(gu.object_properties['is_about'])
logger.info("Processing Gene records")
line_counter = 0
myfile = '/'.join((self.rawdir, self.files['gene2pubmed']['file']))
logger.info("FILE: %s", myfile)
with gzip.open(myfile, 'rb') as f:
for line in f:
# skip comments
line = line.decode().strip()
if re.match('^#', line):
continue
(tax_num, gene_num, pubmed_num) = line.split('\t')
##### set filter=None in init if you don't want to have a filter
#if self.filter is not None:
# if ((self.filter == 'taxids' and (int(tax_num) not in self.tax_ids))
# or (self.filter == 'geneids' and (int(gene_num) not in self.gene_ids))):
# continue
##### end filter
if self.testMode and int(gene_num) not in self.gene_ids:
continue
if int(tax_num) not in self.tax_ids:
continue
if gene_num == '-' or pubmed_num == '-':
continue
line_counter += 1
gene_id = ':'.join(('NCBIGene', gene_num))
pubmed_id = ':'.join(('PMID', pubmed_num))
# add the gene, in case it hasn't before
gu.addClassToGraph(g, gene_id, None)
# add the publication as a NamedIndividual
gu.addIndividualToGraph(g, pubmed_id, None, None) # add type publication
self.graph.add((gu.getNode(pubmed_id), is_about, gu.getNode(gene_id)))
if not self.testMode and limit is not None and line_counter > limit:
break
return
示例2: addRefToGraph
# 需要导入模块: from dipper.utils.GraphUtils import GraphUtils [as 别名]
# 或者: from dipper.utils.GraphUtils.GraphUtils import getNode [as 别名]
def addRefToGraph(self, g):
gu = GraphUtils(curie_map.get())
n = self.short_citation
if n is None:
n = self.title
if self.ref_url is not None:
ref_uri = URIRef(self.ref_url)
g.add((ref_uri, DC['title'], Literal(self.title)))
g.add((ref_uri, RDF['type'], gu.getNode(self.ref_type)))
g.add((ref_uri, RDFS['label'], Literal(n)))
elif self.ref_id is not None:
gu.addIndividualToGraph(g, self.ref_id, n, self.ref_type)
if self.title is not None:
gu.addTitle(g, self.ref_id, self.title)
else:
# should never be true
logger.error("You are missing an identifier for a reference.")
# TODO what is the property here to add the date?
# if self.year is not None:
# gu.addTriple()
# if self.author_list is not None:
# for a in self.author_list:
# gu.addTriple(
# g, self.ref_id, self.props['has_author'], a, True)
return
示例3: test_therapeutic_relationship
# 需要导入模块: from dipper.utils.GraphUtils import GraphUtils [as 别名]
# 或者: from dipper.utils.GraphUtils.GraphUtils import getNode [as 别名]
def test_therapeutic_relationship(self):
from dipper.utils.TestUtils import TestUtils
from dipper.utils.GraphUtils import GraphUtils
from dipper import curie_map
# Make testutils object and load ttl
test_query = TestUtils(self.source.graph)
test_query.load_testgraph_from_turtle(self.source)
# Expected structure
# TODO can this be unified OBAN and the Annot models to be automatically generated?
sparql_query = """
SELECT ?assoc ?pubmed ?disease ?chemical
WHERE {
?assoc a Annotation: ;
dc:evidence OBO:ECO_0000033 ;
dc:source ?pubmed ;
:hasObject ?disease ;
:hasPredicate OBO:RO_0002606 ;
:hasSubject ?chemical .}
"""
# SPARQL variables to check
gu = GraphUtils(curie_map.get())
chem_id = 'MESH:D009538'
chem_uri = gu.getNode(chem_id)
disease_id = 'OMIM:188890'
disease_uri = gu.getNode(disease_id)
eco = 'ECO:0000033'
rel_id = gu.object_properties['substance_that_treats']
pubmed_id = 'PMID:16785264'
pubmed_uri = gu.getNode(pubmed_id)
# consider replacing with make_ctd_chem_disease_assoc_id()
assoc_id = self.source.make_association_id('ctd', chem_id, rel_id, disease_id, eco, pubmed_id)
assoc_uri = gu.getNode(assoc_id)
# One of the expected outputs from query
expected_output = [assoc_uri, pubmed_uri, disease_uri, chem_uri]
# Query graph
sparql_output = test_query.query_graph(sparql_query)
self.assertTrue(expected_output in sparql_output, "did not find expected association: " + assoc_id +
" found: " + pprint.pformat(sparql_output))
logger.info("Test query data finished.")
示例4: test_therapeutic_relationship
# 需要导入模块: from dipper.utils.GraphUtils import GraphUtils [as 别名]
# 或者: from dipper.utils.GraphUtils.GraphUtils import getNode [as 别名]
def test_therapeutic_relationship(self):
from dipper.utils.TestUtils import TestUtils
from dipper.utils.GraphUtils import GraphUtils
# Make testutils object and load bindings
test_query = TestUtils(self.ctd.graph)
self.ctd.load_bindings()
# Expected structure
sparql_query = """
SELECT ?assoc ?pubmed ?disease ?chemical
WHERE {
?assoc a Annotation: ;
dc:evidence OBO:ECO_0000033 ;
dc:source ?pubmed ;
:hasObject ?disease ;
:hasPredicate OBO:RO_0002606 ;
:hasSubject ?chemical .}
"""
# SPARQL variables to check
gu = GraphUtils(curie_map.get())
chem_id = 'MESH:D009538'
chem_uri = gu.getNode(chem_id)
disease_id = 'OMIM:188890'
disease_uri = gu.getNode(disease_id)
pubmed_id = 'PMID:16785264'
pubmed_uri = gu.getNode(pubmed_id)
rel_id = gu.object_properties['substance_that_treats']
eco = 'ECO:0000033'
# TODO PYLINT make_association_id() does not exist in CTD
# there is "_make_association()" with a different sig
assoc_id = self.ctd.make_association_id(
'ctd', chem_id, rel_id, disease_id, eco, pubmed_id)
assoc_uri = gu.getNode(assoc_id)
# Expected output from query
expected_output = [assoc_uri, pubmed_uri, disease_uri, chem_uri]
# Query graph
sparql_output = test_query.query_graph(sparql_query)
self.assertTrue(expected_output in sparql_output)
logger.info("Test finished.")
示例5: test_curieprefixes
# 需要导入模块: from dipper.utils.GraphUtils import GraphUtils [as 别名]
# 或者: from dipper.utils.GraphUtils.GraphUtils import getNode [as 别名]
def test_curieprefixes(self):
"""
This will ensure that we can create identifiers for all of the defined curie prefixes using the
GraphUtils.getNode() method
:return:
"""
from dipper.utils.GraphUtils import GraphUtils
gu = GraphUtils(self.curie_map)
# add one id per curie as classes to the graph
for p in self.curie_map.keys():
testid = p+':testme'
n = gu.getNode(testid)
m = "prefix \""+p+"\" has an error...can't create graph node"
self.assertTrue(n is not None, m)
return
示例6: Feature
# 需要导入模块: from dipper.utils.GraphUtils import GraphUtils [as 别名]
# 或者: from dipper.utils.GraphUtils.GraphUtils import getNode [as 别名]
#.........这里部分代码省略.........
self.gu.addTriple(graph, region_id, self.properties['begin'],
begin_position_id)
if end_position_id is None:
pass
# logger.warn("No end position specified for region %s", region_id)
else:
self.gu.addTriple(graph, region_id, self.properties['end'],
end_position_id)
return
def addPositionToGraph(
self, graph, reference_id, position,
position_types=None, strand=None):
"""
Add the positional information to the graph, following the faldo model.
We assume that if the strand is None,
we give it a generic "Position" only.
Triples:
my_position a (any of: faldo:(((Both|Plus|Minus)Strand)|Exact)Position)
faldo:position Integer(numeric position)
faldo:reference reference_id
:param graph:
:param reference_id:
:param position:
:param position_types:
:param strand:
:return: Identifier of the position created
"""
iid = self._makePositionId(reference_id, position, position_types)
n = self.gu.getNode(iid)
pos = self.gu.getNode(self.properties['position'])
ref = self.gu.getNode(self.properties['reference'])
if position is not None:
graph.add((n, pos, Literal(position, datatype=XSD['integer'])))
graph.add((n, ref, self.gu.getNode(reference_id)))
if position_types is not None:
for t in position_types:
graph.add((n, RDF['type'], self.gu.getNode(t)))
s = None
if strand is not None:
s = strand
if not re.match(r'faldo', strand):
# not already mapped to faldo, so expect we need to map it
s = self._getStrandType(strand)
# else:
# s = self.types['both_strand']
if s is None and (position_types is None or position_types == []):
s = self.types['Position']
if s is not None:
graph.add((n, RDF['type'], self.gu.getNode(s)))
return iid
def addSubsequenceOfFeature(self, graph, parentid):
"""
This will add reciprocal triples like:
feature is_subsequence_of parent
parent has_subsequence feature
:param graph:
:param parentid:
:return:
示例7: Genotype
# 需要导入模块: from dipper.utils.GraphUtils import GraphUtils [as 别名]
# 或者: from dipper.utils.GraphUtils.GraphUtils import getNode [as 别名]
#.........这里部分代码省略.........
:param polypeptide_id:
:param polypeptide_label:
:param polypeptide_type:
:param transcript_id:
:return:
"""
if polypeptide_type is None:
polypeptide_type = self.genoparts['polypeptide']
self.gu.addIndividualToGraph(self.graph, polypeptide_id, polypeptide_label, polypeptide_type)
if transcript_id is not None:
self.gu.addTriple(self.graph, transcript_id, self.properties['translates_to'], polypeptide_id)
return
def addPartsToVSLC(self, vslc_id, allele1_id, allele2_id, zygosity_id=None, allele1_rel=None, allele2_rel=None):
"""
Here we add the parts to the VSLC. While traditionally alleles (reference or variant loci) are
traditionally added, you can add any node (such as sequence_alterations for unlocated variations)
to a vslc if they are known to be paired. However, if a sequence_alteration's loci is unknown,
it probably should be added directly to the GVC.
:param vslc_id:
:param allele1_id:
:param allele2_id:
:param zygosity_id:
:param allele1_rel:
:param allele2_rel:
:return:
"""
# vslc has parts allele1/allele2
gu = self.gu
vslc = gu.getNode(vslc_id)
if allele1_id is not None:
self.addParts(allele1_id, vslc_id, allele1_rel)
if allele2_id is not None and allele2_id.strip() != '':
self.addParts(allele2_id, vslc_id, allele2_rel)
# figure out zygosity if it's not supplied
if zygosity_id is None:
if allele1_id == allele2_id:
zygosity_id = self.zygosity['homozygous']
else:
zygosity_id = self.zygosity['heterozygous']
if zygosity_id is not None:
gu.addTriple(self.graph, vslc_id, self.properties['has_zygosity'], zygosity_id)
return
def addVSLCtoParent(self, vslc_id, parent_id):
"""
The VSLC can either be added to a genotype or to a GVC. The vslc is added as a part of the parent.
:param vslc_id:
:param parent_id:
:return:
"""
self.addParts(vslc_id, parent_id, self.properties['has_alternate_part'])
return
def addParts(self, part_id, parent_id, part_relationship=None):
"""
This will add a has_part (or subproperty) relationship between a parent_id and the supplied part.
By default the relationship will be BFO:has_part, but any relationship could be given here.
示例8: OBAN
# 需要导入模块: from dipper.utils.GraphUtils import GraphUtils [as 别名]
# 或者: from dipper.utils.GraphUtils.GraphUtils import getNode [as 别名]
class Assoc:
"""
An abstract class for OBAN (Monarch)-style associations,
to enable attribution of source and evidence
on statements.
"""
assoc_types = {
'association': 'OBAN:association'
}
annotation_properties = {
'replaced_by': 'IAO:0100001',
'consider': 'OIO:consider',
'hasExactSynonym': 'OIO:hasExactSynonym',
'hasRelatedSynonym': 'OIO:hasRelatedSynonym',
'definition': 'IAO:0000115',
'has_xref': 'OIO:hasDbXref',
}
object_properties = {
'has_disposition': 'GENO:0000208',
'has_phenotype': 'RO:0002200',
'in_taxon': 'RO:0002162',
'has_quality': 'RO:0000086',
'towards': 'RO:0002503',
'has_subject': 'OBAN:association_has_subject',
'has_object': 'OBAN:association_has_object',
'has_predicate': 'OBAN:association_has_object_property',
'is_about': 'IAO:00000136',
'has_evidence': 'RO:0002558',
'has_source': 'dc:source',
'has_provenance': 'OBAN:has_provenance'
}
datatype_properties = {
'position': 'faldo:position',
'has_measurement': 'IAO:0000004'
}
properties = annotation_properties.copy()
properties.update(object_properties)
properties.update(datatype_properties)
OWLCLASS = OWL['Class']
OWLIND = OWL['NamedIndividual']
OBJECTPROP = OWL['ObjectProperty']
ANNOTPROP = OWL['AnnotationProperty']
DATAPROP = OWL['DatatypeProperty']
SUBCLASS = RDFS['subClassOf']
BASE = Namespace(curie_map.get()[''])
def __init__(self, definedby):
self.cu = CurieUtil(curie_map.get())
self.gu = GraphUtils(curie_map.get())
# core parts of the association
self.definedby = definedby
self.sub = self.obj = self.rel = None
self.assoc_id = None
self.description = None
self.source = []
self.evidence = []
# this is going to be used for the refactored evidence/provenance
self.provenance = []
self.score = None
self.score_type = None
self.score_unit = None
return
def get_properties(self):
return self.properties
def _is_valid(self):
# check if sub/obj/rel are none...throw error
if self.sub is None:
raise ValueError('No subject set for this association')
if self.obj is None:
raise ValueError('No object set for this association')
if self.rel is None:
raise ValueError('No relation set for this association')
return True
def _add_basic_association_to_graph(self, g):
if not self._is_valid():
return
# first, add the direct triple
# anonymous (blank) nodes are indicated with underscore
s = self.gu.getNode(self.sub)
o = self.gu.getNode(self.obj)
p = self.gu.getNode(self.rel)
#.........这里部分代码省略.........