Struct biodivine_lib_param_bn::RegulatoryGraph
source · pub struct RegulatoryGraph { /* private fields */ }
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
:
# Regulators of a
a ->? a
b -|? a
# Regulators of b
a -> b
b -| b
Implementations§
source§impl 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.
source§impl 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 remove_regulation(
&mut self,
regulator: VariableId,
target: VariableId
) -> Result<Regulation, String>
pub fn remove_regulation( &mut self, regulator: VariableId, target: VariableId ) -> Result<Regulation, String>
Remove a Regulation from this RegulatoryGraph assuming it exists.
Note that if there is a [BooleanNetwork] that uses this graph internally, this can make some if its functions invalid if they depend on the existence of this regulation.
sourcepub fn add_raw_regulation(
&mut self,
regulation: Regulation
) -> Result<(), String>
pub fn add_raw_regulation( &mut self, regulation: Regulation ) -> Result<(), String>
Add a new regulation using the Regulation object.
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.
sourcepub fn variable_names(&self) -> Vec<String>
pub fn variable_names(&self) -> Vec<String>
Copy the variable names from this graph into a separate vector.
source§impl 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>
pub fn regulators(&self, target: VariableId) -> Vec<VariableId>
Return a sorted list of variables that regulate the given target
variable.
sourcepub fn targets(&self, regulator: VariableId) -> Vec<VariableId>
pub fn targets(&self, regulator: VariableId) -> Vec<VariableId>
Return a sorted list of variables that are regulated by the given regulator
variable.
sourcepub fn components(&self) -> Vec<HashSet<VariableId>>
👎Deprecated
pub fn components(&self) -> Vec<HashSet<VariableId>>
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!
**Deprecated in favor of strongly_connected_components
.
sourcepub fn variables(&self) -> VariableIdIterator
pub fn variables(&self) -> VariableIdIterator
Return an iterator over all variable ids of this graph.
sourcepub fn regulations(&self) -> RegulationIterator<'_>
pub fn regulations(&self) -> RegulationIterator<'_>
Return an iterator over all regulations of this graph.
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.
source§impl 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>
source§impl RegulatoryGraph
impl RegulatoryGraph
Algorithms for analysing the underlying signed directed graph.
sourcepub fn strongly_connected_components(&self) -> Vec<HashSet<VariableId>>
pub fn strongly_connected_components(&self) -> Vec<HashSet<VariableId>>
Compute all non-trivial strongly connected components of the regulatory graph.
The result is sorted by component size.
sourcepub fn restricted_strongly_connected_components(
&self,
restriction: &HashSet<VariableId>
) -> Vec<HashSet<VariableId>>
pub fn restricted_strongly_connected_components( &self, restriction: &HashSet<VariableId> ) -> Vec<HashSet<VariableId>>
Compute all non-trivial strongly connected components restricted within the given set of vertices.
The result is sorted by component size.
sourcepub fn transitive_regulators(&self, target: VariableId) -> HashSet<VariableId>
pub fn transitive_regulators(&self, target: VariableId) -> HashSet<VariableId>
Compute all variables that transitively regulate the given target
variable.
sourcepub fn transitive_targets(&self, regulator: VariableId) -> HashSet<VariableId>
pub fn transitive_targets(&self, regulator: VariableId) -> HashSet<VariableId>
Compute all variables that are transitively regulated by the given regulator
variable.
sourcepub fn shortest_cycle(&self, pivot: VariableId) -> Option<Vec<VariableId>>
pub fn shortest_cycle(&self, pivot: VariableId) -> Option<Vec<VariableId>>
Compute the shortest cycle that contains the given pivot
vertex, or None
if there
is no such cycle.
sourcepub fn shortest_parity_cycle(
&self,
pivot: VariableId,
target_parity: Sign
) -> Option<Vec<VariableId>>
pub fn shortest_parity_cycle( &self, pivot: VariableId, target_parity: Sign ) -> Option<Vec<VariableId>>
Compute the shortest simple cycle that contains the given pivot
vertex and has the
specified target_parity
.
sourcepub fn feedback_vertex_set(&self) -> HashSet<VariableId>
pub fn feedback_vertex_set(&self) -> HashSet<VariableId>
Compute the set of variables that, if removed, cause this RegulatoryGraph
to become
acyclic.
The method tries to obtain a minimal such set, but the minimality is not guaranteed.
sourcepub fn parity_feedback_vertex_set(&self, parity: Sign) -> HashSet<VariableId>
pub fn parity_feedback_vertex_set(&self, parity: Sign) -> HashSet<VariableId>
Compute the set of variables that, if removed, causes this RegulatoryGraph
to lose
all cycles of the specified parity.
The method tries to obtain a minimal such set, but the minimality is not guaranteed.
sourcepub fn independent_cycles(&self) -> Vec<Vec<VariableId>>
pub fn independent_cycles(&self) -> Vec<Vec<VariableId>>
Compute a collection of independent cycles of this RegulatoryGraph
. That is, disjoint
cycles that intersect every cycle in the graph.
The method tries to obtain a maximal such set, but the maximality is not guaranteed.
sourcepub fn independent_parity_cycles(&self, parity: Sign) -> Vec<Vec<VariableId>>
pub fn independent_parity_cycles(&self, parity: Sign) -> Vec<Vec<VariableId>>
Compute a collection of independent cycles of this RegulatoryGraph
with desired parity
.
That is, disjoint cycles of the given parity
that intersect every other cycle of this
parity
in the graph.
The method tries to obtain a maximal such set, but the maximality is not guaranteed.
Trait Implementations§
source§impl Clone for RegulatoryGraph
impl Clone for RegulatoryGraph
source§fn clone(&self) -> RegulatoryGraph
fn clone(&self) -> RegulatoryGraph
1.0.0 · source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source
. Read moresource§impl Debug for RegulatoryGraph
impl Debug for RegulatoryGraph
source§impl Display for RegulatoryGraph
impl Display for RegulatoryGraph
source§impl From<&RegulatoryGraph> for SdGraph
impl From<&RegulatoryGraph> for SdGraph
source§fn from(rg: &RegulatoryGraph) -> Self
fn from(rg: &RegulatoryGraph) -> Self
source§impl Index<VariableId> for RegulatoryGraph
impl Index<VariableId> for RegulatoryGraph
Allow indexing RegulatoryGraph
using VariableId
objects.
source§impl PartialEq for RegulatoryGraph
impl PartialEq 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.