Struct demes::Graph

source ·
pub struct Graph { /* private fields */ }
Expand description

A resolved demes Graph.

Instances of this type will be fully-resolved according to the machine data model described here.

A graph cannot be directly initialized. See:

Implementations§

source§

impl Graph

source

pub fn num_demes(&self) -> usize

The number of Deme instances in the graph.

source

pub fn get_deme_from_name(&self, name: &str) -> Option<&Deme>

👎Deprecated: Use Graph::get_deme instead

Obtain a reference to a Deme by its name.

§Returns

Some(&Deme) if name exists, None otherwise.

§Examples

See here.

source

pub fn deme<'name, I: Into<DemeId<'name>>>(&self, id: I) -> &Deme

Get the Deme at identifier id.

§Parameters
§Panics
  • If either variant of DemeId refers to an invalid deme
§Note

See Graph::get_deme for a version that will not panic

source

pub fn get_deme<'name, I: Into<DemeId<'name>>>(&self, id: I) -> Option<&Deme>

Get the Deme at identifier id.

§Parameters
§Returns
  • Some(&[Deme]) if id is valid
  • None otherwise
source

pub fn demes(&self) -> &[Deme]

Get the Deme instances via a slice.

source

pub fn generation_time(&self) -> GenerationTime

Get the GenerationTime for the graph.

source

pub fn time_units(&self) -> TimeUnits

Get the TimeUnits for the graph.

source

pub fn migrations(&self) -> &[AsymmetricMigration]

Get the migration events for the graph.

source

pub fn pulses(&self) -> &[Pulse]

Get the pulse events for the graph.

source

pub fn metadata(&self) -> Option<Metadata>

Get a copy of the top-level Metadata.

source

pub fn into_generations(self) -> Result<Self, DemesError>

Convert the time units to generations.

§Errors

If the time unit of an event differs sufficiently in magnitude from the generation_time, it is possible that conversion results in epochs (or migration durations) of length zero, which will return an error.

If any field is unresolved, an error will be returned.

source

pub fn into_integer_generations(self) -> Result<Graph, DemesError>

Convert the time units to generations, rounding the output to an integer value.

source

pub fn into_generations_with( self, with: fn(_: Time, _: GenerationTime) -> Time ) -> Result<Graph, DemesError>

Convert the time units to generations with a callback to specify the conversion policy

source

pub fn as_string(&self) -> Result<String, DemesError>

Return a representation of the graph as a string.

The format is in YAML and corresponds to the MDM representation of the data.

§Error

Will return an error if serde_yaml::to_string returns an error.

source

pub fn as_json_string(&self) -> Result<String, DemesError>

Available on crate feature json only.

Return a representation of the graph as a string.

The format is in JSON and corresponds to the MDM representation of the data.

§Error

Will return an error if serde_json::to_string returns an error.

source

pub fn most_recent_deme_end_time(&self) -> Time

Return the most recent end time of any deme in the Graph.

This function is useful to check if the most recent end time is greater than zero, meaning that the model ends at a time point ancestral to “now”.

source

pub fn description(&self) -> Option<&str>

Return the description field.

source

pub fn doi(&self) -> impl Iterator<Item = &str>

Return an iterator over DOI information.

source

pub fn has_non_integer_sizes(&self) -> Option<(&str, usize)>

Check if any epochs have non-integer start_size or end_size.

§Returns
  • The deme name and epoch index where the first non-integer value is encountered
  • None if non non-integer values are encountered
source

pub fn into_integer_start_end_sizes(self) -> Result<Self, DemesError>

Round all epoch start/end sizes to nearest integer value.

§Returns

A modified graph with rounded sizes.

§Error
§Note

Rounding uses f64::round

source

pub fn deme_names(&self) -> Box<[&str]>

Obtain names of all demes in the graph.

§Note

These are ordered by a deme’s index in the model.

§Panics

This function allocates space for the return value, which may panic upon out-of-memory.

Trait Implementations§

source§

impl Clone for Graph

source§

fn clone(&self) -> Graph

Returns a copy of the value. Read more
1.0.0 · source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
source§

impl Debug for Graph

source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
source§

impl Display for Graph

source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
source§

impl PartialEq for Graph

source§

fn eq(&self, other: &Self) -> bool

This method tests for self and other values to be equal, and is used by ==.
1.0.0 · source§

fn ne(&self, other: &Rhs) -> bool

This method tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
source§

impl Serialize for Graph

source§

fn serialize<__S>(&self, __serializer: __S) -> Result<__S::Ok, __S::Error>
where __S: Serializer,

Serialize this value into the given Serde serializer. Read more
source§

impl Eq for Graph

Auto Trait Implementations§

§

impl Freeze for Graph

§

impl RefUnwindSafe for Graph

§

impl Send for Graph

§

impl Sync for Graph

§

impl Unpin for Graph

§

impl UnwindSafe for Graph

Blanket Implementations§

source§

impl<T> Any for T
where T: 'static + ?Sized,

source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
source§

impl<T> Borrow<T> for T
where T: ?Sized,

source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
source§

impl<Q, K> Equivalent<K> for Q
where Q: Eq + ?Sized, K: Borrow<Q> + ?Sized,

source§

fn equivalent(&self, key: &K) -> bool

Compare self to key and return true if they are equal.
source§

impl<T> From<T> for T

source§

fn from(t: T) -> T

Returns the argument unchanged.

source§

impl<T, U> Into<U> for T
where U: From<T>,

source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

source§

impl<T> ToOwned for T
where T: Clone,

§

type Owned = T

The resulting type after obtaining ownership.
source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
source§

impl<T> ToString for T
where T: Display + ?Sized,

source§

default fn to_string(&self) -> String

Converts the given value to a String. Read more
source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

§

type Error = Infallible

The type returned in the event of a conversion error.
source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.