Skip to content

Commit

Permalink
[#7] Set initial parameters for each notebook
Browse files Browse the repository at this point in the history
  • Loading branch information
dnwillia23 committed Jun 22, 2023
1 parent e4cf963 commit 3180f06
Show file tree
Hide file tree
Showing 7 changed files with 2,125 additions and 457 deletions.

Large diffs are not rendered by default.

1,792 changes: 1,730 additions & 62 deletions Documentation/HelloRobokop/HelloRobokop_ARA.ipynb

Large diffs are not rendered by default.

37 changes: 22 additions & 15 deletions Documentation/HelloRobokop/HelloRobokop_Compare.ipynb
Original file line number Diff line number Diff line change
@@ -1,15 +1,5 @@
{
"cells": [
{
"cell_type": "markdown",
"id": "ee4a1a5d",
"metadata": {},
"source": [
"The purpose of this notebook is to demonstrate how to make comparisons between different sets of results. This is demonstrated by using results of a test query using TRAPI. The first section, [TRAPI query results](#TRAPI-query-results), is to get a set of data to use for comparisons and place them in the same output directory shown in the cell immediately below. Here, the pathways `Buprenorphine-OPRM1-Asterixis` and `Brixadi-OPRM1-Asterixis` are compared.\n",
"\n",
"The compare_results() function is then demonstrated by taking the results from the query and showing a Venn diagram plot showing the number of edges in common and comparison plot showing missing edges. For this notebook, if a different query is used or a different comparison is to be made, the files being read for comparison must be specified manually."
]
},
{
"cell_type": "code",
"execution_count": 1,
Expand All @@ -25,6 +15,15 @@
}
],
"source": [
"# Parameter inputs\n",
"# Parameters to set\n",
"URL_node_normalizer = 'https://nodenormalization-sri.renci.org/get_normalized_nodes'\n",
"trapi_submit_url = \"http://automat-u24.apps.renci.org/robokopkg/1.3/query\"\n",
"\n",
"def URL_name_resolution_search(search_string):\n",
" return(f'https://name-resolution-sri.renci.org/lookup?string={search_string}&offset=0&limit=10')\n",
"\n",
"# Initializing directory to write\n",
"from datetime import datetime\n",
"from pathlib import Path\n",
"\n",
Expand All @@ -35,6 +34,16 @@
"write_dir.mkdir(parents=True, exist_ok=True)"
]
},
{
"cell_type": "markdown",
"id": "ee4a1a5d",
"metadata": {},
"source": [
"The purpose of this notebook is to demonstrate how to make comparisons between different sets of results. This is demonstrated by using results of a test query using TRAPI. The first section, [TRAPI query results](#TRAPI-query-results), is to get a set of data to use for comparisons and place them in the same output directory shown in the cell immediately below. Here, the pathways `Buprenorphine-OPRM1-Asterixis` and `Brixadi-OPRM1-Asterixis` are compared.\n",
"\n",
"The compare_results() function is then demonstrated by taking the results from the query and showing a Venn diagram plot showing the number of edges in common and comparison plot showing missing edges. For this notebook, if a different query is used or a different comparison is to be made, the files being read for comparison must be specified manually."
]
},
{
"cell_type": "markdown",
"id": "db32caf1",
Expand Down Expand Up @@ -72,8 +81,7 @@
"import pprint\n",
"pp = pprint.PrettyPrinter(indent=5)\n",
"\n",
"search_string = 'Buprenorphine'\n",
"results = requests.post(f'https://name-resolution-sri.renci.org/lookup?string={search_string}&offset=0&limit=10')\n",
"results = requests.post(URL_name_resolution_search('Buprenorphine'))\n",
"results_json = results.json()\n",
"input_node_id_list = list(results_json.keys())\n",
"\n",
Expand All @@ -82,7 +90,7 @@
" \"conflate\": True\n",
"}\n",
"\n",
"results = requests.post('https://nodenormalization-sri.renci.org/get_normalized_nodes',json=nn_query)\n",
"results = requests.post(URL_node_normalizer,json=nn_query)\n",
"\n",
"print(input_node_id_list)"
]
Expand Down Expand Up @@ -136,8 +144,7 @@
" }\n",
" }\n",
"\n",
"robokop_submit_url = \" http://automat-u24.apps.renci.org/robokopkg/1.3/query\"\n",
"response = requests.post(robokop_submit_url,json=query)\n",
"response = requests.post(trapi_submit_url,json=query)\n",
"print(response.status_code)\n",
"number_pathway_results = len(response.json()['message']['results'])\n",
"print(len(response.json()['message']['results']))"
Expand Down
150 changes: 61 additions & 89 deletions Documentation/HelloRobokop/HelloRobokop_ExEmPLAR.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,52 @@
{
"cell_type": "code",
"execution_count": 1,
"id": "325bd4f1-77a6-4476-94da-09cdaf09868b",
"metadata": {},
"outputs": [],
"source": [
"# Parameter inputs\n",
"automat_cypher_submit_url = 'https://automat.renci.org/robokopkg/cypher'\n",
"robokopkg_bolt_url = \"bolt://robokopkg.renci.org:7687\"\n",
"user = 'neo4j'\n",
"pw = ''\n",
"\n",
"# Initializing Neo4j connection class\n",
"from neo4j import GraphDatabase\n",
"class Neo4jConnection:\n",
" \n",
" def __init__(self, uri, user, pwd):\n",
" self.__uri = uri\n",
" self.__user = user\n",
" self.__pwd = pwd\n",
" self.__driver = None\n",
" try:\n",
" self.__driver = GraphDatabase.driver(self.__uri, auth=(self.__user, self.__pwd))\n",
" except Exception as e:\n",
" print(\"Failed to create the driver:\", e)\n",
" \n",
" def close(self):\n",
" if self.__driver is not None:\n",
" self.__driver.close()\n",
" \n",
" def query(self, query, db=None):\n",
" assert self.__driver is not None, \"Driver not initialized!\"\n",
" session = None\n",
" response = None\n",
" try: \n",
" session = self.__driver.session(database=db) if db is not None else self.__driver.session()\n",
" response = list(session.run(query))\n",
" except Exception as e:\n",
" print(\"Query failed:\", e)\n",
" finally: \n",
" if session is not None:\n",
" session.close()\n",
" return response"
]
},
{
"cell_type": "code",
"execution_count": 2,
"id": "e08945f3",
"metadata": {},
"outputs": [],
Expand All @@ -13,7 +59,7 @@
},
{
"cell_type": "code",
"execution_count": 2,
"execution_count": 3,
"id": "766ccb76",
"metadata": {},
"outputs": [],
Expand Down Expand Up @@ -106,7 +152,7 @@
},
{
"cell_type": "code",
"execution_count": 2,
"execution_count": 4,
"id": "20ecf17d-859e-48d2-a975-5673db7afdce",
"metadata": {},
"outputs": [],
Expand All @@ -116,55 +162,23 @@
"WHERE n0_0.name IN ['Buprenorphine'] AND n2_0.name IN ['Tremor'] \n",
"RETURN [startNode(r0_0),[type(r0_0),properties(r0_0)],endNode(r0_0)] as edge_1, \n",
"[startNode(r1_0),[type(r1_0),properties(r1_0)],endNode(r1_0)] as edge_2, \n",
"[n0_0.name, n1_0.name, n2_0.name] as node_names LIMIT 100\"\"\"\n",
"\n",
"from neo4j import GraphDatabase\n",
"class Neo4jConnection:\n",
" \n",
" def __init__(self, uri, user, pwd):\n",
" self.__uri = uri\n",
" self.__user = user\n",
" self.__pwd = pwd\n",
" self.__driver = None\n",
" try:\n",
" self.__driver = GraphDatabase.driver(self.__uri, auth=(self.__user, self.__pwd))\n",
" except Exception as e:\n",
" print(\"Failed to create the driver:\", e)\n",
" \n",
" def close(self):\n",
" if self.__driver is not None:\n",
" self.__driver.close()\n",
" \n",
" def query(self, query, db=None):\n",
" assert self.__driver is not None, \"Driver not initialized!\"\n",
" session = None\n",
" response = None\n",
" try: \n",
" session = self.__driver.session(database=db) if db is not None else self.__driver.session()\n",
" response = list(session.run(query))\n",
" except Exception as e:\n",
" print(\"Query failed:\", e)\n",
" finally: \n",
" if session is not None:\n",
" session.close()\n",
" return response"
"[n0_0.name, n1_0.name, n2_0.name] as node_names LIMIT 100\"\"\""
]
},
{
"cell_type": "code",
"execution_count": 3,
"execution_count": 5,
"id": "11dea391-9f52-4152-9c53-2069ee072a9b",
"metadata": {},
"outputs": [],
"source": [
"pw = ''\n",
"conn = Neo4jConnection(uri=\"bolt://robokopkg.renci.org:7687\", user = 'neo4j', pwd = pw)\n",
"conn = Neo4jConnection(uri=robokopkg_bolt_url, user = user, pwd = pw)\n",
"record_list = conn.query(cypher)"
]
},
{
"cell_type": "code",
"execution_count": 10,
"execution_count": 6,
"id": "25658f6f-f3dc-451a-a72d-748f797f6abd",
"metadata": {},
"outputs": [
Expand Down Expand Up @@ -247,7 +261,7 @@
},
{
"cell_type": "code",
"execution_count": 12,
"execution_count": 7,
"id": "321cf3d9",
"metadata": {},
"outputs": [],
Expand All @@ -257,7 +271,7 @@
},
{
"cell_type": "code",
"execution_count": 13,
"execution_count": 8,
"id": "0a93074e",
"metadata": {},
"outputs": [],
Expand All @@ -268,7 +282,7 @@
},
{
"cell_type": "code",
"execution_count": 14,
"execution_count": 9,
"id": "ef8fd7bb",
"metadata": {},
"outputs": [],
Expand All @@ -277,13 +291,13 @@
"import json\n",
"\n",
"j = {'query': cypher_exemplar}\n",
"results = requests.post('https://automat.renci.org/robokopkg/cypher',json=j)\n",
"results = requests.post(automat_cypher_submit_url,json=j)\n",
"results_json = results.json()"
]
},
{
"cell_type": "code",
"execution_count": 15,
"execution_count": 10,
"id": "00a244da",
"metadata": {},
"outputs": [
Expand Down Expand Up @@ -354,60 +368,18 @@
},
{
"cell_type": "code",
"execution_count": 4,
"id": "0f99b3e8",
"metadata": {
"tags": []
},
"outputs": [],
"source": [
"from neo4j import GraphDatabase\n",
"class Neo4jConnection:\n",
" \n",
" def __init__(self, uri, user, pwd):\n",
" self.__uri = uri\n",
" self.__user = user\n",
" self.__pwd = pwd\n",
" self.__driver = None\n",
" try:\n",
" self.__driver = GraphDatabase.driver(self.__uri, auth=(self.__user, self.__pwd))\n",
" except Exception as e:\n",
" print(\"Failed to create the driver:\", e)\n",
" \n",
" def close(self):\n",
" if self.__driver is not None:\n",
" self.__driver.close()\n",
" \n",
" def query(self, query, db=None):\n",
" assert self.__driver is not None, \"Driver not initialized!\"\n",
" session = None\n",
" response = None\n",
" try: \n",
" session = self.__driver.session(database=db) if db is not None else self.__driver.session()\n",
" response = list(session.run(query))\n",
" except Exception as e:\n",
" print(\"Query failed:\", e)\n",
" finally: \n",
" if session is not None:\n",
" session.close()\n",
" return response"
]
},
{
"cell_type": "code",
"execution_count": 16,
"execution_count": 14,
"id": "96f112df",
"metadata": {},
"outputs": [],
"source": [
"pw = ''\n",
"conn = Neo4jConnection(uri=\"bolt://robokopkg.renci.org:7687\", user = 'neo4j', pwd = pw)\n",
"conn = Neo4jConnection(uri=robokopkg_bolt_url, user = user, pwd = pw)\n",
"record_list = conn.query(cypher_exemplar)"
]
},
{
"cell_type": "code",
"execution_count": 17,
"execution_count": 16,
"id": "88c90280",
"metadata": {
"tags": []
Expand Down Expand Up @@ -466,7 +438,7 @@
" print(f\"Result {i}:\")\n",
" for label, data in record_data.items():\n",
" if 'r' in label:\n",
" print(f\"{data[0]['name']} - {data[1][0]} - {data[2]['name']}\")\n",
" print(f\"{data[0]['name']} - {data[1]} - {data[2]['name']}\")\n",
" print()"
]
},
Expand Down
Loading

0 comments on commit 3180f06

Please sign in to comment.