| 1 | package Bio::Tradis::CommandLine::RunMapping; | ||
| 2 | $Bio::Tradis::CommandLine::RunMapping::VERSION = '1.4.1'; | ||
| 3 | # ABSTRACT: Perform mapping | ||
| 4 | |||
| 5 | |||
| 6 | use Moose; | ||
| 7 | use Getopt::Long qw(GetOptionsFromArray); | ||
| 8 | use Cwd 'abs_path'; | ||
| 9 | use Bio::Tradis::Map; | ||
| 10 | |||
| 11 | has 'args' => ( is => 'ro', isa => 'ArrayRef', required => 1 ); | ||
| 12 | has 'script_name' => ( is => 'ro', isa => 'Str', required => 1 ); | ||
| 13 | has 'fastqfile' => ( is => 'rw', isa => 'Str', required => 0 ); | ||
| 14 | has 'reference' => ( is => 'rw', isa => 'Str', required => 0 ); | ||
| 15 | has 'help' => ( is => 'rw', isa => 'Bool', required => 0 ); | ||
| 16 | has 'refname' => | ||
| 17 | ( is => 'rw', isa => 'Str', required => 0, default => 'ref.index' ); | ||
| 18 | has 'outfile' => | ||
| 19 | ( is => 'rw', isa => 'Str', required => 0, default => 'mapped.sam' ); | ||
| 20 | has 'smalt_k' => ( is => 'rw', isa => 'Maybe[Int]', required => 0 ); | ||
| 21 | has 'smalt_s' => ( is => 'rw', isa => 'Maybe[Int]', required => 0 ); | ||
| 22 | has 'smalt_y' => ( is => 'rw', isa => 'Maybe[Num]', required => 0, default => 0.96 ); | ||
| 23 | has 'smalt_r' => ( is => 'rw', isa => 'Maybe[Int]', required => 0, default => -1 ); | ||
| 24 | has 'smalt_n' => ( is => 'rw', isa => 'Maybe[Int]', required => 0, default => 1 ); | ||
| 25 | |||
| 26 | sub BUILD { | ||
| 27 | my ($self) = @_; | ||
| 28 | |||
| 29 | my ( $fastqfile, $ref, $refname, $outfile, $smalt_k, $smalt_s, $smalt_y, $smalt_r,$smalt_n, $help ); | ||
| 30 | |||
| 31 | GetOptionsFromArray( | ||
| 32 | $self->args, | ||
| 33 | 'f|fastqfile=s' => \$fastqfile, | ||
| 34 | 'r|reference=s' => \$ref, | ||
| 35 | 'rn|refname=s' => \$refname, | ||
| 36 | 'o|outfile=s' => \$outfile, | ||
| 37 | 'sk|smalt_k=i' => \$smalt_k, | ||
| 38 | 'ss|smalt_s=i' => \$smalt_s, | ||
| 39 | 'sy|smalt_y=f' => \$smalt_y, | ||
| 40 | 'sr|smalt_r=i' => \$smalt_r, | ||
| 41 | 'n|smalt_n=i' => \$smalt_n, | ||
| 42 | 'h|help' => \$help | ||
| 43 | ); | ||
| 44 | |||
| 45 | $self->fastqfile( abs_path($fastqfile) ) if ( defined($fastqfile) ); | ||
| 46 | $self->reference( abs_path($ref) ) if ( defined($ref) ); | ||
| 47 | $self->refname($refname) if ( defined($refname) ); | ||
| 48 | $self->outfile( abs_path($outfile) ) if ( defined($outfile) ); | ||
| 49 | $self->smalt_k( $smalt_k ) if ( defined($smalt_k) ); | ||
| 50 | $self->smalt_s( $smalt_s ) if ( defined($smalt_s) ); | ||
| 51 | $self->smalt_y( $smalt_y ) if ( defined($smalt_y) ); | ||
| 52 | $self->smalt_r( $smalt_r ) if ( defined($smalt_r) ); | ||
| 53 | $self->smalt_n( $smalt_n ) if ( defined($smalt_n) ); | ||
| 54 | $self->help($help) if ( defined($help) ); | ||
| 55 | |||
| 56 | # print usage text if required parameters are not present | ||
| 57 | ($fastqfile && $ref) or die $self->usage_text; | ||
| 58 | } | ||
| 59 | |||
| 60 | sub run { | ||
| 61 | my ($self) = @_; | ||
| 62 | |||
| 63 | if ( defined( $self->help ) ) { | ||
| 64 | #if ( scalar( @{ $self->args } ) == 0 ) { | ||
| 65 | $self->usage_text; | ||
| 66 | } | ||
| 67 | |||
| 68 | my $mapping = Bio::Tradis::Map->new( | ||
| 69 | fastqfile => $self->fastqfile, | ||
| 70 | reference => $self->reference, | ||
| 71 | refname => $self->refname, | ||
| 72 | outfile => $self->outfile, | ||
| 73 | smalt_k => $self->smalt_k, | ||
| 74 | smalt_s => $self->smalt_s, | ||
| 75 | smalt_y => $self->smalt_y, | ||
| 76 | smalt_r => $self->smalt_r | ||
| 77 | ); | ||
| 78 | $mapping->index_ref; | ||
| 79 | $mapping->do_mapping; | ||
| 80 | } | ||
| 81 | |||
| 82 | sub usage_text { | ||
| 83 | print <<USAGE; | ||
| 84 | Indexes the reference genome and maps the given fastq file. | ||
| 85 | -k and -s options for indexing are calculated for the length of | ||
| 86 | the read as follows unless otherwise specified ( --smalt_k & | ||
| 87 | --smalt_s options ) | ||
| 88 | Read length | k | s | ||
| 89 | ---------------+----+----- | ||
| 90 | <70 | 13 | 4 | ||
| 91 | >70 & <100 | 13 | 6 | ||
| 92 | >100 | 20 | 13 | ||
| 93 | |||
| 94 | Usage: run_mapping -f file.fastq -r ref.fa [options] | ||
| 95 | |||
| 96 | Options: | ||
| 97 | -f : fastq file to map | ||
| 98 | -r : reference in fasta format | ||
| 99 | -rn : reference index name (optional. default: ref.index) | ||
| 100 | -o : mapped SAM output name (optional. default: mapped.sam) | ||
| 101 | --smalt_k : custom k-mer value for SMALT mapping | ||
| 102 | --smalt_s : custom step size for SMALT mapping | ||
| 103 | --smalt_r : custom r value for SMALT mapping | ||
| 104 | -n : number of threads to use for SMALT and samtools sort (optional. default = 1) | ||
| 105 | |||
| 106 | USAGE | ||
| 107 | exit; | ||
| 108 | } | ||
| 109 | |||
| 110 | __PACKAGE__->meta->make_immutable; | ||
| 111 | no Moose; | ||
| 112 | 1; | ||
| 113 | |||
| 114 | __END__ | ||
| 115 | |||
| 116 | =pod | ||
| 117 | |||
| 118 | =encoding UTF-8 | ||
| 119 | |||
| 120 | =head1 NAME | ||
| 121 | |||
| 122 | Bio::Tradis::CommandLine::RunMapping - Perform mapping | ||
| 123 | |||
| 124 | =head1 VERSION | ||
| 125 | |||
| 126 | version 1.4.1 | ||
| 127 | |||
| 128 | =head1 SYNOPSIS | ||
| 129 | |||
| 130 | Takes a reference genome and indexes it. | ||
| 131 | Maps given fastq files to ref. | ||
| 132 | |||
| 133 | =head1 AUTHOR | ||
| 134 | |||
| 135 | Carla Cummins <path-help@sanger.ac.uk> | ||
| 136 | |||
| 137 | =head1 COPYRIGHT AND LICENSE | ||
| 138 | |||
| 139 | This software is Copyright (c) 2013 by Wellcome Trust Sanger Institute. | ||
| 140 | |||
| 141 | This is free software, licensed under: | ||
| 142 | |||
| 143 | The GNU General Public License, Version 3, June 2007 | ||
| 144 | |||
| 145 | =cut |