Struct biodivine_lib_param_bn::BooleanNetwork
source · [−]pub struct BooleanNetwork {
pub(crate) graph: RegulatoryGraph,
pub(crate) parameters: Vec<Parameter>,
pub(crate) update_functions: Vec<Option<FnUpdate>>,
pub(crate) parameter_to_index: HashMap<String, ParameterId>,
}
Expand description
A Boolean network, possibly parametrised with uninterpreted Boolean functions.
The structure of the network is based on an underlying RegulatoryGraph
. However,
compared to a RegulatoryGraph
, BooleanNetwork
can have a specific update function
given for each variable.
If the function is not specified (so called implicit parametrisation), all admissible Boolean functions are considered in its place. A function can be also only partially specified by using declared explicit parameters. These are uninterpreted but named Boolean functions, such that, again, all admissible instantiations of these functions are considered. See crate tutorial to learn more.
Boolean network equivalence
Please keep in mind that we consider two networks to be equivalent when they share a regulatory graph, and when they have (syntactically) the same update functions and parameters. We do not perform any semantic checks for whether the update functions are functionally equivalent.
Also keep in mind that the ordering of variables and parameters must be shared by equivalent
networks. This is because we want to preserve the property that VariableId
and ParameterId
objects are interchangeable as log as networks are equivalent.
Fields
graph: RegulatoryGraph
parameters: Vec<Parameter>
update_functions: Vec<Option<FnUpdate>>
parameter_to_index: HashMap<String, ParameterId>
Implementations
sourceimpl BooleanNetwork
impl BooleanNetwork
sourcepub fn make_witness(
&self,
params: &BddParams,
encoder: &BddParameterEncoder
) -> BooleanNetwork
pub fn make_witness(
&self,
params: &BddParams,
encoder: &BddParameterEncoder
) -> BooleanNetwork
Legacy function for creating a fully instantiated BooleanNetwork
using parameters.
In later revisions, this should be part of BddParameterEncoder
.
sourcepub fn make_witness_for_valuation(
&self,
valuation: BddValuation,
encoder: &BddParameterEncoder
) -> BooleanNetwork
pub fn make_witness_for_valuation(
&self,
valuation: BddValuation,
encoder: &BddParameterEncoder
) -> BooleanNetwork
Legacy function for creating a fully instantiated BooleanNetwork
using parameters.
In later revisions, this should be part of BddParameterEncoder
.
fn replace_parameters(
update_function: &FnUpdate,
parameter_expressions: &[BooleanExpression]
) -> Box<FnUpdate>
fn expression_to_fn_update(
expression: &BooleanExpression,
args: &[VariableId]
) -> Box<FnUpdate>
sourceimpl BooleanNetwork
impl BooleanNetwork
sourcepub fn try_from_sbml(
model_file: &str
) -> Result<(BooleanNetwork, Layout), String>
pub fn try_from_sbml(
model_file: &str
) -> Result<(BooleanNetwork, Layout), String>
Try to read a BooleanNetwork
from an SBML string.
Also reads Layout
information from the file. If there is no layout, an empty map is
returned.
sourcepub fn try_from_sbml_strict(
model_file: &str,
warnings: &mut Vec<String>
) -> Result<(BooleanNetwork, Layout), String>
pub fn try_from_sbml_strict(
model_file: &str,
warnings: &mut Vec<String>
) -> Result<(BooleanNetwork, Layout), String>
The same as try_from_sbml
, but provides access to all warnings generated during parsing.
These can be for example due to incompatibility in variable names (which the parser resolves automatically).
sourceimpl BooleanNetwork
impl BooleanNetwork
sourcepub fn to_sbml(&self, layout: Option<&Layout>) -> String
pub fn to_sbml(&self, layout: Option<&Layout>) -> String
Convert this network to an SBML string with an optional Layout
.
sourcepub fn write_as_sbml(
&self,
layout: Option<&Layout>,
out: &mut dyn Write
) -> Result<(), Error>
pub fn write_as_sbml(
&self,
layout: Option<&Layout>,
out: &mut dyn Write
) -> Result<(), Error>
Write an SBML string representation (with an optional Layout
) of this network
to the given out
writer.
fn write_species(&self, out: &mut dyn Write) -> Result<(), Error>
fn write_transitions(&self, out: &mut dyn Write) -> Result<(), Error>
fn write_update_function(
&self,
out: &mut dyn Write,
function: &FnUpdate
) -> Result<(), Error>
sourceimpl BooleanNetwork
impl BooleanNetwork
Methods for parsing BooleanNetwork
s from string representation.
sourcepub fn add_string_update_function(
&mut self,
variable: &str,
update_function: &str
) -> Result<(), String>
pub fn add_string_update_function(
&mut self,
variable: &str,
update_function: &str
) -> Result<(), String>
Add a new UpdateFunction
to the BooleanNetwork
. All variables and parameters
must be already present in the network. Furthermore, all parameters must be used
with their correct cardinality.
sourcepub(crate) fn add_template_update_function(
&mut self,
variable: &str,
update_function: FnUpdateTemp
) -> Result<(), String>
pub(crate) fn add_template_update_function(
&mut self,
variable: &str,
update_function: FnUpdateTemp
) -> Result<(), String>
(internal) Utility method used in other parts of the parser.
sourcefn get_variable_for_name(&self, name: &str) -> Result<VariableId, String>
fn get_variable_for_name(&self, name: &str) -> Result<VariableId, String>
(internal) Utility method to safely obtain variable for the update function with appropriate error message.
sourceimpl BooleanNetwork
impl BooleanNetwork
Basic methods for safely building BooleanNetwork
s.
sourcepub fn new(graph: RegulatoryGraph) -> BooleanNetwork
pub fn new(graph: RegulatoryGraph) -> BooleanNetwork
Construct a new BooleanNetwork
from a RegulatoryGraph
without any parameters.
sourcepub fn add_parameter(
&mut self,
name: &str,
arity: u32
) -> Result<ParameterId, String>
pub fn add_parameter(
&mut self,
name: &str,
arity: u32
) -> Result<ParameterId, String>
Add a new Parameter
to the BooleanNetwork
.
The parameter name must be different from other parameters and variables.
sourcepub fn add_update_function(
&mut self,
variable: VariableId,
function: FnUpdate
) -> Result<(), String>
pub fn add_update_function(
&mut self,
variable: VariableId,
function: FnUpdate
) -> Result<(), String>
Add a new UpdateFunction
to the BooleanNetwork
.
The variable must not already have an update function. We assume all the variables
and parameters in the function are used correctly. If you are not sure how to safely
build an instance of a FnUpdate
, look at the variants of this method which parse
the function safely from a string.
sourcepub fn set_update_function(
&mut self,
variable: VariableId,
function: Option<FnUpdate>
) -> Result<(), String>
pub fn set_update_function(
&mut self,
variable: VariableId,
function: Option<FnUpdate>
) -> Result<(), String>
Allows to directly replace (or remove) the update function.
The function will replace existing function (if any), but it still needs to satisfy the declared regulations.
sourcefn assert_no_such_variable(&self, name: &str) -> Result<(), String>
fn assert_no_such_variable(&self, name: &str) -> Result<(), String>
(internal) Utility method to ensure that a parameter is also not a variable.
sourcefn assert_no_such_parameter(&self, name: &str) -> Result<(), String>
fn assert_no_such_parameter(&self, name: &str) -> Result<(), String>
(internal) Utility method to ensure that a parameter is not a duplicate.
sourcefn assert_no_update_function(&self, variable: VariableId) -> Result<(), String>
fn assert_no_update_function(&self, variable: VariableId) -> Result<(), String>
(internal) Utility method to ensure that an update function is not set yet.
sourcefn assert_arguments_are_valid(
&self,
variable: VariableId,
actual: Vec<VariableId>
) -> Result<(), String>
fn assert_arguments_are_valid(
&self,
variable: VariableId,
actual: Vec<VariableId>
) -> Result<(), String>
(internal) Utility method to check that the arguments of a function are a subset of the actual regulators.
sourceimpl BooleanNetwork
impl BooleanNetwork
Some utility methods for accessing the structure of a BooleanNetwork
. Some of them are just
delegating to the internal RegulatoryGraph
, but we have a copy here as well because they
are used very often.
sourcepub fn as_graph(&self) -> &RegulatoryGraph
pub fn as_graph(&self) -> &RegulatoryGraph
Obtain a reference to the underlying RegulatoryGraph
of the BooleanNetwork
.
sourcepub fn as_graph_mut(&mut self) -> &mut RegulatoryGraph
pub fn as_graph_mut(&mut self) -> &mut RegulatoryGraph
Obtain a mutable reference to the underlying RegulatoryGraph
.
However, note that at the moment, you can’t really do much with this reference, only add new regulations.
sourcepub fn num_parameters(&self) -> usize
pub fn num_parameters(&self) -> usize
The number of explicit parameters in this BooleanNetwork
(there can be network
variables using erased functions–implicit parameters–that are not counted here).
sourcepub fn num_implicit_parameters(&self) -> usize
pub fn num_implicit_parameters(&self) -> usize
The number of variables with erased update functions in this BooleanNetwork
.
sourcepub fn variables(&self) -> VariableIdIterator
pub fn variables(&self) -> VariableIdIterator
Return an iterator over all variable ids of this network.
sourcepub fn get_variable(&self, id: VariableId) -> &Variable
pub fn get_variable(&self, id: VariableId) -> &Variable
Return the variable object based on the given VariableId
.
sourcepub fn get_variable_name(&self, id: VariableId) -> &String
pub fn get_variable_name(&self, id: VariableId) -> &String
Shorthand for self.as_graph().get_variable(id).get_name()
.
sourcepub fn regulators(&self, target: VariableId) -> Vec<VariableId>ⓘNotable traits for Vec<u8, A>impl<A> Write for Vec<u8, A> where
A: Allocator,
pub fn regulators(&self, target: VariableId) -> Vec<VariableId>ⓘNotable traits for Vec<u8, A>impl<A> Write for Vec<u8, A> where
A: Allocator,
A: Allocator,
Return a sorted list of variables that regulate the given target
variable.
sourcepub fn targets(&self, regulator: VariableId) -> Vec<VariableId>ⓘNotable traits for Vec<u8, A>impl<A> Write for Vec<u8, A> where
A: Allocator,
pub fn targets(&self, regulator: VariableId) -> Vec<VariableId>ⓘNotable traits for Vec<u8, A>impl<A> Write for Vec<u8, A> where
A: Allocator,
A: Allocator,
Return a sorted list of variables that are regulated by the given regulator
variable.
sourcepub fn find_parameter(&self, name: &str) -> Option<ParameterId>
pub fn find_parameter(&self, name: &str) -> Option<ParameterId>
Find a ParameterId
corresponding to the given parameter name
.
sourcepub fn get_parameter(&self, id: ParameterId) -> &Parameter
pub fn get_parameter(&self, id: ParameterId) -> &Parameter
Get a Parameter
corresponding to the given ParameterId
.
sourcepub fn get_update_function(&self, variable: VariableId) -> &Option<FnUpdate>
pub fn get_update_function(&self, variable: VariableId) -> &Option<FnUpdate>
Get a FnUpdate
corresponding to the given VariableId
.
sourcepub fn parameters(&self) -> ParameterIdIterator
pub fn parameters(&self) -> ParameterIdIterator
Return an iterator over all parameter ids of this network.
sourcepub fn implicit_parameters(&self) -> Vec<VariableId>ⓘNotable traits for Vec<u8, A>impl<A> Write for Vec<u8, A> where
A: Allocator,
pub fn implicit_parameters(&self) -> Vec<VariableId>ⓘNotable traits for Vec<u8, A>impl<A> Write for Vec<u8, A> where
A: Allocator,
A: Allocator,
Iterate over all variables of this network that do not have update functions assigned for them.
sourcepub fn is_valid_name(name: &str) -> bool
pub fn is_valid_name(name: &str) -> bool
A static check that allows to verify validity of a parameter or variable name.
sourceimpl BooleanNetwork
impl BooleanNetwork
sourcepub fn infer_valid_graph(&self) -> Result<BooleanNetwork, String>
pub fn infer_valid_graph(&self) -> Result<BooleanNetwork, String>
Infer a regulatory graph based on the update functions of this BooleanNetwork
.
The resulting graph is solely based on the information that can be inferred from the update functions. In particular, if the BN contains uninterpreted functions, the monotonicity of variables appearing within these functions is unknown. Overall, this method is typically only useful for fully specified networks with minor errors in the regulatory graph.
The BN still has to satisfy basic integrity constraints. In particular, every uninterpreted function must be used, and must be used consistently (i.e. correct arity). Also, every update function may only used variables declared as regulators. Otherwise, an error is returned.
sourceimpl BooleanNetwork
impl BooleanNetwork
sourcepub fn try_from_bnet(model_string: &str) -> Result<BooleanNetwork, String>
pub fn try_from_bnet(model_string: &str) -> Result<BooleanNetwork, String>
Try to load a Boolean network from a .bnet
model.
Note that this is currently only a “best effort” implementation and you may encounter
unsupported bnet
models.
We also support some features that bnet does not, in particular, you can use Boolean constants. However, there are also other things that we do not support, since bnet can essentially use R syntax to define more complex functions, but in practice this is not used anywhere as far as I know.
sourceimpl BooleanNetwork
impl BooleanNetwork
sourcepub fn to_bnet(&self, rename_if_necessary: bool) -> Result<String, String>
pub fn to_bnet(&self, rename_if_necessary: bool) -> Result<String, String>
Produce a .bnet
string representation of this model.
Returns an error if the network is parametrised and thus cannot be converted to .bnet
.
Also returns an error if the network contains names which are not supported in .bnet
,
such as starting with numbers.
However, you can override this behaviour using rename_if_necessary
. If this flag is set,
all invalid names will be prefixed with _
.
Trait Implementations
sourceimpl Clone for BooleanNetwork
impl Clone for BooleanNetwork
sourcefn clone(&self) -> BooleanNetwork
fn clone(&self) -> BooleanNetwork
Returns a copy of the value. Read more
1.0.0 · sourcefn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
Performs copy-assignment from source
. Read more
sourceimpl Debug for BooleanNetwork
impl Debug for BooleanNetwork
sourceimpl Display for BooleanNetwork
impl Display for BooleanNetwork
sourceimpl Index<ParameterId> for BooleanNetwork
impl Index<ParameterId> for BooleanNetwork
Allow indexing BooleanNetwork
using ParameterId
objects.
sourceimpl Index<VariableId> for BooleanNetwork
impl Index<VariableId> for BooleanNetwork
Allow indexing BooleanNetwork
using VariableId
objects.
sourceimpl PartialEq<BooleanNetwork> for BooleanNetwork
impl PartialEq<BooleanNetwork> for BooleanNetwork
sourcefn eq(&self, other: &BooleanNetwork) -> bool
fn eq(&self, other: &BooleanNetwork) -> bool
This method tests for self
and other
values to be equal, and is used
by ==
. Read more
sourcefn ne(&self, other: &BooleanNetwork) -> bool
fn ne(&self, other: &BooleanNetwork) -> bool
This method tests for !=
.
sourceimpl TryFrom<&'_ str> for BooleanNetwork
impl TryFrom<&'_ str> for BooleanNetwork
impl Eq for BooleanNetwork
impl StructuralEq for BooleanNetwork
impl StructuralPartialEq for BooleanNetwork
Auto Trait Implementations
impl RefUnwindSafe for BooleanNetwork
impl Send for BooleanNetwork
impl Sync for BooleanNetwork
impl Unpin for BooleanNetwork
impl UnwindSafe for BooleanNetwork
Blanket Implementations
sourceimpl<T> BorrowMut<T> for T where
T: ?Sized,
impl<T> BorrowMut<T> for T where
T: ?Sized,
const: unstable · sourcepub fn borrow_mut(&mut self) -> &mut T
pub fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more
sourceimpl<T> ToOwned for T where
T: Clone,
impl<T> ToOwned for T where
T: Clone,
type Owned = T
type Owned = T
The resulting type after obtaining ownership.
sourcepub fn to_owned(&self) -> T
pub fn to_owned(&self) -> T
Creates owned data from borrowed data, usually by cloning. Read more
sourcepub fn clone_into(&self, target: &mut T)
pub fn clone_into(&self, target: &mut T)
toowned_clone_into
)Uses borrowed data to replace owned data, usually by cloning. Read more