Skip to content

Commit

Permalink
style: much prettier code. One broken test.
Browse files Browse the repository at this point in the history
  • Loading branch information
a-frantz committed Feb 9, 2024
1 parent 9b4f6ea commit 33f5afc
Show file tree
Hide file tree
Showing 4 changed files with 590 additions and 575 deletions.
24 changes: 9 additions & 15 deletions src/derive/command/junction_annotation.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
//! Functionality relating to the `ngs derive junction_annotation` subcommand itself.
use std::collections::HashMap;
use std::collections::HashSet;
use std::path::PathBuf;

use anyhow::Context;
Expand Down Expand Up @@ -65,8 +64,10 @@ pub struct JunctionAnnotationArgs {
pub fn derive(args: JunctionAnnotationArgs) -> anyhow::Result<()> {
info!("Starting derive junction_annotation subcommand.");

let mut exon_starts: HashMap<&str, HashSet<usize>> = HashMap::new();
let mut exon_ends: HashMap<&str, HashSet<usize>> = HashMap::new();
let mut exons = compute::ExonSets {
starts: HashMap::new(),
ends: HashMap::new(),
};

// (1) Parse the GFF file and collect all exon features.
debug!("Reading all records in GFF.");
Expand All @@ -85,11 +86,11 @@ pub fn derive(args: JunctionAnnotationArgs) -> anyhow::Result<()> {
debug!("Tabulating GFF exon features.");
for record in &exon_records {
let seq_name = record.reference_sequence_name();
let start: usize = record.start().into();
let end: usize = record.end().into();
let start = record.start();
let end = record.end().checked_add(1).unwrap(); // TODO: why +1? It works.

exon_starts.entry(seq_name).or_default().insert(start);
exon_ends.entry(seq_name).or_default().insert(end + 1); // TODO why +1? It works
exons.starts.entry(seq_name).or_default().insert(start);
exons.ends.entry(seq_name).or_default().insert(end);
}

debug!("Done reading GFF.");
Expand All @@ -112,14 +113,7 @@ pub fn derive(args: JunctionAnnotationArgs) -> anyhow::Result<()> {
// (2) Process each record in the BAM file.
for result in reader.records(&header.parsed) {
let record = result?;
compute::process(
&record,
&exon_starts,
&exon_ends,
&header.parsed,
&params,
&mut results,
)?;
compute::process(&record, &exons, &header.parsed, &params, &mut results)?;
counter.inc();
}

Expand Down
Loading

0 comments on commit 33f5afc

Please sign in to comment.