« CLIPSeqTools/CompareApp/compare_counts.pm
↑ Summary
CLIPSeqTools/PreprocessApp/cleanup_alignment.pm »
| 1 | =head1 NAME | ||
| 2 | |||
| 3 | CLIPSeqTools::PreprocessApp::star_alignment - Do reads alignment with STAR. | ||
| 4 | |||
| 5 | =head1 SYNOPSIS | ||
| 6 | |||
| 7 | clipseqtools-preprocess star_alignment [options/parameters] | ||
| 8 | |||
| 9 | =head1 DESCRIPTION | ||
| 10 | |||
| 11 | Do reads alignment with STAR. | ||
| 12 | |||
| 13 | =head1 OPTIONS | ||
| 14 | |||
| 15 | Input. | ||
| 16 | --fastq <Str> FastQ file with the reads. | ||
| 17 | --star_genome <Str> directory with STAR genome index | ||
| 18 | |||
| 19 | Output | ||
| 20 | --o_prefix <Str> output path prefix. Script will create and add | ||
| 21 | extension to path. [Default: ./] | ||
| 22 | |||
| 23 | Other options. | ||
| 24 | --star_path <Str> path to STAR executable. [Default: STAR]. | ||
| 25 | --threads <Int> number of threads to use. [Default: 4]. | ||
| 26 | -v --verbose print progress lines and extra information. | ||
| 27 | -h -? --usage --help print help message | ||
| 28 | |||
| 29 | =cut | ||
| 30 | |||
| 31 | package CLIPSeqTools::PreprocessApp::star_alignment; | ||
| 32 | $CLIPSeqTools::PreprocessApp::star_alignment::VERSION = '1.0.0'; | ||
| 33 | |||
| 34 | # Make it an app command | ||
| 35 | use MooseX::App::Command; | ||
| 36 | extends 'CLIPSeqTools::PreprocessApp'; | ||
| 37 | |||
| 38 | |||
| 39 | ####################################################################### | ||
| 40 | ####################### Load External modules ##################### | ||
| 41 | ####################################################################### | ||
| 42 | use Modern::Perl; | ||
| 43 | use autodie; | ||
| 44 | use namespace::autoclean; | ||
| 45 | |||
| 46 | |||
| 47 | ####################################################################### | ||
| 48 | ####################### Command line options ###################### | ||
| 49 | ####################################################################### | ||
| 50 | option 'fastq' => ( | ||
| 51 | is => 'rw', | ||
| 52 | isa => 'Str', | ||
| 53 | required => 1, | ||
| 54 | documentation => 'FastQ file with the reads.', | ||
| 55 | ); | ||
| 56 | |||
| 57 | option 'star_genome' => ( | ||
| 58 | is => 'rw', | ||
| 59 | isa => 'Str', | ||
| 60 | required => 1, | ||
| 61 | documentation => 'directory with STAR genome index.', | ||
| 62 | ); | ||
| 63 | |||
| 64 | option 'star_path' => ( | ||
| 65 | is => 'rw', | ||
| 66 | isa => 'Str', | ||
| 67 | default => 'STAR', | ||
| 68 | documentation => 'path to STAR executable.', | ||
| 69 | ); | ||
| 70 | |||
| 71 | option 'threads' => ( | ||
| 72 | is => 'rw', | ||
| 73 | isa => 'Int', | ||
| 74 | default => 4, | ||
| 75 | documentation => 'number of threads to use.', | ||
| 76 | ); | ||
| 77 | |||
| 78 | ####################################################################### | ||
| 79 | ########################## Consume Roles ########################## | ||
| 80 | ####################################################################### | ||
| 81 | with | ||
| 82 | "CLIPSeqTools::Role::Option::OutputPrefix" => { | ||
| 83 | -alias => { validate_args => '_validate_args_for_output_prefix' }, | ||
| 84 | -excludes => 'validate_args', | ||
| 85 | }; | ||
| 86 | |||
| 87 | |||
| 88 | ####################################################################### | ||
| 89 | ######################## Interface Methods ######################## | ||
| 90 | ####################################################################### | ||
| 91 | sub validate_args { | ||
| 92 | my ($self) = @_; | ||
| 93 | |||
| 94 | $self->_validate_args_for_output_prefix; | ||
| 95 | } | ||
| 96 | |||
| 97 | sub run { | ||
| 98 | my ($self) = @_; | ||
| 99 | |||
| 100 | warn "Starting job: star_alignment\n"; | ||
| 101 | |||
| 102 | warn "Validating arguments\n" if $self->verbose; | ||
| 103 | $self->validate_args(); | ||
| 104 | |||
| 105 | warn "Preparing command\n" if $self->verbose; | ||
| 106 | my $cmd = join(' ', | ||
| 107 | $self->star_path, | ||
| 108 | '--genomeDir ' . $self->star_genome, | ||
| 109 | '--readFilesIn ' . $self->fastq, | ||
| 110 | '--runThreadN ' . $self->threads, | ||
| 111 | '--outSAMattributes All', | ||
| 112 | '--outFilterMultimapScoreRange 0', | ||
| 113 | '--alignIntronMax 50000', | ||
| 114 | '--outFilterMatchNmin 15', | ||
| 115 | '--outFilterMatchNminOverLread 0.9', | ||
| 116 | '--outFileNamePrefix ' . $self->o_prefix. 'star_', | ||
| 117 | ); | ||
| 118 | |||
| 119 | if ($self->fastq =~ /\.gz$/) { | ||
| 120 | $cmd .= ' ' . '--readFilesCommand zcat'; | ||
| 121 | } | ||
| 122 | |||
| 123 | warn "Creating output path\n" if $self->verbose; | ||
| 124 | $self->make_path_for_output_prefix(); | ||
| 125 | |||
| 126 | warn "Running cutadapt\n" if $self->verbose; | ||
| 127 | warn "Command: $cmd\n" if $self->verbose; | ||
| 128 | system "$cmd"; | ||
| 129 | } | ||
| 130 | |||
| 131 | |||
| 132 | 1; |