| 1 | package Bio::Tradis::Map; | ||||||||||||||
| 2 | 6 | $Bio::Tradis::Map::VERSION = '1.4.5'; | |||||||||||||
| 3 | # ABSTRACT: Perform mapping | ||||||||||||||
| 4 | |||||||||||||||
| 5 | |||||||||||||||
| 6 | 6 | ▶ | use Moose; | ||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||
| 7 | 6 | ▶ | use Bio::Tradis::Parser::Fastq; | ||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||
| 8 | |||||||||||||||
| 9 | 6 | has 'fastqfile' => ( is => 'rw', isa => 'Str', required => 1 ); | |||||||||||||
| 10 | 6 | has 'reference' => ( is => 'rw', isa => 'Str', required => 1 ); | |||||||||||||
| 11 | 6 | has 'refname' => | |||||||||||||
| 12 | ( is => 'rw', isa => 'Str', required => 0, default => 'ref.index' ); | ||||||||||||||
| 13 | 6 | has 'outfile' => | |||||||||||||
| 14 | ( is => 'rw', isa => 'Str', required => 0, default => 'mapped.sam' ); | ||||||||||||||
| 15 | 6 | has 'min_seed_len' => ( is => 'rw', isa => 'Maybe[Int]', required => 0 ); | |||||||||||||
| 16 | 6 | has 'smalt' => ( is => 'rw', isa => 'Bool', required => 0, default => 0 ); | |||||||||||||
| 17 | 6 | has 'smalt_k' => ( is => 'rw', isa => 'Maybe[Int]', required => 0 ); | |||||||||||||
| 18 | 6 | has 'smalt_s' => ( is => 'rw', isa => 'Maybe[Int]', required => 0 ); | |||||||||||||
| 19 | 6 | has 'smalt_y' => ( is => 'rw', isa => 'Maybe[Num]', required => 0, default => 0.96 ); | |||||||||||||
| 20 | 6 | has 'smalt_r' => ( is => 'rw', isa => 'Maybe[Int]', required => 0, default => -1 ); | |||||||||||||
| 21 | 6 | has 'smalt_n' => ( is => 'rw', isa => 'Maybe[Int]', required => 0, default => 1 ); | |||||||||||||
| 22 | |||||||||||||||
| 23 | 8 | ▶ | sub index_ref { | ||||||||||||
|
Subroutine
index_ref: called CC=2 SCAR=6.9
Pod
documented
| |||||||||||||||
| 24 | 8 | my ($self) = @_; | |||||||||||||
| 25 | 8 | my $ref = $self->reference; | |||||||||||||
| 26 | 8 | my $refname = $self->refname; | |||||||||||||
| 27 | |||||||||||||||
| 28 | 8 | my $cmd = ""; | |||||||||||||
| 29 | 8 | ▶ | if ($self->smalt) { | ||||||||||||
|
Branch: 1 branch
| |||||||||||||||
| 30 | # Calculate index parameters | ||||||||||||||
| 31 | 4 | my $read_len = $self->_calculate_read_len(); | |||||||||||||
| 32 | 4 | my ( $k, $s ) = $self->_calculate_index_parameters($read_len); | |||||||||||||
| 33 | 4 | $cmd = "smalt index -k $k -s $s $refname $ref > /dev/null 2>&1"; | |||||||||||||
| 34 | } else { | ||||||||||||||
| 35 | 4 | $cmd = "bwa index $ref > /dev/null 2>&1" | |||||||||||||
| 36 | } | ||||||||||||||
| 37 | 8 | system($cmd); | |||||||||||||
| 38 | 8 | return $cmd; | |||||||||||||
| 39 | } | ||||||||||||||
| 40 | |||||||||||||||
| 41 | 8 | ▶ | sub _calculate_read_len { | ||||||||||||
|
Subroutine
_calculate_read_len: called CC=1 SCAR=0.0
| |||||||||||||||
| 42 | 8 | my ($self) = @_; | |||||||||||||
| 43 | 8 | my $pars = Bio::Tradis::Parser::Fastq->new( file => $self->fastqfile ); | |||||||||||||
| 44 | 8 | $pars->next_read; | |||||||||||||
| 45 | 8 | my @read = $pars->read_info; | |||||||||||||
| 46 | 8 | return length($read[1]); | |||||||||||||
| 47 | } | ||||||||||||||
| 48 | |||||||||||||||
| 49 | 4 | ▶ | sub _calculate_index_parameters { | ||||||||||||
|
Subroutine
_calculate_index_parameters: called CC=3 SCAR=11.0
| |||||||||||||||
| 50 | 4 | my ($self, $read_len) = @_; | |||||||||||||
| 51 | 4 | my ( $k, $s ); | |||||||||||||
| 52 | |||||||||||||||
| 53 | 4 | ▶ | if ( defined $self->smalt_k ){ $k = $self->smalt_k; } | ||||||||||||
|
Branch: 1 branch
| |||||||||||||||
| 54 | 3 | else{ $k = $self->_smalt_k_default($read_len); } | |||||||||||||
| 55 | |||||||||||||||
| 56 | 4 | ▶ | if( defined $self->smalt_s ){ $s = $self->smalt_s; } | ||||||||||||
|
Branch: 1 branch
| |||||||||||||||
| 57 | 3 | else{ $s = $self->_smalt_s_default($read_len); } | |||||||||||||
| 58 | |||||||||||||||
| 59 | 4 | return ( $k, $s ); | |||||||||||||
| 60 | } | ||||||||||||||
| 61 | |||||||||||||||
| 62 | 4 | ▶ | sub _min_seed_len_default { | ||||||||||||
|
Subroutine
_min_seed_len_default: called CC=2 SCAR=7.6
| |||||||||||||||
| 63 | 4 | my ($self, $read_len) = @_; | |||||||||||||
| 64 | 4 | ▶ | if($read_len < 100){ return 13; } | ||||||||||||
|
Branch: 1 branch
| |||||||||||||||
| 65 | 0 | else{ return 19; } | |||||||||||||
| 66 | } | ||||||||||||||
| 67 | |||||||||||||||
| 68 | 3 | ▶ | sub _smalt_k_default { | ||||||||||||
|
Subroutine
_smalt_k_default: called CC=2 SCAR=7.6
| |||||||||||||||
| 69 | 3 | my ($self, $read_len) = @_; | |||||||||||||
| 70 | 3 | ▶ | if($read_len < 100){ return 13; } | ||||||||||||
|
Branch: 1 branch
| |||||||||||||||
| 71 | 0 | else{ return 20; } | |||||||||||||
| 72 | } | ||||||||||||||
| 73 | |||||||||||||||
| 74 | 3 | ▶ | sub _smalt_s_default { | ||||||||||||
|
Subroutine
_smalt_s_default: called CC=3 SCAR=15.1
| |||||||||||||||
| 75 | 3 | my ( $self, $read_len ) = @_; | |||||||||||||
| 76 | 3 | ▶ | if( $read_len < 70 ){ return 4; } | ||||||||||||
|
Branch: 2 branches
| |||||||||||||||
| 77 | 0 | elsif( $read_len > 100 ){ return 13; } | |||||||||||||
| 78 | 0 | else{ return 6; } | |||||||||||||
| 79 | } | ||||||||||||||
| 80 | |||||||||||||||
| 81 | 8 | ▶ | sub do_mapping { | ||||||||||||
|
Subroutine
do_mapping: called CC=3 SCAR=11.0
Pod
documented
| |||||||||||||||
| 82 | 8 | my ($self) = @_; | |||||||||||||
| 83 | 8 | my $fqfile = $self->fastqfile; | |||||||||||||
| 84 | 8 | my $ref = $self->reference; | |||||||||||||
| 85 | 8 | my $refname = $self->refname; | |||||||||||||
| 86 | 8 | my $outfile = $self->outfile; | |||||||||||||
| 87 | 8 | my $y = $self->smalt_y; | |||||||||||||
| 88 | 8 | my $r = $self->smalt_r; | |||||||||||||
| 89 | 8 | my $n = $self->smalt_n; | |||||||||||||
| 90 | |||||||||||||||
| 91 | 8 | my $align = ""; | |||||||||||||
| 92 | 8 | ▶ | if ($self->smalt) { | ||||||||||||
|
Branch: 1 branch
| |||||||||||||||
| 93 | 4 | $align = "smalt map -n $n -x -r $r -y $y $refname $fqfile 1> $outfile 2> align.stderr"; | |||||||||||||
| 94 | } else { | ||||||||||||||
| 95 | 4 | my $read_len = $self->_calculate_read_len(); | |||||||||||||
| 96 | 4 | ▶ | my $k = ( defined $self->min_seed_len ) ? | ||||||||||||
|
Branch: 1 branch
| |||||||||||||||
| 97 | $self->min_seed_len : | ||||||||||||||
| 98 | $self->_min_seed_len_default($read_len); | ||||||||||||||
| 99 | |||||||||||||||
| 100 | 4 | $align = "bwa mem -k $k -t $n $ref $fqfile 1> $outfile 2> align.stderr"; | |||||||||||||
| 101 | } | ||||||||||||||
| 102 | |||||||||||||||
| 103 | 8 | system($align); | |||||||||||||
| 104 | 8 | unlink('align.stderr'); | |||||||||||||
| 105 | |||||||||||||||
| 106 | 8 | return $align; | |||||||||||||
| 107 | } | ||||||||||||||
| 108 | |||||||||||||||
| 109 | 6 | __PACKAGE__->meta->make_immutable; | |||||||||||||
| 110 | 6 | ▶ | no Moose; | ||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||
| 111 | 6 | 1; | |||||||||||||
| 112 | |||||||||||||||
| 113 | __END__ | ||||||||||||||