Skip to main content

zoe/data/records/
mod.rs

1use crate::{
2    alignment::{LocalProfiles, SharedProfiles},
3    data::fasta::{FastaAA, FastaNT, FastaNTAnnot, FastaSeq},
4    prelude::{
5        AminoAcids, AminoAcidsView, AminoAcidsViewMut, FastQ, FastQView, FastQViewMut, Nucleotides, NucleotidesView,
6        NucleotidesViewMut,
7    },
8};
9
10/// A module for reading and manipulating
11/// [FASTA](https://en.wikipedia.org/wiki/FASTA_format) files.
12pub mod fasta;
13/// A module for reading and manipulating
14/// [FASTQ](https://en.wikipedia.org/wiki/FASTQ_format) files.
15pub mod fastq;
16/// A module for reading and manipulating
17/// [SAM](https://samtools.github.io/hts-specs/SAMv1.pdf) files. Provides some
18/// special-case functions used by [IRMA](https://wonder.cdc.gov/amd/flu/irma/).
19pub mod sam;
20
21/// Getter trait for structures providing read access to a header/name
22pub trait HeaderReadable {
23    /// Gets the header from the record.
24    #[must_use]
25    fn header(&self) -> &str;
26}
27
28impl HeaderReadable for FastQ {
29    #[inline]
30    fn header(&self) -> &str {
31        &self.header
32    }
33}
34
35impl HeaderReadable for FastQView<'_> {
36    #[inline]
37    fn header(&self) -> &str {
38        self.header
39    }
40}
41
42impl HeaderReadable for FastQViewMut<'_> {
43    #[inline]
44    fn header(&self) -> &str {
45        self.header
46    }
47}
48
49impl HeaderReadable for FastaSeq {
50    #[inline]
51    fn header(&self) -> &str {
52        &self.name
53    }
54}
55
56impl HeaderReadable for FastaNT {
57    #[inline]
58    fn header(&self) -> &str {
59        &self.name
60    }
61}
62
63impl HeaderReadable for FastaAA {
64    #[inline]
65    fn header(&self) -> &str {
66        &self.name
67    }
68}
69
70impl HeaderReadable for FastaNTAnnot {
71    #[inline]
72    fn header(&self) -> &str {
73        &self.name
74    }
75}
76
77/// Getter trait for structures providing read access to a sequence.
78///
79/// The sequence can be either nucleotides or amino acids, and is returned as a
80/// byte slice.
81pub trait SequenceReadable {
82    /// Get the sequence from the struct as a byte slice.
83    #[must_use]
84    fn sequence_bytes(&self) -> &[u8];
85}
86
87impl SequenceReadable for Nucleotides {
88    #[inline]
89    fn sequence_bytes(&self) -> &[u8] {
90        self.as_ref()
91    }
92}
93
94impl SequenceReadable for NucleotidesView<'_> {
95    #[inline]
96    fn sequence_bytes(&self) -> &[u8] {
97        self.as_ref()
98    }
99}
100
101impl SequenceReadable for NucleotidesViewMut<'_> {
102    #[inline]
103    fn sequence_bytes(&self) -> &[u8] {
104        self.as_ref()
105    }
106}
107
108impl SequenceReadable for AminoAcids {
109    #[inline]
110    fn sequence_bytes(&self) -> &[u8] {
111        self.as_ref()
112    }
113}
114
115impl SequenceReadable for AminoAcidsView<'_> {
116    #[inline]
117    fn sequence_bytes(&self) -> &[u8] {
118        self.as_ref()
119    }
120}
121
122impl SequenceReadable for AminoAcidsViewMut<'_> {
123    #[inline]
124    fn sequence_bytes(&self) -> &[u8] {
125        self.as_ref()
126    }
127}
128
129impl SequenceReadable for FastQ {
130    #[inline]
131    fn sequence_bytes(&self) -> &[u8] {
132        self.sequence.as_ref()
133    }
134}
135
136impl SequenceReadable for FastQView<'_> {
137    #[inline]
138    fn sequence_bytes(&self) -> &[u8] {
139        self.sequence.as_ref()
140    }
141}
142
143impl SequenceReadable for FastQViewMut<'_> {
144    #[inline]
145    fn sequence_bytes(&self) -> &[u8] {
146        self.sequence.as_ref()
147    }
148}
149
150impl SequenceReadable for FastaSeq {
151    #[inline]
152    fn sequence_bytes(&self) -> &[u8] {
153        self.sequence.as_ref()
154    }
155}
156
157impl SequenceReadable for FastaAA {
158    #[inline]
159    fn sequence_bytes(&self) -> &[u8] {
160        self.sequence.as_ref()
161    }
162}
163
164impl SequenceReadable for FastaNT {
165    #[inline]
166    fn sequence_bytes(&self) -> &[u8] {
167        self.sequence.as_ref()
168    }
169}
170
171impl SequenceReadable for FastaNTAnnot {
172    #[inline]
173    fn sequence_bytes(&self) -> &[u8] {
174        self.sequence.as_ref()
175    }
176}
177
178impl<const M: usize, const N: usize, const O: usize, const S: usize> SequenceReadable for LocalProfiles<'_, M, N, O, S> {
179    #[inline]
180    fn sequence_bytes(&self) -> &[u8] {
181        &self.seq
182    }
183}
184
185impl<const M: usize, const N: usize, const O: usize, const S: usize> SequenceReadable for SharedProfiles<'_, M, N, O, S> {
186    #[inline]
187    fn sequence_bytes(&self) -> &[u8] {
188        &self.seq
189    }
190}