Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add triples converter #279

Draft
wants to merge 14 commits into
base: main
Choose a base branch
from
5 changes: 5 additions & 0 deletions my_experiments/ibd_literature/test.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
Subject Predicate Object
inflammatory bowel disease pro-inflammatory cytokine production
ulcerative colitis to arachidonic acid metabolic process
ulcerative colitis relieving inflammatory response
ulcerative colitis and inflammatory response
40 changes: 40 additions & 0 deletions output_parser_yaml.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
import yaml
from yaml import CLoader as Loader
from oaklib import get_adapter

NULL_VALS = ['', 'Not mentioned', 'none mentioned', 'Not mentioned in the text',
'Not mentioned in the provided text.', 'No exposures mentioned in the text.',
'None', 'N/A', 'No exposures mentioned in the text.', 'None mentioned in the text',
'Not mentioned in the text.', 'None relevant', 'None mentioned in the text.',
'No gene to molecular activity relationships mentioned in the text.',
'No genes mentioned', 'No genes mentioned in the text.', 'NA', '-',
'None mentioned']
output_file = "experiments/ibd_literature/output_2000_1122.yaml"

def filter_dictionary(input_dict, filter_keys):
filtered_dict = {key: value for key, value in input_dict.items() if key in filter_keys}
return filtered_dict

with open(output_file, 'r') as file:
filtered_data = []
for doc in yaml.safe_load_all(file):
try:
for dict in doc["extracted_object"]["disease_cellular_process_relationships"]:
filtered_data.append(filter_dictionary(dict, ["subject", "predicate", "object"]))
except:
continue

for entry in filtered_data:
if (len(entry) == 3 and
entry["subject"] not in NULL_VALS and
entry["predicate"] not in NULL_VALS and
entry["object"] not in NULL_VALS):
if (entry["subject"].startswith("MONDO:") and
entry["object"].startswith("GO:")):
entry["subject"] = get_adapter("sqlite:obo:MONDO").label(entry["subject"])
# if entry["predicate"].startswith("RO:"):
# entry["predicate"] = get_adapter("sqlite:obo:RO").label(entry["predicate"])
entry["object"] = get_adapter("sqlite:obo:GO").label(entry["object"])
if entry["predicate"].startswith("RO:"):
entry["predicate"] = get_adapter("sqlite:obo:RO").label(entry["predicate"])
print(entry)
Loading