From 6b50441528ddb1824551f755c47179a63fc23815 Mon Sep 17 00:00:00 2001 From: "Kevin R. Thornton" Date: Mon, 7 Nov 2022 08:57:33 -0800 Subject: [PATCH] doc: add haploid WF example to book --- book/src/SUMMARY.md | 3 +++ book/src/examples.md | 1 + book/src/examples_haploid_wright_fisher.md | 13 +++++++++++++ examples/haploid_wright_fisher.rs | 2 ++ 4 files changed, 19 insertions(+) create mode 100644 book/src/examples.md create mode 100644 book/src/examples_haploid_wright_fisher.md diff --git a/book/src/SUMMARY.md b/book/src/SUMMARY.md index 5816e741b..39b735f25 100644 --- a/book/src/SUMMARY.md +++ b/book/src/SUMMARY.md @@ -21,6 +21,9 @@ - [Metadata schema](./metadata_schema.md) * [Error handling](./error_handling.md) + +* [Example programs](./examples.md) + - [Haploid Wright-Fisher simulation](./examples_haploid_wright_fisher.md) [Crate prelude](./prelude.md) diff --git a/book/src/examples.md b/book/src/examples.md new file mode 100644 index 000000000..1cb44c5fc --- /dev/null +++ b/book/src/examples.md @@ -0,0 +1 @@ +# Example programs diff --git a/book/src/examples_haploid_wright_fisher.md b/book/src/examples_haploid_wright_fisher.md new file mode 100644 index 000000000..3f30ea21c --- /dev/null +++ b/book/src/examples_haploid_wright_fisher.md @@ -0,0 +1,13 @@ +# Haploid Wright-Fisher simulation + +The following code simulates a haploid Wright-Fisher model. +The code is a reimplementation of an example program distributed with `tskit-c`. + +In addition to `tskit`, the example uses: + +* [rand](https://crates.io/crates/rand) for random number generation. +* [anyhow](https://crates.io/crates/anyhow) for error propagation. + +```rust, noplayground, ignore +{{#include ../../examples/haploid_wright_fisher.rs:haploid_wright_fisher}} +``` diff --git a/examples/haploid_wright_fisher.rs b/examples/haploid_wright_fisher.rs index 81731d8de..a88b0e9ff 100644 --- a/examples/haploid_wright_fisher.rs +++ b/examples/haploid_wright_fisher.rs @@ -8,6 +8,7 @@ use proptest::prelude::*; use rand::distributions::Distribution; use rand::SeedableRng; +// ANCHOR: haploid_wright_fisher fn simulate( seed: u64, popsize: usize, @@ -81,6 +82,7 @@ fn simulate( Ok(treeseq) } +// ANCHOR_END: haploid_wright_fisher #[derive(Clone, clap::Parser)] struct SimParams {