Struct biodivine_lib_param_bn::RegulatoryGraph
source · [−]pub struct RegulatoryGraph {
pub(crate) variables: Vec<Variable>,
pub(crate) regulations: Vec<Regulation>,
pub(crate) variable_to_index: HashMap<String, VariableId>,
}
Expand description
A directed graph representing relationships between a collection of Boolean variables
using Regulations
.
It can be explored using regulators
, targets
, transitive_regulators
, or
transitive_targets
(for example to determine if two variables depend on each other).
We can also compute the SCCs of this graph.
A regulatory graph can be described using a custom string format. In this format,
each line represents a regulation or a comment (starting with #
).
Regulations can be represented as strings in the form of
"regulator_name 'relationship' target_name"
. The ‘relationship’ is one of the arrow strings
->, ->?, -|, -|?, -?, -??
. Here, >
means activation, |
is inhibition and ?
is
unspecified monotonicity. The last question mark signifies observability — if it is present,
the regulation is not necessarily observable. See Regulation
and tutorial module for a more
detailed explanation.
Example of a RegulatoryGraph
:
a ->? a
b -|? a
a -> b
b -| b
Fields
variables: Vec<Variable>
regulations: Vec<Regulation>
variable_to_index: HashMap<String, VariableId>
Implementations
sourceimpl RegulatoryGraph
impl RegulatoryGraph
Methods for parsing RegulatoryGraph
s from string representations.
sourcepub fn try_from_string_regulations(
regulations: Vec<String>
) -> Result<RegulatoryGraph, String>
pub fn try_from_string_regulations(
regulations: Vec<String>
) -> Result<RegulatoryGraph, String>
Create a RegulatoryGraph
from a collection of regulation strings.
The variables of the RegulatoryGraph
are determined from the regulations
and are ordered alphabetically. Otherwise, this is equivalent to iteratively
calling add_string_regulation
.
sourcepub fn add_string_regulation(&mut self, regulation: &str) -> Result<(), String>
pub fn add_string_regulation(&mut self, regulation: &str) -> Result<(), String>
Add a new Regulation
to this RegulatoryGraph
where the regulation is
given in its string representation (e.g. “v1 ->? v2”).
The regulation
parameter must be a valid string representation of a regulation,
plus all conditions of add_regulation
must be satisfied as well.
sourcepub(crate) fn add_temp_regulation(
&mut self,
regulation: RegulationTemp
) -> Result<(), String>
pub(crate) fn add_temp_regulation(
&mut self,
regulation: RegulationTemp
) -> Result<(), String>
(internal) A utility method for adding regulations once they are parsed.
sourceimpl RegulatoryGraph
impl RegulatoryGraph
Methods for safely constructing new instances of RegulatoryGraph
s.
sourcepub fn new(variables: Vec<String>) -> RegulatoryGraph
pub fn new(variables: Vec<String>) -> RegulatoryGraph
Create a new RegulatoryGraph
with variables using the given names
and no regulations.
The ordering of the variables is preserved.
sourcepub fn add_regulation(
&mut self,
regulator: &str,
target: &str,
observable: bool,
monotonicity: Option<Monotonicity>
) -> Result<(), String>
pub fn add_regulation(
&mut self,
regulator: &str,
target: &str,
observable: bool,
monotonicity: Option<Monotonicity>
) -> Result<(), String>
Add a new Regulation
to this RegulatoryGraph
.
Returns Err
if regulator
or target
are not valid graph variables or when
the regulation between the two variables already exists.
sourcepub fn set_variable_name(
&mut self,
id: VariableId,
name: &str
) -> Result<(), String>
pub fn set_variable_name(
&mut self,
id: VariableId,
name: &str
) -> Result<(), String>
Set the name of a network variable. The name must not be used by any other variable.
Note that you don’t have to rename anything else in the network, since all other structures reference variables with ids.
sourcefn get_regulator(&self, name: &str) -> Result<VariableId, String>
fn get_regulator(&self, name: &str) -> Result<VariableId, String>
(internal) Utility method to safely obtain a regulator variable (using an appropriate error message).
sourcefn get_target(&self, name: &str) -> Result<VariableId, String>
fn get_target(&self, name: &str) -> Result<VariableId, String>
(internal) Utility method to safely obtain a target variable (using an appropriate error message).
sourcefn assert_no_regulation(
&self,
regulator: VariableId,
target: VariableId
) -> Result<(), String>
fn assert_no_regulation(
&self,
regulator: VariableId,
target: VariableId
) -> Result<(), String>
(internal) Utility method to ensure there is no regulation between the two variables yet.
sourceimpl RegulatoryGraph
impl RegulatoryGraph
Some basic utility methods for inspecting the RegulatoryGraph
.
sourcepub fn find_variable(&self, name: &str) -> Option<VariableId>
pub fn find_variable(&self, name: &str) -> Option<VariableId>
Find a VariableId
for the given name, or None
if the variable does not exist.
sourcepub fn get_variable(&self, id: VariableId) -> &Variable
pub fn get_variable(&self, id: VariableId) -> &Variable
Return a Variable
corresponding to the given VariableId
.
sourcepub fn get_variable_name(&self, id: VariableId) -> &String
pub fn get_variable_name(&self, id: VariableId) -> &String
Shorthand for self.get_variable(id).get_name()
.
sourcepub fn find_regulation(
&self,
regulator: VariableId,
target: VariableId
) -> Option<&Regulation>
pub fn find_regulation(
&self,
regulator: VariableId,
target: VariableId
) -> Option<&Regulation>
Find a Regulation
between two variables if it exists, None
otherwise.
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 transitive_regulators(&self, target: VariableId) -> HashSet<VariableId>
pub fn transitive_regulators(&self, target: VariableId) -> HashSet<VariableId>
Return the set of direct as well as transitive regulators of target
.
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 transitive_targets(&self, regulator: VariableId) -> HashSet<VariableId>
pub fn transitive_targets(&self, regulator: VariableId) -> HashSet<VariableId>
Return a set of direct as well as transitive targets of regulator
.
sourcepub fn components(&self) -> Vec<HashSet<VariableId>>ⓘNotable traits for Vec<u8, A>impl<A> Write for Vec<u8, A> where
A: Allocator,
pub fn components(&self) -> Vec<HashSet<VariableId>>ⓘNotable traits for Vec<u8, A>impl<A> Write for Vec<u8, A> where
A: Allocator,
A: Allocator,
Compute the strongly connected components of this regulatory graph. The components are sorted topologically based on their position in the graph condensation.
When sorting topologically incomparable components, we use component size as the secondary criterion. Also, note that the algorithm is not particularly efficient, so it should be used on large networks with caution!
sourcepub fn variables(&self) -> VariableIdIterator
pub fn variables(&self) -> VariableIdIterator
Return an iterator over all variable ids of this graph.
pub fn regulations(&self) -> RegulationIterator<'_>
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 variable name.
sourceimpl RegulatoryGraph
impl RegulatoryGraph
sourcepub fn to_dot(&self) -> String
pub fn to_dot(&self) -> String
Export this regulatory graph to a .dot
format.
In the representation, we use red and green color to distinguish positive and negative regulations. Dashed edges show regulations without observability requirement.
pub fn write_as_dot(&self, output: &mut dyn Write) -> Result<(), Error>
Trait Implementations
sourceimpl Clone for RegulatoryGraph
impl Clone for RegulatoryGraph
sourcefn clone(&self) -> RegulatoryGraph
fn clone(&self) -> RegulatoryGraph
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 RegulatoryGraph
impl Debug for RegulatoryGraph
sourceimpl Display for RegulatoryGraph
impl Display for RegulatoryGraph
sourceimpl Index<VariableId> for RegulatoryGraph
impl Index<VariableId> for RegulatoryGraph
Allow indexing RegulatoryGraph
using VariableId
objects.
sourceimpl PartialEq<RegulatoryGraph> for RegulatoryGraph
impl PartialEq<RegulatoryGraph> for RegulatoryGraph
To consider two regulatory graphs equivalent, we generally assume that they have the same
number of variables, with the same names, and stored in the same order. Furthermore, they
also need to have the same regulations, however, these do not have a specific order that
needs to be preserved. The reason why we enforce variable order and not regulation order
is that VariableId
objects should be compatible across equivalent graphs, but there is no
RegulationId
or a similar requirement.
sourceimpl TryFrom<&'_ str> for RegulatoryGraph
impl TryFrom<&'_ str> for RegulatoryGraph
impl Eq for RegulatoryGraph
Auto Trait Implementations
impl RefUnwindSafe for RegulatoryGraph
impl Send for RegulatoryGraph
impl Sync for RegulatoryGraph
impl Unpin for RegulatoryGraph
impl UnwindSafe for RegulatoryGraph
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