Skip to content

Commit

Permalink
Merge pull request #13 from ncsa/develop
Browse files Browse the repository at this point in the history
Adding SeedableRNG and improving error handling.
  • Loading branch information
joshfactorial authored Mar 22, 2024
2 parents 6c4afd4 + 5dd35f0 commit 0e9d094
Show file tree
Hide file tree
Showing 16 changed files with 300 additions and 161 deletions.
2 changes: 2 additions & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 2 additions & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -14,3 +14,5 @@ clap = { version = "4.5.1", features = ["derive"] }
itertools = "0.12.1"
assert_fs = "1.1.1"
rand_distr = "0.5.0-alpha.0"
rand_core = "0.9.0-alpha.0"
rand_chacha = "0.9.0-alpha.0"
34 changes: 26 additions & 8 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@ extern crate simplelog;
extern crate serde_yaml;
extern crate rand_distr;
extern crate itertools;
extern crate rand_core;
extern crate rand_chacha;

mod utils;

Expand All @@ -13,14 +15,16 @@ use std::fs::File;
use clap::{Parser};
use log::*;
use simplelog::*;
use rand::SeedableRng;
use rand::thread_rng;

use rand_core::RngCore;
use utils::cli;
use utils::config::{read_config_yaml, build_config_from_args};
use utils::file_tools::check_parent;
use utils::runner::run_neat;
use utils::neat_rng::NeatRng;

fn main() -> Result<(), std::fmt::Error> {
fn main() {

info!("Begin processing");
// parse the arguments from the command line
Expand Down Expand Up @@ -59,8 +63,6 @@ fn main() -> Result<(), std::fmt::Error> {
)
]).unwrap();

let mut rng = thread_rng();

// set up the config struct based on whether there was an input config. Input config
// overrides any other inputs.
let config = if args.config != "" {
Expand All @@ -69,10 +71,26 @@ fn main() -> Result<(), std::fmt::Error> {
} else {
info!("Using command line arguments.");
debug!("Command line args: {:?}", &args);
Ok(build_config_from_args(args).expect("Problem reading configuration yaml file"))
}.unwrap();
build_config_from_args(args).unwrap_or_else(|error| {
panic!("Problem reading configuration yaml file {:?}", error)
})
};

// Generate the RNG used for this run. If one was given in the config file, use that, or else
// use thread_rng to generate a random seed, then seed using a SeedableRng based on StdRng
let seed: u64;
if !config.rng_seed.is_none() {
seed = config.rng_seed.unwrap();
} else {
// We pick a random u64 to use as a seed
let mut seed_rng = thread_rng();
seed = seed_rng.next_u64();
}
info!("Generating random numbers using the seed: {}", seed);
let mut rng: NeatRng = SeedableRng::seed_from_u64(seed);

run_neat(config, &mut rng).unwrap();
Ok(())
run_neat(config, &mut rng).unwrap_or_else(|error| {
panic!("Neat encountered a problem: {:?}", error)
})
}

2 changes: 1 addition & 1 deletion src/utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,5 +7,5 @@ pub mod mutate;
pub mod fastq_tools;
pub mod vcf_tools;
pub mod nucleotides;

pub mod neat_rng;
pub mod runner;
12 changes: 6 additions & 6 deletions src/utils/cli.rs
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
/// This is a pretty basic implementation of Clap CLI
/// The idea of this interface and supporting code is that the user can enter an optional
/// config file that will take the place of the other command line options, except the logging
/// features, which are handled separately. Either way, these options are read into a configuration
/// struct that holds the variables for the run. Logging, meanwhile, is handled separately,
/// outside run configuration parsing.
// This is a pretty basic implementation of Clap CLI
// The idea of this interface and supporting code is that the user can enter an optional
// config file that will take the place of the other command line options, except the logging
// features, which are handled separately. Either way, these options are read into a configuration
// struct that holds the variables for the run. Logging, meanwhile, is handled separately,
// outside run configuration parsing.

extern crate clap;

Expand Down
Loading

0 comments on commit 0e9d094

Please sign in to comment.