Sequence::samrecord Class Reference
[High-throughput sequencing]

A single alignment record from a SAM file. More...

#include <Sequence/samrecord.hpp>

List of all members.

Public Types

typedef std::vector< std::pair
< char, unsigned >
>::const_iterator 
cigar_iterator
typedef std::vector< samtag >
::const_iterator 
tag_iterator

Public Member Functions

 samrecord (const samrecord &r)
 samrecord (const std::string &s)
std::string qname () const
samflag flag () const
std::string rname () const
unsigned long pos () const
unsigned long mapq () const
std::string cigar () const
std::string mrnm () const
unsigned long mpos () const
int isize () const
std::string seq () const
std::string qual () const
std::string tags () const
std::istream & read (std::istream &i)
std::ostream & print (std::ostream &o) const
cigar_iterator cig_begin () const
cigar_iterator cig_end () const
tag_iterator tag_begin () const
tag_iterator tag_end () const

Detailed Description

A single alignment record from a SAM file.

Intended usage: samtools view (b|s)amfile | ./program_using_this_class

In essence, this class stores a single line of mapping data as a string. This string is then parsed lazily. Here, lazy parsing means that iterators are stored to the beginning and end of each field, rather than storing each data field as a separate variable. This drastically speeds up the speed of reading in records because, in practice, only a subset of the fields may actually be desired.

When a particular field is wanted, the appropriate member function is called, and the iterators are used to construct the desired value.

Note:
The lazy parsing means that repeated calls to retrieve specific fields requires constructing a new value from scratch each time. This is inefficient. So, instead of calling qname() over and over, store the return value in a std::string.

Definition at line 69 of file samrecord.hpp.


Member Typedef Documentation

typedef std::vector< std::pair<char,unsigned> >::const_iterator Sequence::samrecord::cigar_iterator

Iterator over elements of CIGAR string. The char is the field type, and the unsigned integer is the value. Thus, the follwing CIGAR string, 5M2P5M, may be accessed as follows:

      Sequence::samrecord s;
      std::cin >> s;
      for( s::cigar_iterator ci = s.cig_begin() ; ci < s.cig_end() ; ++ci )
      {
      std::cout << ci->first << '\t' << ci->second << '\n';
      }

Will print to the screen:

M 5

P 2

M 5

Definition at line 98 of file samrecord.hpp.

typedef std::vector< samtag >::const_iterator Sequence::samrecord::tag_iterator

Iterator over elements of the optional TAG fields at the end of a SAM record.

Example usage:

      Sequence::samrecord s;
      std::cin >> s;
      for( s::tag_iterator ti = s.tag_begin() ; ti < s.tag_end() ; ++ti )
      {
      std::cout << ti->tag() << '\t' << ti->vtype() << '\t' << ti->value() << '\n';
      }

Definition at line 112 of file samrecord.hpp.


Member Function Documentation

samrecord::cigar_iterator Sequence::samrecord::cig_begin (  )  const
Returns:
Iterator to beginning of cigar data fields

Definition at line 207 of file samrecord.cc.

samrecord::cigar_iterator Sequence::samrecord::cig_end (  )  const
Returns:
Iterator to end of cigar data fields

Definition at line 215 of file samrecord.cc.

std::string Sequence::samrecord::cigar (  )  const
Returns:
the CIGAR field

Definition at line 281 of file samrecord.cc.

samflag Sequence::samrecord::flag (  )  const
Returns:
The SAM flag field as an object of type Sequence::samflag

Definition at line 247 of file samrecord.cc.

int Sequence::samrecord::isize (  )  const
Returns:
the ISIZE field

Definition at line 305 of file samrecord.cc.

unsigned long Sequence::samrecord::mapq (  )  const
Returns:
the MAPQ field

Definition at line 272 of file samrecord.cc.

unsigned long Sequence::samrecord::mpos (  )  const
Returns:
the MPOS field

Definition at line 297 of file samrecord.cc.

std::string Sequence::samrecord::mrnm (  )  const
Returns:
the MRNM field

Definition at line 289 of file samrecord.cc.

unsigned long Sequence::samrecord::pos (  )  const
Returns:
the POS field

Definition at line 263 of file samrecord.cc.

std::ostream & Sequence::samrecord::print ( std::ostream &  o  )  const

called by operator<<

Definition at line 347 of file samrecord.cc.

std::string Sequence::samrecord::qname (  )  const
Returns:
QNAME field

Definition at line 239 of file samrecord.cc.

std::string Sequence::samrecord::qual (  )  const
Returns:
the QUAL field

Definition at line 321 of file samrecord.cc.

std::istream & Sequence::samrecord::read ( std::istream &  i  ) 

called by operator>>

Definition at line 337 of file samrecord.cc.

std::string Sequence::samrecord::rname (  )  const
Returns:
the RNAME field

Definition at line 255 of file samrecord.cc.

std::string Sequence::samrecord::seq (  )  const
Returns:
the SEQ field

Definition at line 313 of file samrecord.cc.

samrecord::tag_iterator Sequence::samrecord::tag_begin (  )  const
Returns:
Iterator to beginning of parsed tag fields

Definition at line 223 of file samrecord.cc.

samrecord::tag_iterator Sequence::samrecord::tag_end (  )  const
Returns:
Iterator to end of parsed tag fields

Definition at line 231 of file samrecord.cc.

string Sequence::samrecord::tags (  )  const
Returns:
the TAGS field

Definition at line 329 of file samrecord.cc.


The documentation for this class was generated from the following files:
Generated on Thu Aug 11 13:22:03 2011 for libsequence by  doxygen 1.6.3