/// iterate over a record from this Reader
iterate over a record from this Reader
iterate over a record from this Reader
pub fn iter_record(&mut self) -> Result<Option<Fastx>> {
		let head = self.data.iter().position(|&x| char::is_whitespace(x as char)).unwrap() + 1;
		let des = self.data.len();
		let mut seq = des + self.reader.read_until(b'\n', &mut self.data)?;
		let mut sep = seq;
		let mut qual = seq;
		let mut is_fasta = true;
		if seq != des {
			if self.data[0] == b'@' {
				is_fasta = false;
				let mut seq_line = 1;
				loop {
					let _data = self.reader.fill_buf()?; // for multiline fastq
					if !_data.is_empty() && _data[0] != b'+' {
						self.data.pop();
						seq += self.reader.read_until(b'\n', &mut self.data)? - 1;
						seq_line += 1;
					}else {
						break;
					}
				}
				sep = seq + self.reader.read_until(b'\n', &mut self.data)?;
				qual = sep + self.reader.read_until(b'\n', &mut self.data)?;
				if qual != sep {
					while seq_line > 1 {
						self.data.pop();
						let r = self.reader.read_until(b'\n', &mut self.data)?;
						if r == 0 {
							qual -= 1;
							break;
						}
						qual += r - 1;
						seq_line -= 1;
					}
					if self.data[qual - 1] != b'\n' { // for files not ending with '\n'
						qual += 1;
					}
				}
			}else{
				loop {
					let _data = self.reader.fill_buf()?; // for multiline fasta
					if !_data.is_empty() && _data[0] != b'>' {
						self.data.pop();
						seq += self.reader.read_until(b'\n', &mut self.data)? - 1;
					}else {
						break;
					}
				}
				if self.data[seq - 1] != b'\n' { // for files not ending with '\n'
					seq += 1;
				}
				sep = seq; //reset sep & qual
				qual = sep;
			}
		}
		if seq == des || !is_fasta && (sep == seq || qual == sep) {
			return Err(ParseError::TruncateFile(String::from_utf8(self.data.to_owned()).unwrap()));
		}
		//println!("head:{:?} des {:?} seq {:?} sep {:?} qual {:?}", head,des,seq,sep,qual);
		let fastx = Fastx {
			_head: head,
			_des: des,
			_seq: seq,
			_sep: sep,
			_qual: qual,
			_data: &self.data
			};
		if is_fasta {
			if !fastx.validate_fasta(){
				return Err(ParseError::InvalidFasta(fastx.head().to_string()));
			}
		}else if !fastx.validate_fastq() {
			return Err(ParseError::InvalidFastq(fastx.head().to_string()));
		}
		Ok(Some(fastx))
	}
pub fn iter_record ( & mut self ) -> Result < Option < Fastx > > { let head = self . data . iter ( ) . position ( | & x | char :: is_whitespace ( x as char ) ) . unwrap ( ) + 1 ; let des = self . data . len ( ) ; let mut seq = des + self . reader . read_until ( b'\n' , & mut self . data ) ? ; let mut sep = seq ; let mut qual = seq ; let mut is_fasta = true ; if seq != des { if self . data [ 0 ] == b'@' { is_fasta = false ; let mut seq_line = 1 ; loop { let _data = self . reader . fill_buf ( ) ? ; // for multiline fastq if ! _data . is_empty ( ) && _data [ 0 ] != b'+' { self . data . pop ( ) ; seq += self . reader . read_until ( b'\n' , & mut self . data ) ? - 1 ; seq_line += 1 ; } else { break ; } } sep = seq + self . reader . read_until ( b'\n' , & mut self . data ) ? ; qual = sep + self . reader . read_until ( b'\n' , & mut self . data ) ? ; if qual != sep { while seq_line > 1 { self . data . pop ( ) ; let r = self . reader . read_until ( b'\n' , & mut self . data ) ? ; if r == 0 { qual -= 1 ; break ; } qual += r - 1 ; seq_line -= 1 ; } if self . data [ qual - 1 ] != b'\n' { // for files not ending with '\n' qual += 1 ; } } } else { loop { let _data = self . reader . fill_buf ( ) ? ; // for multiline fasta if ! _data . is_empty ( ) && _data [ 0 ] != b'>' { self . data . pop ( ) ; seq += self . reader . read_until ( b'\n' , & mut self . data ) ? - 1 ; } else { break ; } } if self . data [ seq - 1 ] != b'\n' { // for files not ending with '\n' seq += 1 ; } sep = seq ; //reset sep & qual qual = sep ; } } if seq == des || ! is_fasta && ( sep == seq || qual == sep ) { return Err ( ParseError :: TruncateFile ( String :: from_utf8 ( self . data . to_owned ( ) ) . unwrap ( ) ) ) ; } //println!("head:{:?} des {:?} seq {:?} sep {:?} qual {:?}", head,des,seq,sep,qual); let fastx = Fastx { _head : head , _des : des , _seq : seq , _sep : sep , _qual : qual , _data : & self . data } ; if is_fasta { if ! fastx . validate_fasta ( ) { return Err ( ParseError :: InvalidFasta ( fastx . head ( ) . to_string ( ) ) ) ; } } else if ! fastx . validate_fastq ( ) { return Err ( ParseError :: InvalidFastq ( fastx . head ( ) . to_string ( ) ) ) ; } Ok ( Some ( fastx ) ) }
iterate over a record from this Reader
iterate over a record from this Reader
&mut self