Hello, I have been experimenting with using htslib to read SAM / BAM
content which has gone well. I'd now like to be able to write SAM / BAM
content de Novo. I see two options:

1) write SAM content myself, then use samtools or htslib to convert from
SAM to BAM format
2) write BAM content directly using htslib.

For example, creating the header seems relatively straightforward:

  header = bam_hdr_init();

  header->n_targets = count;

  header->target_len = (uint32_t*)calloc( count, sizeof(uint32_t) );

  for(int i=0; i < count; i++)

{

    header->target_len[i]  = nameLens[i].length();

    header->target_name[i] = strdup( names[i] );

}


I don't think I need to populate header->text and header->l_text,
correct me if I'm wrong.


Writing looks straight forward as well:


samFile* file = sam_open( tempFile, "w" );

sam_hdr_write( file, header );


I'm assuming the filename extension is used by sam_open to determine if it
should write out using SAM or BAM encoding. Please confirm.


However, in order to write alignments...

for( auto alignment : alignments )

{  sam_write1( file, header, alignment ); }


I'll first need a list of bam1_t objects. I'm seeing guidance for constucting

bam1_t and the related bam1_core_t structures. I have been poking
around in the test folders for both samtools and htslib and must have
overlooked such an example.

Are there any examples of doing this?


Any help would be much appreciated, thanks!


-Will Stokes
_______________________________________________
Samtools-help mailing list
Samtools-help@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/samtools-help

Reply via email to