1

I have a bam file and use bioperl (Bio::DB::Sam) to work with it. Now i wanted to ask if there is any possibility to add tags to alignments in this File?

i use

    my $iterator     = $bam->features(-iterator => 1,
                                      -flags    => {M_UNMAPPED=>0});

    while (my $align = $iterator->next_seq) { 
        ...
    }

to loop through the aligned reads. Now i am searching vor anthing like

    $align->addTag(key=>value)

bye

Timur Shtatland
  • 12,024
  • 2
  • 30
  • 47
I3ilbo
  • 11
  • 1

2 Answers2

1

BedTools has a means of annotating BAM files called TagBam

http://biostar.stackexchange.com/questions/9552/basic-bam-file-annotation

https://github.com/arq5x/bedtools

Jeremy Leipzig
  • 1,914
  • 3
  • 21
  • 26
0

Short answer, no.

It might be possible to do it to the raw SAM and then convert it back to BAM. I've recently been writing a C++ api for BAM and came across this issue myself. The problem is the underlying c structures representing this information are all tightly byte packed and take up a specific amount of memory. Sometimes they might have a little more than they need, but other times they have just the right amount. Adding to these structures would, in most cases, exceed the available memory to them.

So, if I were you I would write out a new SAM file with your additional tags in it and convert it to BAM using samtools

Mike Lyons
  • 22,575
  • 2
  • 16
  • 19