Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 12 additions & 1 deletion d4tools/src/plot/cli.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,20 @@ args:
short: R
long: resolution
help: Specify the resolution of the output image
value_name: widthxheight
- region:
required: true
short: r
long: region
help: Regions to be plotted
value_name: chr[:start[-end]]
value_name: chr[:start[-end]]
- nbins:
short: n
long: nbins
help: Number of bins for data downsampling
value_name: n
- bin-width:
short: w
long: bin-width
help: Width of each bin in base pairs
value_name: width
35 changes: 34 additions & 1 deletion d4tools/src/plot/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,40 @@ pub fn entry_point(args: Vec<String>) -> Result<(), Box<dyn std::error::Error>>
})
.unwrap();

let data = downsample_data(input, &chr, (left, right), 256)?;
let range_length = right as u64 - left as u64 + 1;

let nbins = matches.value_of("nbins").map(|v| v.parse::<u64>().unwrap());
let bin_width = matches
.value_of("bin-width")
.map(|v| v.parse::<u64>().unwrap());

let nbins = match (nbins, bin_width) {
(Some(n), None) => n,
(None, Some(width)) => {
if width == 0 {
panic!("Invalid bin-width: cannot be zero");
}
(range_length / width).max(1)
}
(Some(n), Some(width)) => {
if width == 0 {
panic!("Invalid bin-width: cannot be zero");
}
let calculated_nbins = (range_length / width).max(1);
if n != calculated_nbins {
panic!(
"Conflicting options: --nbins ({}) and --bin-width ({}) do not match.",
n, width
);
}
n
}
(None, None) => 256,
};

let nbins = nbins as usize;

let data = downsample_data(input, &chr, (left, right), nbins)?;

let pos_range = plotters::data::fitting_range(data.iter().map(|x| &x.0));
let mut data_range = plotters::data::fitting_range(data.iter().map(|x| &x.1));
Expand Down
Loading