<jupyter_start><jupyter_text>Export Hetionet v1.0 to an xarray.Dataset<jupyter_code>import os
import pickle
import gzip

import hetio.readwrite

from hetmech.xarray import graph_to_xarray<jupyter_output><empty_output><jupyter_text>Load Hetionet v1.0<jupyter_code>url = 'https://github.com/dhimmel/hetionet/raw/76550e6c93fbe92124edc71725e8c7dd4ca8b1f5/hetnet/json/hetionet-v1.0.json.bz2'
graph = hetio.readwrite.read_graph(url)
metagraph = graph.metagraph<jupyter_output><empty_output><jupyter_text>Create xarray.Dataset<jupyter_code>dataset = graph_to_xarray(graph)
dataset
dataset['Biological Process']
dataset['Gr>G']
dataset.Gene
# Density of each metaedge
dataset.mean()<jupyter_output><empty_output><jupyter_text>Dataset IO<jupyter_code># netcdf file was humongous. Avoid!
# dataset.to_netcdf('xarray_dataset.nc')
path = os.path.join('data', 'xarray_dataset.pkl.gz')
# Save as pickle
with gzip.open(path, 'wb') as write_file:
    pickle.dump(dataset, write_file, protocol=pickle.HIGHEST_PROTOCOL)
# Read pickle
with gzip.open(path) as read_file:
    dataset = pickle.load(read_file)<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.11459265890778872, 'fraction_numerical': 0.02775290957923008, 'mean_word_length': 8.163934426229508, 'pattern_counts': {'":': 0, '<': 17, '<?xml version=': 0, '>': 18, 'https://': 1, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '4', 'dir': 'jupyter-structured-clean-dedup', 'id': '451637', 'license': 'BSD-3-Clause', 'n_tokens_mistral': 456, 'n_tokens_neox': 446, 'n_words': 65, 'path': '2.xarray.ipynb', 'repo_name': 'gwaygenomics/hetmech', 'size': '1117'}