Skip to content

Commit 9acf22a

Browse files
authored
doc: add haploid WF example to book (#397)
1 parent f654d29 commit 9acf22a

File tree

4 files changed

+19
-0
lines changed

4 files changed

+19
-0
lines changed

book/src/SUMMARY.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,9 @@
2121
- [Metadata schema](./metadata_schema.md)
2222

2323
* [Error handling](./error_handling.md)
24+
25+
* [Example programs](./examples.md)
26+
- [Haploid Wright-Fisher simulation](./examples_haploid_wright_fisher.md)
2427

2528

2629
[Crate prelude](./prelude.md)

book/src/examples.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
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">
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
# Haploid Wright-Fisher simulation
2+
3+
The following code simulates a haploid Wright-Fisher model.
4+
The code is a reimplementation of an example program distributed with `tskit-c`.
5+
6+
In addition to `tskit`, the example uses:
7+
8+
* [rand](https://crates.io/crates/rand) for random number generation.
9+
* [anyhow](https://crates.io/crates/anyhow) for error propagation.
10+
11+
```rust, noplayground, ignore
12+
{{#include ../../examples/haploid_wright_fisher.rs:haploid_wright_fisher}}
13+
```

examples/haploid_wright_fisher.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ use proptest::prelude::*;
88
use rand::distributions::Distribution;
99
use rand::SeedableRng;
1010

11+
// ANCHOR: haploid_wright_fisher
1112
fn simulate(
1213
seed: u64,
1314
popsize: usize,
@@ -81,6 +82,7 @@ fn simulate(
8182

8283
Ok(treeseq)
8384
}
85+
// ANCHOR_END: haploid_wright_fisher
8486

8587
#[derive(Clone, clap::Parser)]
8688
struct SimParams {

0 commit comments

Comments
 (0)