Skip to content

Commit

Permalink
2024/10/25-15:04:18 (Linux cray unknown)
Browse files Browse the repository at this point in the history
  • Loading branch information
pbenner committed Oct 25, 2024
1 parent ea5edbe commit 4eeb297
Show file tree
Hide file tree
Showing 4 changed files with 25 additions and 29 deletions.
1 change: 1 addition & 0 deletions src/track.rs
Original file line number Diff line number Diff line change
Expand Up @@ -129,6 +129,7 @@ pub trait Track {

pub trait MutableTrack : Track {
fn as_track(&self) -> &dyn Track;
fn filter_genome(&mut self, f: &dyn Fn(&str, usize) -> bool);
fn get_sequence_mut(&mut self, seqname: &str) -> Result<TrackMutableSequence, Box<dyn Error>>;
}

Expand Down
8 changes: 3 additions & 5 deletions src/track_generic_coverage.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@ use std::error::Error;
use futures::executor::block_on_stream;

use crate::coverage::CoverageConfig;
use crate::genome::Genome;
use crate::read_stream::ReadStream;
use crate::track_generic::GenericMutableTrack;
use crate::bam::BamFile;
Expand All @@ -34,13 +33,12 @@ impl<'a> GenericMutableTrack<'a> {

pub fn coverage_from_bam(
mut config : CoverageConfig,
track1 : GenericMutableTrack,
mut track1 : GenericMutableTrack,
track2_arg : Option<GenericMutableTrack>,
filenames_treatment: &Vec<&str>,
filenames_control : &Vec<&str>,
fraglen_treatment : &Vec<usize>,
fraglen_control : &Vec<usize>,
genome : Genome,
) -> Result<(), Box<dyn Error>> {
// Treatment data
let mut n_treatment = 0;
Expand Down Expand Up @@ -97,7 +95,7 @@ impl<'a> GenericMutableTrack<'a> {
config.pseudocounts[0] *= c;
}

if let Some(track2) = track2_arg {
if let Some(mut track2) = track2_arg {
// Control data

for (i, filename) in filenames_control.iter().enumerate() {
Expand Down Expand Up @@ -174,7 +172,7 @@ impl<'a> GenericMutableTrack<'a> {
if config.remove_filtered_chroms {
if !config.filter_chroms.is_empty() {
log!(config.logger, "Removing chromosomes `{}`", config.filter_chroms.join(", "));
track1.filter_genome(|name, _length| {
track1.track.filter_genome(&|name : &str, _length : usize| {
!config.filter_chroms.contains(&name.to_string())
});
}
Expand Down
39 changes: 19 additions & 20 deletions src/track_simple.rs
Original file line number Diff line number Diff line change
Expand Up @@ -98,26 +98,6 @@ impl SimpleTrack {
position / self.bin_size
}

pub fn filter_genome<F>(&mut self, f: F)
where
F: Fn(&str, usize) -> bool,
{
let retain_seqnames: Vec<String> = self
.data
.keys()
.filter(|seqname| {
let idx = self.genome.seqnames.iter().position(|x| x == *seqname).unwrap();
f(seqname, self.genome.lengths[idx])
})
.cloned()
.collect();

// Retain the seqnames in self.data
self.data.retain(|seqname, _| retain_seqnames.contains(seqname));

// Perform the filtering on genome
self.genome.filter(f);
}
}

/* -------------------------------------------------------------------------- */
Expand Down Expand Up @@ -195,6 +175,25 @@ impl MutableTrack for SimpleTrack {
self
}

fn filter_genome(&mut self, f: &dyn Fn(&str, usize) -> bool)
{
let retain_seqnames: Vec<String> = self
.data
.keys()
.filter(|seqname| {
let idx = self.genome.seqnames.iter().position(|x| x == *seqname).unwrap();
f(seqname, self.genome.lengths[idx])
})
.cloned()
.collect();

// Retain the seqnames in self.data
self.data.retain(|seqname, _| retain_seqnames.contains(seqname));

// Perform the filtering on genome
self.genome.filter(f);
}

fn get_sequence_mut(&mut self, query: &str) -> Result<TrackMutableSequence, Box<dyn Error>> {
match self.data.get_mut(query) {
Some(seq) => Ok(TrackMutableSequence::new(seq.clone(), self.bin_size)),
Expand Down
6 changes: 2 additions & 4 deletions src/track_simple_coverage.rs
Original file line number Diff line number Diff line change
Expand Up @@ -50,8 +50,7 @@ impl SimpleTrack {
filenames_treatment,
filenames_control,
fraglen_treatment,
fraglen_control,
genome)?;
fraglen_control)?;

} else {

Expand All @@ -62,8 +61,7 @@ impl SimpleTrack {
filenames_treatment,
filenames_control,
fraglen_treatment,
fraglen_control,
genome)?;
fraglen_control)?;

};

Expand Down

0 comments on commit 4eeb297

Please sign in to comment.