1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
//! This crate is an implementation of a simple fasta and fastq parser.
//! It handles decompression of a gzipped file. Fasta files with reads on multiple lines are supported.
//! This crate also provides functions to iterate over kmers or their hash values.
//!
//! Examples:
//!
//! Iterating over the reads of a fasta file:
//! ```
//! use fastxgz::fasta_reads;
//!
//! let reads = fasta_reads("data/tests/test.fa").expect("The file cannot be opened.");
//! for read in reads {
//!     println!("{}", read);
//! }
//! ```
//!
//! Iterating over the kmers of the reads of a gzipped fastq file:
//! ```
//! use fastxgz::fastq_reads;
//! use fastxgz::KmerIterator;
//!
//! let reads = fastq_reads("data/tests/test.fq.gz").expect("The file cannot be opened.");
//! let kmers = KmerIterator::from(reads, 31);
//! for kmer in kmers {
//!     println!("{}", kmer);
//! }
//! ```
//!
//! Iterating over the hash of the kmers of the reads of a gzipped fastq file:
//! ```
//! use fastxgz::fastq_reads;
//! use fastxgz::KmerIterator;
//! use fastxgz::HashIterator;
//!
//! let reads = fastq_reads("data/tests/test.fq.gz").expect("The file cannot be opened.");
//! let kmers = KmerIterator::from(reads, 31);
//! let hashes = HashIterator::from(kmers);
//! for hash in hashes {
//!     println!("{}", hash);
//! }
//! ```

mod fastx_iterator;
mod hash_iterator;
mod high_level_interface;
mod kmer_iterator;
mod lines_iterator;

pub use crate::lines_iterator::ResultLinesIterator;
pub use crate::kmer_iterator::KmerIterator;
pub use crate::hash_iterator::HashIterator;
pub use crate::high_level_interface::fasta_reads;
pub use crate::high_level_interface::fastq_reads;
pub use crate::high_level_interface::lines_iterator;
pub use crate::high_level_interface::simple_fasta_reads;



///
#[cfg(test)]
mod tests {
    use crate::high_level_interface::simple_fasta_reads;

    use super::*;
    #[test]
    fn comp_fasta_fasta_gz() {
        let no_gz_reads = fasta_reads("data/tests/test.fa").expect("The file cannot be opened.");
        let no_gz_kmers = KmerIterator::from(no_gz_reads, 31);
        let no_gz_hashes = HashIterator::from(no_gz_kmers);

        let gz_reads = fasta_reads("data/tests/test.fa.gz").expect("The file cannot be opened.");
        let gz_kmers = KmerIterator::from(gz_reads, 31);
        let gz_hashes = HashIterator::from(gz_kmers);

        for (x, y) in std::iter::zip(no_gz_hashes, gz_hashes) {
            assert_eq!(x, y);
        }
    }

    #[test]
    fn comp_fastq_fastq_gz() {
        let no_gz_reads = fastq_reads("data/tests/test.fq").expect("The file cannot be opened.");
        let no_gz_kmers = KmerIterator::from(no_gz_reads, 31);
        let no_gz_hashes = HashIterator::from(no_gz_kmers);

        let gz_reads = fastq_reads("data/tests/test.fq.gz").expect("The file cannot be opened.");
        let gz_kmers = KmerIterator::from(gz_reads, 31);
        let gz_hashes = HashIterator::from(gz_kmers);

        for (x, y) in std::iter::zip(no_gz_hashes, gz_hashes) {
            assert_eq!(x, y);
        }
    }

    #[test]
    fn comp_simple_fasta_simple_fasta_gz() {
        let no_gz_reads =
            simple_fasta_reads("data/tests/test_nosplit.fa").expect("The file cannot be opened.");
        let no_gz_kmers = KmerIterator::from(no_gz_reads, 31);
        let no_gz_hashes = HashIterator::from(no_gz_kmers);

        let gz_reads = simple_fasta_reads("data/tests/test_nosplit.fa.gz")
            .expect("The file cannot be opened.");
        let gz_kmers = KmerIterator::from(gz_reads, 31);
        let gz_hashes = HashIterator::from(gz_kmers);

        for (x, y) in std::iter::zip(no_gz_hashes, gz_hashes) {
            assert_eq!(x, y);
        }
    }

    #[test]
    fn comp_simple_fasta_fasta() {
        let no_gz_reads = fasta_reads("data/tests/test.fa").expect("The file cannot be opened.");
        let no_gz_kmers = KmerIterator::from(no_gz_reads, 31);
        let no_gz_hashes = HashIterator::from(no_gz_kmers);

        let gz_reads =
            simple_fasta_reads("data/tests/test_nosplit.fa").expect("The file cannot be opened.");
        let gz_kmers = KmerIterator::from(gz_reads, 31);
        let gz_hashes = HashIterator::from(gz_kmers);

        for (x, y) in std::iter::zip(no_gz_hashes, gz_hashes) {
            assert_eq!(x, y);
        }
    }

    #[test]
    fn comp_fasta_fastq() {
        let no_gz_reads = fasta_reads("data/tests/test.fa").expect("The file cannot be opened.");
        let no_gz_kmers = KmerIterator::from(no_gz_reads, 31);
        let no_gz_hashes = HashIterator::from(no_gz_kmers);

        let gz_reads = fastq_reads("data/tests/test.fq").expect("The file cannot be opened.");
        let gz_kmers = KmerIterator::from(gz_reads, 31);
        let gz_hashes = HashIterator::from(gz_kmers);

        for (x, y) in std::iter::zip(no_gz_hashes, gz_hashes) {
            assert_eq!(x, y);
        }
    }
}