File Coverage

lib/Bio/Tradis/Map.pm
Criterion Covered Total %
statement 46 49 93.8
branch 6 10 60.0
condition n/a
subroutine 8 8 100.0
pod 2 2 100.0
total 62 69 89.8


line stmt bran cond sub pod time code
1             package Bio::Tradis::Map;
2             $Bio::Tradis::Map::VERSION = '1.3.2';
3             # ABSTRACT: Perform mapping
4              
5              
6 3     3   101084 use Moose;
  3         389356  
  3         18  
7 3     3   18927 use Bio::Tradis::Parser::Fastq;
  3         8  
  3         1185  
8              
9             has 'fastqfile' => ( is => 'rw', isa => 'Str', required => 1 );
10             has 'reference' => ( is => 'rw', isa => 'Str', required => 1 );
11             has 'refname' =>
12             ( is => 'rw', isa => 'Str', required => 0, default => 'ref.index' );
13             has 'outfile' =>
14             ( is => 'rw', isa => 'Str', required => 0, default => 'mapped.sam' );
15             has 'smalt_k' => ( is => 'rw', isa => 'Maybe[Int]', required => 0 );
16             has 'smalt_s' => ( is => 'rw', isa => 'Maybe[Int]', required => 0 );
17             has 'smalt_y' => ( is => 'rw', isa => 'Maybe[Num]', required => 0, default => 0.96 );
18             has 'smalt_r' => ( is => 'rw', isa => 'Maybe[Int]', required => 0, default => -1 );
19             has 'smalt_n' => ( is => 'rw', isa => 'Maybe[Int]', required => 0, default => 1 );
20              
21             sub index_ref {
22 4     4 1 12 my ($self) = @_;
23 4         93 my $ref = $self->reference;
24 4         73 my $refname = $self->refname;
25              
26             # Calculate index parameters
27 4         70 my $pars = Bio::Tradis::Parser::Fastq->new( file => $self->fastqfile );
28 4         20 $pars->next_read;
29 4         24 my @read = $pars->read_info;
30 4         12 my $read_len = length($read[1]);
31 4         17 my ( $k, $s ) = $self->_calculate_index_parameters($read_len);
32              
33 4         24 my $cmd = "smalt index -k $k -s $s $refname $ref > /dev/null 2>&1";
34 4         9921 system($cmd);
35 4         291 return $cmd;
36             }
37              
38             sub _calculate_index_parameters {
39 4     4   14 my ($self, $read_len) = @_;
40 4         9 my ( $k, $s );
41            
42 4 100       106 if( defined $self->smalt_k ){ $k = $self->smalt_k; }
  1         19  
43 3         14 else{ $k = $self->_smalt_k_default($read_len); }
44            
45 4 100       72 if( defined $self->smalt_s ){ $s = $self->smalt_s; }
  1         15  
46 3         14 else{ $s = $self->_smalt_s_default($read_len); }
47            
48 4         11 return ( $k, $s );
49             }
50              
51             sub _smalt_k_default {
52 3     3   7 my ($self, $read_len) = @_;
53 3 50       11 if($read_len < 100){ return 13; }
  3         14  
54 0         0 else{ return 20; }
55             }
56              
57             sub _smalt_s_default {
58 3     3   7 my ( $self, $read_len ) = @_;
59 3 50       11 if( $read_len < 70 ){ return 4; }
  3 0       7  
60 0         0 elsif( $read_len > 100 ){ return 13; }
61 0         0 else{ return 6; }
62             }
63              
64             sub do_mapping {
65 4     4 1 796 my ($self) = @_;
66 4         93 my $fqfile = $self->fastqfile;
67 4         80 my $refname = $self->refname;
68 4         76 my $outfile = $self->outfile;
69 4         90 my $y = $self->smalt_y;
70 4         68 my $r = $self->smalt_r;
71 4         67 my $n = $self->smalt_n;
72              
73 4         49 my $smalt = "smalt map -n $n -x -r $r -y $y $refname $fqfile 1> $outfile 2> smalt.stderr";
74              
75 4         8177 system($smalt);
76 4         431 unlink('smalt.stderr');
77            
78 4         174 return $smalt;
79             }
80              
81             __PACKAGE__->meta->make_immutable;
82 3     3   18 no Moose;
  3         5  
  3         17  
83             1;
84              
85             __END__
86              
87             =pod
88              
89             =encoding UTF-8
90              
91             =head1 NAME
92              
93             Bio::Tradis::Map - Perform mapping
94              
95             =head1 VERSION
96              
97             version 1.3.2
98              
99             =head1 SYNOPSIS
100              
101             Takes a reference genome and indexes it.
102             Maps given fastq files to ref.
103              
104             use Bio::Tradis::Map;
105            
106             my $pipeline = Bio::Tradis::Map->new(fastqfile => 'abc', reference => 'abc');
107             $pipeline->index_ref();
108             $pipeline->do_mapping();
109              
110             =head1 PARAMETERS
111              
112             =head2 Required
113              
114             =over
115              
116             =item * C<fastqfile> - path to/name of file containing reads to map to the reference
117              
118             =item * C<reference> - path to/name of reference genome in fasta format (.fa)
119              
120             =back
121              
122             =head2 Optional
123              
124             =over
125              
126             =item * C<refname> - name to assign to the reference index files. Default = ref.index
127              
128             =item * C<outfile> - name to assign to the mapped SAM file. Default = mapped.sam
129              
130             =back
131              
132             =head1 METHODS
133              
134             =over
135              
136             =item * C<index_ref> - create index files of the reference genome. These are required
137             for the mapping step. Only skip this step if index files already
138             exist. -k and -s options for referencing are calculated based
139             on the length of the reads being mapped as per table:
140              
141             =for html <table>
142             <tr><th>Read length</th><th>k</th><th>s</th></tr>
143             <tr><td><70</td><td>13</td><td>4<td></tr>
144             <tr><td>>70 and <100</td><td>13</td><td>6<td></tr>
145             <tr><td>>100</td><td>20</td><td>6<td></tr>
146             </table>
147              
148             =item * C<do_mapping> - map C<fastqfile> to C<reference>. Options used for mapping are: C<-r -1 -x -y 0.96>
149              
150             =back
151              
152             For more information on the mapping and indexing options discussed here, see the L<SMALT manual|ftp://ftp.sanger.ac.uk/pub4/resources/software/smalt/smalt-manual-0.7.4.pdf>
153              
154             =head1 AUTHOR
155              
156             Carla Cummins <path-help@sanger.ac.uk>
157              
158             =head1 COPYRIGHT AND LICENSE
159              
160             This software is Copyright (c) 2013 by Wellcome Trust Sanger Institute.
161              
162             This is free software, licensed under:
163              
164             The GNU General Public License, Version 3, June 2007
165              
166             =cut