GenOO
view release on metacpan or search on metacpan
cookbook/07-Plugins_And_Extensions.md view on Meta::CPAN
return 0 if $self->is_unmapped;
return 1 if $self->mapq == 255;
return 0;
}
sub is_primary_alignment {
my ($self) = @_;
return 0 if $self->is_unmapped;
return 0 if $self->flag & 256;
return 1;
}
sub is_secondary_alignment {
my ($self) = @_;
return 0 if $self->is_unmapped;
return 1 if $self->flag & 256;
return 0;
}
```
Now you can use this class to override the default class for the records of the SAM aligner.
```perl
my $file_parser = GenOO::Data::File::SAM->new(
file => 'file.sam',
records_class => 'GenOOx::Data::File::SAMstar::Record'
);
while (my $record = $file_parser->next_record) {
# $record is now an instance of GenOOx::Data::File::SAMstar::Record.
print $record->cigar."\n"; # name
print $record->flag."\n"; # flag
print $record->number_of_mappings."\n"; # new stuff not present by default
}
```
# An extension for GenOO DBIC
Similarly an extension module for GenOO DBIC that would support your custom table schema
```
strand,
rname,
start,
stop,
copy_number,
sequence,
query_length,
alignment_length
```
could look like this
```perl
package GenOOx::Data::DB::DBIC::Species::Schema::SampleResultBase::MyCustom;
#######################################################################
####################### Load External modules #####################
#######################################################################
use Modern::Perl;
use Moose;
use namespace::autoclean;
use MooseX::MarkAsMethods autoclean => 1;
#######################################################################
############################ Inheritance ##########################
#######################################################################
extends 'DBIx::Class::Core';
#######################################################################
####################### Interface attributes ######################
#######################################################################
# The interface attributes section provides Moose like accessors for
# the table columns. These methods basically overide those created by
# DBIx::Class. The column types are defined at the end of the class in
# the "Package Methods" section
######################
# The above ones satisfy the Region Role
has 'strand' => (
is => 'rw',
);
has 'rname' => (
is => 'rw',
);
has 'start' => (
is => 'rw',
);
has 'stop' => (
is => 'rw',
);
has 'copy_number' => (
is => 'rw',
);
######################
has 'sequence' => (
is => 'rw',
);
has 'query_length' => (
is => 'rw',
);
has 'alignment_length' => (
is => 'rw',
);
#######################################################################
########################## Consumed roles #########################
#######################################################################
with 'GenOO::Region';
( run in 0.771 second using v1.01-cache-2.11-cpan-ceb78f64989 )