| 1 | # POD documentation - main docs before the code | ||
| 2 | |||
| 3 | =head1 NAME | ||
| 4 | |||
| 5 | GenOOx::Data::File::SAMbwa::Record - Represents a record of a SAM format file generated by BWA | ||
| 6 | |||
| 7 | =head1 SYNOPSIS | ||
| 8 | |||
| 9 | # Object representing a record of a sam file | ||
| 10 | |||
| 11 | # To initialize | ||
| 12 | my $sam_record = GenOOx::Data::File::SAMbwa::Record->new( | ||
| 13 | fields => [qname,flag, rname, pos, mapq, cigar, | ||
| 14 | rnext, pnext, tlen, seq, qual, tags] | ||
| 15 | ); | ||
| 16 | |||
| 17 | |||
| 18 | =head1 DESCRIPTION | ||
| 19 | |||
| 20 | This object represents a record of a sam file generated by BWA and offers methods for accessing the different | ||
| 21 | attributes. It implements several additional methods that transform original attributes in more manageable | ||
| 22 | attributes. eg. from the FLAG attribute the actual strand is extracted etc. | ||
| 23 | |||
| 24 | =head1 EXAMPLES | ||
| 25 | |||
| 26 | # Check if the record corresponds to a match | ||
| 27 | my $mapped = $sam_record->is_mapped; | ||
| 28 | |||
| 29 | # Check if the record corresponds to a non match | ||
| 30 | my $unmapped = $sam_record->is_unmapped; | ||
| 31 | |||
| 32 | # Parse the FLAG attribute and return 1 or -1 for the strand | ||
| 33 | my $strand = $sam_record->strand; | ||
| 34 | |||
| 35 | =cut | ||
| 36 | |||
| 37 | # Let the code begin... | ||
| 38 | |||
| 39 | package GenOOx::Data::File::SAMbwa::Record; | ||
| 40 | $GenOOx::Data::File::SAMbwa::Record::VERSION = '0.0.3'; | ||
| 41 | |||
| 42 | ####################################################################### | ||
| 43 | ####################### Load External modules ##################### | ||
| 44 | ####################################################################### | ||
| 45 | use Moose; | ||
| 46 | use namespace::autoclean; | ||
| 47 | |||
| 48 | |||
| 49 | ####################################################################### | ||
| 50 | ############################ Inheritance ########################## | ||
| 51 | ####################################################################### | ||
| 52 | extends 'GenOO::Data::File::SAM::Record'; | ||
| 53 | |||
| 54 | |||
| 55 | ####################################################################### | ||
| 56 | ######################## Interface Methods ######################## | ||
| 57 | ####################################################################### | ||
| 58 | sub number_of_best_hits { | ||
| 59 | my ($self) = @_; | ||
| 60 | |||
| 61 | return $self->tag('X0:i'); | ||
| 62 | } | ||
| 63 | |||
| 64 | sub number_of_suboptimal_hits { | ||
| 65 | my ($self) = @_; | ||
| 66 | |||
| 67 | return $self->tag('X1:i') || 0; | ||
| 68 | } | ||
| 69 | |||
| 70 | sub number_of_mappings { | ||
| 71 | my ($self) = @_; | ||
| 72 | |||
| 73 | return $self->number_of_best_hits + $self->number_of_suboptimal_hits; | ||
| 74 | } | ||
| 75 | |||
| 76 | sub alternative_mappings { | ||
| 77 | my ($self) = @_; | ||
| 78 | |||
| 79 | my @alternative_mappings; | ||
| 80 | my $value = $self->tag('XA:Z'); | ||
| 81 | if (defined $value) { | ||
| 82 | @alternative_mappings = split(/;/,$value); | ||
| 83 | } | ||
| 84 | return @alternative_mappings; | ||
| 85 | } | ||
| 86 | |||
| 87 | |||
| 88 | ####################################################################### | ||
| 89 | ############################ Finalize ############################# | ||
| 90 | ####################################################################### | ||
| 91 | __PACKAGE__->meta->make_immutable; | ||
| 92 | |||
| 93 | 1; |