How To Edit A Bam File With Bio::Db::Bam
1
1
Entering edit mode
11.1 years ago
Owen S. ▴ 370

I have just begun exploring Lincoln Stein's excellent Bio::DB::Bam perl module and have an elementary question. Is it possible to edit values of an Bio::DB::Bam::Alignment alignment object?

Here is a dead simple script that just copies a bam file.

my $bam = Bio::DB::Bam->open("in.bam") ;
my $fix = Bio::DB::Bam->open("out.bam", "w" ) ;

my $header = $bam->header();
$fix->header_write($header);

while (my $align = $bam->read1 ) {
  # EDIT BAM FIELDS HERE
  $fix->write1($align);
}

What I want to do is edit some of the fields before writing them. For example, for each alignment, I can access the CIGAR field with $align->cigar_str or $align->cigar_array and I can get the sequence of the read with $align->qseq -- but is there a way I can change these values before writing them to the new file?

bioperl samtools perl • 3.7k views
ADD COMMENT
1
Entering edit mode

I read through the CPAN documentation. At a first glance it does not look like there are setter methods? Have you tried giving an argument to the method call. $align->cigar_str(your string)?

ADD REPLY
0
Entering edit mode

Thank you, your hunch was quite right, no setter methods for most of the objects.

ADD REPLY
3
Entering edit mode
11.0 years ago
marcosmorgan ▴ 120

I went through the Bio::DB::Bam::Alignment documentation and found this under “Low-level Bio::DB::Bam::Alignment methods”:

These methods are available to objects of type Bio::DB::Bam::Alignment as well as Bio::DB::Bam::AlignWrapper and closely mirror the native C API.

...

$tid = $align->tid( [$new_tid] ) Return the target ID of the alignment. Optionally you may change the tid by providing it as an argument (currently this is the only field that you can change; the functionality was implemented as a proof of principle).

Therefore, the only value that you can edit is the target ID.

ADD COMMENT
0
Entering edit mode

Hopefully there is continued development on Bio::DB::BAM~!

ADD REPLY

Login before adding your answer.

Traffic: 1872 users visited in the last hour
Help About
FAQ
Access RSS
API
Stats

Use of this site constitutes acceptance of our User Agreement and Privacy Policy.

Powered by the version 2.3.6