Skip to content

Commit

Permalink
rename physical data
Browse files Browse the repository at this point in the history
  • Loading branch information
olive004 committed Oct 17, 2024
1 parent 56a5c81 commit 344ecd7
Show file tree
Hide file tree
Showing 15 changed files with 67 additions and 60 deletions.
2 changes: 1 addition & 1 deletion explanations/1_rna_circuit_simulations.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -387,7 +387,7 @@
"File \u001b[0;32m~/Kode/synbio_morpher/synbio_morpher/utils/circuit/agnostic_circuits/circuit_manager.py:751\u001b[0m, in \u001b[0;36mCircuitModeller.apply_to_circuit\u001b[0;34m(self, circuit, methods)\u001b[0m\n\u001b[1;32m 749\u001b[0m \u001b[39mfor\u001b[39;00m method, kwargs \u001b[39min\u001b[39;00m methods\u001b[39m.\u001b[39mitems():\n\u001b[1;32m 750\u001b[0m \u001b[39mif\u001b[39;00m \u001b[39mhasattr\u001b[39m(\u001b[39mself\u001b[39m, method):\n\u001b[0;32m--> 751\u001b[0m circuit \u001b[39m=\u001b[39m \u001b[39mgetattr\u001b[39;49m(\u001b[39mself\u001b[39;49m, method)(circuit, \u001b[39m*\u001b[39;49m\u001b[39m*\u001b[39;49mkwargs)\n\u001b[1;32m 752\u001b[0m \u001b[39melse\u001b[39;00m:\n\u001b[1;32m 753\u001b[0m logging\u001b[39m.\u001b[39mwarning(\n\u001b[1;32m 754\u001b[0m \u001b[39mf\u001b[39m\u001b[39m'\u001b[39m\u001b[39mCould not find method @\u001b[39m\u001b[39m{\u001b[39;00mmethod\u001b[39m}\u001b[39;00m\u001b[39m in class \u001b[39m\u001b[39m{\u001b[39;00m\u001b[39mself\u001b[39m\u001b[39m}\u001b[39;00m\u001b[39m'\u001b[39m)\n",
"File \u001b[0;32m~/Kode/synbio_morpher/synbio_morpher/utils/circuit/agnostic_circuits/circuit_manager.py:119\u001b[0m, in \u001b[0;36mCircuitModeller.compute_interactions\u001b[0;34m(self, circuit)\u001b[0m\n\u001b[1;32m 118\u001b[0m \u001b[39mdef\u001b[39;00m \u001b[39mcompute_interactions\u001b[39m(\u001b[39mself\u001b[39m, circuit: Circuit):\n\u001b[0;32m--> 119\u001b[0m circuit \u001b[39m=\u001b[39m \u001b[39mself\u001b[39;49m\u001b[39m.\u001b[39;49mcompute_interactions_core(circuit)\n\u001b[1;32m 121\u001b[0m circuit\u001b[39m.\u001b[39minteractions\u001b[39m.\u001b[39mbinding_rates_association \u001b[39m=\u001b[39m circuit\u001b[39m.\u001b[39minteractions\u001b[39m.\u001b[39mbinding_rates_association \u001b[39m*\u001b[39m \\\n\u001b[1;32m 122\u001b[0m \u001b[39mself\u001b[39m\u001b[39m.\u001b[39minteraction_factor\n\u001b[1;32m 123\u001b[0m circuit\u001b[39m.\u001b[39minteractions\u001b[39m.\u001b[39mbinding_rates_dissociation \u001b[39m=\u001b[39m circuit\u001b[39m.\u001b[39minteractions\u001b[39m.\u001b[39mbinding_rates_dissociation \u001b[39m*\u001b[39m \\\n\u001b[1;32m 124\u001b[0m \u001b[39mself\u001b[39m\u001b[39m.\u001b[39minteraction_factor\n",
"File \u001b[0;32m~/Kode/synbio_morpher/synbio_morpher/utils/circuit/agnostic_circuits/circuit_manager.py:102\u001b[0m, in \u001b[0;36mCircuitModeller.compute_interactions_core\u001b[0;34m(self, circuit)\u001b[0m\n\u001b[1;32m 99\u001b[0m input_species \u001b[39m=\u001b[39m circuit\u001b[39m.\u001b[39mget_input_species()\n\u001b[1;32m 100\u001b[0m reactant_species \u001b[39m=\u001b[39m [\n\u001b[1;32m 101\u001b[0m r\u001b[39m.\u001b[39mspecies \u001b[39mfor\u001b[39;00m r \u001b[39min\u001b[39;00m circuit\u001b[39m.\u001b[39mqreactions\u001b[39m.\u001b[39mreactants]\n\u001b[0;32m--> 102\u001b[0m interactions \u001b[39m=\u001b[39m \u001b[39mself\u001b[39;49m\u001b[39m.\u001b[39;49mrun_interaction_simulator(\n\u001b[1;32m 103\u001b[0m species\u001b[39m=\u001b[39;49minput_species,\n\u001b[1;32m 104\u001b[0m filename\u001b[39m=\u001b[39;49mfilename,\n\u001b[1;32m 105\u001b[0m quantities\u001b[39m=\u001b[39;49m[circuit\u001b[39m.\u001b[39;49mqreactions\u001b[39m.\u001b[39;49mreactants[reactant_species\u001b[39m.\u001b[39;49mindex(s)]\u001b[39m.\u001b[39;49mquantity \u001b[39mfor\u001b[39;49;00m s \u001b[39min\u001b[39;49;00m input_species])\n\u001b[1;32m 106\u001b[0m circuit\u001b[39m.\u001b[39minteractions \u001b[39m=\u001b[39m interactions\n\u001b[1;32m 107\u001b[0m circuit\u001b[39m.\u001b[39minteractions_state \u001b[39m=\u001b[39m \u001b[39m'\u001b[39m\u001b[39mcomputed\u001b[39m\u001b[39m'\u001b[39m\n",
"File \u001b[0;32m~/Kode/synbio_morpher/synbio_morpher/utils/circuit/agnostic_circuits/circuit_manager.py:174\u001b[0m, in \u001b[0;36mCircuitModeller.run_interaction_simulator\u001b[0;34m(self, species, quantities, filename)\u001b[0m\n\u001b[1;32m 170\u001b[0m data \u001b[39m=\u001b[39m {s: s\u001b[39m.\u001b[39mphysical_data \u001b[39mfor\u001b[39;00m s \u001b[39min\u001b[39;00m species}\n\u001b[1;32m 171\u001b[0m \u001b[39m# if filename is not None:\u001b[39;00m\n\u001b[1;32m 172\u001b[0m \u001b[39m# return self.interaction_simulator.run((filename, data), compute_by_filename=True)\u001b[39;00m\n\u001b[1;32m 173\u001b[0m \u001b[39m# else:\u001b[39;00m\n\u001b[0;32m--> 174\u001b[0m \u001b[39mreturn\u001b[39;00m \u001b[39mself\u001b[39;49m\u001b[39m.\u001b[39;49minteraction_simulator\u001b[39m.\u001b[39;49mrun(data, quantities\u001b[39m=\u001b[39;49mquantities, compute_by_filename\u001b[39m=\u001b[39;49m\u001b[39mFalse\u001b[39;49;00m)\n",
"File \u001b[0;32m~/Kode/synbio_morpher/synbio_morpher/utils/circuit/agnostic_circuits/circuit_manager.py:174\u001b[0m, in \u001b[0;36mCircuitModeller.run_interaction_simulator\u001b[0;34m(self, species, quantities, filename)\u001b[0m\n\u001b[1;32m 170\u001b[0m data \u001b[39m=\u001b[39m {s: s\u001b[39m.\u001b[39msequence \u001b[39mfor\u001b[39;00m s \u001b[39min\u001b[39;00m species}\n\u001b[1;32m 171\u001b[0m \u001b[39m# if filename is not None:\u001b[39;00m\n\u001b[1;32m 172\u001b[0m \u001b[39m# return self.interaction_simulator.run((filename, data), compute_by_filename=True)\u001b[39;00m\n\u001b[1;32m 173\u001b[0m \u001b[39m# else:\u001b[39;00m\n\u001b[0;32m--> 174\u001b[0m \u001b[39mreturn\u001b[39;00m \u001b[39mself\u001b[39;49m\u001b[39m.\u001b[39;49minteraction_simulator\u001b[39m.\u001b[39;49mrun(data, quantities\u001b[39m=\u001b[39;49mquantities, compute_by_filename\u001b[39m=\u001b[39;49m\u001b[39mFalse\u001b[39;49;00m)\n",
"File \u001b[0;32m~/Kode/synbio_morpher/synbio_morpher/srv/parameter_prediction/interactions.py:221\u001b[0m, in \u001b[0;36mInteractionSimulator.run\u001b[0;34m(self, input, quantities, compute_by_filename)\u001b[0m\n\u001b[1;32m 217\u001b[0m \u001b[39m\"\"\" Makes nested dictionary for querying interactions as \u001b[39;00m\n\u001b[1;32m 218\u001b[0m \u001b[39m{sample1: {sample2: interaction}} \"\"\"\u001b[39;00m\n\u001b[1;32m 219\u001b[0m \u001b[39mself\u001b[39m\u001b[39m.\u001b[39mdata_handler \u001b[39m=\u001b[39m InteractionDataHandler(\n\u001b[1;32m 220\u001b[0m simulation_handler\u001b[39m=\u001b[39m\u001b[39mself\u001b[39m\u001b[39m.\u001b[39msimulation_handler, quantities\u001b[39m=\u001b[39mquantities)\n\u001b[0;32m--> 221\u001b[0m data \u001b[39m=\u001b[39m \u001b[39mself\u001b[39;49m\u001b[39m.\u001b[39;49msimulator(\u001b[39minput\u001b[39;49m, compute_by_filename\u001b[39m=\u001b[39;49mcompute_by_filename)\n\u001b[1;32m 222\u001b[0m data \u001b[39m=\u001b[39m \u001b[39mself\u001b[39m\u001b[39m.\u001b[39mdata_handler\u001b[39m.\u001b[39minit_data(data)\n\u001b[1;32m 223\u001b[0m \u001b[39mreturn\u001b[39;00m data\n",
"File \u001b[0;32m~/Kode/synbio_morpher/synbio_morpher/srv/parameter_prediction/simulator.py:172\u001b[0m, in \u001b[0;36msimulate_IntaRNA\u001b[0;34m(input, compute_by_filename, allow_self_interaction, sim_kwargs, simulator, filename)\u001b[0m\n\u001b[1;32m 170\u001b[0m \u001b[39melse\u001b[39;00m:\n\u001b[1;32m 171\u001b[0m f \u001b[39m=\u001b[39m simulate_IntaRNA_data\n\u001b[0;32m--> 172\u001b[0m \u001b[39mreturn\u001b[39;00m f(\u001b[39minput\u001b[39;49m, allow_self_interaction\u001b[39m=\u001b[39;49mallow_self_interaction, sim_kwargs\u001b[39m=\u001b[39;49msim_kwargs, simulator\u001b[39m=\u001b[39;49msimulator)\n",
"File \u001b[0;32m~/Kode/synbio_morpher/synbio_morpher/srv/parameter_prediction/simulator.py:209\u001b[0m, in \u001b[0;36msimulate_IntaRNA_fn\u001b[0;34m(inputs, allow_self_interaction, sim_kwargs, simulator, remove_file)\u001b[0m\n\u001b[1;32m 207\u001b[0m sim_kwargs[\u001b[39m\"\u001b[39m\u001b[39mquery\u001b[39m\u001b[39m\"\u001b[39m] \u001b[39m=\u001b[39m filename\n\u001b[1;32m 208\u001b[0m sim_kwargs[\u001b[39m\"\u001b[39m\u001b[39mtarget\u001b[39m\u001b[39m\"\u001b[39m] \u001b[39m=\u001b[39m filename\n\u001b[0;32m--> 209\u001b[0m output \u001b[39m=\u001b[39m simulator\u001b[39m.\u001b[39;49mrun(\u001b[39m*\u001b[39;49m\u001b[39m*\u001b[39;49msim_kwargs)\n\u001b[1;32m 210\u001b[0m \u001b[39mif\u001b[39;00m output:\n\u001b[1;32m 211\u001b[0m \u001b[39mif\u001b[39;00m \u001b[39mtype\u001b[39m(output) \u001b[39m==\u001b[39m \u001b[39mdict\u001b[39m:\n",
Expand Down
2 changes: 1 addition & 1 deletion notebooks/16_Monte_Carlo_circuit_adaptability.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -3187,7 +3187,7 @@
" \n",
" for i, c in enumerate(circuits):\n",
" circuits[i].name = make_next_name(c.name, c.subname)\n",
" # sequences = {s.name: s.physical_data for s in c.model.species if s.physical_data}\n",
" # sequences = {s.name: s.sequence for s in c.model.species if s.sequence}\n",
" sequences = load_seq_from_FASTA(c.data.source, as_type='dict')\n",
" circuits[i].data.source = write_mutated_circuit(\n",
" name=circuits[i].name, subname='ref_circuit', sequences=sequences, data_writer=data_writer)\n",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,8 +49,8 @@
"experiment": {
"purpose": "mutation_effect_on_interactions_signal",
"no_visualisations": false,
"no_numerical": true,
"debug_mode": 1
"no_numerical": false,
"debug_mode": 0
},
"interaction_simulator": {
"name": "IntaRNA",
Expand Down
4 changes: 2 additions & 2 deletions synbio_morpher/scripts/mc_evolution/run_mc_evolution.py
Original file line number Diff line number Diff line change
Expand Up @@ -298,7 +298,7 @@ def process_for_next_run(circuits: list, data_writer: DataWriter):

for i, c in enumerate(circuits):
circuits[i].name = make_next_name(c.name)
# sequences = {s.name: s.physical_data for s in c.model.species if s.physical_data}
# sequences = {s.name: s.sequence for s in c.model.species if s.sequence}
sequences = load_seq_from_FASTA(c.data.source, as_type='dict')
circuits[i].data.source = write_mutated_circuit(
name=circuits[i].name, subname='ref_circuit', sequences=sequences, data_writer=data_writer)
Expand Down Expand Up @@ -452,7 +452,7 @@ def main(config=None, data_writer=None):
def write(summary_datas, data_writer):
data_writer.subdivide_writing('summary_datas')
for step, sdata in summary_datas.items():
data_writer.output('csv', out_name='sdata_' +
data_writer.output(out_type='csv', out_name='sdata_' +
str(step), write_master=False, data=sdata)
data_writer.unsubdivide()

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,7 @@ def logging_circuit(clist: list):
write_to_subsystem=True, batch_size=config_file['simulation'].get('batch_size', 100),
methods={
"compute_interactions": {},
"write_interactions": {},
"init_circuits": {'batch': True},
"simulate_signal_batch": {'ref_circuit': None,
'batch': True},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ def create_circuits(config: dict, interaction_matrices: np.ndarray):

def write_all(all_analytic_matrices, analytic_types, data_writer, out_type='npy'):
for m, analytic in enumerate(analytic_types):
data_writer.output(out_type, out_name=analytic,
data_writer.output(out_type=out_type, out_name=analytic,
data=all_analytic_matrices[m].astype(np.float32), overwrite=True,
write_to_top_dir=True)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,7 @@ def make_indices(iteration):
# Write full matrices
def write_all(stitched_parameter_grids, out_type='npy'):
for analytic_name, grid in stitched_parameter_grids.items():
data_writer.output(out_type, out_name=analytic_name,
data_writer.output(out_type=out_type, out_name=analytic_name,
data=grid.astype(np.float32), overwrite=True,
write_to_top_dir=True)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,12 +21,13 @@

def main(config=None, data_writer=None):
# Set configs
config, data_writer = script_preamble(config, data_writer, alt_cfg_filepath=os.path.join(
alt_cfg_filepath = os.path.join(
# "synbio_morpher", "scripts", "summarise_simulation", "configs", "analyse_mutated_templates_20_highmag.json"))
"synbio_morpher", "scripts", "summarise_simulation", "configs", "base_config.json"))
"synbio_morpher", "scripts", "summarise_simulation", "configs", "base_config.json")
config, data_writer = script_preamble(config, data_writer, alt_cfg_filepath=alt_cfg_filepath)
config_file = load_json_as_dict(config)

# Start_experiment
# Start_experiments
if data_writer is None:
data_writer = ResultWriter(purpose=config_file.get('experiment', {}).get('purpose'))

Expand Down
7 changes: 4 additions & 3 deletions synbio_morpher/utils/circuit/agnostic_circuits/circuit.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,19 +5,20 @@
# This source code is licensed under the MIT-style license found in the
# LICENSE file in the root directory of this source tree.

from typing import Union
from typing import Union, Dict
import pandas as pd
import numpy as np
import logging

from synbio_morpher.srv.parameter_prediction.interactions import MolecularInteractions, InteractionMatrix
from synbio_morpher.srv.io.manage.data_manager import DataManager
from synbio_morpher.utils.circuit.common.system_setup import construct_bioreaction_model
from synbio_morpher.utils.evolution.mutation import Mutations
from synbio_morpher.utils.misc.string_handling import make_circuit_name
from synbio_morpher.utils.misc.type_handling import flatten_listlike, get_unique
from synbio_morpher.utils.results.results import ResultCollector
from synbio_morpher.utils.signal.signals_new import Signal
from bioreaction.model.data_containers import BasicModel, QuantifiedReactions, MedModel
from bioreaction.model.data_containers import BasicModel, QuantifiedReactions


FORMAT = "[%(filename)s:%(lineno)s - %(funcName)20s() ] %(message)s"
Expand Down Expand Up @@ -65,7 +66,7 @@ def init_refcircuit(self, config: dict):
assert self.interactions_state != 'uninitialised', f'The interactions should have been initialised from {config.get("interactions")}'
self.signal: Signal # = None
self.mutations_args: dict = config.get('mutations_args', {})
self.mutations = {}
self.mutations: Dict[str, Mutations] = {}

self.update_species_simulated_rates(self.interactions)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
# LICENSE file in the root directory of this source tree.

from copy import deepcopy
from typing import List, Tuple, Union
from typing import List, Tuple, Union, Optional
from functools import partial
from datetime import datetime
import multiprocessing
Expand Down Expand Up @@ -37,7 +37,8 @@
from synbio_morpher.utils.results.visualisation import VisODE
from synbio_morpher.utils.modelling.deterministic import bioreaction_sim_dfx_expanded, bioreaction_sim_dfx_naive
from synbio_morpher.utils.modelling.solvers import get_diffrax_solver, make_stepsize_controller
from synbio_morpher.utils.evolution.mutation import implement_mutation
from synbio_morpher.utils.evolution.evolver import implement_mutation
from synbio_morpher.utils.evolution.mutation import Mutations
from synbio_morpher.utils.results.analytics.timeseries import generate_analytics
from synbio_morpher.utils.results.result_writer import ResultWriter

Expand Down Expand Up @@ -222,7 +223,7 @@ def compute_interactions_batch(self, circuits: List[Circuit], batch=True):
return circuits

def run_interaction_simulator(self, species: List[Species], quantities, filename=None) -> InteractionDataHandler:
data = {s: s.physical_data for s in species}
data = {s: s.sequence for s in species}
# if filename is not None:
# return self.interaction_simulator.run((filename, data), compute_by_filename=True)
# else:
Expand Down Expand Up @@ -539,7 +540,7 @@ def prepare_batch_params(circuits: List[Circuit]):
for i, (circuit, analytics) in enumerate(zip(circuits, b_analytics_l)):
if self.discard_numerical_mutations and circuit.subname != 'ref_circuit':
sig_data = None
vis_func = lambda x: x
vis_func = lambda **kwargs: kwargs
else:
sig_data = b_new_copynumbers[i]
vis_func=VisODE().plot
Expand All @@ -558,7 +559,7 @@ def prepare_batch_params(circuits: List[Circuit]):
clear_caches()
return circuits

def make_subcircuit(self, circuit: Circuit, mutation_name: str, mutation=None):
def make_subcircuit(self, circuit: Circuit, mutation_name: str, mutation: Optional[Mutations] =None):

subcircuit = deepcopy(circuit)
subcircuit.reset_to_initial_state()
Expand Down
2 changes: 1 addition & 1 deletion synbio_morpher/utils/circuit/common/system_setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ def get_system_type(sys_type):
def add_data_to_species(model: BasicModel, data: Data):
for i, s in enumerate(model.species):
if s.name in data.data.keys():
model.species[i].physical_data = data.data[s.name]
model.species[i].sequence = data.data[s.name]
return model


Expand Down
Loading

0 comments on commit 344ecd7

Please sign in to comment.