Skip to content

Commit

Permalink
remove unnecessary clone of FiberseqData in constructor
Browse files Browse the repository at this point in the history
  • Loading branch information
sjneph committed Aug 10, 2024
1 parent 39a43e8 commit 1972150
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 11 deletions.
15 changes: 7 additions & 8 deletions src/fiber.rs
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ impl FiberseqData {
let m6a = base_mods.m6a();
let cpg = base_mods.cpg();

let fsd = &mut FiberseqData {
let mut fsd = FiberseqData {
record,
msp,
nuc,
Expand All @@ -84,19 +84,18 @@ impl FiberseqData {
if let Some(s) = filters.filter_expression.as_ref() {
if !s.is_empty() {
let parser = parse_filter(s.as_str());
let rng = if parser.rng_name == "msp" {
&mut fsd.msp
if parser.rng_name == "msp" {
fsd.msp = apply_filter_to_range(&parser, fsd.msp).unwrap();
} else if parser.rng_name == "nuc" {
&mut fsd.nuc
fsd.nuc = apply_filter_to_range(&parser, fsd.nuc).unwrap();
} else if parser.rng_name == "m6a" {
&mut fsd.m6a
fsd.m6a = apply_filter_to_range(&parser, fsd.m6a).unwrap();
} else { // 5mC
&mut fsd.cpg
fsd.cpg = apply_filter_to_range(&parser, fsd.cpg).unwrap();
};
apply_filter_to_range(&parser, rng).unwrap();
}
}
fsd.clone()
fsd
}

pub fn dict_from_head_view(head_view: &HeaderView) -> HashMap<i32, String> {
Expand Down
6 changes: 3 additions & 3 deletions src/utils/ftexpression_v2.rs
Original file line number Diff line number Diff line change
Expand Up @@ -108,8 +108,8 @@ pub fn parse_filter(filter_orig: &str) -> ParsedExpr {

pub fn apply_filter_to_range(
parsed: &ParsedExpr,
range: &mut bamranges::Ranges,
) -> Result<(), anyhow::Error> {
mut range: bamranges::Ranges,
) -> Result<bamranges::Ranges, anyhow::Error> {
let starting_len = range.starts.len();

let to_keep: Vec<bool> = if parsed.fn_name == "len" {
Expand Down Expand Up @@ -156,7 +156,7 @@ pub fn apply_filter_to_range(
let n_dropped = to_keep.iter().filter(|&&x| !x).count();
assert_eq!(starting_len, range.starts.len() + n_dropped);

Ok(())
Ok(range)
}

/// tests
Expand Down

0 comments on commit 1972150

Please sign in to comment.