| 1 | package Bio::Tradis::CommandLine::PlotCombine; | ||
| 2 | $Bio::Tradis::CommandLine::PlotCombine::VERSION = '1.4.5'; | ||
| 3 | # ABSTRACT: Combine multiple plotfiles and generate updated statistics for the combined files | ||
| 4 | |||
| 5 | |||
| 6 | use Moose; | ||
| 7 | use Getopt::Long qw(GetOptionsFromArray); | ||
| 8 | use Cwd 'abs_path'; | ||
| 9 | use Bio::Tradis::CombinePlots; | ||
| 10 | |||
| 11 | has 'args' => ( is => 'ro', isa => 'ArrayRef', required => 1 ); | ||
| 12 | has 'script_name' => ( is => 'ro', isa => 'Str', required => 1 ); | ||
| 13 | has 'plotfile' => ( is => 'rw', isa => 'Str', required => 0 ); | ||
| 14 | has 'output_dir' => ( is => 'rw', isa => 'Str', default => 'combined' ); | ||
| 15 | has 'help' => ( is => 'rw', isa => 'Bool', required => 0 ); | ||
| 16 | |||
| 17 | sub BUILD { | ||
| 18 | my ($self) = @_; | ||
| 19 | |||
| 20 | my ( $plotfile, $output_dir, $help ); | ||
| 21 | |||
| 22 | GetOptionsFromArray( | ||
| 23 | $self->args, | ||
| 24 | 'p|plotfile=s' => \$plotfile, | ||
| 25 | 'o|output_dir' => \$output_dir, | ||
| 26 | 'h|help' => \$help | ||
| 27 | ); | ||
| 28 | |||
| 29 | $self->plotfile( abs_path($plotfile) ) if ( defined($plotfile) ); | ||
| 30 | $self->help($help) if ( defined($help) ); | ||
| 31 | |||
| 32 | # print usage text if required parameters are not present | ||
| 33 | ($plotfile) or die $self->usage_text; | ||
| 34 | } | ||
| 35 | |||
| 36 | sub run { | ||
| 37 | my ($self) = @_; | ||
| 38 | |||
| 39 | $self->usage_text if ( defined( $self->help ) ); | ||
| 40 | |||
| 41 | Bio::Tradis::CombinePlots->new( | ||
| 42 | plotfile => $self->plotfile, | ||
| 43 | combined_dir => $self->output_dir, | ||
| 44 | )->combine; | ||
| 45 | } | ||
| 46 | |||
| 47 | sub usage_text { | ||
| 48 | print <<USAGE; | ||
| 49 | Combine multiple plotfiles and generate updated statistics for the combined | ||
| 50 | files. Takes a tab-delimited file with an ID as the first column followed by | ||
| 51 | a list of plotfiles to combine per row. The ID will be used to name the new | ||
| 52 | plotfile and as an identifier in the stats file, so ensure these are unique. | ||
| 53 | |||
| 54 | For example, an input file named plots_to_combine.txt: | ||
| 55 | |||
| 56 | tradis1 plot1.1.gz plot1.2.gz plot1.3.gz | ||
| 57 | tradis2 plot2.1.gz plot2.2.gz | ||
| 58 | tradis3 plot3.1.gz plot3.2.gz plot3.3.gz plot3.4.gz | ||
| 59 | |||
| 60 | will produce | ||
| 61 | 1. a directory named combined with 3 files - tradis1.insertion_site_plot.gz, | ||
| 62 | tradis2.insertion_site_plot.gz, tradis3.insertion_site_plot.gz | ||
| 63 | 2. a stats file named plots_to_combine.stats | ||
| 64 | |||
| 65 | Usage: combine_tradis_plots -p plots.txt | ||
| 66 | |||
| 67 | Options: | ||
| 68 | -p|plotfile : file with plots to be combined | ||
| 69 | -o|output_dir : name of directory for output (default: combined) | ||
| 70 | |||
| 71 | USAGE | ||
| 72 | exit; | ||
| 73 | } | ||
| 74 | |||
| 75 | __PACKAGE__->meta->make_immutable; | ||
| 76 | no Moose; | ||
| 77 | 1; | ||
| 78 | |||
| 79 | __END__ |