fastxgz 0.4.0

A fasta/fastq parser for both compressed and not compressed files.
Documentation
pub struct SimpleFastaReadsIterator<I>
where
    I: Iterator<Item = Vec<u8>>,
{
    lines_iterator: I,
}

impl<I> SimpleFastaReadsIterator<I>
where
    I: Iterator<Item = Vec<u8>>,
{
    pub fn from(lines_iterator: I) -> Self {
        Self { lines_iterator }
    }
}

impl<I> Iterator for SimpleFastaReadsIterator<I>
where
    I: Iterator<Item = Vec<u8>>,
{
    type Item = Vec<u8>;

    fn next(&mut self) -> Option<Self::Item> {
        let _first = self.lines_iterator.next()?;
        let second = self.lines_iterator.next()?;
        Some(second)
    }
}

pub struct FastaReadsIterator<I>
where
    I: Iterator<Item = Vec<u8>>,
{
    lines_iterator: I,
    next_line: Option<Vec<u8>>,
    end_reached: bool,
}

impl<I> FastaReadsIterator<I>
where
    I: Iterator<Item = Vec<u8>>,
{
    pub fn from(lines_iterator: I) -> Self {
        Self {
            lines_iterator,
            next_line: None,
            end_reached: false,
        }
    }
}

impl<I> Iterator for FastaReadsIterator<I>
where
    I: Iterator<Item = Vec<u8>>,
{
    type Item = Vec<u8>;

    fn next(&mut self) -> Option<Self::Item> {
        if self.end_reached {
            return None;
        }

        // ignore the first line (line)
        let _first = match &self.next_line {
            None => self.lines_iterator.next()?,
            Some(x) => x.clone(),
        };
        self.next_line = None;

        let mut second: Vec<Vec<u8>> = vec![self.lines_iterator.next()?];
        let mut second_size = second[0].len();
        // get all the lines of the next read
        loop {
            match self.lines_iterator.next() {
                Some(x) => {
                    if x[0] == b'>' {
                        self.next_line = Some(x);
                        break;
                    } else {
                        second.push(x.clone());
                        second_size += x.len();
                    }
                }
                None => {
                    self.end_reached = true;
                    break;
                }
            }
        }

        // merge all parts of the read
        let mut merge: Vec<u8> = Vec::with_capacity(second_size);
        for x in second {
            merge.extend(x);
        }

        Some(merge)
    }
}

pub struct FastqReadsIterator<I>
where
    I: Iterator<Item = Vec<u8>>,
{
    lines_iterator: I,
}

impl<I> FastqReadsIterator<I>
where
    I: Iterator<Item = Vec<u8>>,
{
    pub fn from(lines_iterator: I) -> Self {
        Self { lines_iterator }
    }
}

impl<I> Iterator for FastqReadsIterator<I>
where
    I: Iterator<Item = Vec<u8>>,
{
    type Item = Vec<u8>;

    fn next(&mut self) -> Option<Self::Item> {
        let _first = self.lines_iterator.next()?;
        let second = self.lines_iterator.next()?;
        let _third = self.lines_iterator.next()?;
        let _fourth = self.lines_iterator.next()?;
        Some(second)
    }
}