Modules¶
Learn¶
-
class
caspo.learn.
Learner
(graph, dataset, length, discrete, factor)¶ Learner of (nearly) optimal logical networks with respect to a given prior knownledge network and a phospho-proteomics dataset.
Parameters: - graph (
caspo.core.graph.Graph
) – Prior knowledge network - dataset (
caspo.core.dataset.Dataset
) – Experimental dataset - length (int) – Maximum length for conjunction clauses
- discrete (str) – Discretization function: round, ceil, or floor
- factor (int) – Discretization factor, e.g. 10, 100, 1000
-
graph
¶
-
dataset
¶
-
length
¶ int
-
factor
¶ int
-
discrete
¶ str
-
hypergraph
¶
-
instance
¶ str
-
encodings
¶ dict
-
stats
¶ dict
-
ceil
(factor, value)¶ Discretize a given value using a given factor and the ceil integer function
Parameters: - factor (int) – The factor to be used for the discretization
- value (float) – The value to be discretized
Returns: The discretized value
Return type: int
-
floor
(factor, value)¶ Discretize a given value using a given factor and the floor integer function
Parameters: - factor (int) – The factor to be used for the discretization
- value (float) – The value to be discretized
Returns: The discretized value
Return type: int
-
learn
(fit=0, size=0, configure=None)¶ Learns all (nearly) optimal logical networks with give fitness and size tolerance. The first optimum logical network found is saved in the attribute
optimum
while all enumerated logical networks are saved in the attributenetworks
.Example:
>>> from caspo import core, learn >>> graph = core.Graph.read_sif('pkn.sif') >>> dataset = core.Dataset('dataset.csv', 30) >>> zipped = graph.compress(dataset.setup) >>> learner = learn.Learner(zipped, dataset, 2, 'round', 100) >>> learner.learn(0.02, 1) >>> learner.networks.to_csv('networks.csv')
Parameters: - fit (float) – Fitness tolerance, e.g., use 0.1 for 10% tolerance with respect to the optimum
- size (int) – Size tolerance with respect to the optimum
- configure (callable) – Callable object responsible of setting a custom clingo configuration
-
random
(size, n_and, max_in, n=1)¶ Generates n random logical networks with given size range, number of AND gates and maximum input signals for AND gates. Logical networks are saved in the attribute
networks
.Parameters: - n (int) – Number of random logical networks to be generated
- size ((int,int)) – Minimum and maximum sizes
- n_and ((int,int)) – Minimum and maximum AND gates
- max_in (int) – Maximum input signals for AND gates
-
round
(factor, value)¶ Discretize a given value using a given factor and the closest integer function
Parameters: - factor (int) – The factor to be used for the discretization
- value (float) – The value to be discretized
Returns: The discretized value
Return type: int
- graph (
Classify¶
-
class
caspo.classify.
Classifier
(networks, setup)¶ Classifier of given list of logical networks with respect to a given experimental setup.
Parameters: - networks (
caspo.core.logicalnetwork.LogicalNetworkList
) – The list of logical networks - setup (
caspo.core.setup.Setup
) – The experimental setup with respect to which the input-output behaviors must be computed
-
setup
¶
-
stats
¶ dict
-
classify
(n_jobs=-1, configure=None)¶ Returns input-output behaviors for the list of logical networks in the attribute
networks
Example:
>>> from caspo import core, classify >>> networks = core.LogicalNetworkList.from_csv('networks.csv') >>> setup = core.Setup.from_json('setup.json') >>> classifier = classify.Classifier(networks, setup) >>> behaviors = classifier.classify() >>> behaviors.to_csv('behaviors.csv', networks=True)
- n_jobs : int
- Number of jobs to run in parallel. Default to -1 (all cores available)
- configure : callable
- Callable object responsible of setting clingo configuration
Returns: The list of networks with one representative for each behavior Return type: caspo.core.logicalnetwork.LogicalNetworkList
- networks (
Design¶
-
class
caspo.design.
Designer
(networks, setup, candidates=None)¶ Experimental designer to discriminate among a list of logical networks (input-output behaviors representatives)
Parameters: - networks (
caspo.core.logicalnetwork.LogicalNetworkList
) – List of logical networks to discriminate - setup (
caspo.core.setup.Setup
) – Experimental setup - candidates (
caspo.core.clamping.ClampingList
) – Optional list of candidate experiments given as a list of clampings
-
setup
¶
-
candidates
¶
-
designs
¶
-
instance
¶ str
-
encodings
¶ dict
-
stats
¶ dict
-
design
(max_stimuli=-1, max_inhibitors=-1, max_experiments=10, relax=False, configure=None)¶ Finds all optimal experimental designs using up to
max_experiments
experiments, such that each experiment has up tomax_stimuli
stimuli andmax_inhibitors
inhibitors. Each optimal experimental design is appended in the attributedesigns
as an instance ofcaspo.core.clamping.ClampingList
.Example:
>>> from caspo import core, design >>> networks = core.LogicalNetworkList.from_csv('behaviors.csv') >>> setup = core.Setup.from_json('setup.json') >>> designer = design.Designer(networks, setup) >>> designer.design(3, 2) >>> for i,d in enumerate(designer.designs): ... f = 'design-%s' % i ... d.to_csv(f, stimuli=self.setup.stimuli, inhibitors=self.setup.inhibitors)
Parameters: - max_stimuli (int) – Maximum number of stimuli per experiment
- max_inhibitors (int) – Maximum number of inhibitors per experiment
- max_experiments (int) – Maximum number of experiments per design
- relax (boolean) – Whether to relax the full-pairwise networks discrimination (True) or not (False).
If relax equals True, the number of experiments per design is fixed to
max_experiments
- configure (callable) – Callable object responsible of setting clingo configuration
- networks (
Predict¶
-
class
caspo.predict.
Predictor
(networks, setup)¶ Predictor of all possible experimental conditions over a given experimental setup using a given list of logical networks.
Parameters: - networks (
caspo.core.logicalnetwork.LogicalNetworkList
) – The list of logical networks used to generate the ensemble of predictions - setup (
caspo.core.setup.Setup
) – The experimental setup to generate possible experimental conditions
-
setup
¶
-
predict
()¶ Computes all possible weighted average predictions and their variances
Example:
>>> from caspo import core, predict >>> networks = core.LogicalNetworkList.from_csv('behaviors.csv') >>> setup = core.Setup.from_json('setup.json') >>> predictor = predict.Predictor(networks, setup) >>> df = predictor.predict() >>> df.to_csv('predictions.csv'), index=False)
Returns: DataFrame with the weighted average predictions and variance of all readouts for each possible clamping Return type: pandas.DataFrame
- networks (
Control¶
-
class
caspo.control.
Controller
(networks, scenarios)¶ Controller of logical networks family for various intervention scenarios
Parameters: - networks (
caspo.core.logicalnetwork.LogicalNetworkList
) – List of logical networks - scenarios (
caspo.control.ScenarioList
) – List of intervention scenarios
-
scenarios
¶
-
strategies
¶
-
instance
¶ str
-
encodings
¶ dict
-
stats
¶ dict
-
control
(size=0, configure=None)¶ Finds all inclusion-minimal intervention strategies up to the given size. Intervention strategies found are saved in the attribute
strategies
as acaspo.core.clamping.ClampingList
object instance.Example:
>>> from caspo import core, control >>> networks = core.LogicalNetworkList.from_csv('networks.csv') >>> scenarios = control.ScenarioList('scenarios.csv') >>> controller = control.Controller(networks, scenarios) >>> controller.control() >>> controller.strategies.to_csv('strategies.csv')
Parameters: - size (int) – Maximum number of intervention per intervention strategy
- configure (callable) – Callable object responsible of setting clingo configuration
- networks (
-
class
caspo.control.
ScenarioList
(filename, allow_constraints=False, allow_goals=False)¶ List of intervention scenarios
Parameters: - filename (str) – Absolute PATH to a CSV file specifying several intervention scenarios
- allow_constraints (boolean) – Either to allow intervention over constraints or not
- allow_goals (boolean) – Either to allow intervention over goals or not
-
constraints
¶
-
to_funset
()¶ Converts the intervention scenarios to a set of gringo.Fun instances
Returns: Representation of the intervention scenarios as a set of gringo.Fun instances Return type: set
Visualize¶
-
caspo.visualize.
behaviors_distribution
(df, filepath=None)¶ Plots the distribution of logical networks across input-output behaviors. Optionally, input-output behaviors can be grouped by MSE.
Parameters: - df (pandas.DataFrame) – DataFrame with columns networks and optionally mse
- filepath (str) – Absolute path to a folder where to write the plot
Returns: Generated plot
Return type: plot
-
caspo.visualize.
coloured_network
(network, setup, filename)¶ Plots a coloured (hyper-)graph to a dot file
Parameters: - network (object) – An object implementing a method __plot__ which must return the networkx.MultiDiGraph instance to be coloured.
Typically, it will be an instance of either
caspo.core.graph.Graph
,caspo.core.logicalnetwork.LogicalNetwork
orcaspo.core.logicalnetwork.LogicalNetworkList
- setup (
caspo.core.setup.Setup
) – Experimental setup to be coloured in the network
- network (object) – An object implementing a method __plot__ which must return the networkx.MultiDiGraph instance to be coloured.
Typically, it will be an instance of either
-
caspo.visualize.
differences_distribution
(df, filepath=None)¶ For each experimental design it plot all the corresponding generated differences in different plots
Parameters: - df (pandas.DataFrame) – DataFrame with columns id, pairs, and starting with DIF:
- filepath (str) – Absolute path to a folder where to write the plots
Returns: Generated plots
Return type: list
-
caspo.visualize.
experimental_designs
(df, filepath=None)¶ For each experimental design it plot all the corresponding experimental conditions in a different plot
Parameters: - df (pandas.DataFrame) – DataFrame with columns id and starting with TR:
- filepath (str) – Absolute path to a folder where to write the plot
Returns: Generated plots
Return type: list
-
caspo.visualize.
intervention_strategies
(df, filepath=None)¶ Plots all intervention strategies
Parameters: - df (pandas.DataFrame) – DataFrame with columns starting with TR:
- filepath (str) – Absolute path to a folder where to write the plot
Returns: Generated plot
Return type: plot
-
caspo.visualize.
interventions_frequency
(df, filepath=None)¶ Plots the frequency of occurrence for each intervention
Parameters: - df (pandas.DataFrame) – DataFrame with columns frequency and intervention
- filepath (str) – Absolute path to a folder where to write the plot
Returns: Generated plot
Return type: plot
-
caspo.visualize.
mappings_frequency
(df, filepath=None)¶ Plots the frequency of logical conjunction mappings
Parameters: - df (pandas.DataFrame) – DataFrame with columns frequency and mapping
- filepath (str) – Absolute path to a folder where to write the plot
Returns: Generated plot
Return type: plot
-
caspo.visualize.
networks_distribution
(df, filepath=None)¶ Generates two alternative plots describing the distribution of variables mse and size. It is intended to be used over a list of logical networks.
Parameters: - df (pandas.DataFrame) – DataFrame with columns mse and size
- filepath (str) – Absolute path to a folder where to write the plots
Returns: Generated plots
Return type: tuple
-
caspo.visualize.
predictions_variance
(df, filepath=None)¶ Plots the mean variance prediction for each readout
Parameters: - df (pandas.DataFrame) – DataFrame with columns starting with VAR:
- filepath (str) – Absolute path to a folder where to write the plots
Returns: Generated plot
Return type: plot