-
Notifications
You must be signed in to change notification settings - Fork 3
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
7 changed files
with
91 additions
and
5 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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 |
---|---|---|
@@ -1,6 +1,6 @@ | ||
[package] | ||
name = "fqkit" | ||
version = "0.4.8" | ||
version = "0.4.9" | ||
edition = "2021" | ||
authors = ["sharkLoc <[email protected]>"] | ||
rust-version = "1.77.2" | ||
|
@@ -28,6 +28,7 @@ env_logger = "0.10.0" | |
flate2 = "1.0.24" | ||
log = "0.4.20" | ||
lowcharts = "0.5.8" | ||
nthash = "0.5.1" | ||
plotters = "0.3.4" | ||
rand = "0.8.5" | ||
rand_pcg = "0.3.1" | ||
|
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 |
---|---|---|
|
@@ -40,7 +40,7 @@ cargo install --git https://github.com/sharkLoc/fqkit.git | |
```bash | ||
FqKit -- A simple and cross-platform program for fastq file manipulation | ||
|
||
Version: 0.4.8 | ||
Version: 0.4.9 | ||
|
||
Authors: sharkLoc <[email protected]> | ||
Source code: https://github.com/sharkLoc/fqkit.git | ||
|
@@ -72,6 +72,7 @@ Commands: | |
search search reads/motifs from fastq file | ||
grep grep fastq sequence by read id or full name | ||
stats summary for fastq format file [aliases: stat] | ||
kmer sample kmer count | ||
shuffle shuffle fastq sequences | ||
size report the number sequences and bases | ||
slide extract subsequences in sliding windows | ||
|
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,56 @@ | ||
use anyhow::Error; | ||
use bio::io::fastq; | ||
use log::*; | ||
use std::{collections::HashMap, time::Instant}; | ||
use crate::utils::*; | ||
use nthash::nthash; | ||
|
||
|
||
pub fn kmer_count( | ||
input: Option<&String>, | ||
kmer_len: usize, | ||
header: bool, | ||
output: Option<&String>, | ||
compression_level: u32, | ||
) -> Result<(),Error> { | ||
let start = Instant::now(); | ||
let reader = file_reader(input).map(fastq::Reader::new)?; | ||
if let Some(file) = input { | ||
info!("reading from file: {}", file); | ||
} else { | ||
info!("reading from stdin"); | ||
} | ||
|
||
let mut writer = file_writer(output, compression_level)?; | ||
let mut kmers = HashMap::new(); | ||
let (mut sidx, mut eidx) = (0,kmer_len); | ||
|
||
for rec in reader.records().flatten() { | ||
let khash = nthash(rec.seq(), kmer_len); | ||
|
||
let end = rec.seq().len() - kmer_len + 1; | ||
while eidx <= end { | ||
let kseq = &rec.seq()[sidx..eidx]; | ||
let khash_this = nthash(kseq, kmer_len)[0]; | ||
for k in khash.iter() { | ||
if khash_this.eq(k) { | ||
*kmers.entry(kseq.to_owned()).or_insert(0_u64) += 1; | ||
} | ||
} | ||
|
||
sidx += 1; | ||
eidx += 1; | ||
} | ||
} | ||
|
||
if header { | ||
writer.write_all("kmer\tcount\n".as_bytes())?; | ||
} | ||
for (k,v) in kmers { | ||
writer.write_all(k.as_slice())?; | ||
writer.write_all(format!("\t{}\n",v).as_bytes())?; | ||
} | ||
writer.flush()?; | ||
info!("time elapsed is: {:?}", start.elapsed()); | ||
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 |
---|---|---|
|
@@ -31,3 +31,4 @@ pub mod tail; | |
pub mod top; | ||
pub mod trimfq; | ||
pub mod view; | ||
pub mod kmer; |
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