Skip to content

Commit

Permalink
feat: add simplify options to center
Browse files Browse the repository at this point in the history
  • Loading branch information
mrvollger committed Oct 27, 2023
1 parent c4d0c93 commit 6855072
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 1 deletion.
12 changes: 11 additions & 1 deletion src/center.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ pub struct CenteredFiberData {
center_position: CenterPosition,
pub offset: i64,
pub reference: bool,
pub simplify: bool,
}

impl CenteredFiberData {
Expand All @@ -30,6 +31,7 @@ impl CenteredFiberData {
center_position: CenterPosition,
dist: Option<i64>,
reference: bool,
simplify: bool,
) -> Option<Self> {
let (ref_offset, mol_offset) =
CenteredFiberData::find_offsets(&fiber.record, &center_position);
Expand All @@ -43,6 +45,7 @@ impl CenteredFiberData {
center_position,
offset,
reference,
simplify,
})
}
/// find both the ref and mol offsets
Expand Down Expand Up @@ -75,6 +78,9 @@ impl CenteredFiberData {

/// Get the sequence
pub fn subset_sequence(&self) -> String {
if self.simplify {
return "N".to_string();
}
let dist = if let Some(dist) = self.dist { dist } else { 0 };
let seq = self.fiber.record.seq().as_bytes();

Expand Down Expand Up @@ -289,6 +295,7 @@ pub fn center(
wide: bool,
dist: Option<i64>,
reference: bool,
simplify: bool,
buffer: &mut Box<dyn std::io::Write>,
) {
let fiber_data = FiberseqData::from_records(records, header_view, min_ml_score);
Expand All @@ -298,7 +305,8 @@ pub fn center(
fiber_data
.into_par_iter()
.map(|fiber| {
match CenteredFiberData::new(fiber, center_position.clone(), dist, reference) {
match CenteredFiberData::new(fiber, center_position.clone(), dist, reference, simplify)
{
Some(centered_fiber) => {
if wide {
centered_fiber.write()
Expand Down Expand Up @@ -335,6 +343,7 @@ pub fn center_fiberdata(
wide: bool,
dist: Option<i64>,
reference: bool,
simplify: bool,
) {
// header needed for the contig name...
let header = bam::Header::from_template(bam.header());
Expand Down Expand Up @@ -378,6 +387,7 @@ pub fn center_fiberdata(
wide,
dist,
reference,
simplify,
&mut buffer,
);
pb.inc(1);
Expand Down
3 changes: 3 additions & 0 deletions src/cli.rs
Original file line number Diff line number Diff line change
Expand Up @@ -231,6 +231,9 @@ pub enum Commands {
/// Return relative reference position instead of relative molecular position
#[clap(short, long)]
reference: bool,
/// Replace the sequence output column with just "N".
#[clap(short, long)]
simplify: bool,
},
/// Remove HiFi kinetics tags from the input bam file
ClearKinetics {
Expand Down
2 changes: 2 additions & 0 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,7 @@ pub fn main() -> Result<(), Error> {
dist,
wide,
reference,
simplify,
}) => {
// read in the bam from stdin or from a file
let mut bam = bam::IndexedReader::from_path(bam)?;
Expand All @@ -118,6 +119,7 @@ pub fn main() -> Result<(), Error> {
*wide,
*dist,
*reference,
*simplify,
);
}
#[cfg(feature = "predict")]
Expand Down

0 comments on commit 6855072

Please sign in to comment.