| 1 | package Bio::Tradis::Map; | ||
| 2 | $Bio::Tradis::Map::VERSION = '1.4.1'; | ||
| 3 | # ABSTRACT: Perform mapping | ||
| 4 | |||
| 5 | |||
| 6 | use Moose; | ||
| 7 | use Bio::Tradis::Parser::Fastq; | ||
| 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 | my ($self) = @_; | ||
| 23 | my $ref = $self->reference; | ||
| 24 | my $refname = $self->refname; | ||
| 25 | |||
| 26 | # Calculate index parameters | ||
| 27 | my $pars = Bio::Tradis::Parser::Fastq->new( file => $self->fastqfile ); | ||
| 28 | $pars->next_read; | ||
| 29 | my @read = $pars->read_info; | ||
| 30 | my $read_len = length($read[1]); | ||
| 31 | my ( $k, $s ) = $self->_calculate_index_parameters($read_len); | ||
| 32 | |||
| 33 | my $cmd = "smalt index -k $k -s $s $refname $ref > /dev/null 2>&1"; | ||
| 34 | system($cmd); | ||
| 35 | return $cmd; | ||
| 36 | } | ||
| 37 | |||
| 38 | sub _calculate_index_parameters { | ||
| 39 | my ($self, $read_len) = @_; | ||
| 40 | my ( $k, $s ); | ||
| 41 | |||
| 42 | if( defined $self->smalt_k ){ $k = $self->smalt_k; } | ||
| 43 | else{ $k = $self->_smalt_k_default($read_len); } | ||
| 44 | |||
| 45 | if( defined $self->smalt_s ){ $s = $self->smalt_s; } | ||
| 46 | else{ $s = $self->_smalt_s_default($read_len); } | ||
| 47 | |||
| 48 | return ( $k, $s ); | ||
| 49 | } | ||
| 50 | |||
| 51 | sub _smalt_k_default { | ||
| 52 | my ($self, $read_len) = @_; | ||
| 53 | if($read_len < 100){ return 13; } | ||
| 54 | else{ return 20; } | ||
| 55 | } | ||
| 56 | |||
| 57 | sub _smalt_s_default { | ||
| 58 | my ( $self, $read_len ) = @_; | ||
| 59 | if( $read_len < 70 ){ return 4; } | ||
| 60 | elsif( $read_len > 100 ){ return 13; } | ||
| 61 | else{ return 6; } | ||
| 62 | } | ||
| 63 | |||
| 64 | sub do_mapping { | ||
| 65 | my ($self) = @_; | ||
| 66 | my $fqfile = $self->fastqfile; | ||
| 67 | my $refname = $self->refname; | ||
| 68 | my $outfile = $self->outfile; | ||
| 69 | my $y = $self->smalt_y; | ||
| 70 | my $r = $self->smalt_r; | ||
| 71 | my $n = $self->smalt_n; | ||
| 72 | |||
| 73 | my $smalt = "smalt map -n $n -x -r $r -y $y $refname $fqfile 1> $outfile 2> smalt.stderr"; | ||
| 74 | |||
| 75 | system($smalt); | ||
| 76 | unlink('smalt.stderr'); | ||
| 77 | |||
| 78 | return $smalt; | ||
| 79 | } | ||
| 80 | |||
| 81 | __PACKAGE__->meta->make_immutable; | ||
| 82 | no Moose; | ||
| 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.4.1 | ||
| 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 |