Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
def make_ontology_from_local_file(file_name: str):
print("Creating ontology from file: " + file_name)
return ontobio.ontol_factory.OntologyFactory().create(file_name)
cp = subprocess.run(['owltools', file_name, '-o', '-f', 'json', temp_file_name])
# robot commented out because it is giving a NullPointerException on umls_semantictypes.owl
# cp = subprocess.run(['robot', 'convert', '--input', file_name, '--output', temp_file_name])
if cp.stdout is not None:
log_message(message="OWL convert result: " + cp.stdout, ontology_name=None, output_stream=sys.stdout)
if cp.stderr is not None:
log_message(message="OWL convert result: " + cp.stderr, ontology_name=None, output_stream=sys.stderr)
assert cp.returncode == 0
json_file = file_name_without_ext + ".json"
shutil.move(temp_file_name, json_file)
size = os.path.getsize(json_file)
log_message(message="Reading ontology JSON file: " + json_file + "; size: " + "{0:.2f}".format(size/1024) + " KiB",
ontology_name=None)
# if not USE_ONTOBIO_JSON_CACHE:
# delete_ontobio_cache_json(file_name)
ont_return = ontobio.ontol_factory.OntologyFactory().create(json_file, ignore_cache=True)
else:
size = os.path.getsize(file_name_with_pickle_ext)
log_message("Reading ontology file: " + file_name_with_pickle_ext + "; size: " + "{0:.2f}".format(size/1024) + " KiB", ontology_name=None)
ont_return = pickle.load(open(file_name_with_pickle_ext, "rb"))
return ont_return
# Once robot no longer gives a NullPointerException, we can use it like this:
# cp = subprocess.run(['robot', 'convert', '--input', file_name, '--output', temp_file_name])
if cp.stdout is not None:
kg2_util.log_message(message="OWL convert result: " + cp.stdout, ontology_name=None, output_stream=sys.stdout)
if cp.stderr is not None:
kg2_util.log_message(message="OWL convert result: " + cp.stderr, ontology_name=None, output_stream=sys.stderr)
assert cp.returncode == 0
json_file = file_name_without_ext + ".json"
shutil.move(temp_file_name, json_file)
else:
json_file = file_name
size = os.path.getsize(json_file)
kg2_util.log_message(message="Reading ontology JSON file: " + json_file + "; size: " + "{0:.2f}".format(size/1024) + " KiB",
ontology_name=None)
ont_return = ontobio.ontol_factory.OntologyFactory().create(json_file, ignore_cache=True)
else:
size = os.path.getsize(file_name_with_pickle_ext)
kg2_util.log_message("Reading ontology file: " + file_name_with_pickle_ext + "; size: " + "{0:.2f}".format(size/1024) + " KiB", ontology_name=None)
ont_return = pickle.load(open(file_name_with_pickle_ext, "rb"))
return ont_return
# Once robot no longer gives a NullPointerException, we can use it like this:
# cp = subprocess.run(['robot', 'convert', '--input', file_name, '--output', temp_file_name])
if cp.stdout is not None:
kg2_util.log_message(message="OWL convert result: " + cp.stdout, ontology_name=None, output_stream=sys.stdout)
if cp.stderr is not None:
kg2_util.log_message(message="OWL convert result: " + cp.stderr, ontology_name=None, output_stream=sys.stderr)
assert cp.returncode == 0
json_file = file_name_without_ext + ".json"
shutil.move(temp_file_name, json_file)
else:
json_file = file_name
size = os.path.getsize(json_file)
kg2_util.log_message(message="Reading ontology JSON file: " + json_file + "; size: " + "{0:.2f}".format(size/1024) + " KiB",
ontology_name=None)
ont_return = ontobio.ontol_factory.OntologyFactory().create(json_file, ignore_cache=True)
else:
size = os.path.getsize(file_name_with_pickle_ext)
kg2_util.log_message("Reading ontology file: " + file_name_with_pickle_ext + "; size: " + "{0:.2f}".format(size/1024) + " KiB", ontology_name=None)
ont_return = pickle.load(open(file_name_with_pickle_ext, "rb"))
return ont_return
def get_nodes_dict_from_ontology_dict(ont_dict: dict,
map_curie_to_biolink_category: dict,
category_label_to_iri_mapper: callable):
ontology = ont_dict['ontology']
assert type(ontology) == ontobio.ontol.Ontology
ontology_iri = ont_dict['id']
assert ontology_iri.startswith('http:')
ontology_curie_id = shorten_iri_to_curie(ontology_iri)
ret_dict = {ontology_curie_id: {
'id': ontology_curie_id,
'iri': ontology_iri,
'full name': ont_dict['title'],
'name': ont_dict['title'],
'category': category_label_to_iri_mapper('data source'),
'category label': 'data source',
'description': ont_dict['description'],
'synonyms': None,
'xrefs': None,
'creation date': None,
'update date': ont_dict['file last modified timestamp'],