Core¶
caspo.core.setup¶
-
class
caspo.core.setup.
Setup
(stimuli, inhibitors, readouts)¶ Experimental setup describing stimuli, inhibitors and readouts species names
Parameters: - stimuli (list[str]) – List of stimuli species
- inhibitors (list[str]) – List of inhibitors species
- readouts (list[str]) – List of readouts species
-
stimuli
¶ list[str]
-
inhibitors
¶ list[str]
-
readouts
¶ list[str]
-
__len__
()¶ Returns the sum of stimuli, inhibitors, and readouts
Returns: Sum of stimuli, inhibitors, and readouts Return type: int
-
clampings_iter
(cues=None)¶ Iterates over all possible clampings of this experimental setup
Parameters: cues (Optional[iterable]) – If given, restricts clampings over given species names Yields: caspo.core.clamping.Clamping – The next clamping with respect to the experimental setup
-
cues
(rename_inhibitors=False)¶ Returns stimuli and inhibitors species of this experimental setup
Parameters: rename_inhibitors (boolean) – If True, rename inhibitors with an ending ‘i’ as in MIDAS files. Returns: List of species names in order: first stimuli followed by inhibitors Return type: list
-
filter
(networks)¶ Returns a new experimental setup restricted to species present in the given list of networks
Parameters: networks ( caspo.core.logicalnetwork.LogicalNetworkList
) – List of logical networksReturns: The restricted experimental setup Return type: caspo.core.setup.Setup
-
classmethod
from_json
(klass, filename)¶ Creates an experimental setup from a JSON file
Parameters: filename (str) – Absolute path to JSON file Returns: Created object instance Return type: caspo.core.setup.Setup
-
nodes
¶ frozenset: unique species names in the experimental setup
-
to_funset
()¶ Converts the experimental setup to a set of gringo.Fun object instances
Returns: The set of gringo.Fun object instances Return type: set
-
to_json
(filename)¶ Writes the experimental setup to a JSON file
Parameters: filename (str) – Absolute path where to write the JSON file
caspo.core.literal¶
-
class
caspo.core.literal.
Literal
¶ A literal is a variable or its negation
-
variable
¶ str
-
signature
¶ int (either 1 or -1)
-
__str__
()¶ Returns the string representation of the literal
Returns: String representation of the literal Return type: str
-
classmethod
from_str
(klass, string)¶ Creates a literal from a string
Parameters: string (str) – If the string starts with ‘!’, it’s interpreted as a negated variable Returns: Created object instance Return type: caspo.core.literal.Literal
-
caspo.core.clamping¶
-
class
caspo.core.clamping.
Clamping
¶ A clamping is a frozenset of
caspo.core.literal.Literal
object instances where each literal describes a clamped variable-
bool
(variable)¶ Returns whether the given variable is positively clamped
Parameters: variable (str) – The variable name Returns: True if the given variable is positively clamped, False otherwise Return type: boolean
-
drop_literals
(literals)¶ Returns a new clamping without the given literals
Parameters: literals (iterable[ caspo.core.literal.Literal
]) – Iterable of literals to be removedReturns: A new clamping without the given literals Return type: caspo.core.clamping.Clamping
-
classmethod
from_tuples
(klass, tuples)¶ Creates a clamping from tuples of the form (variable, sign)
Parameters: tuples (iterable[(str,int)]) – An iterable of tuples describing clamped variables Returns: Created object instance Return type: caspo.core.clamping.Clamping
-
has_variable
(variable)¶ Returns whether the given variable is present in the clamping
Parameters: variable (str) – The variable name Returns: True if the given variable is present in the clamping, False otherwise Return type: boolean
-
to_array
(variables)¶ Converts the clamping to a 1-D array with respect to the given variables
Parameters: variables (list[str]) – List of variables names Returns: 1-D array where position i correspond to the sign of the clamped variable at position i in the given list of variables Return type: numpy.ndarray
-
to_funset
(index, name='clamped')¶ Converts the clamping to a set of gringo.Fun object instances
Parameters: - index (int) – An external identifier to associate several clampings together in ASP
- name (str) – A function name for the clamping
Returns: The set of gringo.Fun object instances
Return type: set
-
-
class
caspo.core.clamping.
ClampingList
¶ A list of
caspo.core.clamping.Clamping
object instances-
combinatorics
()¶ Returns mutually exclusive/inclusive clampings
Returns: A tuple of 2 dictionaries. For each literal key, the first dict has as value the set of mutually exclusive clampings while the second dict has as value the set of mutually inclusive clampings. Return type: (dict,dict)
-
differences
(networks, readouts, prepend='')¶ Returns the total number of pairwise differences over the given readouts for the given networks
Parameters: - networks (iterable[
caspo.core.logicalnetwork.LogicalNetwork
]) – Iterable of logical networks to compute pairwise differences - readouts (list[str]) – List of readouts species names
- prepend (str) – Columns are renamed using the given string at the beginning
Returns: Total number of pairwise differences for each clamping over each readout
Return type: - networks (iterable[
-
drop_literals
(literals)¶ Returns a new list of clampings without the given literals
Parameters: literals (iterable[ caspo.core.literal.Literal
]) – Iterable of literals to be removed from each clampingReturns: The new list of clampings Return type: caspo.core.clamping.ClampingList
-
frequencies_iter
()¶ Iterates over the frequencies of all clamped variables
Yields: tuple[ caspo.core.literal.Literal, float ] – The next tuple of the form (literal, frequency)
-
frequency
(literal)¶ Returns the frequency of a clamped variable
Parameters: literal ( caspo.core.literal.Literal
) – The clamped variableReturns: The frequency of the given literal Return type: float Raises: ValueError
– If the variable is not present in any of the clampings
-
classmethod
from_csv
(klass, filename, inhibitors=[])¶ Creates a list of clampings from a CSV file. Column names are expected to be of the form TR:species_name
Parameters: - filename (str) – Absolute path to a CSV file to be loaded with pandas.read_csv. The resulting DataFrame is passed to
from_dataframe()
. - inhibitors (Optional[list[str]]) –
If given, species names ending with i and found in the list (without the i) will be interpreted as inhibitors. That is, if they are set to 1, the corresponding species is inhibited and therefore its negatively clamped. Apart from that, all 1s (resp. 0s) are interpreted as positively (resp. negatively) clamped.
Otherwise (if inhibitors=[]), all 1s (resp. -1s) are interpreted as positively (resp. negatively) clamped.
Returns: Created object instance
Return type: - filename (str) – Absolute path to a CSV file to be loaded with pandas.read_csv. The resulting DataFrame is passed to
-
classmethod
from_dataframe
(klass, df, inhibitors=[])¶ Creates a list of clampings from a pandas.DataFrame object instance. Column names are expected to be of the form TR:species_name
Parameters: - df (pandas.DataFrame) – Columns and rows correspond to species names and individual clampings, respectively.
- inhibitors (Optional[list[str]]) –
If given, species names ending with i and found in the list (without the i) will be interpreted as inhibitors. That is, if they are set to 1, the corresponding species is inhibited and therefore its negatively clamped. Apart from that, all 1s (resp. 0s) are interpreted as positively (resp. negatively) clamped.
Otherwise (if inhibitors=[]), all 1s (resp. -1s) are interpreted as positively (resp. negatively) clamped.
Returns: Created object instance
Return type: caspo.core.ClampingList
-
to_csv
(filename, stimuli=[], inhibitors=[], prepend='')¶ Writes the list of clampings to a CSV file
Parameters: - filename (str) – Absolute path where to write the CSV file
- stimuli (Optional[list[str]]) – List of stimuli names. If given, stimuli are converted to {0,1} instead of {-1,1}.
- inhibitors (Optional[list[str]]) – List of inhibitors names. If given, inhibitors are renamed and converted to {0,1} instead of {-1,1}.
- prepend (str) – Columns are renamed using the given string at the beginning
-
to_dataframe
(stimuli=[], inhibitors=[], prepend='')¶ Converts the list of clampigns to a pandas.DataFrame object instance
Parameters: - stimuli (Optional[list[str]]) – List of stimuli names. If given, stimuli are converted to {0,1} instead of {-1,1}.
- inhibitors (Optional[list[str]]) – List of inhibitors names. If given, inhibitors are renamed and converted to {0,1} instead of {-1,1}.
- prepend (str) – Columns are renamed using the given string at the beginning
Returns: DataFrame representation of the list of clampings
Return type:
-
to_funset
(lname='clamping', cname='clamped')¶ Converts the list of clampings to a set of gringo.Fun instances
Parameters: - lname (str) – Predicate name for the clamping id
- cname (str) – Predicate name for the clamped variable
Returns: Representation of all clampings as a set of gringo.Fun instances
Return type: set
-
caspo.core.dataset¶
-
class
caspo.core.dataset.
Dataset
(midas, time)¶ An experimental phospho-proteomics dataset extending pandas.DataFrame
Parameters: - midas (Absolute PATH to a MIDAS file) –
- time (Data acquisition time-point for the early response) –
-
setup
¶
-
clampings
¶
-
readouts
¶
-
is_inhibitor
(name)¶ Returns if the given species name is a inhibitor or not
Parameters: name (str) – Returns: True if the given name is a inhibitor, False otherwise. Return type: boolean
-
is_readout
(name)¶ Returns if the given species name is a readout or not
Parameters: name (str) – Returns: True if the given name is a readout, False otherwise. Return type: boolean
-
is_stimulus
(name)¶ Returns if the given species name is a stimulus or not
Parameters: name (str) – Returns: True if the given name is a stimulus, False otherwise. Return type: boolean
-
to_funset
(discrete)¶ Converts the dataset to a set of gringo.Fun instances
Parameters: discrete (callable) – A discretization function Returns: Representation of the dataset as a set of gringo.Fun instances Return type: set
caspo.core.graph¶
-
class
caspo.core.graph.
Graph
¶ Prior knowledge network (aka interaction graph) extending networkx.MultiDiGraph
-
__plot__
()¶ Returns a copy of this graph ready for plotting
Returns: A copy of the object instance Return type: caspo.core.graph.Graph
-
compress
(setup)¶ Returns the compressed graph according to the given experimental setup
Parameters: setup ( caspo.core.setup.Setup
) – Experimental setup used to compress the graphReturns: Compressed graph Return type: caspo.core.graph.Graph
-
classmethod
from_tuples
(klass, tuples)¶ Creates a graph from an iterable of tuples describing edges like (source, target, sign)
Parameters: tuples (iterable[(str,str,int))]) – Tuples describing signed and directed edges Returns: Created object instance Return type: caspo.core.graph.Graph
-
predecessors
(node, exclude_compressed=True)¶ Returns the list of predecessors of a given node
Parameters: - node (str) – The target node
- exclude_compressed (boolean) – If true, compressed nodes are excluded from the predecessors list
Returns: List of predecessors nodes
Return type: list
-
classmethod
read_sif
(klass, path)¶ Creates a graph from a simple interaction format (SIF) file
Parameters: path (str) – Absolute path to a SIF file Returns: Created object instance Return type: caspo.core.graph.Graph
-
successors
(node, exclude_compressed=True)¶ Returns the list of successors of a given node
Parameters: - node (str) – The target node
- exclude_compressed (boolean) – If true, compressed nodes are excluded from the successors list
Returns: List of successors nodes
Return type: list
-
caspo.core.hypergraph¶
-
class
caspo.core.hypergraph.
HyperGraph
(nodes, hyper, edges)¶ Signed and directed hypergraph representation providing the link between logical networks and the corresponding expanded prior knowledge network.
Parameters: - nodes (pandas.Series) – Values in the Series correspond to variables names
- hyper (pandas.Series) – Values in the Series correspond to the index in attribute
nodes
(interpreted as the target node) - edges (pandas.DataFrame) – Hyperedges details as a DataFrame with columns hyper_idx (corresponds to the index in attribute
hyper
), name (interpreted as a source node), and sign (1 or -1)
-
nodes
¶
-
hyper
¶
-
edges
¶
-
clauses
¶ dict
A mapping from an hyperedge id (hyper_idx) to a
caspo.core.clause.Clause
object instance
-
mappings
¶ caspo.core.mapping.MappingList
The list of all possible
caspo.core.mapping.Mapping
for this hypergraph
-
classmethod
from_graph
(klass, graph, length=0)¶ Creates a hypergraph (expanded graph) from a
caspo.core.graph.Graph
object instanceParameters: - graph (
caspo.core.graph.Graph
) – The base interaction graph to be expanded - length (int) – Maximum length for hyperedges source sets. If 0, use maximum possible in each case.
Returns: Created object instance
Return type: - graph (
-
to_funset
()¶ Converts the hypergraph to a set of gringo.Fun instances
Returns: Representation of the hypergraph as a set of gringo.Fun instances Return type: set
-
variable
(index)¶ Returns the variable name for a given variable id
Parameters: index (int) – Variable id Returns: Variable name Return type: str
caspo.core.mapping¶
-
class
caspo.core.mapping.
Mapping
¶ A logical conjunction mapping as a tuple made of a
caspo.core.clause.Clause
and a target-
clause
¶
-
target
¶ str
-
__str__
()¶ Returns the string representation of the mapping
Returns: String representation of the mapping as target<=clause Return type: str
-
classmethod
from_str
(klass, string)¶ Creates a mapping from a string
Parameters: string (str) – String of the form target<-clause where clause is a valid string for caspo.core.clause.Clause
Returns: Created object instance Return type: caspo.core.mapping.Mapping
-
-
class
caspo.core.mapping.
MappingList
(mappings, indexes=None)¶ A list of indexed
caspo.core.mapping.Mapping
objects.Parameters: - mappings ([
caspo.core.mapping.Mapping
]) – The list of logical mappings - indexes ([int]) – An optional list of integers to use as indexes
-
__getitem__
(index)¶ A list of mappings can be indexed by:
- a tuple
caspo.core.mapping.Mapping
to get its corresponding index - a list of integers to get all the corresponding mappings objects
- a single integer to get its corresponding mapping object
Returns: An integer, a MappingList or a single mapping Return type: object - a tuple
-
__iter__
()¶ Iterates over mappings
Yields: caspo.core.mapping.Mapping – The next logical mapping
-
__len__
()¶ Returns the number of mappings
Returns: Number of mappings Return type: int
-
iteritems
()¶ Iterates over all mappings
Yields: (int,Mapping) – The next pair (index, mapping)
- mappings ([
caspo.core.clause¶
-
class
caspo.core.clause.
Clause
¶ A conjunction clause is a frozenset of
caspo.core.literal.Literal
object instances-
__str__
()¶ Returns the string representation of the clause
-
bool
(state)¶ Returns the Boolean evaluation of the clause with respect to a given state
Parameters: state (dict) – Key-value mapping describing a Boolean state or assignment Returns: The evaluation of the clause with respect to the given state or assignment Return type: boolean
-
classmethod
from_str
(klass, string)¶ Creates a clause from a given string.
Parameters: string (str) – A string of the form a+!b which translates to a AND NOT b. Returns: Created object instance Return type: caspo.core.clause.Clause
-
caspo.core.logicalnetwork¶
-
class
caspo.core.logicalnetwork.
LogicalNetwork
¶ Logical network class extends networkx.DiGraph with nodes being, either
caspo.core.clause.Clause
object instances or species names (str).-
networks
¶ int
Number of networks having the same behavior (including this network as the representative network)
-
__plot__
()¶ Returns a networkx.MultiDiGraph ready for plotting.
Returns: Network object instance ready for plotting Return type: networkx.MultiDiGraph
-
fixpoint
(clamping, steps=0)¶ Computes the fixpoint with respect to a given
caspo.core.clamping.Clamping
Parameters: - clamping (
caspo.core.clamping.Clamping
) – The clamping with respect to the fixpoint is computed - steps (int) – If greater than zero, a maximum number of steps is performed. Otherwise it continues until reaching a fixpoint. Note that if no fixpoint exists, e.g. a network with a negative feedback-loop, this will never end unless you provide a maximum number of steps.
Returns: The key-value mapping describing the state of the logical network
Return type: dict
- clamping (
-
formulas_iter
()¶ Iterates over all variable-clauses in the logical network
Yields: tuple[str,frozenset[caspo.core.clause.Clause]] – The next tuple of the form (variable, set of clauses) in the logical network.
-
classmethod
from_hypertuples
(klass, hg, tuples)¶ Creates a logical network from an iterable of integer tuples matching mappings in the given
caspo.core.hypergraph.HyperGraph
Parameters: - hg (
caspo.core.hypergraph.HyperGraph
) – Underlying hypergraph - tuples ((int,int)) – tuples matching mappings in the given hypergraph
Returns: Created object instance
Return type: - hg (
-
predictions
(clampings, readouts, stimuli=[], inhibitors=[], nclampings=-1)¶ Computes network predictions for the given iterable of clampings
Parameters: - clampings (iterable) – Iterable over clampings
- readouts (list[str]) – List of readouts names
- stimuli (Optional[list[str]]) – List of stimuli names
- inhibitors (Optional[list[str]]) – List of inhibitors names
- nclampings (Optional[int]) – If greater than zero, it must be the number of clampings in the iterable. Otherwise,
clampings must implement the special method
__len__()
Returns: DataFrame with network predictions for each clamping. If stimuli and inhibitors are given, columns are included describing each clamping. Otherwise, columns correspond to readouts only.
Return type:
-
size
¶ int: The size (complexity) of this logical network as the sum of clauses’ length
-
step
(state, clamping)¶ Performs a simulation step from the given state and with respect to the given clamping
Parameters: - state (dict) – The key-value mapping describing the current state of the logical network
- clamping (caspo.core.clamping.Clamping) – A clamping over variables in the logical network
Returns: The key-value mapping describing the next state of the logical network
Return type: dict
-
to_array
(mappings)¶ Converts the logical network to a binary array with respect to the given mappings from a
caspo.core.hypergraph.HyperGraph
object instance.Parameters: mappings ( caspo.core.mapping.MappingList
) – Mappings to create the binary arrayReturns: Binary array with respect to the given mappings describing the logical network. Position i in the array will be 1 if the network has the mapping at position i in the given list of mappings. Return type: numpy.ndarray
-
to_graph
()¶ Converts the logical network to its underlying interaction graph
Returns: The underlying interaction graph Return type: caspo.core.graph.Graph
-
variables
()¶ Returns variables in the logical network
Returns: Unique variables names Return type: set[str]
-
-
class
caspo.core.logicalnetwork.
LogicalNetworkList
(hg, matrix=None, networks=None)¶ List of
caspo.core.logicalnetwork.LogicalNetwork
object instancesParameters: - hg (
caspo.core.hypergraph.HyperGraph
) – Underlying hypergraph of all logical networks. - matrix (Optional[numpy.ndarray]) – 2-D binary array representation of all logical networks. If None, an empty array is initialised
- networks (Optional[numpy.ndarray]) – For each network in the list, it gives the number of networks having the same behavior. If None, an array of ones is initialised with the same length as the number of networks in the list.
-
__getitem__
(index)¶ Returns logical network(s) at the given index
Parameters: index (object) – It can be an int or an iterable of int Returns: Either a caspo.core.logicalnetwork.LogicalNetwork
or acaspo.core.logicalnetwork.LogicalNetworkList
objectReturn type: object
-
__iter__
()¶ Iterates over all logical networks in the list
Yields: caspo.core.logicalnetwork.LogicalNetwork – The next logical network in the list
-
__len__
()¶ Returns the number of logical networks
Returns: Number of logical networks Return type: int
-
__plot__
()¶ Returns a networkx.MultiDiGraph ready for plotting. Edges weights correspond to mappings frequencies.
Returns: Network object instance ready for plotting Return type: networkx.MultiDiGraph
-
add_network
(pos, network)¶ Adds a network to the logical network at the given position
-
append
(network)¶ Append a
caspo.core.logicalnetwork.LogicalNetwork
to the listParameters: network ( caspo.core.logicalnetwork.LogicalNetwork
) – The network to append
-
combinatorics
()¶ Returns mutually exclusive/inclusive mappings
Returns: A tuple of 2 dictionaries. For each mapping key, the first dict has as value the set of mutually exclusive mappings while the second dict has as value the set of mutually inclusive mappings. Return type: (dict,dict)
-
concat
(other)¶ Returns the concatenation with another
caspo.core.logicalnetwork.LogicalNetworkList
object instance. It is assumed (not checked) that both have the same underlying hypergraph.Parameters: other ( caspo.core.logicalnetwork.LogicalNetworkList
) – The list to concatenateReturns: If other is empty returns self, if self is empty returns other, otherwise a new caspo.core.LogicalNetworkList
is created by concatenating self and other.Return type: caspo.core.logicalnetwork.LogicalNetworkList
-
frequencies_iter
()¶ Iterates over all non-zero frequencies of logical conjunction mappings in this list
Yields: tuple[caspo.core.mapping.Mapping, float] – The next pair (mapping,frequency)
-
frequency
(mapping)¶ Returns frequency of a given
caspo.core.mapping.Mapping
Parameters: mapping ( caspo.core.mapping.Mapping
) – A logical conjuntion mappingReturns: Frequency of the given mapping over all logical networks Return type: float Raises: ValueError
– If the given mapping is not found in the mappings of the underlying hypergraph of this list
-
classmethod
from_csv
(klass, filename)¶ Creates a list of logical networks from a CSV file. Columns that cannot be parsed as a
caspo.core.mapping.Mapping
are ignored except for a column named networks which (if present) is interpreted as the number of logical networks having the same input-output behavior.Parameters: filename (str) – Absolute path to CSV file Returns: Created object instance Return type: caspo.core.logicalnetwork.LogicalNetworkList
-
classmethod
from_hypergraph
(klass, hypergraph, networks=[])¶ Creates a list of logical networks from a given hypergraph and an optional list of
caspo.core.logicalnetwork.LogicalNetwork
object instancesParameters: - hypegraph (
caspo.core.hypergraph.HyperGraph
) – Underlying hypergraph for this logical network list - networks (Optional[list]) – List of
caspo.core.logicalnetwork.LogicalNetwork
object instances
Returns: Created object instance
Return type: - hypegraph (
-
mappings
¶ caspo.core.mapping.MappingList
: the list of mappings present in at least one logical network in this list
-
predictions
(setup, n_jobs=-1)¶ Returns a pandas.DataFrame with the weighted average predictions and variance of all readouts for each possible clampings in the given experimental setup. For each logical network the weight corresponds to the number of networks having the same behavior.
Parameters: - setup (
caspo.core.setup.Setup
) – Experimental setup - n_jobs (int) – Number of jobs to run in parallel. Default to -1 (all cores available)
Returns: DataFrame with the weighted average predictions and variance of all readouts for each possible clamping
Return type: See also
- setup (
-
reset
()¶ Drop all networks in the list
-
split
(indices)¶ Splits logical networks according to given indices
Parameters: indices (list) – 1-D array of sorted integers, the entries indicate where the array is split Returns: List of caspo.core.logicalnetwork.LogicalNetworkList
object instancesReturn type: list See also
-
to_csv
(filename, networks=False, dataset=None, size=False, n_jobs=-1)¶ Writes the list of logical networks to a CSV file
Parameters: - filename (str) – Absolute path where to write the CSV file
- networks (boolean) – If True, a column with number of networks having the same behavior is included in the file
- dataset (Optional[
caspo.core.dataset.Dataset
]) – If not None, a column with the MSE with respect to the given dataset is included - size (boolean) – If True, a column with the size of each logical network is included
- n_jobs (int) – Number of jobs to run in parallel. Default to -1 (all cores available)
-
to_dataframe
(networks=False, dataset=None, size=False, n_jobs=-1)¶ Converts the list of logical networks to a pandas.DataFrame object instance
Parameters: - networks (boolean) – If True, a column with number of networks having the same behavior is included in the DataFrame
- dataset (Optional[
caspo.core.dataset.Dataset
]) – If not None, a column with the MSE with respect to the given dataset is included in the DataFrame - size (boolean) – If True, a column with the size of each logical network is included in the DataFrame
- n_jobs (int) – Number of jobs to run in parallel. Default to -1 (all cores available)
Returns: DataFrame representation of the list of logical networks.
Return type:
-
to_funset
()¶ Converts the list of logical networks to a set of gringo.Fun instances
Returns: Representation of all networks as a set of gringo.Fun instances Return type: set
-
weighted_mse
(dataset, n_jobs=-1)¶ Returns the weighted MSE over all logical networks with respect to the given
caspo.core.dataset.Dataset
object instance. For each logical network the weight corresponds to the number of networks having the same behavior.Parameters: - dataset (
caspo.core.dataset.Dataset
) – Dataset to compute MSE - n_jobs (int) – Number of jobs to run in parallel. Default to -1 (all cores available)
Returns: Weighted MSE
Return type: float
- dataset (
- hg (