Loading...
Searching...
No Matches
BamTools::BamAlignment Class Reference

The main BAM alignment data structure. More...

`#include <BamAlignment.h>`

## Public Member Functions

| BamAlignment ()
| constructor
bool | IsDuplicate () const
bool | IsFailedQC () const
bool | IsFirstMate () const
bool | IsMapped () const
bool | IsMateMapped () const
bool | IsMateReverseStrand () const
bool | IsPaired () const
bool | IsSupplementary () const
bool | IsPrimaryAlignment () const
bool | IsProperPair () const
bool | IsReverseStrand () const
bool | IsSecondMate () const
void | SetIsDuplicate (bool ok)
| Sets value of "PCR duplicate" flag to ok.
void | SetIsFailedQC (bool ok)
| Sets "failed quality control" flag to ok.
void | SetIsFirstMate (bool ok)
| Sets "alignment is first mate" flag to ok.
void | SetIsMapped (bool ok)
| Sets "alignment is mapped" flag to ok.
void | SetIsMateMapped (bool ok)
| Sets "alignment's mate is mapped" flag to ok.
void | SetIsMateReverseStrand (bool ok)
| Sets "alignment's mate mapped to reverse strand" flag to ok.
void | SetIsPaired (bool ok)
| Sets "alignment part of paired-end read" flag to ok.
void | SetIsPrimaryAlignment (bool ok)
| Sets "position is primary alignment" flag to ok.
void | SetIsProperPair (bool ok)
| Sets "alignment is part of read that satisfied paired-end resolution" flag to ok.
void | SetIsReverseStrand (bool ok)
| Sets "alignment mapped to reverse strand" flag to ok.
void | SetIsSecondMate (bool ok)
| Sets "alignment is second mate on read" flag to ok.
template<typename T>
bool | AddTag (const std::string &tag, const std::string &type, const T &value)
template<typename T>
bool | AddTag (const std::string &tag, const std::vector< T > &values)
template<typename T>
bool | EditTag (const std::string &tag, const std::string &type, const T &value)
template<typename T>
bool | EditTag (const std::string &tag, const std::vector< T > &values)
template<typename T>
bool | GetTag (const std::string &tag, T &destination) const
template<typename T>
bool | GetTag (const std::string &tag, std::vector< T > &destination) const
std::vector< std::string > | GetTagNames () const
| Retrieves the BAM tag names.
bool | GetTagType (const std::string &tag, char &type) const
| Retrieves the BAM tag type-code associated with requested tag name.
bool | GetArrayTagType (const std::string &tag, char &type) const
| Retrieves the BAM tag type-code for the array elements associated with requested tag name.
bool | HasTag (const std::string &tag) const
| Returns true if alignment has a record for requested tag.
void | RemoveTag (const std::string &tag)
| Removes field from BAM tags.
bool | BuildCharData ()
| Populates alignment string fields (read name, bases, qualities, tag data).
int | GetEndPosition (bool usePadded=false, bool closedInterval=false) const
| Calculates alignment end position, based on its starting position and CIGAR data.
std::string | GetErrorString () const
| Returns a human-readable description of the last error that occurred.
bool | GetSoftClips (std::vector< int > &clipSizes, std::vector< int > &readPositions, std::vector< int > &genomePositions, bool usePadded=false) const
| Identifies if an alignment has a soft clip. If so, identifies the sizes of the soft clips, as well as their positions in the read and reference.

## Public Attributes

std::string | Name
| read name
int32_t | Length
| length of query sequence
std::string | QueryBases
| 'original' sequence (as reported from sequencing machine)
std::string | AlignedBases
| 'aligned' sequence (includes any indels, padding, clipping)
std::string | Qualities
| FASTQ qualities (ASCII characters, not numeric values).
std::string | TagData
| tag data (use the provided methods to query/modify)
int32_t | RefID
| ID number for reference sequence.
int32_t | Position
| position (0-based) where alignment starts
uint16_t | Bin
| BAM (standard) index bin number for this alignment.
uint16_t | MapQuality
| mapping quality score
uint32_t | AlignmentFlag
| alignment bit-flag (use the provided methods to query/modify)
std::vector< CigarOp > | CigarData
| CIGAR operations for this alignment.
int32_t | MateRefID
| ID number for reference sequence where alignment's mate was aligned.
int32_t | MatePosition
| position (0-based) where alignment's mate starts
int32_t | InsertSize
| mate-pair insert size
std::string | Filename
| name of BAM file which this alignment comes from

