SeqAn3 3.4.0-rc.3
The Modern C++ library for sequence analysis.
|
Provides files and formats for handling read mapping data. More...
Classes | |
class | seqan3::format_bam |
The BAM format. More... | |
class | seqan3::format_sam |
The SAM format (tag). More... | |
struct | seqan3::ref_info_not_given |
Type tag which indicates that no reference information has been passed to the SAM file on construction. More... | |
class | seqan3::sam_file_header< ref_ids_type > |
Stores the header information of SAM/BAM files. More... | |
class | seqan3::sam_file_input< traits_type_, selected_field_ids_, valid_formats_ > |
A class for reading SAM files, both SAM and its binary representation BAM are supported. More... | |
struct | seqan3::sam_file_input_default_traits< ref_sequences_t, ref_ids_t > |
The default traits for seqan3::sam_file_input. More... | |
interface | seqan3::sam_file_input_format< t > |
The generic concept for alignment file input formats. More... | |
struct | seqan3::sam_file_input_options< sequence_legal_alphabet > |
The options type defines various option members that influence the behaviour of all or some formats. More... | |
interface | sam_file_input_traits |
The requirements a traits_type for seqan3::sam_file_input must meet. More... | |
class | seqan3::sam_file_output< selected_field_ids_, valid_formats_, ref_ids_type > |
A class for writing SAM files, both SAM and its binary representation BAM are supported. More... | |
interface | seqan3::sam_file_output_format< t > |
The generic concept for alignment file out formats. More... | |
struct | seqan3::sam_file_output_options |
The options type defines various option members that influence the behavior of all or some formats. More... | |
struct | seqan3::sam_file_program_info_t |
Stores information of the program/tool that was used to create a SAM/BAM file. More... | |
struct | seqan3::sam_flag_printer< sam_flag > |
A sam_flag can be printed as an integer value. More... | |
class | seqan3::sam_record< field_types, field_ids > |
The record type of seqan3::sam_file_input. More... | |
class | seqan3::sam_tag_dictionary |
The SAM tag dictionary class that stores all optional SAM fields. More... | |
struct | seqan3::sam_tag_type< tag_value > |
The generic base class. More... | |
Enumerations | |
enum class | seqan3::sam_flag : uint16_t { seqan3::sam_flag::none = 0 , seqan3::sam_flag::paired = 0x1 , seqan3::sam_flag::proper_pair = 0x2 , seqan3::sam_flag::unmapped = 0x4 , seqan3::sam_flag::mate_unmapped = 0x8 , seqan3::sam_flag::on_reverse_strand = 0x10 , seqan3::sam_flag::mate_on_reverse_strand = 0x20 , seqan3::sam_flag::first_in_pair = 0x40 , seqan3::sam_flag::second_in_pair = 0x80 , seqan3::sam_flag::secondary_alignment = 0x100 , seqan3::sam_flag::failed_filter = 0x200 , seqan3::sam_flag::duplicate = 0x400 , seqan3::sam_flag::supplementary_alignment = 0x800 } |
An enum flag that describes the properties of an aligned read (given as a SAM record). More... | |
Other literals | |
template<small_string< 2 > str> | |
constexpr uint16_t | seqan3::literals::operator""_tag () |
The SAM tag literal, such that tags can be used in constant expressions. | |
template<small_string< 2 > str> | |
constexpr uint16_t | operator""_tag () |
The SAM tag literal, such that tags can be used in constant expressions. | |
Provides files and formats for handling read mapping data.
SAM/BAM files are primarily used to store pairwise alignments of read mapping data.
The SAM file abstraction supports reading 10 different fields:
There exists one more field for SAM files, the seqan3::field::header_ptr, but this field is mostly used internally. Please see the seqan3::sam_file_output::header member function for details on how to access the seqan3::sam_file_header of the file.
All of these fields are retrieved by default (and in that order).
sam_file_input<>
(with angle brackets). In the latter case they are explicitly set to their default values, in the former case automatic deduction happens which chooses different parameters depending on the constructor arguments. For opening from file, sam_file_input<>
would have also worked, but for opening from stream it would not have. rec
has the type seqan3::sam_file_input::record_type which is a specialisation of seqan3::record and behaves like a std::tuple (that's why we can access it via get
). Instead of using the seqan3::field based interface on the record, you could also use std::get<0>
or even std::get<dna4_vector>
to retrieve the sequence, but it is not recommended, because it is more error-prone.auto &
and not just auto
, otherwise you will copy the record on every iteration. Since the buffer gets "refilled" on every iteration, you can also move the data out of the record if you want to store it somewhere without copying:selected_field_ids
parameter) are ignored and the respective value in the record stays empty.get
on the record, you can also use structured bindings to decompose the record into its elements. Considering the example of reading only the flag and mapping quality like before you can also write:flag
of seqan3::sam_file_input::flag_type and mapq
of seqan3::sam_file_input::mapq_type.seqan3::aligned_sequence
s.The conversion from a CIGAR string to an alignment can be done with the function seqan3::alignment_from_cigar
. You need to pass the reference sequence with the position the read was aligned to and the read sequence. All of it is already in the record
when reading a SAM file:begin()
and end()
(if they are the same, the file is at its end).sam_file_output<>
(with angle brackets). In the latter case they are explicitly set to their default values, in the former case automatic deduction happens which chooses different parameters depending on the constructor arguments. For opening from file, sam_file_output<>
would have also worked, but for opening from stream it would not have.push_back()
member functions. These work similarly to how they work on a std::vector. You may also use a tuple like interface or the emplace_back()
function but this is not recommended since one would have to keep track of the correct order of many fields (14 in total). For the record based interface using push_back()
please also see the seqan3::record documentation on how to specify a record with the correct field and type lists. field_traits
object.push_back()
. The seqan3::record clearly indicates which of its elements has which seqan3::field so the file will use that information instead of the template argument. This is especially handy when reading from one file and writing to another, because you don't have to configure the output file to match the input file, it will just work:
|
strong |
An enum flag that describes the properties of an aligned read (given as a SAM record).
The SAM flag are bitwise flags, which means that each value corresponds to a specific bit that is set and that they can be combined and tested using binary operations. See this tutorial for an introduction on bitwise operations on enum flags.
Example:
Adapted from the SAM specifications are the following additional information to some flag values:
FLAG & 0x900 == 0
). This line is called the primary alignment of the read.0x100
) marks the alignment not to be used in certain analyses when the tools in use are aware of this bit. It is typically used to flag alternative mappings when multiple mappings are presented in a SAM.0x800
) indicates that the corresponding alignment line is part of a chimeric alignment. If the SAM/BAM file corresponds to long reads (nanopore/pacbio) this happens when reads are split before being aligned and the best matching part is marked as primary, while all other aligned parts are marked supplementary.0x4
) is the only reliable place to tell whether the read is unmapped. If seqan3::sam_flag::unmapped is set, no assumptions can be made about RNAME, POS, CIGAR, MAPQ, and seqan3::sam_flag::proper_pair, seqan3::sam_flag::secondary_alignment, and seqan3::sam_flag::supplementary_alignment (bits 0x2
, 0x100
, and 0x800
).0x10
) indicates whether the read sequence has been reverse complemented and the quality string is reversed. When bit seqan3::sam_flag::unmapped (0x4
) is unset, this corresponds to the strand to which the segment has been mapped: seqan3::sam_flag::on_reverse_strand (bit 0x10
) unset indicates the forward strand, while set indicates the reverse strand. When seqan3::sam_flag::unmapped (0x4
) is set, this indicates whether the unmapped read is stored in its original orientation as it came off the sequencing machine.0x40
and 0x80
) reflect the read ordering within each template inherent in the sequencing technology used. If seqan3::sam_flag::first_in_pair and seqan3::sam_flag::second_in_pair (0x40
and 0x80
) are both set, the read is part of a linear template, but it is neither the first nor the last read. If both are unset, the index of the read in the template is unknown. This may happen for a non-linear template or when this information is lost during data processing.0x1
) is unset, no assumptions can be made about seqan3::sam_flag::proper_pair, seqan3::sam_flag::mate_unmapped, seqan3::sam_flag::mate_on_reverse_strand, seqan3::sam_flag::first_in_pair and seqan3::sam_flag::second_in_pair (bits 0x2
, 0x8
, 0x20
, 0x40
and 0x80
).Enumerator | |
---|---|
none | None of the flags below are set. |
paired | The aligned read is paired (paired-end sequencing). |
proper_pair | The two aligned reads in a pair have a proper distance between each other. |
unmapped | The read is not mapped to a reference (unaligned). |
mate_unmapped | The mate of this read is not mapped to a reference (unaligned). |
on_reverse_strand | The read sequence has been reverse complemented before being mapped (aligned). |
mate_on_reverse_strand | The mate sequence has been reverse complemented before being mapped (aligned). |
first_in_pair | Indicates the ordering (see details in the seqan3::sam_flag description). |
second_in_pair | Indicates the ordering (see details in the seqan3::sam_flag description). |
secondary_alignment | This read alignment is an alternative (possibly suboptimal) to the primary. |
failed_filter | The read alignment failed a filter, e.g. quality controls. |
duplicate | The read is marked as a PCR duplicate or optical duplicate. |
supplementary_alignment | This sequence is part of a split alignment and is not the primary alignment. |
|
constexpr |
The SAM tag literal, such that tags can be used in constant expressions.
char_t | The char type. Usually char . Parameter pack ...s must be of length 2 since SAM tags consist of two letters (char0 and char1). |
A SAM tag consists of two letters, initialized via the string literal ""_tag, which delegate to its unique id.
The purpose of those tags is to fill or query the seqan3::sam_tag_dictionary for a specific key (tag_id) and retrieve the corresponding value.
|
related |
The SAM tag literal, such that tags can be used in constant expressions.
char_t | The char type. Usually char . Parameter pack ...s must be of length 2 since SAM tags consist of two letters (char0 and char1). |
A SAM tag consists of two letters, initialized via the string literal ""_tag, which delegate to its unique id.
The purpose of those tags is to fill or query the seqan3::sam_tag_dictionary for a specific key (tag_id) and retrieve the corresponding value.