Skip to content

Commit

Permalink
fmt
Browse files Browse the repository at this point in the history
  • Loading branch information
k3yavi committed Aug 3, 2020
1 parent 4f6760e commit ef29d0e
Show file tree
Hide file tree
Showing 5 changed files with 73 additions and 50 deletions.
49 changes: 30 additions & 19 deletions libradicl/src/cellfilter.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,19 +8,19 @@ use self::slog::crit;
use self::slog::info;

use crate as libradicl;
use libradicl::exit_codes;
use fasthash::sea::Hash64;
use fasthash::RandomState;
use libradicl::exit_codes;
use num_format::{Locale, ToFormattedString};
use std::collections::HashMap;
use std::fs::File;
use std::io::BufReader;
use std::io::{BufWriter, Write};

/// Given the input RAD file `input_file`, compute
/// Given the input RAD file `input_file`, compute
/// and output (in `output_dir`) the list of valid
/// (i.e. "permitted") barcode values, as well as
/// a map from each correctable barcode to the
/// (i.e. "permitted") barcode values, as well as
/// a map from each correctable barcode to the
/// permitted barcode to which it maps.
pub fn generate_permit_list(
input_file: String,
Expand All @@ -47,22 +47,29 @@ pub fn generate_permit_list(
info!(log, "read {:?} read-level tags", rl_tags.tags.len());

// right now, we only handle BC and UMI types of U8鈥擴64, so validate that
const BNAME : &str = "b";
const UNAME : &str = "u";
const BNAME: &str = "b";
const UNAME: &str = "u";

let mut bct : Option<u8> = None;
let mut umit : Option<u8> = None;
let mut bct: Option<u8> = None;
let mut umit: Option<u8> = None;

for rt in &rl_tags.tags {
// if this is one of our tags
if &rt.name == BNAME || &rt.name == UNAME {
if libradicl::decode_int_type_tag(rt.typeid).is_none() {
crit!(log, "currently only RAD types 1--4 are supported for 'b' and 'u' tags.");
crit!(
log,
"currently only RAD types 1--4 are supported for 'b' and 'u' tags."
);
std::process::exit(exit_codes::EXIT_UNSUPPORTED_TAG_TYPE);
}

if &rt.name == BNAME { bct = Some(rt.typeid); }
if &rt.name == UNAME { umit = Some(rt.typeid); }

if &rt.name == BNAME {
bct = Some(rt.typeid);
}
if &rt.name == UNAME {
umit = Some(rt.typeid);
}
}
}

Expand All @@ -77,8 +84,10 @@ pub fn generate_permit_list(

let s = RandomState::<Hash64>::new();
let mut hm = HashMap::with_hasher(s);
let bc_type = libradicl::decode_int_type_tag(bct.expect("no barcode tag description present.")).expect("unknown barcode type id.");
let umi_type = libradicl::decode_int_type_tag(umit.expect("no umi tag description present")).expect("unknown barcode type id.");
let bc_type = libradicl::decode_int_type_tag(bct.expect("no barcode tag description present."))
.expect("unknown barcode type id.");
let umi_type = libradicl::decode_int_type_tag(umit.expect("no umi tag description present"))
.expect("unknown barcode type id.");

for _ in 0..(hdr.num_chunks as usize) {
let c = libradicl::Chunk::from_bytes(&mut br, &bc_type, &umi_type);
Expand All @@ -88,8 +97,8 @@ pub fn generate_permit_list(

info!(
log,
"observed {} reads in {} chunks",
num_reads.to_formatted_string(&Locale::en),
"observed {} reads in {} chunks",
num_reads.to_formatted_string(&Locale::en),
hdr.num_chunks.to_formatted_string(&Locale::en)
);

Expand Down Expand Up @@ -150,8 +159,10 @@ pub fn generate_permit_list(
bincode::serialize_into(&mut s_writer, &full_permit_list)
.expect("couldn't serialize permit list.");

info!(log, "total number of corrected barcodes : {}",
num_corrected.to_formatted_string(&Locale::en)
);
info!(
log,
"total number of corrected barcodes : {}",
num_corrected.to_formatted_string(&Locale::en)
);
Ok(num_corrected)
}
2 changes: 1 addition & 1 deletion libradicl/src/exit_codes.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,4 @@
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.

pub(super) static EXIT_UNSUPPORTED_TAG_TYPE : i32 = 65;
pub(super) static EXIT_UNSUPPORTED_TAG_TYPE: i32 = 65;
63 changes: 37 additions & 26 deletions libradicl/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@ extern crate fasthash;
extern crate needletail;
extern crate num;
extern crate quickersort;
extern crate scroll;
extern crate sce;
extern crate scroll;

use bio_types::strand::*;
use needletail::bitkmer::*;
Expand Down Expand Up @@ -103,27 +103,34 @@ pub enum RADIntID {
U64,
}

pub trait PrimitiveInteger : AsPrimitive<u8>
+ AsPrimitive<u16>
+ AsPrimitive<u32>
+ AsPrimitive<u64>
+ AsPrimitive<usize>
+ AsPrimitive<i8>
+ AsPrimitive<i16>
+ AsPrimitive<i32>
+ AsPrimitive<i64>
+ AsPrimitive<isize>{}

impl<T: AsPrimitive<u8>
+ AsPrimitive<u16>
+ AsPrimitive<u32>
+ AsPrimitive<u64>
+ AsPrimitive<usize>
+ AsPrimitive<i8>
+ AsPrimitive<i16>
+ AsPrimitive<i32>
+ AsPrimitive<i64>
+ AsPrimitive<isize>> PrimitiveInteger for T {}
pub trait PrimitiveInteger:
AsPrimitive<u8>
+ AsPrimitive<u16>
+ AsPrimitive<u32>
+ AsPrimitive<u64>
+ AsPrimitive<usize>
+ AsPrimitive<i8>
+ AsPrimitive<i16>
+ AsPrimitive<i32>
+ AsPrimitive<i64>
+ AsPrimitive<isize>
{
}

impl<
T: AsPrimitive<u8>
+ AsPrimitive<u16>
+ AsPrimitive<u32>
+ AsPrimitive<u64>
+ AsPrimitive<usize>
+ AsPrimitive<i8>
+ AsPrimitive<i16>
+ AsPrimitive<i32>
+ AsPrimitive<i64>
+ AsPrimitive<isize>,
> PrimitiveInteger for T
{
}

impl RADIntID {
pub fn bytes_for_type(&self) -> usize {
Expand All @@ -136,12 +143,16 @@ impl RADIntID {
}

/// Based on the variant of the current enum, write the value `v`
/// out using `owrite`. Here, `v` is bound to be some primitive
/// integer type. It is the responsibility of the caller to ensure
/// that, if `v` is wider than the enum type on which this function
/// out using `owrite`. Here, `v` is bound to be some primitive
/// integer type. It is the responsibility of the caller to ensure
/// that, if `v` is wider than the enum type on which this function
/// is called, no important information is lost by discarding the higher
/// order bits.
pub fn write_to<T: PrimitiveInteger, U: Write>(&self, v: T, owriter: &mut BufWriter<U>) -> std::io::Result<()> {
pub fn write_to<T: PrimitiveInteger, U: Write>(
&self,
v: T,
owriter: &mut BufWriter<U>,
) -> std::io::Result<()> {
match self {
Self::U8 => {
let vo: u8 = v.as_();
Expand Down
7 changes: 4 additions & 3 deletions libradicl/src/quant.rs
Original file line number Diff line number Diff line change
Expand Up @@ -429,9 +429,10 @@ pub fn quantify(
//sprs::io::write_matrix_market(&mat_path, &omat)?;

let mat_path = output_path.join("counts.eds.gz");
sce::eds::writer(&mat_path.to_str().expect("can't find file"),
&omat.to_csr())?;

sce::eds::writer(
&mat_path.to_str().expect("can't create output file"),
&omat.to_csr(),
)?;

let gn_path = output_path.join("gene_names.txt");
let gn_file = File::create(gn_path).expect("couldn't create gene name file.");
Expand Down
2 changes: 1 addition & 1 deletion src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ use libradicl::cellfilter::generate_permit_list;
use libradicl::schema::ResolutionStrategy;
use mimalloc::MiMalloc;
use rand::Rng;
use slog::{info, warn, crit, o, Drain};
use slog::{crit, info, o, warn, Drain};

#[global_allocator]
static GLOBAL: MiMalloc = MiMalloc;
Expand Down

0 comments on commit ef29d0e

Please sign in to comment.