本文整理汇总了Python中dipper.models.Reference.Reference.addRefToGraph方法的典型用法代码示例。如果您正苦于以下问题:Python Reference.addRefToGraph方法的具体用法?Python Reference.addRefToGraph怎么用?Python Reference.addRefToGraph使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类dipper.models.Reference.Reference
的用法示例。
在下文中一共展示了Reference.addRefToGraph方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: _parse_curated_chem_disease
# 需要导入模块: from dipper.models.Reference import Reference [as 别名]
# 或者: from dipper.models.Reference.Reference import addRefToGraph [as 别名]
def _parse_curated_chem_disease(self, limit):
line_counter = 0
file_path = '/'.join((self.rawdir, self.static_files['publications']['file']))
gu = GraphUtils(curie_map.get())
with open(file_path, 'r') as tsvfile:
reader = csv.reader(tsvfile, delimiter="\t")
for row in reader:
# catch comment lines
if re.match('^#', ' '.join(row)):
continue
line_counter += 1
self._check_list_len(row, 10)
(pub_id, disease_label, disease_id, disease_cat, evidence,
chem_label, chem_id, cas_rn, gene_symbol, gene_acc) = row
rel_id = self._get_relationship_id(evidence)
chem_id = 'MESH:'+chem_id
gu.addClassToGraph(self.g, chem_id, chem_label)
gu.addClassToGraph(self.g, disease_id, None)
if pub_id != '':
pub_id = 'PMID:'+pub_id
r = Reference(pub_id, Reference.ref_types['journal_article'])
r.addRefToGraph(self.g)
else:
pub_id = None
self._make_association('MESH:'+chem_id, disease_id, rel_id, ['PMID:'+pub_id])
if not self.testMode and limit is not None and line_counter >= limit:
break
return
示例2: _process_article_row
# 需要导入模块: from dipper.models.Reference import Reference [as 别名]
# 或者: from dipper.models.Reference.Reference import addRefToGraph [as 别名]
def _process_article_row(self, row):
# don't bother in test mode
if self.testMode:
return
iarticle_id = self._make_internal_id('article', row['article_id'])
self.id_hash['article'][row['article_id']] = iarticle_id
rtype = None
if row['journal'] != '':
rtype = Reference.ref_types['journal_article']
r = Reference(iarticle_id, rtype)
if row['title'] is not None:
r.setTitle(row['title'].strip())
if row['year'] is not None:
r.setYear(row['year'])
r.addRefToGraph(self.g)
if row['pubmed_id'] is not None:
pmid = 'PMID:'+str(row['pubmed_id'])
self.id_hash['article'][row['article_id']] = pmid
self.gu.addSameIndividual(self.g, iarticle_id, pmid)
self.gu.addComment(self.g, pmid, iarticle_id)
return
示例3: _process_pathway_pubmed
# 需要导入模块: from dipper.models.Reference import Reference [as 别名]
# 或者: from dipper.models.Reference.Reference import addRefToGraph [as 别名]
def _process_pathway_pubmed(self, limit):
"""
Indicate that a pathway is annotated directly to a paper (is about)
via it's pubmed id.
:param limit:
:return:
"""
LOG.info("Processing KEGG pathways to pubmed ids")
if self.test_mode:
graph = self.testgraph
else:
graph = self.graph
raw = '/'.join((self.rawdir, self.files['pathway_pubmed']['file']))
with open(raw, 'r', encoding="iso-8859-1") as csvfile:
reader = csv.reader(csvfile, delimiter='\t', quotechar='\"')
for row in reader:
(pubmed_id, kegg_pathway_num) = row
if self.test_mode and kegg_pathway_num not in self.test_ids['pathway']:
continue
pubmed_id = pubmed_id.upper()
# will look like KEGG-path:map04130
kegg_id = 'KEGG-' + kegg_pathway_num
r = Reference(graph, pubmed_id, self.globaltt['journal article'])
r.addRefToGraph()
graph.addTriple(pubmed_id, self.globaltt['is_about'], kegg_id)
if not self.test_mode and limit is not None and reader.line_num > limit:
break
示例4: _make_association
# 需要导入模块: from dipper.models.Reference import Reference [as 别名]
# 或者: from dipper.models.Reference.Reference import addRefToGraph [as 别名]
def _make_association(self, subject_id, object_id, rel_id, pubmed_ids):
"""
Make a reified association given an array of pubmed identifiers.
Args:
:param subject_id id of the subject of the association (gene/chem)
:param object_id id of the object of the association (disease)
:param rel_id relationship id
:param pubmed_ids an array of pubmed identifiers
Returns:
:return None
"""
# TODO pass in the relevant Assoc class rather than relying on G2P
assoc = G2PAssoc(self.g, self.name, subject_id, object_id, rel_id)
if pubmed_ids is not None and len(pubmed_ids) > 0:
eco = self._get_evidence_code('TAS')
for pmid in pubmed_ids:
r = Reference(
self.g, pmid, Reference.ref_types['journal_article'])
r.addRefToGraph()
assoc.add_source(pmid)
assoc.add_evidence(eco)
assoc.add_association_to_graph()
return
示例5: _make_association
# 需要导入模块: from dipper.models.Reference import Reference [as 别名]
# 或者: from dipper.models.Reference.Reference import addRefToGraph [as 别名]
def _make_association(self, subject_id, object_id, rel_id, pubmed_ids):
"""
Make a reified association given an array of pubmed identifiers.
Args:
:param subject_id id of the subject of the association (gene/chem)
:param object_id id of the object of the association (disease)
:param rel_id relationship id
:param pubmed_ids an array of pubmed identifiers
Returns:
:return None
"""
# TODO pass in the relevant Assoc class rather than relying on G2P
assoc = G2PAssoc(self.graph, self.name, subject_id, object_id, rel_id)
if pubmed_ids is not None and len(pubmed_ids) > 0:
for pmid in pubmed_ids:
ref = Reference(
self.graph, pmid, self.globaltt['journal article'])
ref.addRefToGraph()
assoc.add_source(pmid)
assoc.add_evidence(self.globaltt['traceable author statement'])
assoc.add_association_to_graph()
return
示例6: parse
# 需要导入模块: from dipper.models.Reference import Reference [as 别名]
# 或者: from dipper.models.Reference.Reference import addRefToGraph [as 别名]
def parse(self, limit=None):
zfin_parser = ZFIN(self.graph_type, self.are_bnodes_skized)
model = Model(self.graph)
zp_file = '/'.join((self.rawdir, self.files['zpmap']['file']))
g2p_file = '/'.join((self.rawdir, self.files['g2p_clean']['file']))
zfin_parser.zp_map = zfin_parser._load_zp_mappings(zp_file)
with open(g2p_file, 'r', encoding="utf8") as csvfile:
filereader = csv.reader(csvfile, delimiter='\t', quotechar='\"')
for row in filereader:
(internal_id, symbol, gene_id, subterm1_id, subterm1_label,
pc_rel_id, pc_rel_label, superterm1_id, superterm1_label,
quality_id, quality_name, modifier, subterm2_id,
subterm2_label, pc_rel2_id, pc_rel2_id, superterm2_id,
superterm2_label, fish_id, fish_label, start_stage, end_stage,
environment, pub_id, figure_id, unknown_field) = row
zp_id = zfin_parser._map_sextuple_to_phenotype(
superterm1_id, subterm1_id, quality_id, superterm2_id,
subterm2_id, modifier)
gene_curie = "ZFIN:{0}".format(gene_id)
model.makeLeader(gene_curie)
pub_curie = "ZFIN:{0}".format(pub_id)
if zp_id:
assoc = G2PAssoc(self.graph, self.name, gene_curie, zp_id)
if pub_id:
reference = Reference(self.graph, pub_curie,
Reference.ref_types['document'])
reference.addRefToGraph()
assoc.add_source(pub_curie)
assoc.add_evidence('ECO:0000059')
assoc.add_association_to_graph()
示例7: process_pub_xrefs
# 需要导入模块: from dipper.models.Reference import Reference [as 别名]
# 或者: from dipper.models.Reference.Reference import addRefToGraph [as 别名]
def process_pub_xrefs(self, limit=None):
raw = '/'.join((self.rawdir, self.files['pub_xrefs']['file']))
if self.testMode:
g = self.testgraph
else:
g = self.graph
gu = GraphUtils(curie_map.get())
logger.info("Processing publication xrefs")
line_counter = 0
with open(raw, 'r') as csvfile:
filereader = csv.reader(csvfile, delimiter='\t', quotechar='\"')
for row in filereader:
line_counter += 1
(wb_ref, xref) = row
# WBPaper00000009 pmid8805<BR>
# WBPaper00000011 doi10.1139/z78-244<BR>
# WBPaper00000012 cgc12<BR>
if self.testMode and wb_ref not in self.test_ids['pub']:
continue
ref_id = 'WormBase:'+wb_ref
xref_id = r = None
xref = re.sub(r'<BR>', '', xref)
xref = xref.strip()
if re.match(r'pmid', xref):
xref_id = 'PMID:'+re.sub(r'pmid\s*', '', xref)
r = Reference(
xref_id, Reference.ref_types['journal_article'])
elif re.search(r'[\(\)\<\>\[\]\s]', xref):
continue
elif re.match(r'doi', xref):
xref_id = 'DOI:'+re.sub(r'doi', '', xref.strip())
r = Reference(xref_id)
elif re.match(r'cgc', xref):
# TODO not sure what to do here with cgc xrefs
continue
else:
# logger.debug("Other xrefs like %s", xref)
continue
if xref_id is not None:
r.addRefToGraph(g)
gu.addSameIndividual(g, ref_id, xref_id)
if not self.testMode \
and limit is not None and line_counter > limit:
break
return
示例8: _add_variant_trait_association
# 需要导入模块: from dipper.models.Reference import Reference [as 别名]
# 或者: from dipper.models.Reference.Reference import addRefToGraph [as 别名]
def _add_variant_trait_association(self, variant_id, mapped_trait_uri,
efo_ontology, pubmed_id,
description=None):
if self.testMode:
g = self.testgraph
else:
g = self.graph
model = Model(g)
# make associations to the EFO terms; there can be >1
if mapped_trait_uri.strip() != '':
for trait in re.split(r',', mapped_trait_uri):
trait = trait.strip()
trait_curie = trait.replace("http://www.ebi.ac.uk/efo/EFO_", "EFO:")
phenotype_query = """
SELECT ?trait
WHERE {{
<{0}> rdfs:subClassOf+ <http://www.ebi.ac.uk/efo/EFO_0000651> .
<{0}> rdfs:label ?trait .
}}
""".format(trait)
query_result = efo_ontology.query(phenotype_query)
if len(list(query_result)) > 0:
if re.match(r'^EFO', trait_curie):
model.addClassToGraph(
trait_curie,
list(query_result)[0][0],
'UPHENO:0001001')
pubmed_curie = 'PMID:' + pubmed_id
ref = Reference(
g, pubmed_curie, Reference.ref_types['journal_article'])
ref.addRefToGraph()
assoc = G2PAssoc(
g, self.name, variant_id, trait_curie,
model.object_properties['contributes_to'])
assoc.add_source(pubmed_curie)
# combinatorial evidence
# used in automatic assertion
eco_id = 'ECO:0000213'
assoc.add_evidence(eco_id)
if description is not None:
assoc.set_description(description)
# FIXME score should get added to provenance/study
# assoc.set_score(pvalue)
if trait_curie is not None:
assoc.add_association_to_graph()
示例9: parse
# 需要导入模块: from dipper.models.Reference import Reference [as 别名]
# 或者: from dipper.models.Reference.Reference import addRefToGraph [as 别名]
def parse(self, limit=None):
count = 0
for num in range(10, 100):
fuzzy_gene = "MGI:{0}*".format(num)
gene = "MGI:{0}".format(num)
service = Service("http://www.mousemine.org/mousemine/service")
logging.getLogger('Model').setLevel(logging.ERROR)
logging.getLogger('JSONIterator').setLevel(logging.ERROR)
query = service.new_query("OntologyAnnotation")
query.add_constraint("subject", "SequenceFeature")
query.add_constraint("ontologyTerm", "MPTerm")
query.add_view(
"subject.primaryIdentifier", "subject.symbol",
"subject.sequenceOntologyTerm.name", "ontologyTerm.identifier",
"ontologyTerm.name", "evidence.publications.pubMedId",
"evidence.comments.type", "evidence.comments.description"
)
query.add_sort_order("OntologyAnnotation.ontologyTerm.name", "ASC")
query.add_constraint("subject.organism.taxonId", "=", self.txid, code="A")
query.add_constraint("subject", "LOOKUP", fuzzy_gene, code="B")
query.add_constraint(
"subject.primaryIdentifier", "CONTAINS", gene, code="C")
query.outerjoin("evidence.comments")
for row in query.rows():
mgi_curie = row["subject.primaryIdentifier"]
mp_curie = row["ontologyTerm.identifier"]
pub_curie = "PMID:{0}".format(row["evidence.publications.pubMedId"])
assoc = G2PAssoc(self.graph, self.name, mgi_curie, mp_curie)
if row["evidence.publications.pubMedId"]:
reference = Reference(
self.graph, pub_curie, self.globaltt['journal article'])
reference.addRefToGraph()
assoc.add_source(pub_curie)
assoc.add_evidence(self.globaltt['experimental phenotypic evidence'])
assoc.add_association_to_graph()
if not count % 10 and count != 0:
count_from = count - 10
LOG.info(
"%s processed ids from MGI:%i* to MGI:%i*",
datetime.datetime.now(), count_from, count)
count += 1
if limit and count >= limit:
break
return
示例10: _get_pubs
# 需要导入模块: from dipper.models.Reference import Reference [as 别名]
# 或者: from dipper.models.Reference.Reference import addRefToGraph [as 别名]
def _get_pubs(self, entry, g):
"""
Extract mentioned publications from the reference list
:param entry:
:return:
"""
ref_to_pmid = {}
entry_num = entry['mimNumber']
model = Model(g)
if 'referenceList' in entry:
reflist = entry['referenceList']
for r in reflist:
if 'pubmedID' in r['reference']:
pub_id = 'PMID:' + str(r['reference']['pubmedID'])
ref = \
Reference(
g, pub_id,
Reference.ref_types['journal_article'])
else:
# make blank node for internal reference
pub_id = \
'_:OMIM' + str(entry_num) + 'ref' + \
str(r['reference']['referenceNumber'])
ref = Reference(g, pub_id)
title = author_list = source = citation = None
if 'title' in r['reference']:
title = r['reference']['title']
ref.setTitle(title)
if 'authors' in r['reference']:
author_list = r['reference']['authors']
ref.setAuthorList(author_list)
citation = re.split(r'\.\,', author_list)[0] + ' et al'
if 'source' in r['reference']:
source = r['reference']['source']
citation = '; '.join(
list(filter(None.__ne__, [citation, title, source])))
ref.setShortCitation(citation)
ref.addRefToGraph()
ref_to_pmid[r['reference']['referenceNumber']] = pub_id
# add is_about for the pub
omim_id = 'OMIM:'+str(entry_num)
g.addTriple(omim_id, model.object_properties['mentions'],
pub_id)
return ref_to_pmid
示例11: make_association
# 需要导入模块: from dipper.models.Reference import Reference [as 别名]
# 或者: from dipper.models.Reference.Reference import addRefToGraph [as 别名]
def make_association(self, record):
"""
contstruct the association
:param record:
:return: modeled association of genotype to mammalian phenotype
"""
model = Model(self.graph)
record['relation']['id'] = self.resolve("has phenotype")
# define the triple
gene = record['subject']['id']
relation = record['relation']['id']
phenotype = record['object']['id']
# instantiate the association
g2p_assoc = Assoc(self.graph, self.name, sub=gene, obj=phenotype, pred=relation)
# add the references
references = record['evidence']['has_supporting_reference']
# created RGDRef prefix in curie map to route to proper reference URL in RGD
references = [
x.replace('RGD', 'RGDRef') if 'PMID' not in x else x for x in references]
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],
self.globaltt['publication']
)
ref_model.addRefToGraph()
if len(references) > 1:
# create equivalent source for any other refs in list
# This seems to be specific to this source and
# there could be non-equivalent references in this list
for ref in references[1:]:
model.addSameIndividual(sub=references[0], obj=ref)
# add the date created on
g2p_assoc.add_date(date=record['date'])
g2p_assoc.add_evidence(self.resolve(record['evidence']['type'])) # ?set where?
g2p_assoc.add_association_to_graph()
return
示例12: _get_pubs
# 需要导入模块: from dipper.models.Reference import Reference [as 别名]
# 或者: from dipper.models.Reference.Reference import addRefToGraph [as 别名]
def _get_pubs(self, entry, g):
"""
Extract mentioned publications from the reference list
:param entry:
:return:
"""
ref_to_pmid = {}
du = DipperUtil()
entry_num = entry['mimNumber']
gu = GraphUtils(curie_map.get())
if 'referenceList' in entry:
reflist = entry['referenceList']
for r in reflist:
if 'pubmedID' in r['reference']:
pub_id = 'PMID:' + str(r['reference']['pubmedID'])
ref = Reference(pub_id, Reference.ref_types['journal_article'])
else:
# make blank node for internal reference
pub_id = '_OMIM' + str(entry_num) + 'ref' + str(r['reference']['referenceNumber'])
if self.nobnodes:
pub_id = ':' + pub_id
ref = Reference(pub_id)
title = author_list = source = citation = None
if 'title' in r['reference']:
title = r['reference']['title']
ref.setTitle(title)
if 'authors' in r['reference']:
author_list = r['reference']['authors']
ref.setAuthorList(author_list)
citation = re.split('\.\,', author_list)[0] + ' et al'
if 'source' in r['reference']:
source = r['reference']['source']
citation = '; '.join(du.flatten([citation, title, source]))
ref.setShortCitation(citation)
ref.addRefToGraph(g)
ref_to_pmid[r['reference']['referenceNumber']] = pub_id
# add is_about for the pub
omim_id = 'OMIM:'+str(entry_num)
gu.addTriple(g, omim_id, gu.object_properties['mentions'], pub_id)
return ref_to_pmid
示例13: _process_pathway_pubmed
# 需要导入模块: from dipper.models.Reference import Reference [as 别名]
# 或者: from dipper.models.Reference.Reference import addRefToGraph [as 别名]
def _process_pathway_pubmed(self, limit):
"""
Indicate that a pathway is annotated directly to a paper (is about)
via it's pubmed id.
:param limit:
:return:
"""
logger.info("Processing KEGG pathways to pubmed ids")
if self.testMode:
g = self.testgraph
else:
g = self.graph
line_counter = 0
gu = GraphUtils(curie_map.get())
raw = '/'.join((self.rawdir, self.files['pathway_pubmed']['file']))
with open(raw, 'r', encoding="iso-8859-1") as csvfile:
filereader = csv.reader(csvfile, delimiter='\t', quotechar='\"')
for row in filereader:
line_counter += 1
(pubmed_id, kegg_pathway_num) = row
if self.testMode and \
kegg_pathway_num not in self.test_ids['pathway']:
continue
pubmed_id = pubmed_id.upper()
# will look like KEGG-path:map04130
kegg_id = 'KEGG-'+kegg_pathway_num
r = Reference(
pubmed_id, Reference.ref_types['journal_article'])
r.addRefToGraph(g)
gu.addTriple(g, pubmed_id,
GraphUtils.object_properties['is_about'], kegg_id)
if not self.testMode and \
limit is not None and line_counter > limit:
break
return
示例14: _parse_curated_chem_disease
# 需要导入模块: from dipper.models.Reference import Reference [as 别名]
# 或者: from dipper.models.Reference.Reference import addRefToGraph [as 别名]
def _parse_curated_chem_disease(self, limit):
model = Model(self.graph)
line_counter = 0
file_path = '/'.join(
(self.rawdir, self.static_files['publications']['file']))
with open(file_path, 'r') as tsvfile:
reader = csv.reader(tsvfile, delimiter="\t")
for row in reader:
# catch comment lines
if re.match(r'^#', ' '.join(row)):
continue
line_counter += 1
self._check_list_len(row, 10)
(pub_id, disease_label, disease_id, disease_cat, evidence,
chem_label, chem_id, cas_rn, gene_symbol, gene_acc) = row
if disease_id.strip() == '' or chem_id.strip() == '':
continue
rel_id = self.resolve(evidence)
chem_id = 'MESH:' + chem_id
model.addClassToGraph(chem_id, chem_label)
model.addClassToGraph(disease_id, None)
if pub_id != '':
pub_id = 'PMID:' + pub_id
ref = Reference(
self.graph, pub_id, ref_type=self.globaltt['journal article'])
ref.addRefToGraph()
pubids = [pub_id]
else:
pubids = None
self._make_association(chem_id, disease_id, rel_id, pubids)
if not self.test_mode and limit is not None and line_counter >= limit:
break
return
示例15: make_association
# 需要导入模块: from dipper.models.Reference import Reference [as 别名]
# 或者: from dipper.models.Reference.Reference import addRefToGraph [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()
#.........这里部分代码省略.........