« CLIPSeqTools/PlotApp/genomic_distribution.pm
↑ Summary
CLIPSeqTools/PlotApp/nucleotide_composition.pm »
| 1 | =head1 NAME | ||
| 2 | |||
| 3 | CLIPSeqTools::PlotApp::libraries_relative_read_density - Create plots for | ||
| 4 | script libraries_relative_read_density. | ||
| 5 | |||
| 6 | =head1 SYNOPSIS | ||
| 7 | |||
| 8 | clipseqtools-plot libraries_relative_read_density [options/parameters] | ||
| 9 | |||
| 10 | =head1 DESCRIPTION | ||
| 11 | |||
| 12 | Create plots for script libraries_relative_read_density. | ||
| 13 | |||
| 14 | =head1 OPTIONS | ||
| 15 | |||
| 16 | Input. | ||
| 17 | --file <Str> input file. | ||
| 18 | |||
| 19 | Output | ||
| 20 | --o_prefix <Str> output path prefix. Script will create and add | ||
| 21 | extension to path. [Default: ./] | ||
| 22 | |||
| 23 | -v --verbose print progress lines and extra information. | ||
| 24 | -h -? --usage --help print help message | ||
| 25 | |||
| 26 | =cut | ||
| 27 | |||
| 28 | package CLIPSeqTools::PlotApp::libraries_relative_read_density; | ||
| 29 | $CLIPSeqTools::PlotApp::libraries_relative_read_density::VERSION = '1.0.0'; | ||
| 30 | |||
| 31 | # Make it an app command | ||
| 32 | use MooseX::App::Command; | ||
| 33 | extends 'CLIPSeqTools::PlotApp'; | ||
| 34 | |||
| 35 | |||
| 36 | ####################################################################### | ||
| 37 | ####################### Load External modules ##################### | ||
| 38 | ####################################################################### | ||
| 39 | use Modern::Perl; | ||
| 40 | use autodie; | ||
| 41 | use namespace::autoclean; | ||
| 42 | use Statistics::R; | ||
| 43 | |||
| 44 | |||
| 45 | ####################################################################### | ||
| 46 | ####################### Command line options ###################### | ||
| 47 | ####################################################################### | ||
| 48 | option 'file' => ( | ||
| 49 | is => 'rw', | ||
| 50 | isa => 'Str', | ||
| 51 | required => 1, | ||
| 52 | documentation => 'input file.', | ||
| 53 | ); | ||
| 54 | |||
| 55 | ####################################################################### | ||
| 56 | ########################## Consume Roles ########################## | ||
| 57 | ####################################################################### | ||
| 58 | with | ||
| 59 | "CLIPSeqTools::Role::Option::OutputPrefix" => { | ||
| 60 | -alias => { validate_args => '_validate_args_for_output_prefix' }, | ||
| 61 | -excludes => 'validate_args', | ||
| 62 | }; | ||
| 63 | |||
| 64 | |||
| 65 | ####################################################################### | ||
| 66 | ######################## Interface Methods ######################## | ||
| 67 | ####################################################################### | ||
| 68 | sub validate_args { | ||
| 69 | my ($self) = @_; | ||
| 70 | |||
| 71 | $self->_validate_args_for_output_prefix; | ||
| 72 | } | ||
| 73 | |||
| 74 | sub run { | ||
| 75 | my ($self) = @_; | ||
| 76 | |||
| 77 | warn "Validating arguments\n" if $self->verbose; | ||
| 78 | $self->validate_args(); | ||
| 79 | |||
| 80 | warn "Creating output path\n" if $self->verbose; | ||
| 81 | $self->make_path_for_output_prefix(); | ||
| 82 | |||
| 83 | warn "Creating plots with R\n" if $self->verbose; | ||
| 84 | $self->run_R; | ||
| 85 | } | ||
| 86 | |||
| 87 | sub run_R { | ||
| 88 | my ($self) = @_; | ||
| 89 | |||
| 90 | my $figfile = $self->o_prefix . 'libraries_relative_read_density.pdf'; | ||
| 91 | |||
| 92 | # Start R | ||
| 93 | my $R = Statistics::R->new(); | ||
| 94 | |||
| 95 | # Pass arguments to R | ||
| 96 | $R->set('ifile', $self->file); | ||
| 97 | $R->set('figfile', $figfile); | ||
| 98 | |||
| 99 | # Read table with data | ||
| 100 | $R->run(q{idata = read.delim(ifile)}); | ||
| 101 | |||
| 102 | # Convert counts to density | ||
| 103 | $R->run(q{idata$norm_counts_with_copy_number_sense = | ||
| 104 | idata$counts_with_copy_number_sense / | ||
| 105 | (sum(as.numeric(idata$counts_with_copy_number_sense)) + 1)}); | ||
| 106 | $R->run(q{idata$norm_counts_no_copy_number_sense = | ||
| 107 | idata$counts_no_copy_number_sense / | ||
| 108 | (sum(as.numeric(idata$counts_no_copy_number_sense)) + 1)}); | ||
| 109 | $R->run(q{idata$norm_counts_with_copy_number_antisense = | ||
| 110 | idata$counts_with_copy_number_antisense / | ||
| 111 | (sum(as.numeric(idata$counts_with_copy_number_antisense)) + 1)}); | ||
| 112 | $R->run(q{idata$norm_counts_no_copy_number_antisense = | ||
| 113 | idata$counts_no_copy_number_antisense / | ||
| 114 | (sum(as.numeric(idata$counts_no_copy_number_antisense)) + 1)}); | ||
| 115 | |||
| 116 | # Find plot y_lim | ||
| 117 | $R->run(q{ylimit = max(idata$norm_counts_with_copy_number_sense, | ||
| 118 | idata$norm_counts_no_copy_number_sense, | ||
| 119 | idata$norm_counts_with_copy_number_antisense, | ||
| 120 | idata$norm_counts_no_copy_number_antisense)}); | ||
| 121 | |||
| 122 | # Do plots | ||
| 123 | $R->run(q{pdf(figfile, width=28)}); | ||
| 124 | $R->run(q{par(mfrow = c(1, 4), cex.lab=1.8, cex.axis=1.7, cex.main=2, | ||
| 125 | lwd=1.5, oma=c(0, 0, 2, 0))}); | ||
| 126 | $R->run(q{plot(idata$relative_position, | ||
| 127 | idata$norm_counts_with_copy_number_sense, type="o", main="Sense | ||
| 128 | records (with copy number)", xlab="Relative position", ylab="Density", | ||
| 129 | col="darkred", ylim=c(0,ylimit))}); | ||
| 130 | $R->run(q{abline(v=0, lty=2, col="grey", lwd=1.5)}); | ||
| 131 | $R->run(q{plot(idata$relative_position, | ||
| 132 | idata$norm_counts_no_copy_number_sense, type="o", main="Sense records | ||
| 133 | (no copy number)", xlab="Relative position", ylab="Density", | ||
| 134 | col="orange", ylim=c(0,ylimit))}); | ||
| 135 | $R->run(q{abline(v=0, lty=2, col="grey", lwd=1.5)}); | ||
| 136 | $R->run(q{plot(idata$relative_position, | ||
| 137 | idata$norm_counts_with_copy_number_antisense, type="o", | ||
| 138 | main="Anti-sense records (with copy number)", xlab="Relative | ||
| 139 | position", ylab="Density", col="lightblue", ylim=c(0,ylimit))}); | ||
| 140 | $R->run(q{abline(v=0, lty=2, col="grey", lwd=1.5)}); | ||
| 141 | $R->run(q{plot(idata$relative_position, | ||
| 142 | idata$norm_counts_no_copy_number_antisense, type="o", main="Anti-sense | ||
| 143 | records (no copy number)", xlab="Relative position", ylab="Density", | ||
| 144 | col="darkblue", ylim=c(0,ylimit))}); | ||
| 145 | $R->run(q{abline(v=0, lty=2, col="grey", lwd=1.5)}); | ||
| 146 | $R->run(q{graphics.off()}); | ||
| 147 | |||
| 148 | # Close R | ||
| 149 | $R->stop(); | ||
| 150 | } | ||
| 151 | |||
| 152 | 1; |