| 1 | package Bio::Tradis::CommandLine::RunMapping; | ||
| 2 | |||
| 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 | |||
| 21 | sub BUILD { | ||
| 22 | my ($self) = @_; | ||
| 23 | |||
| 24 | my ( $fastqfile, $ref, $refname, $outfile, $help ); | ||
| 25 | |||
| 26 | GetOptionsFromArray( | ||
| 27 | $self->args, | ||
| 28 | 'f|fastqfile=s' => \$fastqfile, | ||
| 29 | 'r|reference=s' => \$ref, | ||
| 30 | 'rn|refname=s' => \$refname, | ||
| 31 | 'o|outfile=s' => \$outfile, | ||
| 32 | 'h|help' => \$help | ||
| 33 | ); | ||
| 34 | |||
| 35 | $self->fastqfile( abs_path($fastqfile) ) if ( defined($fastqfile) ); | ||
| 36 | $self->reference( abs_path($ref) ) if ( defined($ref) ); | ||
| 37 | $self->refname($refname) if ( defined($refname) ); | ||
| 38 | $self->outfile( abs_path($outfile) ) if ( defined($outfile) ); | ||
| 39 | $self->help($help) if ( defined($help) ); | ||
| 40 | |||
| 41 | # print usage text if required parameters are not present | ||
| 42 | ($fastqfile && $ref) or die $self->usage_text; | ||
| 43 | } | ||
| 44 | |||
| 45 | sub run { | ||
| 46 | my ($self) = @_; | ||
| 47 | |||
| 48 | if ( defined( $self->help ) ) { | ||
| 49 | #if ( scalar( @{ $self->args } ) == 0 ) { | ||
| 50 | $self->usage_text; | ||
| 51 | } | ||
| 52 | |||
| 53 | my $mapping = Bio::Tradis::Map->new( | ||
| 54 | fastqfile => $self->fastqfile, | ||
| 55 | reference => $self->reference, | ||
| 56 | refname => $self->refname, | ||
| 57 | outfile => $self->outfile | ||
| 58 | ); | ||
| 59 | $mapping->index_ref; | ||
| 60 | $mapping->do_mapping; | ||
| 61 | } | ||
| 62 | |||
| 63 | sub usage_text { | ||
| 64 | print <<USAGE; | ||
| 65 | Indexes the reference genome and maps the given fastq file. | ||
| 66 | -k and -s options for indexing are calculated for the length of | ||
| 67 | the read as follows | ||
| 68 | Read length | k | s | ||
| 69 | ---------------+----+----- | ||
| 70 | <70 | 13 | 4 | ||
| 71 | >70 & <100 | 13 | 6 | ||
| 72 | >100 | 20 | 13 | ||
| 73 | |||
| 74 | Usage: run_mapping -f file.fastq -r ref.fa [options] | ||
| 75 | |||
| 76 | Options: | ||
| 77 | -f : fastq file to map | ||
| 78 | -r : reference in fasta format | ||
| 79 | -rn : reference index name (optional. default: ref.index) | ||
| 80 | -o : mapped SAM output name (optional. default: mapped.sam) | ||
| 81 | |||
| 82 | USAGE | ||
| 83 | exit; | ||
| 84 | } | ||
| 85 | |||
| 86 | __PACKAGE__->meta->make_immutable; | ||
| 87 | no Moose; | ||
| 88 | 1; | ||
| 89 | |||
| 90 | __END__ | ||
| 91 | |||
| 92 | =pod | ||
| 93 | |||
| 94 | =head1 NAME | ||
| 95 | |||
| 96 | Bio::Tradis::CommandLine::RunMapping - Perform mapping | ||
| 97 | |||
| 98 | =head1 VERSION | ||
| 99 | |||
| 100 | version 1.132190 | ||
| 101 | |||
| 102 | =head1 SYNOPSIS | ||
| 103 | |||
| 104 | Takes a reference genome and indexes it. | ||
| 105 | Maps given fastq files to ref. | ||
| 106 | |||
| 107 | =head1 AUTHOR | ||
| 108 | |||
| 109 | Carla Cummins <cc21@sanger.ac.uk> | ||
| 110 | |||
| 111 | =head1 COPYRIGHT AND LICENSE | ||
| 112 | |||
| 113 | This software is Copyright (c) 2013 by Wellcome Trust Sanger Institute. | ||
| 114 | |||
| 115 | This is free software, licensed under: | ||
| 116 | |||
| 117 | The GNU General Public License, Version 3, June 2007 | ||
| 118 | |||
| 119 | =cut |