Skip to content

Commit

Permalink
bed/example: Add index example
Browse files Browse the repository at this point in the history
  • Loading branch information
zaeleus committed Feb 24, 2025
1 parent e00d669 commit d443360
Showing 1 changed file with 25 additions and 0 deletions.
25 changes: 25 additions & 0 deletions noodles-bed/examples/bed_index.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
//! Builds and writes a tabix index from a bgzip-compressed BED file.
//!
//! This writes the output to stdout rather than `<src>.tbi`.
//!
//! The output is similar to the output of `tabix --preset bed <src>`.
use std::{
env,
io::{self, BufWriter},
};

use noodles_bed as bed;
use noodles_tabix as tabix;

fn main() -> io::Result<()> {
let src = env::args().nth(1).expect("missing src");

let index = bed::fs::index(src)?;

let stdout = io::stdout().lock();
let mut writer = tabix::io::Writer::new(BufWriter::new(stdout));
writer.write_index(&index)?;

Ok(())
}

0 comments on commit d443360

Please sign in to comment.