## Friends

class | Internal::BamReaderPrivate
class | Internal::BamWriterPrivate

## Detailed Description

The main BAM alignment data structure.

Provides methods to query/modify BAM alignment data fields.

## Constructor & Destructor Documentation

## BamAlignment()

BamAlignment::BamAlignment | ( |  | ) |

constructor

## Member Function Documentation

## AddTag() [1/2]

template<typename T>

bool BamTools::BamAlignment::AddTag | ( | const std::string & | tag,
|  | const std::string & | type,
|  | const T & | value )

## AddTag() [2/2]

template<typename T>

bool BamTools::BamAlignment::AddTag | ( | const std::string & | tag,
|  | const std::vector< T > & | values )

## BuildCharData()

bool BamAlignment::BuildCharData | ( |  | ) |

Populates alignment string fields (read name, bases, qualities, tag data).

An alignment retrieved using BamReader::GetNextAlignmentCore() lacks this data. Using that method makes parsing much quicker when only positional data is required.

However, if you later want to access the character data fields from such an alignment, use this method to populate those fields. Provides ability to do 'lazy evaluation' of alignment parsing.

Returns
  `true` if character data populated successfully (or was already available to begin with)

## EditTag() [1/2]

template<typename T>

bool BamTools::BamAlignment::EditTag | ( | const std::string & | tag,
|  | const std::string & | type,
|  | const T & | value )

## EditTag() [2/2]

template<typename T>

bool BamTools::BamAlignment::EditTag | ( | const std::string & | tag,
|  | const std::vector< T > & | values )

## GetArrayTagType()

bool BamAlignment::GetArrayTagType | ( | const std::string & | tag,
|  | char & | type ) const

Retrieves the BAM tag type-code for the array elements associated with requested tag name.

Parameters

  [in] | tag | 2-character tag name
  [out] | type | retrieved (1-character) type-code

Returns
  `true` if found. False if not found, or if tag is not an array type.

See also
  http://samtools.sourceforge.net/SAM1.pdf for more details on reserved tag names, supported tag types, etc.

## GetEndPosition()

int BamAlignment::GetEndPosition | ( | bool | usePadded = false,
|  | bool | closedInterval = false ) const

Calculates alignment end position, based on its starting position and CIGAR data.

Warning
  The position returned now represents a zero-based, HALF-OPEN interval. In previous versions of BamTools (0.x & 1.x) all intervals were treated as zero-based, CLOSED.

Parameters

  [in] | usePadded | Allow inserted bases to affect the reported position. Default is false, so that reported position stays synced with reference coordinates.
  [in] | closedInterval | Setting this to true will return a 0-based end coordinate. Default is false, so that his value represents a standard, half-open interval.

Returns
  alignment end position

## GetErrorString()

std::string BamAlignment::GetErrorString | ( |  | ) | const

Returns a human-readable description of the last error that occurred.

This method allows elimination of STDERR pollution. Developers of client code may choose how the messages are displayed to the user, if at all.

Returns
  error description

## GetSoftClips()

bool BamAlignment::GetSoftClips | ( | std::vector< int > & | clipSizes,
|  | std::vector< int > & | readPositions,
|  | std::vector< int > & | genomePositions,
|  | bool | usePadded = false ) const

Identifies if an alignment has a soft clip. If so, identifies the sizes of the soft clips, as well as their positions in the read and reference.

