dinkum-bio / dinkum

very simple cis-regulatory gene regulatory network simulation
GNU Affero General Public License v3.0
0 stars 1 forks source link

can we improve dinkum custom activation classes? #37

Closed ctb closed 1 month ago

ctb commented 1 month ago

As of https://github.com/dinkum-bio/dinkum/pull/36, we can now do:

# test approach with fn
# this is a simple example! gene names are learned from the parameters to the function.
dinkum.reset()

def activation_at_threshold(*, A):
    if A.level > 20:
        return 50, True

m = Tissue(name='M')
a = Gene(name='A')
b = Gene(name='B')

a.is_present(where=m, decay=2, start=1)
b.custom_activation2(state_fn=activation_at_threshold)

gene_names = vfg.get_gene_names()
display_fn, conc_df, active_df = dinkum.run_and_display_df(start=1, stop=5, gene_names=gene_names)
display_fn

and also:

dinkum.reset()

# a more complicated example. Here we want something that can be parametrized with multiple different
# threshold/output levels/etc.

class ActivateAtThreshold(vfg.CustomActivation):
    def __init__(self, *, input_gene, threshold, output_level):
        super().__init__(input_genes=[input_gene])
        self.threshold = threshold
        self.output_level = output_level

    def __call__(self, *, A):
        if A.level > self.threshold:
            return self.output_level, True

m = Tissue(name='M')
a = Gene(name='A')
b = Gene(name='B')

a.is_present(where=m, decay=2, start=1)
state_fn = ActivateAtThreshold(input_gene='A', threshold=20, output_level=50)
b.custom_activation2(state_fn=state_fn)

display_fn, conc_df, active_df = dinkum.run_and_display_df(start=1, stop=5)
display_fn

a few thoughts -

ideally (...) there would be a way to never specify the gene names, right? Except ... how would dinkum know what to feed in! and how would the function know what to run!? value: think about multiple and, multiple or... I guess we could provide some template examples. and/or class level things, where it picks up info from the initial class.

ctb commented 1 month ago

https://github.com/dinkum-bio/dinkum/pull/36 now does a few more nice things with custom activation classes:

gonna close this based on that PR.