In [24]:
from dipper.graph.StreamedGraph import StreamedGraph
from dipper.graph.RDFGraph import RDFGraph
from dipper.models.Model import Model
from dipper.models.assoc.Association import Assoc as Association
import pandas as pd
columns = ['variant', 'variant_label', 'variant_type',
'phenotype','relation', 'source', 'evidence', 'dbxref']
data = [
['ClinVarVariant:254143', 'C326F', 'SO:0000694',
'HP:0000748','RO:0002200', 'PMID:12503095', 'ECO:0000220',
'dbSNP:886037891']
]
# Initialize graph, here we demo the RDFGraph
# which is a subclass of RDFLib.graph()
graph = RDFGraph()
# Our model class writes to the graph and takes
# a graph object as it's only instance variable
model = Model(graph)
# Create a pandas dataframe
dataframe = pd.DataFrame(data=data, columns=columns)
for index, row in dataframe.iterrows():
# Add the triple ClinVarVariant:254143 RO:0002200 HP:0000504
# RO:0002200 is the has_phenotype relation
# HP:0000748 is the phenotype 'Inappropriate laughter', haha
model.addTriple(row['variant'], row['relation'], row['phenotype'])
# The addLabel method adds a label using the rdfs:label relation
model.addLabel(row['variant'], row['variant_label'])
# addType makes the variant an individual of a class,
# in this case SO:0000694 'SNP'
model.addType(row['variant'], row['variant_type'])
# addXref uses the relation OIO:hasDbXref
model.addXref(row['variant'], row['dbxref'])
# Serialize the graph as turtle
print(graph.serialize(format='turtle').decode("utf-8"))
In [25]:
# Add source (publication) and evidence (ECO code) to association
association = Association(graph, 'test_source',
row['variant'], row['phenotype'],
row['relation'])
association.add_source(row['source'])
association.add_evidence(row['evidence'])
# Let's inspect the association object
association.__dict__
Out[25]:
In [27]:
# After the association object is composed, add it to the RDF graph
# This generates an association ID by hashing its attributes (if not manually set),
# and writes triples to the rdf graph, linking the subject, predicate, and object
# using the OBAN reification model - https://github.com/EBISPOT/OBAN
association.add_association_to_graph()
# Serialize the graph. When using RDFGraphs, see
# http://rdflib.readthedocs.io/en/stable/apidocs/rdflib.html#rdflib.graph.Graph.serialize
# for a list of serialization options
print(graph.serialize(format='turtle').decode("utf-8"))
In [28]:
# as xml
print(graph.serialize(format='pretty-xml').decode("utf-8"))