Skip to content

Commit

Permalink
feat: log seed used when --seed not passed
Browse files Browse the repository at this point in the history
  • Loading branch information
mbhall88 committed Aug 19, 2024
1 parent 1fd13d4 commit 6e1f37d
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 8 deletions.
11 changes: 5 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -404,12 +404,11 @@ of the reads.

##### `-s`, `--seed`

This option allows you to specify the [random seed][seed] used by the random subsampler.
By explicitly setting this parameter, you make the subsample for the input reproducible.
The seed is an integer, and by default it is not set, meaning the operating system will
seed the random subsampler. You should only pass this parameter if you are likely to
want to subsample the same input file again in the future and want the same subset of
reads.
This option allows you to specify the [random seed][seed] used by the random subsampler. By explicitly setting this
parameter, you make the subsample for the input reproducible. You only need to pass this parameter if you are likely
to want to subsample the same input file again in the future and want the same subset of reads. However, if you forget
to use this option, the seed generated by the system will be printed to the log output, allowing you to use it in the
future.

#### Verbosity

Expand Down
6 changes: 5 additions & 1 deletion src/alignment.rs
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,11 @@ impl Runner for Alignment {

let mut rng = match self.seed {
Some(s) => rand_pcg::Pcg64::seed_from_u64(s),
None => rand_pcg::Pcg64::seed_from_u64(random()),
None => {
let seed = random();
info!("Using seed: {}", seed);
rand_pcg::Pcg64::seed_from_u64(seed)
}
};

let mut reader =
Expand Down
8 changes: 7 additions & 1 deletion src/subsampler.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
use log::info;
use rand::prelude::*;

/// A `Struct` for dealing with the randomised part of sub-sampling.
Expand Down Expand Up @@ -39,9 +40,14 @@ impl SubSampler {
/// ```
fn shuffled_indices<T>(&self, v: &[T]) -> Vec<u32> {
let mut indices: Vec<u32> = (0..v.len() as u32).collect();

let mut rng = match self.seed {
Some(s) => rand_pcg::Pcg64::seed_from_u64(s),
None => rand_pcg::Pcg64::seed_from_u64(random()),
None => {
let seed = random();
info!("Using seed: {}", seed);
rand_pcg::Pcg64::seed_from_u64(seed)
}
};

indices.shuffle(&mut rng);
Expand Down

0 comments on commit 6e1f37d

Please sign in to comment.