Parameters

  [out] | clipSizes | vector of the sizes of each soft clip in the alignment
  [out] | readPositions | vector of the 0-based read locations of each soft clip in the alignment. These positions are basically indexes within the read, not genomic positions.
  [out] | genomePositions | vector of the 0-based genome locations of each soft clip in the alignment
  [in] | usePadded | inserted bases affect reported position. Default is false, so that reported position stays 'sync-ed' with reference coordinates.

Returns
  `true` if any soft clips were found in the alignment

## GetTag() [1/2]

template<typename T>

bool BamTools::BamAlignment::GetTag | ( | const std::string & | tag,
|  | std::vector< T > & | destination ) const

## GetTag() [2/2]

template<typename T>

bool BamTools::BamAlignment::GetTag | ( | const std::string & | tag,
|  | T & | destination ) const

## GetTagNames()

std::vector< std::string > BamAlignment::GetTagNames | ( |  | ) | const

Retrieves the BAM tag names.

When paired with GetTagType() and GetTag(), this method allows you to iterate over an alignment's tag data without knowing the names (or types) beforehand.

Returns
  `vector` containing all tag names found (empty if none available)

See also
  http://samtools.sourceforge.net/SAM1.pdf for more details on reserved tag names, supported tag types, etc.

## GetTagType()

bool BamAlignment::GetTagType | ( | const std::string & | tag,
|  | char & | type ) const

Retrieves the BAM tag type-code associated with requested tag name.

Parameters

  [in] | tag | 2-character tag name
  [out] | type | retrieved (1-character) type-code

Returns
  `true` if found

See also
  http://samtools.sourceforge.net/SAM1.pdf for more details on reserved tag names, supported tag types, etc.

## HasTag()

bool BamAlignment::HasTag | ( | const std::string & | tag | ) | const

Returns true if alignment has a record for requested tag.

Parameters

  [in] | tag | 2-character tag name

Returns
  `true` if alignment has a record for tag

## IsDuplicate()

bool BamAlignment::IsDuplicate | ( |  | ) | const

Returns
  `true` if this read is a PCR duplicate

## IsFailedQC()

bool BamAlignment::IsFailedQC | ( |  | ) | const

Returns
  `true` if this read failed quality control

## IsFirstMate()

bool BamAlignment::IsFirstMate | ( |  | ) | const

Returns
  `true` if alignment is first mate on paired-end read

## IsMapped()

bool BamAlignment::IsMapped | ( |  | ) | const

Returns
  `true` if alignment is mapped

## IsMateMapped()

bool BamAlignment::IsMateMapped | ( |  | ) | const

Returns
  `true` if alignment's mate is mapped

## IsMateReverseStrand()

bool BamAlignment::IsMateReverseStrand | ( |  | ) | const

Returns
  `true` if alignment's mate mapped to reverse strand

## IsPaired()

bool BamAlignment::IsPaired | ( |  | ) | const

Returns
  `true` if alignment part of paired-end read

## IsPrimaryAlignment()

bool BamAlignment::IsPrimaryAlignment | ( |  | ) | const

Returns
  `true` if reported position is primary alignment

## IsProperPair()

bool BamAlignment::IsProperPair | ( |  | ) | const

Returns
  `true` if alignment is part of read that satisfied paired-end resolution

## IsReverseStrand()

bool BamAlignment::IsReverseStrand | ( |  | ) | const

Returns
  `true` if alignment mapped to reverse strand

## IsSecondMate()

bool BamAlignment::IsSecondMate | ( |  | ) | const

Returns
  `true` if alignment is second mate on read

## IsSupplementary()

bool BamAlignment::IsSupplementary | ( |  | ) | const

Returns
  `true` if this read is supplementary

## RemoveTag()

void BamAlignment::RemoveTag | ( | const std::string & | tag | ) |

Removes field from BAM tags.

Parameters

  [in] | tag | 2-character name of field to remove

## SetIsDuplicate()

void BamAlignment::SetIsDuplicate | ( | bool | ok | ) |

Sets value of "PCR duplicate" flag to ok.

## SetIsFailedQC()

void BamAlignment::SetIsFailedQC | ( | bool | ok | ) |

