-
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.
feat: Add fa2fq and fq2fa conversion functions
- Loading branch information
Showing
6 changed files
with
83 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
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,25 @@ | ||
use anyhow::Result; | ||
use noodles_fasta as fasta; | ||
use noodles_fastq as fastq; | ||
use std::path::Path; | ||
|
||
pub fn fa2fq<P: AsRef<Path>>(input: P) -> Result<()> { | ||
let mut reader = fasta::reader::Builder.build_from_path(input)?; | ||
|
||
let mut writer = fastq::Writer::new(std::io::stdout()); | ||
|
||
for result in reader.records() { | ||
let record = result?; | ||
let name = record.name().to_string(); | ||
let sequence = record.sequence().as_ref().to_vec(); | ||
let qualities = vec![b'@'; sequence.len()]; | ||
let fastq_record = fastq::Record::new( | ||
fastq::record::Definition::new(name, ""), | ||
sequence, | ||
qualities, | ||
); | ||
writer.write_record(&fastq_record)?; | ||
} | ||
|
||
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
use anyhow::Result; | ||
use noodles_fasta as fasta; | ||
use noodles_fastq as fastq; | ||
use std::path::Path; | ||
use std::{ | ||
fs::File, | ||
io::{self, BufReader}, | ||
}; | ||
|
||
pub fn fq2fa<P: AsRef<Path>>(input: P) -> Result<()> { | ||
let mut readerr = File::open(input) | ||
.map(BufReader::new) | ||
.map(fastq::Reader::new)?; | ||
|
||
let mut writer = fasta::Writer::new(io::stdout()); | ||
|
||
for result in readerr.records() { | ||
let record = result?; | ||
let name = String::from_utf8(record.name().to_vec())?; | ||
let sequence = fasta::record::Sequence::from(record.sequence().to_vec()); | ||
let fasta_record = fasta::Record::new(fasta::record::Definition::new(name, None), sequence); | ||
writer.write_record(&fasta_record)?; | ||
} | ||
|
||
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
>sequence1 | ||
ATGCTAGCTAGCTAGCTAGCTAGCTA | ||
GCTAGCTAGCTAGCTAGCTAGCTAGC | ||
TAGCTAGCTAGCTAGCTAGCTAGCTA |
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,4 @@ | ||
@sequence1 | ||
ATGCTAGCTAGCTAGCTAGCTAGCTAGCTAGCTAGCTAGCTAGCTAGCTAGCTAGCTAGCTAGCTAGCTAGCTAGCTA | ||
+ | ||
@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@ |