use std::path::PathBuf;
use anyhow::bail;
use clap::Args;
use crate::utils::formats::BioinformaticsFileFormat;
#[derive(Args)]
pub struct ViewArgs {
#[arg(value_name = "FILE")]
src: PathBuf,
query: Option<String>,
#[arg(short, long)]
reference_fasta: Option<PathBuf>,
#[arg(short, long, value_enum, default_value = "full")]
mode: Mode,
}
#[derive(clap::ValueEnum, PartialEq, Eq, Clone)]
pub enum Mode {
Full,
HeaderOnly,
RecordsOnly,
}
pub fn view(args: ViewArgs) -> anyhow::Result<()> {
let src = args.src;
let query = args.query;
let reference_fasta = args.reference_fasta;
let mode = args.mode;
let rt = tokio::runtime::Builder::new_current_thread()
.enable_all()
.build()
.unwrap();
match BioinformaticsFileFormat::try_detect(&src) {
Some(BioinformaticsFileFormat::SAM) => rt.block_on(super::sam::view(src, query, mode)),
Some(BioinformaticsFileFormat::BAM) => rt.block_on(super::bam::view(src, query, mode)),
Some(BioinformaticsFileFormat::CRAM) => {
if let Some(reference_fasta) = reference_fasta {
rt.block_on(super::cram::view(src, query, reference_fasta, mode))
} else {
bail!(
"--reference-fasta is a required argument when converting to/from a CRAM file"
)
}
}
Some(BioinformaticsFileFormat::GFF) | Some(BioinformaticsFileFormat::GFF_GZ) => {
super::gff::view(src)
}
Some(format) => {
bail!(
"{} files are not supported by this command. This may be \
because we haven't supported this file format yet or because \
it does not make sense to view a file of this kind. \
If you believe this format should be supported, please search \
for and upvote the related issue on Github (or file a new one).",
format
)
}
None => {
bail!(
"Not able to determine bioinformatics file type for path: {}",
src.display()
)
}
}
}