From ca10f3eb018e1186f4713e1ce47b2ba777c5ec63 Mon Sep 17 00:00:00 2001 From: "Mitchell R. Vollger" Date: Wed, 10 Jan 2024 07:05:24 -0800 Subject: [PATCH] clippy --- Cargo.toml | 2 ++ src/bamlift/mod.rs | 16 ++++++++-------- src/basemods/mod.rs | 4 ++-- src/bio_io/mod.rs | 12 ++++++------ src/fiber.rs | 4 ++-- src/footprint.rs | 1 + tests/extract_test.rs | 1 + 7 files changed, 22 insertions(+), 18 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index 34b680e1..865b8b47 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -42,6 +42,8 @@ spin = "0.9.8" tch = {version = "0.14.0", optional = true} tempfile = "3.3.0" derive_builder = "0.12.0" +gzp = "0.11.3" +niffler = {version = "2.5.0", default-features = false, features = ["gz"]} [features] cli = ["dep:clap", "dep:clap_complete", "dep:clap_mangen", "dep:console"] diff --git a/src/bamlift/mod.rs b/src/bamlift/mod.rs index f5b30e32..28a86850 100644 --- a/src/bamlift/mod.rs +++ b/src/bamlift/mod.rs @@ -20,7 +20,7 @@ where /// Normal sort is supposed to be very fast on two sorted lists /// /// ``` -/// use bamlift::*; +/// use fibertools_rs::bamlift::*; /// let x = vec![1,3]; /// let x_q = vec!["a","b"]; /// let y = vec![2,4]; @@ -76,7 +76,7 @@ pub fn positions_on_complimented_sequence( /// get positions on the complimented sequence in the cigar record pub fn positions_on_complimented_sequence_in_place( record: &bam::Record, - input_positions: &mut Vec, + input_positions: &mut [i64], part_of_range: bool, ) { if !record.is_reverse() { @@ -107,7 +107,7 @@ where /// a\[i-1\] <= v < a\[i\] /// /// ``` -/// use bamlift::*; +/// use fibertools_rs::bamlift::*; /// let a = vec![1, 2, 3, 5, 6, 7, 8, 9, 10]; /// let v = vec![0, 1, 3, 4, 11, 11]; /// let indexes = search_sorted(&a, &v); @@ -187,14 +187,14 @@ fn liftover_closest( // get the previous closest position let (best_r_pos, best_diff) = pos_mapping.get_mut(cur_pos).unwrap(); // exact match found - if cur_pos >= &q_st && cur_pos < &q_en { + if cur_pos >= q_st && cur_pos < q_en { let dist_from_start = cur_pos - q_st; *best_diff = 0; *best_r_pos = r_st + dist_from_start; break; } // we are before the start of the block - else if cur_pos < &q_st { + else if cur_pos < q_st { let diff = (q_st - cur_pos).abs(); if diff < *best_diff { *best_diff = diff; @@ -202,7 +202,7 @@ fn liftover_closest( } } // we are past the end of the block - else if cur_pos >= &q_en { + else if cur_pos >= q_en { let diff = (q_en - cur_pos).abs(); if diff < *best_diff { *best_diff = diff; @@ -237,7 +237,7 @@ pub fn lift_reference_positions( /// find the closest query positions for a list of reference positions pub fn lift_query_positions( - aligned_block_pairs: &Vec<([i64; 2], [i64; 2])>, + aligned_block_pairs: &[([i64; 2], [i64; 2])], reference_positions: &[i64], ) -> Vec> { // if lifting to the query, we need to reverse the pairs @@ -266,7 +266,7 @@ fn lift_range( assert_eq!(ref_starts.len(), ref_ends.len()); let rtn = ref_starts .into_iter() - .zip(ref_ends.into_iter()) + .zip(ref_ends) .map(|(start, end)| match (start, end) { (Some(start), Some(end)) => { if start == end { diff --git a/src/basemods/mod.rs b/src/basemods/mod.rs index d4c21135..14f48fc8 100644 --- a/src/basemods/mod.rs +++ b/src/basemods/mod.rs @@ -1,6 +1,6 @@ -use bamlift::*; +use super::bamlift::*; +use super::bio_io::*; use bio::alphabets::dna::revcomp; -use bio_io::*; use itertools::{izip, multiunzip}; use lazy_static::lazy_static; use regex::Regex; diff --git a/src/bio_io/mod.rs b/src/bio_io/mod.rs index 9c2d958c..43516a3e 100644 --- a/src/bio_io/mod.rs +++ b/src/bio_io/mod.rs @@ -43,8 +43,7 @@ pub fn no_length_progress_bar() -> ProgressBar { let bar = ProgressBar::new(0); bar.set_style(style); let finish = indicatif::ProgressFinish::AndLeave; - let bar = bar.with_finish(finish); - bar + bar.with_finish(finish) } /* @@ -98,12 +97,12 @@ pub fn write_to_file(out: &str, buffer: &mut Box) { /// a reader that can read compressed files but also stdin (indicated by -) /// ``` -/// use bio_io::buffer_from; +/// use fibertools_rs::bio_io::buffer_from; /// use std::io; -/// let reader = buffer_from("../tests/data/test.txt.gz").expect("Error: cannot open file"); +/// let reader = buffer_from("tests/data/test.txt.gz").expect("Error: cannot open file"); /// let msg = io::read_to_string(reader).unwrap(); /// assert_eq!(msg, "Hello World!\n"); -/// let reader = buffer_from("../tests/data/test.txt").expect("Error: cannot open file"); +/// let reader = buffer_from("tests/data/test.txt").expect("Error: cannot open file"); /// let msg = io::read_to_string(reader).unwrap(); /// assert_eq!(msg, "Hello World!\n"); /// ``` @@ -321,8 +320,9 @@ pub fn find_pb_polymerase(header: &bam::Header) -> PbChem { ///``` /// use rust_htslib::{bam, bam::Read}; +/// use fibertools_rs::bio_io; /// use log; -/// let mut bam = bam::Reader::from_path(&"../tests/data/all.bam").unwrap(); +/// let mut bam = bam::Reader::from_path(&"tests/data/all.bam").unwrap(); /// for record in bam.records() { /// let record = record.unwrap(); /// let n_s = bio_io::get_u32_tag(&record, b"ns"); diff --git a/src/fiber.rs b/src/fiber.rs index b40dfec7..c1b40636 100644 --- a/src/fiber.rs +++ b/src/fiber.rs @@ -1,8 +1,8 @@ +use super::bamlift::*; use super::basemods::BaseMods; +use super::bio_io::*; use super::center::CenterPosition; use super::center::CenteredFiberData; -use bamlift::*; -use bio_io::*; use rayon::prelude::*; use rust_htslib::bam::Read; use rust_htslib::{bam, bam::ext::BamRecordExtensions, bam::record::Aux, bam::HeaderView}; diff --git a/src/footprint.rs b/src/footprint.rs index c1b5d789..9dd8f383 100644 --- a/src/footprint.rs +++ b/src/footprint.rs @@ -1,6 +1,7 @@ use crate::center::CenterPosition; use super::bam_writer; +use super::bio_io; use super::cli::FootprintOptions; use super::fiber::*; use anyhow; diff --git a/tests/extract_test.rs b/tests/extract_test.rs index 2fbb78dd..97d483de 100644 --- a/tests/extract_test.rs +++ b/tests/extract_test.rs @@ -1,3 +1,4 @@ +use fibertools_rs::bio_io; use rust_htslib::bam::Read; fn get_fiber_data_from_test_bam(bam_file: &str) -> Vec {