Difference between revisions of "SAM/BAM Classes FAQs"

From Genome Analysis Wiki
Jump to navigationJump to search
Line 1: Line 1:
 
== How Do I? ==
 
== How Do I? ==
  
===== Q: Map between a query/read sequence and a reference sequence to do things like looking up a base/quality at a given reference position or looking up a reference base for a given read position?=====
+
===== Q: Map between a query/read sequence and a reference sequence to do things like looking up a base/quality at a given reference position or looking up a reference base for a given read position? =====
 
* A: Use [[C++ Class: CigarRoller#Mapping Between Reference and Read/Query|CigarRoller::getQueryIndex & CigarRoller::getRefOffset]]
 
* A: Use [[C++ Class: CigarRoller#Mapping Between Reference and Read/Query|CigarRoller::getQueryIndex & CigarRoller::getRefOffset]]
 +
 +
===== Q: Read only portions of a sorted & indexed BAM file that fall within a specified region? =====
 +
* A:
 +
*# open a sorted and indexed BAM file for reading (<code>SamFile::OpenForRead</code>)
 +
*# read the BAM Index file (<code>SamFile::ReadBamIndex</code>)
 +
*# read the header (<code>SamFile::ReadHeader</code>)
 +
*# set the region to be read (<code>SamFile::SetReadSection</code>)
 +
*# Loop calling <code>SamFile::ReadRecord</code> until it returns false - indicating there are no more reads within this region. 
 +
These methods are found in [[C++ Class: SamFile]].
 +
 +
NOTE: ReadRecord will also return false on an error - use <code>SamFile::GetStatus()</code> to determine if it was an error or the end of the region.  <code>GetStatus</code> returns SamStatus::NO_MORE_RECS for the end of the region.
 +
 +
* Q: How do I read multiple regions?
 +
** A: Use the above solution, but loop on the SetReadSection/ReadRecord steps until all sections have been processed.
 +
 +
===== Q: Get additional information on this library? =====
 +
* A: Email me, Mary Kate, at mktrost@umich.edu.

Revision as of 17:49, 29 July 2010

How Do I?

Q: Map between a query/read sequence and a reference sequence to do things like looking up a base/quality at a given reference position or looking up a reference base for a given read position?
Q: Read only portions of a sorted & indexed BAM file that fall within a specified region?
  • A:
    1. open a sorted and indexed BAM file for reading (SamFile::OpenForRead)
    2. read the BAM Index file (SamFile::ReadBamIndex)
    3. read the header (SamFile::ReadHeader)
    4. set the region to be read (SamFile::SetReadSection)
    5. Loop calling SamFile::ReadRecord until it returns false - indicating there are no more reads within this region.

These methods are found in C++ Class: SamFile.

NOTE: ReadRecord will also return false on an error - use SamFile::GetStatus() to determine if it was an error or the end of the region. GetStatus returns SamStatus::NO_MORE_RECS for the end of the region.

  • Q: How do I read multiple regions?
    • A: Use the above solution, but loop on the SetReadSection/ReadRecord steps until all sections have been processed.
Q: Get additional information on this library?
  • A: Email me, Mary Kate, at mktrost@umich.edu.