Skip to content

Commit

Permalink
multi-expression support added
Browse files Browse the repository at this point in the history
  • Loading branch information
sjneph committed Aug 25, 2024
1 parent 2988fba commit d2f3cbd
Showing 1 changed file with 22 additions and 11 deletions.
33 changes: 22 additions & 11 deletions src/utils/ftexpression.rs
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,15 @@ pub struct ParsedExpr {
threshold: Threshold,
}

pub fn parse_filter_all(full_expr: &str) -> Vec<ParsedExpr> {
let mut v = Vec::new();
let expressions: Vec<String> = full_expr.split(',').map(|s| s.to_string()).collect();
for expr in expressions.iter() {
v.push(parse_filter(expr.as_str()));
}
v
}

pub fn parse_filter(filter_orig: &str) -> ParsedExpr {
let mut filter = filter_orig.to_string();
filter.retain(|c| !c.is_whitespace());
Expand Down Expand Up @@ -183,17 +192,19 @@ pub fn apply_filter_to_range(
pub fn apply_filter_fsd(fsd: &mut FiberseqData, filt: &FiberFilters) -> Result<(), anyhow::Error> {
if let Some(s) = filt.filter_expression.as_ref() {
if !s.is_empty() {
let parser = parse_filter(s.as_str());
match parser.feat_name.as_str() {
"msp" => apply_filter_to_range(&parser, &mut fsd.msp)?,
"nuc" => apply_filter_to_range(&parser, &mut fsd.nuc)?,
"m6a" => apply_filter_to_range(&parser, &mut fsd.m6a)?,
"cpg" => apply_filter_to_range(&parser, &mut fsd.cpg)?,
_ => {
return Err(anyhow::anyhow!(
"Unknown feature name: {}",
parser.feat_name
));
let parsers = parse_filter_all(s.as_str());
for parser in parsers.iter() {
match parser.feat_name.as_str() {
"msp" => apply_filter_to_range(parser, &mut fsd.msp)?,
"nuc" => apply_filter_to_range(parser, &mut fsd.nuc)?,
"m6a" => apply_filter_to_range(parser, &mut fsd.m6a)?,
"cpg" => apply_filter_to_range(parser, &mut fsd.cpg)?,
_ => {
return Err(anyhow::anyhow!(
"Unknown feature name: {}",
parser.feat_name
));
}
}
}
}
Expand Down

0 comments on commit d2f3cbd

Please sign in to comment.