Skip to content

Commit

Permalink
Don't fail silently when attempting to read unreadable input
Browse files Browse the repository at this point in the history
  • Loading branch information
jch-13 committed Apr 23, 2024
1 parent dbdaf4e commit 5f78457
Showing 1 changed file with 9 additions and 14 deletions.
23 changes: 9 additions & 14 deletions src/map/record.rs
Original file line number Diff line number Diff line change
Expand Up @@ -177,25 +177,20 @@ impl TryFrom<&dyn sam::alignment::Record> for Record {

let mut base_qualities = input.quality_scores().as_ref().iter().collect::<Vec<_>>();

if let Ok(flags) = input.flags() {
if flags.is_reverse_complemented() {
base_qualities.reverse();
sequence = dna::revcomp(sequence);
}
} else {
warn!("Dropped unreadable flags");
};
if input.flags()?.is_reverse_complemented() {
base_qualities.reverse();
sequence = dna::revcomp(sequence);
}

let input_tags = input
.data()
.iter()
.filter_map(|maybe_tv| {
.map(|maybe_tv| {
maybe_tv
.ok()
.as_ref()
.map(|(tag, value)| (tag.as_ref().to_owned(), value.into()))
.map(|(tag, value)| (tag.as_ref().to_owned(), (&value).into()))
.map_err(Into::into)
})
.collect::<Vec<_>>();
.collect::<Result<Vec<_>>>()?;

let read_name = input.name().map(|name| name.as_bytes().to_owned());

Expand All @@ -204,7 +199,7 @@ impl TryFrom<&dyn sam::alignment::Record> for Record {
base_qualities,
name: read_name,
bam_tags: input_tags,
bam_flags: input.flags().map(|flags| flags.bits()).unwrap_or(0),
bam_flags: input.flags().map(|flags| flags.bits())?,
})
}
}
Expand Down

0 comments on commit 5f78457

Please sign in to comment.