« CLIPSeqTools/PlotApp/distribution_on_introns_exons.pm
↑ Summary
CLIPSeqTools/PlotApp/libraries_relative_read_density.pm »
| 1 | =head1 NAME | ||
| 2 | |||
| 3 | CLIPSeqTools::PlotApp::genomic_distribution - Create plots for script genomic_distribution. | ||
| 4 | |||
| 5 | =head1 SYNOPSIS | ||
| 6 | |||
| 7 | clipseqtools-plot genomic_distribution [options/parameters] | ||
| 8 | |||
| 9 | =head1 DESCRIPTION | ||
| 10 | |||
| 11 | Create plots for script genomic_distribution. | ||
| 12 | |||
| 13 | =head1 OPTIONS | ||
| 14 | |||
| 15 | Input. | ||
| 16 | --file <Str> input file. | ||
| 17 | |||
| 18 | Output | ||
| 19 | --o_prefix <Str> output path prefix. Script will create and add | ||
| 20 | extension to path. [Default: ./] | ||
| 21 | |||
| 22 | -v --verbose print progress lines and extra information. | ||
| 23 | -h -? --usage --help print help message | ||
| 24 | |||
| 25 | =cut | ||
| 26 | |||
| 27 | package CLIPSeqTools::PlotApp::genomic_distribution; | ||
| 28 | $CLIPSeqTools::PlotApp::genomic_distribution::VERSION = '1.0.0'; | ||
| 29 | |||
| 30 | # Make it an app command | ||
| 31 | use MooseX::App::Command; | ||
| 32 | extends 'CLIPSeqTools::PlotApp'; | ||
| 33 | |||
| 34 | |||
| 35 | ####################################################################### | ||
| 36 | ####################### Load External modules ##################### | ||
| 37 | ####################################################################### | ||
| 38 | use Modern::Perl; | ||
| 39 | use autodie; | ||
| 40 | use namespace::autoclean; | ||
| 41 | use Statistics::R; | ||
| 42 | |||
| 43 | |||
| 44 | ####################################################################### | ||
| 45 | ####################### Command line options ###################### | ||
| 46 | ####################################################################### | ||
| 47 | option 'file' => ( | ||
| 48 | is => 'rw', | ||
| 49 | isa => 'Str', | ||
| 50 | required => 1, | ||
| 51 | documentation => 'input file.', | ||
| 52 | ); | ||
| 53 | |||
| 54 | ####################################################################### | ||
| 55 | ########################## Consume Roles ########################## | ||
| 56 | ####################################################################### | ||
| 57 | with | ||
| 58 | "CLIPSeqTools::Role::Option::OutputPrefix" => { | ||
| 59 | -alias => { validate_args => '_validate_args_for_output_prefix' }, | ||
| 60 | -excludes => 'validate_args', | ||
| 61 | }; | ||
| 62 | |||
| 63 | |||
| 64 | ####################################################################### | ||
| 65 | ######################## Interface Methods ######################## | ||
| 66 | ####################################################################### | ||
| 67 | sub validate_args { | ||
| 68 | my ($self) = @_; | ||
| 69 | |||
| 70 | $self->_validate_args_for_output_prefix; | ||
| 71 | } | ||
| 72 | |||
| 73 | sub run { | ||
| 74 | my ($self) = @_; | ||
| 75 | |||
| 76 | warn "Validating arguments\n" if $self->verbose; | ||
| 77 | $self->validate_args(); | ||
| 78 | |||
| 79 | warn "Creating output path\n" if $self->verbose; | ||
| 80 | $self->make_path_for_output_prefix(); | ||
| 81 | |||
| 82 | warn "Creating plots with R\n" if $self->verbose; | ||
| 83 | $self->run_R; | ||
| 84 | } | ||
| 85 | |||
| 86 | sub run_R { | ||
| 87 | my ($self) = @_; | ||
| 88 | |||
| 89 | my $figfile = $self->o_prefix . 'genomic_distribution.pdf'; | ||
| 90 | |||
| 91 | # Start R | ||
| 92 | my $R = Statistics::R->new(); | ||
| 93 | |||
| 94 | # Pass arguments to R | ||
| 95 | $R->set('ifile', $self->file); | ||
| 96 | $R->set('figfile', $figfile); | ||
| 97 | |||
| 98 | # Read table with data - Do exra calulations | ||
| 99 | $R->run(q{idata = read.delim(ifile)}); | ||
| 100 | $R->run(q{idata$percent = (idata$count / idata$total) * 100}); | ||
| 101 | |||
| 102 | # Do plots | ||
| 103 | $R->run(q{pdf(figfile, width=14)}); | ||
| 104 | $R->run(q{par(mfrow = c(1, 2), mar=c(10, 4.1, 3.1, 2.1));}); | ||
| 105 | |||
| 106 | $R->run(q{mypal = c(rep("black",2), rep("darkgrey",3), rep("grey",3), | ||
| 107 | rep("lightgrey",3), rep("lightblue",3))}); | ||
| 108 | |||
| 109 | $R->run(q{x = barplot(idata$percent, names.arg=idata$category, col=mypal, | ||
| 110 | ylim=c(0,100), ylab="Percent of total reads", xaxt="n");}); | ||
| 111 | $R->run(q{text(x=x, y=-max(idata$percent)/100, idata$category, xpd=TRUE, | ||
| 112 | srt=50, adj=c(1, 1))}); | ||
| 113 | |||
| 114 | $R->run(q{x = barplot(height=idata$count, names.arg=idata$category, | ||
| 115 | col=mypal, ylab="Number of reads", xaxt="n");}); | ||
| 116 | $R->run(q{text(x=x, y=-max(idata$count)/100, idata$category, xpd=TRUE, | ||
| 117 | srt=50, adj=c(1, 1))}); | ||
| 118 | |||
| 119 | $R->run(q{graphics.off()}); | ||
| 120 | |||
| 121 | # Close R | ||
| 122 | $R->stop(); | ||
| 123 | } | ||
| 124 | |||
| 125 | 1; |