Skip to content

Commit

Permalink
fix in reading context rules
Browse files Browse the repository at this point in the history
  • Loading branch information
proycon committed Aug 4, 2022
1 parent 57e79b6 commit bed0680
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 5 deletions.
2 changes: 1 addition & 1 deletion bindings/python/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ license = "GPL-3.0+"
name = "analiticcl-python"
readme = "README.md"
repository = "https://github.com/proycon/analiticcl"
version = "0.4.3" #also change version in dependencies below
version = "0.4.2" #also change version in dependencies below

[lib]
name = "analiticcl"
Expand Down
12 changes: 8 additions & 4 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -496,18 +496,22 @@ impl VariantModel {
let f_buffer = BufReader::new(f);
let mut linenr = 0;
for line in f_buffer.lines() {
linenr += 1;
if let Ok(line) = line {
linenr += 1;
if !line.is_empty() && !line.starts_with('#') {
let fields: Vec<&str> = line.split("\t").collect();
if fields.len() < 2 {
return Err(std::io::Error::new(std::io::ErrorKind::Other, format!("Expected at least two columns in context rules file {}, line {}",filename,linenr)));
}

let pattern: &str = fields.get(0).unwrap();
if pattern.is_empty() {
continue;
}

let score = fields.get(1).unwrap().parse::<f32>();
if let Err(_) = score {
return Err(std::io::Error::new(std::io::ErrorKind::Other, format!("context rule score should be a floating point value above or below 1.0 ({}, line {})", filename,linenr)));
return Err(std::io::Error::new(std::io::ErrorKind::Other, format!("context rule score should be a floating point value above or below 1.0, got {} ({}, line {})", fields.get(1).unwrap(), filename,linenr)));
}
let score = score.unwrap();

Expand All @@ -524,11 +528,11 @@ impl VariantModel {
if tag.len() == 1 && tagoffset.len() == 0 {
tagoffset.push("0:");
} else if tag.len() != tagoffset.len() {
return Err(std::io::Error::new(std::io::ErrorKind::Other, format!("Multiple tags are specified for a context rule, expected the same number of tag offsets! (semicolon separated) ({}, line {}", filename, linenr)));
return Err(std::io::Error::new(std::io::ErrorKind::Other, format!("Multiple tags are specified for a context rule, expected the same number of tag offsets! (semicolon separated) ({}, line {})", filename, linenr)));
}

if let Err(error) = self.add_contextrule(pattern, score, tag, tagoffset) {
return Err(std::io::Error::new(std::io::ErrorKind::Other, format!("Error adding context rule: {} ({}, line {}", error, filename, linenr)));
return Err(std::io::Error::new(std::io::ErrorKind::Other, format!("Error adding context rule: {} ({}, line {})", error, filename, linenr)));
}

}
Expand Down

0 comments on commit bed0680

Please sign in to comment.