-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #46 from cauliyang/dev
feat: Add Fasta module and Fasta2Parquet CLI
- Loading branch information
Showing
22 changed files
with
146 additions
and
76 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
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
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
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
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,65 @@ | ||
use anyhow::Result; | ||
use clap::Parser; | ||
use log::warn; | ||
|
||
use std::path::PathBuf; | ||
|
||
use super::set_up_threads; | ||
use deepbiop_fa as fa; | ||
use fa::encode::Encoder; | ||
|
||
use deepbiop_utils as utils; | ||
|
||
#[derive(Debug, Parser)] | ||
pub struct FaToParquet { | ||
/// path to the fa file | ||
#[arg(value_name = "fa")] | ||
fa: PathBuf, | ||
|
||
/// if convert the fa file to parquet by chunk or not | ||
#[arg(long)] | ||
chunk: bool, | ||
|
||
/// chunk size | ||
#[arg(long, default_value = "1000000")] | ||
chunk_size: usize, | ||
|
||
/// result path | ||
#[arg(long, value_name = "result")] | ||
output: Option<PathBuf>, | ||
|
||
/// threads number | ||
#[arg(short, long, default_value = "2")] | ||
threads: Option<usize>, | ||
} | ||
|
||
impl FaToParquet { | ||
pub fn run(&self) -> Result<()> { | ||
set_up_threads(self.threads)?; | ||
let option = fa::encode::FaEncoderOptionBuilder::default() | ||
.bases(fa::encode::BASES.to_vec()) | ||
.build()?; | ||
let mut fa_encoder = fa::encode::ParquetEncoderBuilder::default() | ||
.option(option) | ||
.build()?; | ||
|
||
if self.chunk { | ||
fa_encoder.encode_chunk(&self.fa, self.chunk_size, false)?; | ||
return Ok(()); | ||
} | ||
|
||
let (record_batch, schema) = fa_encoder.encode(&self.fa)?; | ||
// result file is fq_path with .parquet extension | ||
let parquet_path = if let Some(path) = &self.output { | ||
if path.with_extension("parquet").exists() { | ||
warn!("{} already exists, overwriting", path.display()); | ||
} | ||
path.with_extension("parquet") | ||
} else { | ||
self.fa.with_extension("parquet") | ||
}; | ||
utils::io::write_parquet(parquet_path, record_batch, schema)?; | ||
|
||
Ok(()) | ||
} | ||
} |
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
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
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
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
Binary file not shown.
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
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
Oops, something went wrong.