Beefy Boxes and Bandwidth Generously Provided by pair Networks
P is for Practical
 
PerlMonks  

cigar string

by prbndr (Acolyte)
on Nov 29, 2011 at 04:32 UTC ( [id://940529]=perlquestion: print w/replies, xml ) Need Help??

prbndr has asked for the wisdom of the Perl Monks concerning the following question:

hi all, i'm relatively new to perl and i'm just starting off with my first script to create a text based alignment viewer using the Bio_Samtools perl module. What i'm trying to do is parse a sam file to get all the reads that overlap a certain genomic window from the reference fasta sequence file. i have the following code to get all the reads that overlap a certain genomic window:
my @all_reads = $segment->features( -type => 'match', -seq_id => $seq_ids[0], -start => $window_start, -end => $window_end, -filter => sub { shift->strand == -1 }, );
i'm trying to recreate the real read sequence from its cigar string by adding insertions to the read (with a ^ character) and deletions (with a - character). i'm not exactly sure how to do this, since i can't access the cigar string. it seems to be stored in a reference to an array. see the following code:
for my $read (@all_reads) { print $read->qname,',',$read->aux_get("MD"), ',',$read->cigar_arra +y,',', $read->strand, "\n"; };
i don't know how to display the reference to the array denoted by the $read->cigar_array part of the code. it prints out ARRAY(0x100a2d058) or something similar instead of the split cigar string. once i get this working, i would need to add my desired characters to the read sequence to get to create the raw read. does anyone have any help? thanks!

Replies are listed 'Best First'.
Re: cigar string
by aaron_baugher (Curate) on Nov 29, 2011 at 05:06 UTC

    According to the pod for the module, $read->cigar_array returns a reference to an array of arrays. You could print it with Data::Dumper to see its structure. You can dereference it to get at the top array like this: @{$read->cigar_array} . Then you can loop through that array of references, and dereference those to access those subarrays:

    for my $toparray (@{$read->cigar_array}){ my( $operation, $count ) = @{$toparray}; # do stuff with this CIGAR operation and count }

    Aaron B.
    My Woefully Neglected Blog, where I occasionally mention Perl.

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: perlquestion [id://940529]
Approved by keszler
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others sharing their wisdom with the Monastery: (5)
As of 2024-04-23 09:24 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found