-
Notifications
You must be signed in to change notification settings - Fork 1
/
baseutil.py
executable file
·68 lines (61 loc) · 2.68 KB
/
baseutil.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
56
57
58
59
60
61
62
63
64
65
66
67
68
import platform
import sys
import sys
import json
from json import dump
import os
import re
from os.path import exists
from pathlib import Path
import logging
import shutil
print("python version " + platform.python_version())
from configparser import ConfigParser
logger = logging.getLogger(__name__)
logger.setLevel(logging.INFO)
config = ConfigParser()
if not exists(str(Path.home()) + '/.kbase/config'):
if exists("/scratch/shared/code/sharedconfig.cfg"):
shutil.copyfile("/scratch/shared/code/sharedconfig.cfg",str(Path.home()) + '/.kbase/config')
else:
print("You much create a config file in ~/.kbase/config before running this notebook. See instructions: https://docs.google.com/document/d/1fQ6iS_uaaZKbjWtw1MgzqilklttIibNO9XIIJWgxWKo/edit")
sys.exit(1)
config.read(str(Path.home()) + '/.kbase/config')
paths = config.get("DevEnv","syspaths").split(";")
codebase = config.get("DevEnv","codebase",fallback="")
for i,filepath in enumerate(paths):
if filepath[0:1] != "/":
paths[i] = codebase+"/"+filepath
sys.path = paths + sys.path
from chenry_utility_module.kbdevutils import KBDevUtils
class BaseUtil(KBDevUtils):
def __init__(self,name):
KBDevUtils.__init__(self,name,output_root=os.path.dirname(os.path.realpath(__file__)))
self.kbdevutil = self
self.annoapi = self.anno_client(native_python_api=True)
self.obs_ec = None
#self.media={"auxo":self.msrecon.get_media("94026/Auxotrophy_media")}
self.msrecon.util = self
def simulate_biolog_phenotypes(
self,
model,
objective="bio1",
phenotypeset="157564/Full_Biolog_Dataset",
base_media="auxo",
base_uptake=100,
base_excretion=1000,
global_atom_limits={"C":1},
add_missing_exchanges=True,
save_fluxes=False,
save_reaction_list=False,
ignore_experimental_data=False,
flux_coefficients=None,
recall_phenotypes=True):
if base_media and type(base_media) == str:
base_media = self.media[base_media]
if type(phenotypeset) == str:
phenotypeset = self.msrecon.get_phenotypeset(phenotypeset, base_media=base_media, base_uptake=base_uptake, base_excretion=base_excretion, global_atom_limits=global_atom_limits)
model.model.objective = objective
output = phenotypeset.simulate_phenotypes(model,multiplier=3,add_missing_exchanges=add_missing_exchanges,save_fluxes=save_fluxes,save_reaction_list=save_reaction_list,ignore_experimental_data=ignore_experimental_data,flux_coefficients=flux_coefficients)
output["phenotypeset"] = phenotypeset
return output