本文整理汇总了Python中dipper.models.Model.Model.addLabel方法的典型用法代码示例。如果您正苦于以下问题:Python Model.addLabel方法的具体用法?Python Model.addLabel怎么用?Python Model.addLabel使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类dipper.models.Model.Model
的用法示例。
在下文中一共展示了Model.addLabel方法的9个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: make_triples
# 需要导入模块: from dipper.models.Model import Model [as 别名]
# 或者: from dipper.models.Model.Model import addLabel [as 别名]
def make_triples(self, source, package):
model = Model(self.graph)
if source == 'drugbank':
for target in package['targets']:
model.addTriple(subject_id=package['unii'],
predicate_id=target['action'],
obj=target['uniprot'])
model.addLabel(subject_id=target['uniprot'], label=target['name'])
model.addTriple(subject_id=target['uniprot'],
predicate_id=Model.object_properties['subclass_of'],
obj='SO:0000104')
model.addTriple(subject_id=package['drugbank_id'],
predicate_id=Model.object_properties['equivalent_class'],
obj=package['unii'])
model.addTriple(subject_id=target['action'],
predicate_id='rdfs:subPropertyOf',
obj='RO:0002436')
model.addTriple(subject_id=package['unii'],
predicate_id=Model.object_properties['subclass_of'],
obj='CHEBI:23367')
if source == 'drugcentral':
for indication in package['indications']:
model.addTriple(subject_id=package['unii'],
predicate_id='RO:0002606',
obj=indication['snomed_id'])
model.addTriple(subject_id=package['unii'],
predicate_id=Model.object_properties['subclass_of'],
obj='CHEBI:23367')
model.addTriple(subject_id=indication['snomed_id'],
predicate_id=Model.object_properties['subclass_of'],
obj='DOID:4')
model.addLabel(subject_id=indication['snomed_id'], label=indication['snomed_name'])
for interaction in package['interactions']:
model.addTriple(subject_id=package['unii'],
predicate_id='RO:0002436',
obj=interaction['uniprot'])
# model.addLabel(subject_id=interaction['uniprot'], label='Protein_{}'.format(interaction['uniprot']))
model.addLabel(subject_id=interaction['uniprot'], label=interaction['target_name'])
model.addTriple(subject_id=package['unii'],
predicate_id=Model.object_properties['subclass_of'],
obj='CHEBI:23367')
model.addDescription(subject_id=interaction['uniprot'], description=interaction['target_class'])
model.addTriple(subject_id=interaction['uniprot'],
predicate_id=Model.object_properties['subclass_of'],
obj='SO:0000104')
return
示例2: _parse_aeolus_data
# 需要导入模块: from dipper.models.Model import Model [as 别名]
# 或者: from dipper.models.Model.Model import addLabel [as 别名]
def _parse_aeolus_data(self, document, or_limit=None):
model = Model(self.graph)
rxcui_curie = "RXCUI:{}".format(document['aeolus']['rxcui'])
uni_curie = "UNII:{}".format(document['aeolus']['unii'])
model.addLabel(rxcui_curie, document['aeolus']['drug_name'])
model.addLabel(uni_curie, document['aeolus']['drug_name'])
model.addSameIndividual(rxcui_curie, uni_curie)
self.graph.addTriple(
rxcui_curie, self.globaltt['inchi_key'], document['unii']['inchikey'],
object_is_literal=True)
if or_limit is not None:
outcomes = (outcome for outcome in document['aeolus']['outcomes']
if 'ror' in outcome and outcome['ror'] >= or_limit)
else:
outcomes = (outcome for outcome in document['aeolus']['outcomes'])
for outcome in outcomes:
drug2outcome_assoc = Assoc(self.graph, self.name)
meddra_curie = "MEDDRA:{}".format(outcome['code'])
model.addLabel(meddra_curie, outcome['name'])
drug2outcome_assoc.sub = rxcui_curie
drug2outcome_assoc.obj = meddra_curie
drug2outcome_assoc.rel = self.globaltt['causes_or_contributes']
drug2outcome_assoc.description = \
"A proportional reporting ratio or odds " \
"ratio greater than or equal to {} in the " \
"AEOLUS data was the significance cut-off " \
"used for creating drug-outcome associations".format(or_limit)
drug2outcome_assoc.add_association_to_graph()
drug2outcome_assoc.add_predicate_object(
self.globaltt['probabalistic_quantifier'], outcome['ror'], 'Literal')
self._add_outcome_evidence(drug2outcome_assoc.assoc_id, outcome)
self._add_outcome_provenance(drug2outcome_assoc.assoc_id, outcome)
示例3: make_association
# 需要导入模块: from dipper.models.Model import Model [as 别名]
# 或者: from dipper.models.Model.Model import addLabel [as 别名]
def make_association(self, record):
"""
contstruct the association
:param record:
:return: modeled association of genotype to mammalian phenotype
"""
# prep record
# remove description and mapp Experiment Type to apo term
experiment_type = record['Experiment Type'].split('(')[0]
experiment_type = experiment_type.split(',')
record['experiment_type'] = list()
for exp_type in experiment_type:
exp_type = exp_type.lstrip().rstrip()
record['experiment_type'].append(
{
'id': self.apo_term_id[exp_type],
'term': exp_type,
})
sgd_phenotype = record['Phenotype']
pheno_obj = {
'entity': {
'term': None,
'apo_id': None
},
'quality': {
'term': None,
'apo_id': None
},
'has_quality': False # False = phenotype was descriptive and don't bother looking for a quality
}
phenotype = record['Phenotype']
if ':' in phenotype:
pheno_obj['has_quality'] = True
ent_qual = sgd_phenotype.split(': ')
entity = ent_qual[0]
quality = ent_qual[1]
pheno_obj['entity']['term'] = entity
pheno_obj['entity']['apo_id'] = self.apo_term_id[entity]
pheno_obj['quality']['term'] = quality
pheno_obj['quality']['apo_id'] = self.apo_term_id[quality]
else:
pheno_obj['entity']['term'] = phenotype
pheno_obj['entity']['apo_id'] = self.apo_term_id[phenotype]
record['pheno_obj'] = pheno_obj
# begin modeling
model = Model(self.graph)
# define the triple
gene = 'SGD:{}'.format(record['SGDID'])
relation = Model.object_properties['has_phenotype'] # has phenotype
if record['pheno_obj']['has_quality']:
pheno_label = '{0}:{1}'.format(
record['pheno_obj']['entity']['term'],
record['pheno_obj']['quality']['term'])
pheno_id = 'MONARCH:{0}{1}'.format(
record['pheno_obj']['entity']['apo_id'].replace(':', '_'),
record['pheno_obj']['quality']['apo_id'].replace(':', '_')
)
g2p_assoc = Assoc(self.graph, self.name, sub=gene, obj=pheno_id, pred=relation)
else:
pheno_label = record['pheno_obj']['entity']['term']
pheno_id = record['pheno_obj']['entity']['apo_id']
g2p_assoc = Assoc(self.graph, self.name, sub=gene, obj=pheno_id, pred=relation)
assoc_id = g2p_assoc.make_association_id(definedby='yeastgenome.org', subject=gene, predicate=relation,
object=pheno_id)
g2p_assoc.set_association_id(assoc_id=assoc_id)
# add to graph to mint assoc id
g2p_assoc.add_association_to_graph()
model.addLabel(subject_id=gene, label=record['Gene Name'])
# add the association triple
model.addTriple(subject_id=gene, predicate_id=relation, obj=pheno_id)
# make pheno subclass of UPHENO:0001001
model.addTriple(subject_id=pheno_id, predicate_id=Model.object_properties['subclass_of'], obj='UPHENO:0001001')
# label nodes
# pheno label
model.addLabel(subject_id=pheno_id, label=pheno_label)
g2p_assoc.description = self._make_description(record)
# add the references
references = record['Reference']
references = references.replace(' ', '')
references = references.split('|')
# created RGDRef prefix in curie map to route to proper reference URL in RGD
if len(references) > 0:
# make first ref in list the source
g2p_assoc.add_source(identifier=references[0])
ref_model = Reference(
self.graph, references[0],
Reference.ref_types['publication']
)
ref_model.addRefToGraph()
#.........这里部分代码省略.........
示例4: _build_gene_disease_model
# 需要导入模块: from dipper.models.Model import Model [as 别名]
# 或者: from dipper.models.Model.Model import addLabel [as 别名]
def _build_gene_disease_model(
self,
gene_id,
relation_id,
disease_id,
variant_label,
consequence_predicate=None,
consequence_id=None,
allelic_requirement=None,
pmids=None):
"""
Builds gene variant disease model
:return: None
"""
model = Model(self.graph)
geno = Genotype(self.graph)
pmids = [] if pmids is None else pmids
is_variant = False
variant_or_gene = gene_id
variant_id_string = variant_label
variant_bnode = self.make_id(variant_id_string, "_")
if consequence_predicate is not None \
and consequence_id is not None:
is_variant = True
model.addTriple(variant_bnode,
consequence_predicate,
consequence_id)
# Hack to add labels to terms that
# don't exist in an ontology
if consequence_id.startswith(':'):
model.addLabel(consequence_id,
consequence_id.strip(':').replace('_', ' '))
if is_variant:
variant_or_gene = variant_bnode
# Typically we would type the variant using the
# molecular consequence, but these are not specific
# enough for us to make mappings (see translation table)
model.addIndividualToGraph(variant_bnode,
variant_label,
self.globaltt['variant_locus'])
geno.addAffectedLocus(variant_bnode, gene_id)
model.addBlankNodeAnnotation(variant_bnode)
assoc = G2PAssoc(
self.graph, self.name, variant_or_gene, disease_id, relation_id)
assoc.source = pmids
assoc.add_association_to_graph()
if allelic_requirement is not None and is_variant is False:
model.addTriple(
assoc.assoc_id, self.globaltt['has_allelic_requirement'],
allelic_requirement)
if allelic_requirement.startswith(':'):
model.addLabel(
allelic_requirement,
allelic_requirement.strip(':').replace('_', ' '))
示例5: _add_variant_gene_relationship
# 需要导入模块: from dipper.models.Model import Model [as 别名]
# 或者: from dipper.models.Model.Model import addLabel [as 别名]
def _add_variant_gene_relationship(self, patient_var_map, gene_coordinate_map):
"""
Right now it is unclear the best approach on how to connect
variants to genes. In most cases has_affected_locus/GENO:0000418
is accurate; however, there are cases where a variant is in the intron
on one gene and is purported to causally affect another gene down or
upstream. In these cases we must first disambiguate which gene
is the affected locus, and which gene(s) are predicated to be
causully influenced by (RO:0002566)
UPDATE 8-30: In the latest dataset we no longer have 1-many mappings
between variants and genes, but leaving this here in case we see
these in the future
The logic followed here is:
if mutation type contains downstream/upstream and more than one
gene of interest, investigate coordinates of all genes to
see if we can disambiguate which genes are which
:return: None
"""
# genotype = Genotype(self.graph)
dipper_util = DipperUtil()
model = Model(self.graph)
# Note this could be compressed in someway to remove one level of for looping
for patient in patient_var_map:
for variant_id, variant in patient_var_map[patient].items():
variant_bnode = self.make_id("{0}".format(variant_id), "_")
genes_of_interest = variant['genes_of_interest']
if len(genes_of_interest) == 1:
# Assume variant is variant allele of gene
gene = genes_of_interest[0]
gene_id = dipper_util.get_ncbi_id_from_symbol(gene)
self._add_gene_to_graph(
gene, variant_bnode, gene_id,
self.globaltt['has_affected_feature'])
elif re.search(r'upstream|downstream', variant['type'], flags=re.I):
# Attempt to disambiguate
ref_gene = []
up_down_gene = []
unmatched_genes = []
for gene in variant['genes_of_interest']:
if gene_id and gene_id != '' and gene_id in gene_coordinate_map:
if gene_coordinate_map[gene_id]['start'] \
<= variant['position']\
<= gene_coordinate_map[gene_id]['end']:
gene_info = {
'symbol': gene,
'strand': gene_coordinate_map[gene_id]['strand']
}
ref_gene.append(gene_info)
else:
up_down_gene.append(gene)
else:
unmatched_genes.append(gene)
if len(ref_gene) == 1:
self._add_gene_to_graph(
ref_gene[0]['symbol'], variant_bnode, gene_id,
self.globaltt['has_affected_feature'])
# update label with gene
gene_list = [ref_gene[0]['symbol']] # build label expects list
variant_label = self._build_variant_label(
variant['build'], variant['chromosome'],
variant['position'], variant['reference_allele'],
variant['variant_allele'], gene_list)
model.addLabel(variant_bnode, variant_label)
# In some cases there are multiple instances
# of same gene from dupe rows in the source
# Credit http://stackoverflow.com/a/3844832
elif len(ref_gene) > 0 and ref_gene[1:] == ref_gene[:-1]:
self._add_gene_to_graph(
ref_gene[0]['symbol'], variant_bnode, gene_id,
self.globaltt['has_affected_feature'])
# build label function expects list
gene_list = [ref_gene[0]['symbol']]
variant_label = self._build_variant_label(
variant['build'], variant['chromosome'],
variant['position'], variant['reference_allele'],
variant['variant_allele'], gene_list)
model.addLabel(variant_bnode, variant_label)
# Check if reference genes are on different strands
elif len(ref_gene) == 2:
strands = [st['strand'] for st in ref_gene]
if "minus" in strands and "plus" in strands:
for r_gene in ref_gene:
self._add_gene_to_graph(
r_gene['symbol'], variant_bnode, gene_id,
self.globaltt['has_affected_feature'])
else:
LOG.warning(
"unable to map intron variant to gene coordinates: %s",
variant)
for r_gene in ref_gene:
self._add_gene_to_graph(
r_gene['symbol'], variant_bnode, gene_id,
self.globaltt['causally_influences'])
#.........这里部分代码省略.........
示例6: _parse_patient_variants
# 需要导入模块: from dipper.models.Model import Model [as 别名]
# 或者: from dipper.models.Model.Model import addLabel [as 别名]
def _parse_patient_variants(self, file):
"""
:param file: file handler
:return:
"""
patient_var_map = self._convert_variant_file_to_dict(file)
gene_coordinate_map = self._parse_gene_coordinates(
self.map_files['gene_coord_map'])
rs_map = self._parse_rs_map_file(self.map_files['dbsnp_map'])
genotype = Genotype(self.graph)
model = Model(self.graph)
self._add_variant_gene_relationship(patient_var_map, gene_coordinate_map)
for patient in patient_var_map:
patient_curie = ':{0}'.format(patient)
# make intrinsic genotype for each patient
intrinsic_geno_bnode = self.make_id(
"{0}-intrinsic-genotype".format(patient), "_")
genotype_label = "{0} genotype".format(patient)
genotype.addGenotype(
intrinsic_geno_bnode, genotype_label,
model.globaltt['intrinsic_genotype'])
self.graph.addTriple(
patient_curie, model.globaltt['has_genotype'], intrinsic_geno_bnode)
for variant_id, variant in patient_var_map[patient].items():
build = variant['build']
chromosome = variant['chromosome']
position = variant['position']
reference_allele = variant['reference_allele']
variant_allele = variant['variant_allele']
genes_of_interest = variant['genes_of_interest']
rs_id = variant['rs_id']
variant_label = ''
variant_bnode = self.make_id("{0}".format(variant_id), "_")
# maybe should have these look like the elif statements below
if position and reference_allele and variant_allele:
variant_label = self._build_variant_label(
build, chromosome, position, reference_allele,
variant_allele, genes_of_interest)
elif not position and reference_allele and variant_allele \
and len(genes_of_interest) == 1:
variant_label = self._build_variant_label(
build, chromosome, position, reference_allele, variant_allele,
genes_of_interest)
elif position and (not reference_allele or not variant_allele) \
and len(genes_of_interest) == 1:
variant_label = "{0}{1}({2}):g.{3}".format(
build, chromosome, genes_of_interest[0], position)
elif len(genes_of_interest) == 1:
variant_label = 'variant of interest in {0} gene of patient' \
' {1}'.format(genes_of_interest[0], patient)
else:
variant_label = 'variant of interest in patient {0}'.format(patient)
genotype.addSequenceAlteration(variant_bnode, None)
# check if it we have built the label
# in _add_variant_gene_relationship()
labels = self.graph.objects(
BNode(re.sub(r'^_:', '', variant_bnode, 1)), RDFS['label'])
label_list = list(labels)
if len(label_list) == 0:
model.addLabel(variant_bnode, variant_label)
self.graph.addTriple(
variant_bnode, self.globaltt['in taxon'],
self.globaltt['Homo sapiens'])
self.graph.addTriple(
intrinsic_geno_bnode, self.globaltt['has_variant_part'],
variant_bnode)
if rs_id:
dbsnp_curie = 'dbSNP:{0}'.format(rs_id)
model.addSameIndividual(variant_bnode, dbsnp_curie)
self._add_variant_sameas_relationships(patient_var_map, rs_map)
return
示例7: make_triples
# 需要导入模块: from dipper.models.Model import Model [as 别名]
# 或者: from dipper.models.Model.Model import addLabel [as 别名]
def make_triples(self, source, package):
model = Model(self.graph)
if source == 'drugbank':
for target in package['targets']:
model.addTriple(
subject_id=package['unii'],
predicate_id=target['action'],
obj=target['uniprot'])
model.addLabel(subject_id=target['uniprot'], label=target['name'])
model.addTriple(
subject_id=target['uniprot'],
predicate_id=self.globaltt['subclass_of'],
obj=self.globaltt['polypeptide'])
model.addTriple(
subject_id=package['drugbank_id'],
predicate_id=self.globaltt['equivalent_class'],
obj=package['unii'])
model.addTriple(
subject_id=target['action'],
predicate_id=self.globaltt['subPropertyOf'],
obj=self.globaltt['molecularly_interacts_with'])
model.addTriple(
subject_id=package['unii'],
predicate_id=self.globaltt['subclass_of'],
obj=self.globaltt['molecular entity'])
if source == 'drugcentral':
for indication in package['indications']:
model.addTriple(
subject_id=package['unii'],
predicate_id=self.globaltt['is substance that treats'],
obj=indication['snomed_id'])
model.addTriple(
subject_id=package['unii'],
predicate_id=self.globaltt['subclass_of'],
obj=self.globaltt['molecular entity'])
model.addTriple(
subject_id=indication['snomed_id'],
predicate_id=self.globaltt['subclass_of'],
obj=self.globaltt['disease'])
model.addLabel(
subject_id=indication['snomed_id'], label=indication['snomed_name'])
for interaction in package['interactions']:
model.addTriple(
subject_id=package['unii'],
predicate_id=self.globaltt['molecularly_interacts_with'],
obj=interaction['uniprot'])
# model.addLabel(
# subject_id=interaction['uniprot'],
# label='Protein_{}'.format(interaction['uniprot']))
model.addLabel(
subject_id=interaction['uniprot'], label=interaction['target_name'])
model.addTriple(
subject_id=package['unii'],
predicate_id=self.globaltt['subclass_of'],
obj=self.globaltt['molecular entity'])
model.addDescription(
subject_id=interaction['uniprot'],
description=interaction['target_class'])
model.addTriple(
subject_id=interaction['uniprot'],
predicate_id=self.globaltt['subclass_of'],
obj=self.globaltt['polypeptide'])
return
示例8: __init__
# 需要导入模块: from dipper.models.Model import Model [as 别名]
# 或者: from dipper.models.Model.Model import addLabel [as 别名]
#.........这里部分代码省略.........
self.ref_url = None
self.title = None
self.year = None
self.author_list = None
self.short_citation = None
self.model = Model(self.graph)
self.globaltt = self.graph.globaltt
self.globaltcid = self.graph.globaltcid
self.curie_map = self.graph.curie_map
if ref_type is None:
self.ref_type = self.globaltt['document']
else:
self.ref_type = ref_type
if ref_type[:4] not in ('IAO:', 'SIO:'):
LOG.warning("Got Pub ref type of: %s", ref_type)
if ref_id is not None and ref_id[:4] == 'http':
self.ref_url = ref_id
return
def setTitle(self, title):
self.title = title
return
def setYear(self, year):
self.year = year
return
def setType(self, reference_type):
self.ref_type = reference_type
return
def setAuthorList(self, author_list):
"""
:param author_list: Array of authors
:return:
"""
self.author_list = author_list
return
def addAuthor(self, author):
self.author_list += [author]
return
def setShortCitation(self, citation):
self.short_citation = citation
return
def addPage(self, subject_id, page_url):
self.graph.addTriple(
subject_id, self.globaltt['page'], # foaf:page not <sio:web page>
page_url, object_is_literal=True)
return
def addTitle(self, subject_id, title):
if title is not None and title != '':
self.graph.addTriple(
subject_id, self.globaltt['title (dce)'], title, object_is_literal=True)
return
def addRefToGraph(self):
cite = self.short_citation
if cite is None and self.title is not None:
cite = self.title
if self.ref_url is not None:
if self.title is not None:
self.addTitle(self.ref_url, self.title)
self.model.addType(self.ref_url, self.ref_type)
if cite is not None:
self.model.addLabel(self.ref_url, cite)
elif self.ref_id is not None:
self.model.addIndividualToGraph(self.ref_id, cite, self.ref_type)
if self.title is not None:
self.addTitle(self.ref_id, self.title)
else:
# should never be true
LOG.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 auth in self.author_list:
# gu.addTriple(
# graph, self.ref_id, self.props['has_author'], auth, True)
return
示例9: __init__
# 需要导入模块: from dipper.models.Model import Model [as 别名]
# 或者: from dipper.models.Model.Model import addLabel [as 别名]
#.........这里部分代码省略.........
def __init__(self, graph, ref_id=None, ref_type=None):
if isinstance(graph, Graph):
self.graph = graph
else:
raise ValueError("{} is not a graph".graph)
self.ref_id = ref_id
self.ref_url = None
self.title = None
self.year = None
self.author_list = None
self.short_citation = None
self.model = Model(self.graph)
if ref_type is None:
self.ref_type = self.ref_types['document']
else:
self.ref_type = ref_type
if ref_id is not None and re.match(r'http', ref_id):
self.ref_url = ref_id
return
def setTitle(self, title):
self.title = title
return
def setYear(self, year):
self.year = year
return
def setType(self, reference_type):
self.ref_type = reference_type
return
def setAuthorList(self, author_list):
"""
:param author_list: Array of authors
:return:
"""
self.author_list = author_list
return
def addAuthor(self, author):
self.author_list += [author]
return
def setShortCitation(self, citation):
self.short_citation = citation
return
def addPage(self, subject_id, page_url):
self.graph.addTriple(
subject_id, self.annotation_properties['page'],
page_url, object_is_literal=True)
return
def addTitle(self, subject_id, title):
self.graph.addTriple(
subject_id, self.annotation_properties['title'],
title, object_is_literal=True)
return
def addRefToGraph(self):
n = self.short_citation
if n is None:
n = self.title
if self.ref_url is not None:
self.addTitle(self.ref_url, self.title)
self.model.addType(self.ref_url, self.ref_type)
self.model.addLabel(self.ref_url, n)
elif self.ref_id is not None:
self.model.addIndividualToGraph(self.ref_id, n, self.ref_type)
if self.title is not None:
self.addTitle(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