forked from INM-6/human-multi-area-model
-
Notifications
You must be signed in to change notification settings - Fork 0
/
snakemake_network.py
55 lines (45 loc) · 1.63 KB
/
snakemake_network.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
"""
Helper script that creates the network using an `experiment.py` file,
dumps the network and writes the network hash to a network_hash file.
Mainly evoked by snakemake
"""
import os
import sys
import importlib.util
from helpers.snakemake import nested_dict_update, get_git_revision_hash
from default_net_params import params as net_params
from data_preprocessing.cytoarchitecture import NeuronNumbers
from data_preprocessing.connectivity import SynapseNumbers
from network import Network
# Load script from specified path sys.argv[1] (snakemake {input})
# Does nothing else than `import path/to/script as exp` would do
conf_name, _ = os.path.splitext(os.path.basename(sys.argv[1]))
conf_path = os.path.join(os.getcwd(), sys.argv[1])
spec = importlib.util.spec_from_file_location(conf_name, conf_path)
exp = importlib.util.module_from_spec(spec)
spec.loader.exec_module(exp)
# Update default parameters with parameters specified in exp
nested_dict_update(net_params, exp.net_params)
outpath = net_params['outpath']
# Create Network class
NN = NeuronNumbers(
surface_area=net_params['surface_area'],
**net_params['cytoarchitecture_params']
)
SN = SynapseNumbers(
NN=NN,
**net_params['predictive_connectomic_params']
)
net = Network(NN, SN, net_params)
# Export the network
net.dump(outpath)
# Save the network hash
hash_file = sys.argv[2]
hash_fn = os.path.join(os.getcwd(), hash_file)
with open(hash_fn, 'w') as f:
f.write(net.getHash())
# Save the humam repository hash
net_folder = os.path.join(outpath, net.getHash())
git_fn = os.path.join(net_folder, "git_hash.txt")
with open(git_fn, 'w') as f:
f.write(get_git_revision_hash())