A toolkit for working with phylogenetic data.
v0.24.0
FastqWriter Class Reference

#include <genesis/sequence/formats/fastq_writer.hpp>

Detailed Description

Write Fastq data.

This class provides simple facilities for writing Fastq data.

Exemplary usage:

std::string outfile = "path/to/file.fastq";
SequenceSet sequence_set;

FastqWriter().write( sequence_set, utils::to_file( outfile ));

See FastqReader for a description of the Fastq format. Sequences are written to Fastq format, using the Sanger encoding (phred score plus offset 33), see also quality_encode_from_phred_score().

We expect Sequences to have a phred quality score by default, and throw an exception otherwise. To change this behaviour, and instead fill Sequences without quality scores with a constant quality score value, use fill_missing_quality( unsigned char ).

Definition at line 73 of file fastq_writer.hpp.

Public Member Functions

 FastqWriter ()=default
 
 FastqWriter (FastqWriter const &)=default
 
 FastqWriter (FastqWriter &&)=default
 
 ~FastqWriter ()=default
 
FastqWriterfill_missing_quality (unsigned char value)
 Set the value to fill the quality scores of sequences that do not have a phread score assigned to them. More...
 
unsigned char fill_missing_quality () const
 Get the current value to fill missing phred quality scores. More...
 
FastqWriterline_length (size_t value)
 Set the line length, which determines after how many chars (Sequence sites) lines breaks are inserted when writing the Fastq file. More...
 
size_t line_length () const
 Get the current line length. More...
 
FastqWriteroperator= (FastqWriter const &)=default
 
FastqWriteroperator= (FastqWriter &&)=default
 
FastqWriterrepeat_label (bool value)
 Set whether to repeat the sequence identifier (label) on the third line of each sequence. More...
 
bool repeat_label () const
 Get whether the setting to repeat the sequence identifier (label) on the third line is set. More...
 
void write (Sequence const &sequence, std::shared_ptr< utils::BaseOutputTarget > target) const
 Write a single Sequence to an output target, using the Fastq format. More...
 
void write (SequenceSet const &sequence_set, std::shared_ptr< utils::BaseOutputTarget > target) const
 Write a SequenceSet to an output target, using the Fastq format. More...
 
void write_sequence (Sequence const &sequence, std::ostream &os) const
 Write a single Sequence to an output stream in Fastq format. More...
 

Constructor & Destructor Documentation

◆ FastqWriter() [1/3]

FastqWriter ( )
default

◆ ~FastqWriter()

~FastqWriter ( )
default

◆ FastqWriter() [2/3]

FastqWriter ( FastqWriter const &  )
default

◆ FastqWriter() [3/3]

FastqWriter ( FastqWriter &&  )
default

Member Function Documentation

◆ fill_missing_quality() [1/2]

FastqWriter & fill_missing_quality ( unsigned char  value)

Set the value to fill the quality scores of sequences that do not have a phread score assigned to them.

By default, we do not accept sequences without phred scores assigned to them. If such a sequence occurs while writing, an exception is thrown. To change that behaviour, set the value to fill all sites of sequences that are missing their phread scores with this function. All values in the range [0, 254] are valid, but the encoding used in Fastq only ranges from 0 to 93 - all values above that are clamped to be 93. See quality_encode_from_phred_score() for details.

Lastly, in order to restore the original behaviour (that is, throw an exception if a sequence is missing phred scores), set this function to the magic value 255.

Definition at line 156 of file fastq_writer.cpp.

◆ fill_missing_quality() [2/2]

unsigned char fill_missing_quality ( ) const

Get the current value to fill missing phred quality scores.

Definition at line 162 of file fastq_writer.cpp.

◆ line_length() [1/2]

FastqWriter & line_length ( size_t  value)

Set the line length, which determines after how many chars (Sequence sites) lines breaks are inserted when writing the Fastq file.

Default is 0, which means, no line breaks are inserted. This is because many other parsing tools are implemented lazily and expect sequences in Fastq format to be on one line, so we use this by default. If set to any value greater than zero, line breaks are inserted into both the sequence and the quality score lines so that the do not exceed the specified length.

The functions returns the FastqWriter object to allow fluent interfaces.

Definition at line 145 of file fastq_writer.cpp.

◆ line_length() [2/2]

size_t line_length ( ) const

Get the current line length.

See the setter line_length( size_t ) for details.

Definition at line 151 of file fastq_writer.cpp.

◆ operator=() [1/2]

FastqWriter& operator= ( FastqWriter const &  )
default

◆ operator=() [2/2]

FastqWriter& operator= ( FastqWriter &&  )
default

◆ repeat_label() [1/2]

FastqWriter & repeat_label ( bool  value)

Set whether to repeat the sequence identifier (label) on the third line of each sequence.

Fastq allows the third line (starting with a + char) to either only contain that char, or to repeat the label of the first line (for whatever reason...). By default, we do not write the label again, to save a bit of storage space. Use this function to change that behaviour.

Definition at line 167 of file fastq_writer.cpp.

◆ repeat_label() [2/2]

bool repeat_label ( ) const

Get whether the setting to repeat the sequence identifier (label) on the third line is set.

Definition at line 173 of file fastq_writer.cpp.

◆ write() [1/2]

void write ( Sequence const &  sequence,
std::shared_ptr< utils::BaseOutputTarget target 
) const

Write a single Sequence to an output target, using the Fastq format.

See the output target convenience functions utils::to_file(), utils::to_stream(), and utils::to_string() for examples of how to obtain a suitable output target.

Definition at line 51 of file fastq_writer.cpp.

◆ write() [2/2]

void write ( SequenceSet const &  sequence_set,
std::shared_ptr< utils::BaseOutputTarget target 
) const

Write a SequenceSet to an output target, using the Fastq format.

See the output target convenience functions utils::to_file(), utils::to_stream(), and utils::to_string() for examples of how to obtain a suitable output target.

Definition at line 56 of file fastq_writer.cpp.

◆ write_sequence()

void write_sequence ( Sequence const &  sequence,
std::ostream &  os 
) const

Write a single Sequence to an output stream in Fastq format.

Definition at line 64 of file fastq_writer.cpp.


The documentation for this class was generated from the following files: