pub fn build<P: AsRef<Path>>(
bcf_path: P,
idx_path: Option<P>,
n_threads: u32,
index_type: Type,
) -> Result<(), BcfBuildError>
Expand description
Build a bcf or vcf.gz index. Builds tbi or csi depending on index_type.
// Index a sorted bcf file with csi.
let bcf_path = concat!(env!("CARGO_MANIFEST_DIR"), "/test/test_multi.bcf");
rust_htslib::bcf::index::build(&bcf_path, Some(&"built_test.csi"), /*n_threads=*/ 4u32, rust_htslib::bcf::index::Type::Csi(14)).expect("Failed to build csi index for bcf file.");
assert!(std::path::Path::new(&"built_test.csi").exists());
// Index a bgzip-compresed vcf file with tabix.
let vcf_path = concat!(env!("CARGO_MANIFEST_DIR"), "/test/test_left.vcf.gz");
rust_htslib::bcf::index::build(&vcf_path, Some(&"built_test_vcf.tbx"), /*n_threads=*/ 4u32, rust_htslib::bcf::index::Type::Tbx).expect("Failed to build tbx index for vcf file.");
assert!(std::path::Path::new(&"built_test_vcf.tbx").exists());
// Cannot build a tbi index for a bcf file: returns an Err(BcfBuildError).
assert!(std::panic::catch_unwind(|| rust_htslib::bcf::index::build(bcf_path, Some("built_test.tbi"), 4u32, rust_htslib::bcf::index::Type::Tbx).unwrap()).is_err());
// Cannot built a csi index for a vcf file: returns an Err(BcfBuildError).
let vcf_path = concat!(env!("CARGO_MANIFEST_DIR"), "/test/test_various.vcf");
assert!(std::panic::catch_unwind(|| rust_htslib::bcf::index::build(&vcf_path, Some(&"built_test_vcf.csi"), /*n_threads=*/ 4u32, rust_htslib::bcf::index::Type::Csi(14)).expect("Failed to build csi index for vcf file.")).is_err());