Sets "failed quality control" flag to ok.

## SetIsFirstMate()

void BamAlignment::SetIsFirstMate | ( | bool | ok | ) |

Sets "alignment is first mate" flag to ok.

## SetIsMapped()

void BamAlignment::SetIsMapped | ( | bool | ok | ) |

Sets "alignment is mapped" flag to ok.

## SetIsMateMapped()

void BamAlignment::SetIsMateMapped | ( | bool | ok | ) |

Sets "alignment's mate is mapped" flag to ok.

## SetIsMateReverseStrand()

void BamAlignment::SetIsMateReverseStrand | ( | bool | ok | ) |

Sets "alignment's mate mapped to reverse strand" flag to ok.

## SetIsPaired()

void BamAlignment::SetIsPaired | ( | bool | ok | ) |

Sets "alignment part of paired-end read" flag to ok.

## SetIsPrimaryAlignment()

void BamAlignment::SetIsPrimaryAlignment | ( | bool | ok | ) |

Sets "position is primary alignment" flag to ok.

## SetIsProperPair()

void BamAlignment::SetIsProperPair | ( | bool | ok | ) |

Sets "alignment is part of read that satisfied paired-end resolution" flag to ok.

## SetIsReverseStrand()

void BamAlignment::SetIsReverseStrand | ( | bool | ok | ) |

Sets "alignment mapped to reverse strand" flag to ok.

## SetIsSecondMate()

void BamAlignment::SetIsSecondMate | ( | bool | ok | ) |

Sets "alignment is second mate on read" flag to ok.

## Friends And Related Symbol Documentation

## Internal::BamReaderPrivate

friend class Internal::BamReaderPrivate

friend

## Internal::BamWriterPrivate

friend class Internal::BamWriterPrivate

friend

## Member Data Documentation

## AlignedBases

std::string BamTools::BamAlignment::AlignedBases

'aligned' sequence (includes any indels, padding, clipping)

This field will be completely empty after reading from BamReader/BamMultiReader when QueryBases is empty.

## AlignmentFlag

uint32_t BamTools::BamAlignment::AlignmentFlag

alignment bit-flag (use the provided methods to query/modify)

## Bin

uint16_t BamTools::BamAlignment::Bin

BAM (standard) index bin number for this alignment.

## CigarData

std::vector<CigarOp> BamTools::BamAlignment::CigarData

CIGAR operations for this alignment.

## Filename

std::string BamTools::BamAlignment::Filename

name of BAM file which this alignment comes from

## InsertSize

int32_t BamTools::BamAlignment::InsertSize

mate-pair insert size

## Length

int32_t BamTools::BamAlignment::Length

length of query sequence

## MapQuality

uint16_t BamTools::BamAlignment::MapQuality

mapping quality score

## MatePosition

int32_t BamTools::BamAlignment::MatePosition

position (0-based) where alignment's mate starts

## MateRefID

int32_t BamTools::BamAlignment::MateRefID

ID number for reference sequence where alignment's mate was aligned.

## Name

std::string BamTools::BamAlignment::Name

read name

## Position

int32_t BamTools::BamAlignment::Position

position (0-based) where alignment starts

## Qualities

std::string BamTools::BamAlignment::Qualities

FASTQ qualities (ASCII characters, not numeric values).

Note
  Setting this field to "*" indicates to BamWriter that the quality scores are not to be stored, but instead will be output as a sequence of '0xFF'. Otherwise, QueryBases must not be a "*" and the length of this field should equal the length of QueryBases.

## QueryBases

std::string BamTools::BamAlignment::QueryBases

'original' sequence (as reported from sequencing machine)

Note
  Setting this field to "*" indicates that the sequence is not to be stored on output. In this case, the contents of the Qualities field should be invalidated as well (cleared or marked as "*").

## RefID

int32_t BamTools::BamAlignment::RefID

ID number for reference sequence.

## TagData

std::string BamTools::BamAlignment::TagData

tag data (use the provided methods to query/modify)

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

- BamAlignment.h
- BamAlignment.cpp