-
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.
Merge pull request #367 from nanglo123/add_graph_to_docker
Add obo pickled graphs to docker build
- Loading branch information
Showing
3 changed files
with
45 additions
and
20 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
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,34 @@ | ||
from pyobo.api.utils import get_version | ||
from pyobo.getters import _ensure_ontology_path | ||
from pyobo.utils.path import prefix_directory_join | ||
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 = prefix_directory_join(resource_prefix, | ||
name="relabeled_obo_graph.pkl", | ||
version=version) | ||
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) | ||
|
||
# Normalize node indices | ||
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() |