Skip to content

Commit

Permalink
clippy is happy
Browse files Browse the repository at this point in the history
  • Loading branch information
Rob Patro committed Mar 6, 2024
1 parent e74dde2 commit 423f9bc
Showing 1 changed file with 8 additions and 20 deletions.
28 changes: 8 additions & 20 deletions src/convert.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,9 @@ use std::fs::File;
use std::io::{stdout, BufReader, BufWriter, Cursor, Seek, SeekFrom, Write};
// use std::sync::{Arc, Mutex};
//
use rust_htslib::{bam, bam::record::Aux, bam::Read};

use noodles::bam as nbam;
use noodles::{bgzf, sam};
use noodles_util::alignment;
use sam::alignment::record::data::field::{tag::Tag as SamTag, value::Value as SamTagValue};

use libradicl::rad_types::{self, RadType};
Expand Down Expand Up @@ -112,7 +110,6 @@ where
}
let ofile = File::create(rad_file.as_ref()).unwrap();

let mut bam = bam::Reader::from_path(&input_file).unwrap();
let bam_bytes = fs::metadata(&input_file).unwrap().len();
info! {
log,
Expand All @@ -123,6 +120,7 @@ where
// noodles reading
let file = File::open(&input_file)?;

// example from https://github.com/zaeleus/noodles/issues/227
let mut reader: Box<dyn sam::alignment::io::Read<_>> =
match input_file.as_ref().extension().and_then(|ext| ext.to_str()) {
Some("bam") | Some("BAM") => {
Expand Down Expand Up @@ -152,18 +150,10 @@ where
for result in reader.records(&header) {
let record = result?;
}
let hdrv = bam.header().to_owned();
*/

if num_threads > 1 {
bam.set_threads((num_threads as usize) - 1).unwrap();
} else {
bam.set_threads(1).unwrap();
}

//let hdrv = bam.header().to_owned();

let hdrv = reader.read_alignment_header()?;

let mut data = Cursor::new(vec![]);
// initialize the header (do we need this ?)
// let mut hdr = libradicl::RadHeader::from_bam_header(&hdrv);
Expand All @@ -177,8 +167,8 @@ where

// file writer
// let owriter = Arc::new(Mutex::new(BufWriter::with_capacity(1048576, ofile)));
let mut owriter = BufWriter::with_capacity(1048576, ofile);
// intermediate buffer
let mut owriter = BufWriter::with_capacity(1048576, ofile);

// write the header
{
Expand All @@ -191,7 +181,7 @@ where
data.write_all(&ref_count.to_le_bytes())
.expect("couldn't write to output file");
// create longest buffer
for (k, v) in hdrv.reference_sequences().iter() {
for (k, _v) in hdrv.reference_sequences().iter() {
let name_size = k.len() as u16;
data.write_all(&name_size.to_le_bytes())
.expect("coudn't write to output file");
Expand Down Expand Up @@ -256,7 +246,7 @@ where
let bc_string_in: &str = if let Some(Ok(bcs)) = flag_data.get(&CR) {
match bcs {
SamTagValue::String(bstr) => {
str::from_utf8(<BStr as AsRef<[u8]>>::as_ref(bstr).as_ref())?
str::from_utf8(<BStr as AsRef<[u8]>>::as_ref(bstr))?
}
_ => {
bail!("cannot convert non-string (Z) tag into barcode string.");
Expand All @@ -269,7 +259,7 @@ where
let umi_string_in: &str = if let Some(Ok(umis)) = flag_data.get(&UR) {
match umis {
SamTagValue::String(bstr) => {
str::from_utf8(<BStr as AsRef<[u8]>>::as_ref(bstr).as_ref())?
str::from_utf8(<BStr as AsRef<[u8]>>::as_ref(bstr))?
}
_ => {
bail!("cannot convert non-string (Z) tag into umi string.");
Expand Down Expand Up @@ -378,14 +368,12 @@ where
let mut bc = 0u64;
let mut umi = 0u64;
let mut tid_list = Vec::<u32>::new();
let mut first_pass = true;
//for r in bam.records(){
loop {
let rec_res = record_it.next();
if rec_res.is_none() {
break;
}
first_pass = false;
// the iterator returns a result, so
// make sure it's an Ok variant here.
let rec = match rec_res.unwrap() {
Expand Down Expand Up @@ -461,7 +449,7 @@ where
let bc_string_in: &str = if let Some(Ok(bcs)) = flag_data.get(&CR) {
match bcs {
SamTagValue::String(bstr) => {
str::from_utf8(<BStr as AsRef<[u8]>>::as_ref(bstr).as_ref())?
str::from_utf8(<BStr as AsRef<[u8]>>::as_ref(bstr))?
}
_ => {
bail!("cannot convert non-string (Z) tag into umi string.");
Expand All @@ -474,7 +462,7 @@ where
let umi_string_in: &str = if let Some(Ok(umis)) = flag_data.get(&UR) {
match umis {
SamTagValue::String(bstr) => {
str::from_utf8(<BStr as AsRef<[u8]>>::as_ref(bstr).as_ref())?
str::from_utf8(<BStr as AsRef<[u8]>>::as_ref(bstr))?
}
_ => {
bail!("cannot convert non-string (Z) tag into umi string.");
Expand Down

0 comments on commit 423f9bc

Please sign in to comment.