C++ Class: SamRecord

From Genome Analysis Wiki
Jump to: navigation, search

This class is part of C++ Library: libStatGen.

Getting/Setting fields in a SAM/BAM Record

The SamRecord class contains accessors to "set" and "get" the fields of a SAM/BAM record.

The "set" accessors are used for creating a record that is not read from a SAM/BAM file. By using these set methods to setup the record, they can be pulled back out using the get accessors or the record can be later written as either a SAM/BAM record.

The "get" accessors assume that the class has already been populated, either by using the set commands or by calling SamFile::ReadRecord. Not all of the values that can be retrieved using these get accessors have set methods. That is because they are either read from the file or are internally calculated values.

See: http://csg.sph.umich.edu//mktrost/doxygen/current/classSamFileHeader.html for documentation.

Example of using getNextSamTag

   // record is a previously setup SamRecord.
   String recordString = "";
   char tag[3];
   char vtype;
   void* value;

   // While there are more tags, write them to the recordString.
   while(record.getNextSamTag(tag, vtype, &value) != false)
      recordString += "\t";
      recordString += tag;
      recordString += ":"; 
      recordString += vtype;
      recordString += ":";
         recordString += (int)*(int*)value;
      else if(record.isDoubleType(vtype))
         recordString += (double)*(double*)value;
      else if(record.isCharType(vtype))
         recordString += (char)*(char*)value;
         // String type.
         recordString += (String)*(String*)value;

   recordString += "\n";