-
Notifications
You must be signed in to change notification settings - Fork 10
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
EVA-3732 - New script to help find children that match the definition of a new term #452
base: master
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change | ||||||
---|---|---|---|---|---|---|---|---|
@@ -0,0 +1,56 @@ | ||||||||
import argparse | ||||||||
|
||||||||
from cmat.clinvar_xml_io.ontology_uri import OntologyUri | ||||||||
from cmat.trait_mapping.ols import build_ols_query | ||||||||
from cmat.trait_mapping.utils import json_request | ||||||||
|
||||||||
def append_embedded(results, json_response): | ||||||||
if json_response and '_embedded' in json_response: | ||||||||
for key in json_response['_embedded']: | ||||||||
if key not in results: | ||||||||
results[key] = [] | ||||||||
results[key].extend(json_response['_embedded'][key]) | ||||||||
|
||||||||
def query_and_depaginate(url): | ||||||||
json_response = json_request(url) | ||||||||
results = {} | ||||||||
append_embedded(results, json_response) | ||||||||
while 'next' in json_response['_links']: | ||||||||
json_response = json_request(json_response['_links']['next']['href']) | ||||||||
append_embedded(results, json_response) | ||||||||
return results | ||||||||
|
||||||||
def search_in(keywords, text): | ||||||||
return set((keyword for keyword in keywords if keyword in text)) | ||||||||
|
||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
& same elsewhere |
||||||||
def main(): | ||||||||
parser = argparse.ArgumentParser('Search OLS for children of a term that match certain keywords in their label, description or synonyms') | ||||||||
parser.add_argument('--ontology', type=str, default='MONDO', help='Name of the Ontology to find the parent and children') | ||||||||
parser.add_argument('--parent_curie', type=str, help='Curie of the parent term', required=True) | ||||||||
parser.add_argument('--keywords', type=str, nargs='+', help="Words that must be present in the child's ontology label, description or synonyms to be reported") | ||||||||
|
||||||||
args = parser.parse_args() | ||||||||
|
||||||||
|
||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||||
keywords = set(args.keywords) | ||||||||
db = args.ontology | ||||||||
parent_curie = args.parent_curie | ||||||||
url = build_ols_query(OntologyUri(parent_curie, db).uri) | ||||||||
results = query_and_depaginate(url) | ||||||||
for term in results['terms']: | ||||||||
if term['ontology_prefix'] == db: | ||||||||
results2 = query_and_depaginate(term['_links']['children']['href']) | ||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Could maybe call this |
||||||||
for term in results2['terms']: | ||||||||
if term['ontology_prefix'] == db: | ||||||||
keyword_found = set() | ||||||||
keyword_found.update(search_in(keywords, term['label'])) | ||||||||
keyword_found.update(search_in(keywords, term['description'])) | ||||||||
for synonym in term['synonyms']: | ||||||||
keyword_found.update(search_in(keywords, synonym)) | ||||||||
if keyword_found == keywords: | ||||||||
print(term['iri'], term['label']) | ||||||||
|
||||||||
|
||||||||
if __name__ == '__main__': | ||||||||
main() | ||||||||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Could be a
defaultdict(list)