Skip to content

Commit

Permalink
fix: Add error messages for missing annotations (#206)
Browse files Browse the repository at this point in the history
* fix: Add error messages for missing annotations

* Return anyhow error instead of Option<T>
  • Loading branch information
fxwiegand committed Dec 6, 2021
1 parent e19b4fb commit 6210dd2
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 10 deletions.
8 changes: 2 additions & 6 deletions src/bcf/report/oncoprint.rs
Original file line number Diff line number Diff line change
Expand Up @@ -64,9 +64,7 @@ pub fn oncoprint(
for (sample, path) in sample_calls.iter().sorted() {
let bcf_reader = bcf::Reader::from_path(path)?;
let header_records = bcf_reader.header().header_records();
let ann_fields: Vec<_> = get_ann_description(header_records).unwrap_or_else(|| {
panic!("No ANN field found. Please only use VEP-annotated VCF-files.")
});
let ann_fields: Vec<_> = get_ann_description(header_records)?;
clin_sig_present.insert(
sample.to_owned(),
ann_fields.contains(&"CLIN_SIG".to_owned()),
Expand Down Expand Up @@ -97,9 +95,7 @@ pub fn oncoprint(
sample_names.push(String::from_utf8(s.to_owned())?);
}
let header_records = header.header_records();
let ann_fields: Vec<_> = get_ann_description(header_records).unwrap_or_else(|| {
panic!("No ANN field found. Please only use VEP-annotated VCF-files.")
});
let ann_fields: Vec<_> = get_ann_description(header_records)?;

for (i, field) in ann_fields.iter().enumerate() {
ann_indices.insert(field, i);
Expand Down
11 changes: 7 additions & 4 deletions src/bcf/report/table_report/create_report_table.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
use crate::bcf::report::table_report::fasta_reader::{get_fasta_lengths, read_fasta};
use crate::bcf::report::table_report::static_reader::{get_static_reads, Variant};
use crate::common::Region;
use anyhow::anyhow;
use anyhow::Context as AnyhowContext;
use anyhow::Result;
use chrono::{DateTime, Local};
Expand Down Expand Up @@ -62,7 +63,7 @@ pub(crate) fn make_table_report(
let mut vcf = rust_htslib::bcf::Reader::from_path(&vcf_path).unwrap();
let header = vcf.header().clone();
let header_records = header.header_records();
let ann_field_description: Vec<_> = get_ann_description(header_records).unwrap();
let ann_field_description: Vec<_> = get_ann_description(header_records)?;
let samples: Vec<_> = header
.samples()
.iter()
Expand Down Expand Up @@ -441,7 +442,7 @@ fn escape_hgvsg(hgvsg: &str) -> String {
hgvsg.replace(".", "_").replace(">", "_").replace(":", "_")
}

pub(crate) fn get_ann_description(header_records: Vec<HeaderRecord>) -> Option<Vec<String>> {
pub(crate) fn get_ann_description(header_records: Vec<HeaderRecord>) -> Result<Vec<String>> {
for rec in header_records {
if let rust_htslib::bcf::HeaderRecord::Info { key: _, values } = rec {
if values.get("ID").unwrap() == "ANN" {
Expand All @@ -457,11 +458,13 @@ pub(crate) fn get_ann_description(header_records: Vec<HeaderRecord>) -> Option<V
entry = entry.trim();
owned_fields.push(entry.to_owned());
}
return Some(owned_fields);
return Ok(owned_fields);
}
}
}
None
Err(anyhow!(
"Could not find any annotations by VEP. Please only use VEP-annotated VCF-files."
))
}

pub(crate) fn read_tag_entries(
Expand Down

0 comments on commit 6210dd2

Please sign in to comment.