def load(bnd_filename, *cfg_filenames, **extra_args): """Loads a network from a MaBoSS format file. :param str bnd_filename: Network file :param str cfg_filename: Configuraton file :keyword str simulation_name: name of the returned :py:class:`.Simulation` object :rtype: :py:class:`.Simulation` """ assert bnd_filename.lower().endswith( ".bnd"), "wrong extension for bnd file" if "://" in bnd_filename: from colomoto_jupyter.io import ensure_localfile bnd_filename = ensure_localfile(bnd_filename) if not cfg_filenames: cfg_filenames = [ ".".join([".".join(bnd_filename.split(".")[:-1]), "cfg"]) ] elif "://" in " ".join(cfg_filenames): from colomoto_jupyter.io import ensure_localfile cfg_filenames = [ ensure_localfile(cfg_filename) if "://" in cfg_filename else cfg_filename for cfg_filename in cfg_filenames ] if extra_args.get("cmaboss"): return CMaBoSSSimulation(bnd_filename, *cfg_filenames) command = extra_args.get("command") with ExitStack() as stack: bnd_file = stack.enter_context(open(bnd_filename, 'r')) bnd_content = bnd_file.read() cfg_content = "" for cfg_filename in tuple(cfg_filenames): cfg_file = stack.enter_context(open(cfg_filename, 'r')) cfg_content += cfg_file.read() (variables, parameters, is_internal_list, istate_list, refstate_list) = _read_cfg(cfg_content) nodes = _read_bnd(bnd_content, is_internal_list) net = Network(nodes) for istate in istate_list: net.set_istate(istate, istate_list[istate]) for v in variables: lhs = '$' + v parameters[lhs] = variables[v] ret = Simulation(net, parameters, command=command) ret.refstate = refstate_list return ret
def loadBNet(bnet_filename): assert bnet_filename.lower().endswith( ".bnet"), "wrong extension for BNet file" if "://" in bnet_filename: from colomoto_jupyter.io import ensure_localfile bnet_filename = ensure_localfile(bnet_filename) from colomoto_jupyter import import_colomoto_tool biolqm = import_colomoto_tool("biolqm") return biolqm.to_maboss(biolqm.load(bnet_filename))
def load(identifier, auto_persistent=True): """ Load a CellCollective model from its URL or SBML export. `identifier` can be: - a URL of the form ``"cellcollective://{model_id}:{model_version}"`` - the model URL from `research.cellcollective.org` - the location of the SBML file exported from CellCollective Whenever `identifier` is one of the two first cases, the module relies on the online API of CellCollective to download the SBML file. As the API may change over time, it is strongly recommended to rely on instead on downloaded SBML files and attach them with the notebook to ensure its repeatibility over time. With the option ``auto_persistent=True``, the module first looks for an existing downloaded SBML file. If it does not exists, it uses the online API to download it and move it alongside the notebook. """ conn = None if isinstance(identifier, CellCollectiveConnector): conn = identifier elif url_matches(identifier): conn = CellCollectiveConnector(identifier) else: from colomoto_jupyter.io import ensure_localfile sbmlfile = ensure_localfile(identifier) if conn: from colomoto_jupyter.io import auto_download urls = conn.sbml_urls bname = conn.sbml_basename if not os.path.isfile(bname) and not auto_persistent: logger.warning(f"""This command relies on the online CellCollective API which may change over time! To improve the repeatibility of this notebook, consider using the command cellcollective.load("{identifier}", auto_persistent=True) and attach the "{bname}" file along with your notebook.""") for i, url in enumerate(urls): try: sbmlfile = auto_download(url, bname) break except HTTPError: if i == len(urls)-1: raise return CellCollectiveSBMLModel(sbmlfile)
def loadSBML(sbml_filename, cfg_filename=None, use_sbml_names=False, cmaboss=False): """Loads a network from a SBML format file. :param str sbml_filename: Network file :param str cfg_filename: Configuraton file :keyword str simulation_name: name of the returned :py:class:`.Simulation` object :rtype: :py:class:`.Simulation` """ assert sbml_filename.lower().endswith(".xml") or sbml_filename.lower().endswith(".sbml") if "://" in sbml_filename: from colomoto_jupyter.io import ensure_localfile sbml_filename = ensure_localfile(sbml_filename) if cmaboss: return SBMLSSimulation(sbml_filename, cfg_filename, use_sbml_names) return sbml_to_maboss(sbml_filename, cfg_filename, use_sbml_names)
def loadBNet(bnet_filename, cfg_filename=None, cmaboss=False): """Loads a network from a MaBoSS format file. :param str bnet_filename: Network file :param str cfg_filename: Configuration file :keyword str simulation_name: name of the returned :py:class:`.Simulation` object :rtype: :py:class:`.Simulation` """ assert bnet_filename.lower().endswith(".bnet"), "wrong extension for BNet file" if "://" in bnet_filename: from colomoto_jupyter.io import ensure_localfile bnet_filename = ensure_localfile(bnet_filename) if cmaboss: return BNetSimulation(bnet_filename, cfg_filename) return bnet_to_maboss(bnet_filename, cfg_filename)
def __init__(self, model, uppfile=None, previous_run=None, nodes_init=None, verbose=False): self.model = model self.uppfile = uppfile self.previous_run = previous_run self.nodes_init = nodes_init self.time_step = float(model.param['max_time']) self.time_shift = 0.0 self.base_ratio = 1.0 self.node_list = list(model.network.keys()) self.division_node = "" self.death_node = "" self.update_var = {} self.nodes_formula = {} self.pop_ratio = 1.0 self.step_number = -1 self.verbose = verbose if previous_run: # Chain the results!! prev_pop_ratios = previous_run.get_population_ratios() self.time_shift = prev_pop_ratios.last_valid_index() self.base_ratio = prev_pop_ratios.iloc[-1] self.model = model.copy() if self.uppfile is not None: if "://" in self.uppfile: from colomoto_jupyter.io import ensure_localfile self.uppfile = ensure_localfile(self.uppfile) self._readUppFile()
def load(model, fixed=None, mcl="", msm="", quiet=False): """ Execute StableMotifs analysis on the given Boolean network model. :param model: either a ``biolqm`` or ``ginsim`` object, or filename/URL of Boolean network in BooleanNet format :keyword dict[str,int] fixed: fix the given nodes to their associated given values :keyword str mcl: Optional threshold in the maximum cycle length (mcl). One must specify both a mcl and msm. :keyword str msm: Optional threshold in the maximum stable motif size (msm). One must specify both a mcl and msm. :keyword bool quiet: If True, skip computation output :rtype: :py:class:`.results.StableMotifsResult` instance """ # prepare temporary working space wd = tempfile.mkdtemp(prefix="StableMotifs-") # cleanup working directory at exit def cleanup(): shutil.rmtree(wd) atexit.register(cleanup) def biolqm_import(biolqm, lqm): if fixed: pert = " ".join((f"{node}%{value}" for node, value in fixed.items())) lqm = biolqm.perturbation(lqm, pert) modelfile = os.path.join(wd, "model.txt") assert biolqm.save(lqm, modelfile, "booleannet"), "Error converting from bioLQM" return modelfile, False is_modelfile = True if isinstance(model, BooleanNetwork): lqm = model.to_biolqm() biolqm = import_colomoto_tool("biolqm") modelfile, is_modelfile = biolqm_import(biolqm, lqm) elif "biolqm" in sys.modules: biolqm = sys.modules["biolqm"] if biolqm.is_biolqm_object(model): modelfile, is_modelfile = biolqm_import(biolqm, model) if is_modelfile and "ginsim" in sys.modules: ginsim = sys.modules["ginsim"] if ginsim.is_ginsim_object(model): model = ginsim.to_biolqm(model) biolqm = import_colomoto_tool("biolqm") modelfile, is_modelfile = biolqm_import(biolqm, model) if is_modelfile: modelfile = ensure_localfile(model) if fixed: biolqm = import_colomoto_tool("biolqm") model = biolqm.load(modelfile, "booleannet") modelfile, is_modelfile = biolqm_import(biolqm, model) else: shutil.copy(modelfile, wd) modelbase = os.path.basename(modelfile) model_name = modelbase.split(".")[0] # invoke StableMotifs argv = ["StableMotifs", modelbase] if mcl and msm: argv += list(map(str, [mcl, msm])) proc = subprocess.Popen(argv, cwd=wd, stdout=subprocess.PIPE, stderr=subprocess.STDOUT) with proc.stdout: for line in iter(proc.stdout.readline, b''): if quiet: continue sys.stdout.write(line) assert proc.wait() == 0, "An error occured while running StableMotifs" # return interface to results return StableMotifsResult(wd, model_name, fixed)
def load(filename, *args): filename = ensure_localfile(filename) obj = japi.lqm.load(filename, *args) assert obj is not None, "Error while loading model" return obj
def load(filename, *args): filename = ensure_localfile(filename) return japi.lqm.load(filename, *args)
def load(celf, filename, **kwargs): f = celf(**kwargs) filename = ensure_localfile(filename) with open(filename) as data: f.import_data(data) return f