-
Notifications
You must be signed in to change notification settings - Fork 56
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
1 changed file
with
36 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
//! Queries a bgzip-compressed GFF file with a given region. | ||
//! | ||
//! The input must have an associated coordinate-sorted index (CSI) in the same directory. | ||
//! | ||
//! The result matches the output of `tabix <src> <region>`. | ||
use std::{env, fs::File, io}; | ||
|
||
use noodles_bgzf as bgzf; | ||
use noodles_csi as csi; | ||
use noodles_gff as gff; | ||
|
||
fn main() -> Result<(), Box<dyn std::error::Error>> { | ||
let mut args = env::args().skip(1); | ||
let src = args.next().expect("missing src"); | ||
let region = args.next().expect("missing region").parse()?; | ||
|
||
let index_src = format!("{src}.csi"); | ||
let index = csi::read(index_src)?; | ||
|
||
let mut reader = File::open(src) | ||
.map(bgzf::Reader::new) | ||
.map(gff::io::Reader::new)?; | ||
|
||
let query = reader.query(&index, ®ion)?; | ||
|
||
let stdout = io::stdout().lock(); | ||
let mut writer = gff::io::Writer::new(stdout); | ||
|
||
for result in query { | ||
let record = result?; | ||
writer.write_record(&record)?; | ||
} | ||
|
||
Ok(()) | ||
} |