-
Notifications
You must be signed in to change notification settings - Fork 14
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #12 from rurimatsuri3/master
an example from Riken database
- Loading branch information
Showing
6 changed files
with
64,919 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
157 changes: 157 additions & 0 deletions
157
use-cases/yoko/.ipynb_checkpoints/play_with_allen-checkpoint.ipynb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,157 @@ | ||
{ | ||
"cells": [ | ||
{ | ||
"cell_type": "code", | ||
"execution_count": 1, | ||
"metadata": { | ||
"collapsed": false | ||
}, | ||
"outputs": [], | ||
"source": [ | ||
"import rdflib" | ||
] | ||
}, | ||
{ | ||
"cell_type": "code", | ||
"execution_count": 2, | ||
"metadata": { | ||
"collapsed": false | ||
}, | ||
"outputs": [], | ||
"source": [ | ||
"g=rdflib.Graph()\n", | ||
"g.parse('rikenbrc_mouse-6-Gene_Turtle.ttl',format='turtle')\n", | ||
"query=\"\"\"\n", | ||
"PREFIX riken: <http://metadb.riken.jp/db>\n", | ||
"SELECT DISTINCT *\n", | ||
"WHERE \n", | ||
"{ ?s ?p ?o .\n", | ||
"}\n", | ||
"\"\"\"\n", | ||
"\n", | ||
"# print every triplet\n", | ||
"#for e in g.query(query):\n", | ||
"# print e" | ||
] | ||
}, | ||
{ | ||
"cell_type": "markdown", | ||
"metadata": {}, | ||
"source": [ | ||
"### this is a simple query" | ||
] | ||
}, | ||
{ | ||
"cell_type": "code", | ||
"execution_count": 3, | ||
"metadata": { | ||
"collapsed": false, | ||
"scrolled": true | ||
}, | ||
"outputs": [ | ||
{ | ||
"name": "stdout", | ||
"output_type": "stream", | ||
"text": [ | ||
"(rdflib.term.Literal(u'http://www.informatics.jax.org/marker/MGI:97371', datatype=rdflib.term.URIRef(u'http://www.w3.org/2001/XMLSchema#anyURI')),)\n" | ||
] | ||
} | ||
], | ||
"source": [ | ||
"query=\"\"\"\n", | ||
"PREFIX riken: <http://metadb.riken.jp/db>\n", | ||
"SELECT DISTINCT ?url\n", | ||
"WHERE \n", | ||
"{ ?s a <http://metadb.riken.jp/db/rikenbrc_mouse/animal_0000006> .\n", | ||
" ?s <http://www.w3.org/2004/02/skos/core#altLabel> \"Npr1\"^^<http://www.w3.org/2001/XMLSchema#string> .\n", | ||
" ?s <http://metadb.riken.jp/db/brc_beta/brc_0000037> ?url .\n", | ||
"}\n", | ||
"\"\"\"\n", | ||
"for e in g.query(query):\n", | ||
" print e" | ||
] | ||
}, | ||
{ | ||
"cell_type": "code", | ||
"execution_count": 4, | ||
"metadata": { | ||
"collapsed": false | ||
}, | ||
"outputs": [], | ||
"source": [ | ||
"def get_url(gene_name):\n", | ||
" \"\"\"\n", | ||
" constr8uct query with name of gene \n", | ||
" \n", | ||
" parameter: \n", | ||
" ----------\n", | ||
" gene_name: String, \n", | ||
" the name of the gene\n", | ||
" \"\"\"\n", | ||
" \n", | ||
" prefix = \"PREFIX riken: <http://metadb.riken.jp/db>\"\n", | ||
" \n", | ||
" query=\"\"\"\n", | ||
"SELECT DISTINCT ?url\n", | ||
"WHERE \n", | ||
"{ ?s a <http://metadb.riken.jp/db/rikenbrc_mouse/animal_0000006> .\n", | ||
" ?s <http://www.w3.org/2004/02/skos/core#altLabel> \"%s\"^^<http://www.w3.org/2001/XMLSchema#string> .\n", | ||
" ?s <http://metadb.riken.jp/db/brc_beta/brc_0000037> ?url .\n", | ||
"}\n", | ||
"\"\"\"%gene_name\n", | ||
" \n", | ||
" # print prefix + query\n", | ||
" return g.query(prefix + query)\n", | ||
" \n", | ||
" " | ||
] | ||
}, | ||
{ | ||
"cell_type": "code", | ||
"execution_count": 5, | ||
"metadata": { | ||
"collapsed": false | ||
}, | ||
"outputs": [ | ||
{ | ||
"name": "stdout", | ||
"output_type": "stream", | ||
"text": [ | ||
"e is : (rdflib.term.Literal(u'http://www.informatics.jax.org/marker/MGI:1922151', datatype=rdflib.term.URIRef(u'http://www.w3.org/2001/XMLSchema#anyURI')),)\n", | ||
"<class 'rdflib.term.Literal'> <class 'rdflib.query.ResultRow'>\n", | ||
"dir e[0] is : ['__abs__', '__add__', '__class__', '__contains__', '__delattr__', '__doc__', '__eq__', '__format__', '__ge__', '__getattribute__', '__getitem__', '__getnewargs__', '__getslice__', '__getstate__', '__gt__', '__hash__', '__init__', '__invert__', '__le__', '__len__', '__lt__', '__mod__', '__module__', '__mul__', '__ne__', '__neg__', '__new__', '__nonzero__', '__pos__', '__reduce__', '__reduce_ex__', '__repr__', '__rmod__', '__rmul__', '__setattr__', '__setstate__', '__sizeof__', '__slots__', '__str__', '__subclasshook__', '_comparable_to', '_datatype', '_formatter_field_name_split', '_formatter_parser', '_language', '_literal_n3', '_quote_encode', '_value', 'capitalize', 'center', 'count', 'datatype', 'decode', 'encode', 'endswith', 'eq', 'expandtabs', 'find', 'format', 'index', 'isalnum', 'isalpha', 'isdecimal', 'isdigit', 'islower', 'isnumeric', 'isspace', 'istitle', 'isupper', 'join', 'language', 'ljust', 'lower', 'lstrip', 'md5_term_hash', 'n3', 'neq', 'normalize', 'partition', 'replace', 'rfind', 'rindex', 'rjust', 'rpartition', 'rsplit', 'rstrip', 'split', 'splitlines', 'startswith', 'strip', 'swapcase', 'title', 'toPython', 'translate', 'upper', 'value', 'zfill']\n", | ||
"http://www.informatics.jax.org/marker/MGI:1922151\n" | ||
] | ||
} | ||
], | ||
"source": [ | ||
"for e in get_url(\"Kbtbd11\"):\n", | ||
" print \"e is :\", e\n", | ||
" print type(e[0]), type(e)\n", | ||
" print \"dir e[0] is :\", dir(e[0])\n", | ||
" print e[0]" | ||
] | ||
} | ||
], | ||
"metadata": { | ||
"kernelspec": { | ||
"display_name": "Python 2", | ||
"language": "python", | ||
"name": "python2" | ||
}, | ||
"language_info": { | ||
"codemirror_mode": { | ||
"name": "ipython", | ||
"version": 2 | ||
}, | ||
"file_extension": ".py", | ||
"mimetype": "text/x-python", | ||
"name": "python", | ||
"nbconvert_exporter": "python", | ||
"pygments_lexer": "ipython2", | ||
"version": "2.7.10" | ||
} | ||
}, | ||
"nbformat": 4, | ||
"nbformat_minor": 0 | ||
} |
Oops, something went wrong.