Skip to content

Commit

Permalink
move more options into structs
Browse files Browse the repository at this point in the history
  • Loading branch information
Rob Patro committed Jun 3, 2022
1 parent c981ee0 commit b5f30ee
Show file tree
Hide file tree
Showing 3 changed files with 42 additions and 31 deletions.
26 changes: 12 additions & 14 deletions src/cellfilter.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ use anyhow::{anyhow, Context};
use slog::crit;
use slog::info;

use crate::prog_opts::GenPermitListOpts;
use crate::utils as afutils;
#[allow(unused_imports)]
use ahash::{AHasher, RandomState};
Expand All @@ -30,6 +31,7 @@ use std::io::{BufRead, BufReader, Read};
use std::io::{BufWriter, Write};
use std::time::Instant;

#[derive(Debug)]
pub enum CellFilterMethod {
// cut off at this cell in
// the frequency sorted list
Expand Down Expand Up @@ -580,20 +582,16 @@ fn process_filtered(
/// (i.e. "permitted") barcode values, as well as
/// a map from each correctable barcode to the
/// permitted barcode to which it maps.
#[allow(clippy::too_many_arguments)]
pub fn generate_permit_list(
rad_dir: String,
output_dir: String,
filter_meth: CellFilterMethod,
expected_ori: Strand,
version: &str,
velo_mode: bool,
cmdline: &str,
//top_k: Option<usize>,
//valid_bc_file: Option<String>,
//use_knee_distance: bool,
log: &slog::Logger,
) -> anyhow::Result<u64> {
pub fn generate_permit_list(gpl_opts: GenPermitListOpts) -> anyhow::Result<u64> {
let rad_dir = gpl_opts.input_dir;
let output_dir = gpl_opts.output_dir;
let filter_meth = gpl_opts.fmeth;
let expected_ori = gpl_opts.expected_ori;
let version = gpl_opts.version;
let velo_mode = gpl_opts.velo_mode;
let cmdline = gpl_opts.cmdline;
let log = gpl_opts.log;

let i_dir = std::path::Path::new(&rad_dir);

if !i_dir.exists() {
Expand Down
29 changes: 13 additions & 16 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ use slog::{crit, o, warn, Drain};
use std::path::Path;

use alevin_fry::cellfilter::{generate_permit_list, CellFilterMethod};
use alevin_fry::prog_opts::QuantOpts;
use alevin_fry::prog_opts::{GenPermitListOpts, QuantOpts};
use alevin_fry::quant::{ResolutionStrategy, SplicedAmbiguityModel};

#[global_allocator]
Expand Down Expand Up @@ -336,16 +336,18 @@ fn main() -> anyhow::Result<()> {
// velo_mode --- currently, on this branch, it is always false
let velo_mode = false; //t.is_present("velocity-mode");

match generate_permit_list(
input_dir,
output_dir,
fmeth,
expected_ori,
VERSION,
velo_mode,
&cmdline,
&log,
) {
let gpl_opts = GenPermitListOpts::builder()
.input_dir(input_dir)
.output_dir(output_dir)
.fmeth(fmeth)
.expected_ori(expected_ori)
.version(VERSION)
.velo_mode(velo_mode)
.cmdline(&cmdline)
.log(&log)
.build();

match generate_permit_list(gpl_opts) {
Ok(nc) if nc == 0 => {
warn!(log, "found 0 corrected barcodes; please check the input.");
}
Expand Down Expand Up @@ -589,16 +591,11 @@ fn main() -> anyhow::Result<()> {
let eq_label_file = t.value_of_t("eq-labels").unwrap();
let filter_list = t.value_of("quant-subset");
let usa_mode = t.is_present("usa");
//let bc_file = t.value_of_t("barcodes").unwrap();

alevin_fry::infer::infer(
//num_bootstraps,
//init_uniform,
//summary_stat,
count_mat,
eq_label_file,
usa_mode,
//bc_file,
use_mtx,
num_threads,
filter_list,
Expand Down
18 changes: 17 additions & 1 deletion src/prog_opts.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,11 @@
use crate::quant::{ResolutionStrategy, SplicedAmbiguityModel};
//use derive_builder::Builder;
use bio_types::strand::Strand;
use slog;
use typed_builder::TypedBuilder;

use crate::cellfilter::CellFilterMethod;
use crate::quant::{ResolutionStrategy, SplicedAmbiguityModel};

#[derive(TypedBuilder, Debug)]
//#[builder(name = "QuantOptsBuilder")]
pub struct QuantOpts<'a, 'b, 'c, 'd> {
Expand All @@ -24,3 +28,15 @@ pub struct QuantOpts<'a, 'b, 'c, 'd> {
pub version: &'c str,
pub log: &'d slog::Logger,
}

#[derive(TypedBuilder, Debug)]
pub struct GenPermitListOpts<'a, 'b, 'c> {
pub input_dir: String,
pub output_dir: String,
pub fmeth: CellFilterMethod,
pub expected_ori: Strand,
pub velo_mode: bool,
pub cmdline: &'a str,
pub version: &'b str,
pub log: &'c slog::Logger,
}

0 comments on commit b5f30ee

Please sign in to comment.