Skip to content

Commit

Permalink
work on intersect
Browse files Browse the repository at this point in the history
  • Loading branch information
brentp committed Dec 12, 2024
1 parent 770ec34 commit 293eabd
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 17 deletions.
34 changes: 17 additions & 17 deletions examples/intersect.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,15 @@ use std::fs;
use std::io::{self, BufReader, BufWriter, Write};
use std::path::PathBuf;

//use bedder::sniff;
use bedder::sniff;
use bedder::writer::{ColumnReporter, InputHeader};
use clap::Parser;
extern crate bedder;
use crate::bedder::chrom_ordering::parse_genome;
use crate::bedder::hts;
use crate::bedder::intersection::IntersectionIterator;
use crate::bedder::intersections::{IntersectionMode, IntersectionPart, OverlapAmount};
//use crate::bedder::writer;
use crate::bedder::writer;

#[derive(Parser, Debug)]
struct Args {
Expand Down Expand Up @@ -78,8 +80,14 @@ fn main() -> io::Result<()> {
// bedder always requires a hashmap that indicates the chromosome order
let fh = BufReader::new(fs::File::open(&args.fai)?);
let h = parse_genome(fh)?;

let mut wtr = match writer::Writer::init(aformat, None, sniff::Compression::None) {
let format = hts::htsExactFormat_bed;

let mut wtr = match writer::Writer::init(
"output.bed.gz",
Some(format),
Some(hts::htsCompression_bgzf),
InputHeader::None,
) {
Ok(w) => w,
Err(e) => {
eprintln!("error: {:?}", e);
Expand Down Expand Up @@ -141,20 +149,12 @@ fn main() -> io::Result<()> {
}
//eprintln!("report: {:?}", report);
//eprintln!("args: {:?}", &args);
let columns = vec![
"chrom", "start", "stop", "a_id", "b_id", "a_count", "b_count",
];
let c = ColumnReporter::new();

for r in report.into_iter() {
let a = r.a.as_ref().expect("a");
writeln!(
&mut stdout,
"{}\t{}\t{}\t{:?}",
a.chrom(),
a.start(),
a.stop(),
r.b.iter()
.map(|r| format!("{}:{}-{}", r.chrom(), r.start(), r.stop()))
.collect::<Vec<_>>()
)?;
}
wtr.write(&report, columns)?;
}

Ok(())
Expand Down
2 changes: 2 additions & 0 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,8 @@ pub mod writer;
/// Bed parser implementing the PositionedIterator trait.
pub mod bedder_bed;

pub use rust_htslib::htslib as hts;

//#[cfg(feature = "vcf")]
/// Vcf parser implementing the PositionedIterator trait.
pub mod bedder_vcf;
Expand Down

0 comments on commit 293eabd

Please sign in to comment.