Skip to content

doc: add haploid WF example to book #397

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Nov 7, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions book/src/SUMMARY.md
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
1 change: 1 addition & 0 deletions book/src/examples.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
# Example programs <img align="right" width="73" height="45" src="https://raw.githubusercontent.com/tskit-dev/administrative/main/logos/svg/tskit-rust/Tskit_rust_logo.eps.svg">
13 changes: 13 additions & 0 deletions book/src/examples_haploid_wright_fisher.md
Original file line number Diff line number Diff line change
@@ -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}}
```
2 changes: 2 additions & 0 deletions examples/haploid_wright_fisher.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ use proptest::prelude::*;
use rand::distributions::Distribution;
use rand::SeedableRng;

// ANCHOR: haploid_wright_fisher
fn simulate(
seed: u64,
popsize: usize,
Expand Down Expand Up @@ -81,6 +82,7 @@ fn simulate(

Ok(treeseq)
}
// ANCHOR_END: haploid_wright_fisher

#[derive(Clone, clap::Parser)]
struct SimParams {
Expand Down