-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Create script to generate ncbitaxon obo graph and add it to mira dock…
…er image
- Loading branch information
Showing
2 changed files
with
41 additions
and
0 deletions.
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
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,26 @@ | ||
from pyobo import get_version | ||
from pyobo.getters import _ensure_ontology_path | ||
from pathlib import Path | ||
from obonet import read_obo | ||
import networkx | ||
import pickle | ||
|
||
def download_convert_ncbitaxon_obo_to_graph(): | ||
resource_prefix = "ncbitaxon" | ||
version = get_version(resource_prefix) | ||
|
||
# Checks to see if the pickled ncbitaxon obo graph exists in the container | ||
cached_relabeled_obo_graph_path = Path("/graphs/relabeled_obo_graph.pkl") | ||
if not cached_relabeled_obo_graph_path.exists(): | ||
_, obo_path = _ensure_ontology_path(resource_prefix, force=False, | ||
version=version) | ||
obo_graph = read_obo(obo_path) | ||
relabeled_graph = networkx.relabel_nodes(obo_graph, | ||
lambda node_index: | ||
node_index.lower()) | ||
with open(cached_relabeled_obo_graph_path, | ||
'wb') as relabeled_graph_file: | ||
pickle.dump(relabeled_graph, relabeled_graph_file) | ||
|
||
if __name__ == "__main__": | ||
download_convert_ncbitaxon_obo_to_graph() |