File Coverage

lib/Bio/VertRes/Config/CommandLine/Common.pm
Criterion Covered Total %
statement 1 3 33.3
branch n/a
condition n/a
subroutine 1 1 100.0
pod n/a
total 2 4 50.0


line stmt bran cond sub pod time code
1             package Bio::VertRes::Config::CommandLine::Common;
2              
3             # ABSTRACT: Create config scripts
4              
5              
6 1     1   145438 use Moose;
  0            
  0            
7             use Getopt::Long qw(GetOptionsFromArray);
8             use Bio::VertRes::Config::CommandLine::LogParameters;
9             use Bio::VertRes::Config::CommandLine::ConstructLimits;
10             use Bio::VertRes::Config::Exceptions;
11              
12             has 'args' => ( is => 'ro', isa => 'ArrayRef', required => 1 );
13             has 'script_name' => ( is => 'ro', isa => 'Str', required => 1 );
14              
15             has 'database' => ( is => 'rw', isa => 'Str', default => 'pathogen_prok_track' );
16             has 'config_base' => ( is => 'rw', isa => 'Str', default => '/nfs/pathnfs05/conf' );
17             has 'root_base' => ( is => 'rw', isa => 'Str', default => '/lustre/scratch108/pathogen/pathpipe' );
18             has 'log_base' => ( is => 'rw', isa => 'Str', default => '/nfs/pathnfs05/log' );
19             has 'database_connect_file' =>
20             ( is => 'rw', isa => 'Str', default => '/software/pathogen/config/database_connection_details' );
21             has 'reference_lookup_file' =>
22             ( is => 'rw', isa => 'Str', default => '/lustre/scratch108/pathogen/pathpipe/refs/refs.index' );
23             has 'reference' => ( is => 'rw', isa => 'Maybe[Str]', );
24             has 'available_references' => ( is => 'rw', isa => 'Maybe[Str]' );
25             has 'type' => ( is => 'rw', isa => 'Maybe[Str]' );
26             has 'id' => ( is => 'rw', isa => 'Maybe[Str]' );
27             has 'species' => ( is => 'rw', isa => 'Maybe[Str]' );
28             has 'mapper' => ( is => 'rw', isa => 'Maybe[Str]' );
29             has 'protocol' => ( is => 'rw', isa => 'Str', default => 'StrandSpecificProtocol' );
30             has 'regeneration_log_file' => ( is => 'rw', isa => 'Maybe[Str]' );
31             has 'overwrite_existing_config_file' => ( is => 'rw', isa => 'Bool', default => 0 );
32             has 'help' => ( is => 'rw', isa => 'Bool', default => 0 );
33              
34             # mapper specific
35             has 'smalt_index_k' => ( is => 'rw', isa => 'Maybe[Int]' );
36             has 'smalt_index_s' => ( is => 'rw', isa => 'Maybe[Int]' );
37             has 'smalt_mapper_r' => ( is => 'rw', isa => 'Maybe[Int]' );
38             has 'smalt_mapper_x' => ( is => 'rw', isa => 'Maybe[Bool]' );
39             has 'smalt_mapper_y' => ( is => 'rw', isa => 'Maybe[Num]' );
40             has 'smalt_mapper_l' => ( is => 'rw', isa => 'Maybe[Str]' );
41             has 'tophat_mapper_I' => ( is => 'rw', isa => 'Maybe[Int]' );
42             has 'tophat_mapper_i' => ( is => 'rw', isa => 'Maybe[Int]' );
43             has 'tophat_mapper_g' => ( is => 'rw', isa => 'Maybe[Int]' );
44              
45             # set assembler
46             has 'assembler' => ( is => 'rw', isa => 'Maybe[Str]' );
47              
48             sub BUILD {
49             my ($self) = @_;
50             my $log_params =
51             Bio::VertRes::Config::CommandLine::LogParameters->new( args => $self->args, script_name => $self->script_name );
52              
53             my (
54             $database, $config_base, $reference_lookup_file,
55             $available_references, $reference, $type,
56             $id, $species, $mapper,
57             $regeneration_log_file, $overwrite_existing_config_file, $protocol,
58             $smalt_index_k, $smalt_index_s, $smalt_mapper_r,
59             $smalt_mapper_y, $smalt_mapper_x, $smalt_mapper_l,
60             $tophat_mapper_I, $tophat_mapper_i, $tophat_mapper_g,
61             $assembler, $root_base, $log_base,
62             $database_connect_file, $help
63             );
64              
65             GetOptionsFromArray(
66             $self->args,
67             'd|database=s' => \$database,
68             'c|config_base=s' => \$config_base,
69             'l|reference_lookup_file=s' => \$reference_lookup_file,
70             'r|reference=s' => \$reference,
71             'a|available_references=s' => \$available_references,
72             't|type=s' => \$type,
73             'i|id=s' => \$id,
74             's|species=s' => \$species,
75             'm|mapper=s' => \$mapper,
76             'b|regeneration_log_file=s' => \$regeneration_log_file,
77             'overwrite_existing_config_file' => \$overwrite_existing_config_file,
78             'p|protocol=s' => \$protocol,
79             'smalt_index_k=i' => \$smalt_index_k,
80             'smalt_index_s=i' => \$smalt_index_s,
81             'smalt_mapper_r=i' => \$smalt_mapper_r,
82             'smalt_mapper_y=f' => \$smalt_mapper_y,
83             'smalt_mapper_x' => \$smalt_mapper_x,
84             'smalt_mapper_l=s' => \$smalt_mapper_l,
85             'tophat_mapper_max_intron=i' => \$tophat_mapper_I,
86             'tophat_mapper_min_intron=i' => \$tophat_mapper_i,
87             'tophat_mapper_max_multihit=i' => \$tophat_mapper_g,
88             'assembler=s' => \$assembler,
89             'root_base=s' => \$root_base,
90             'log_base=s' => \$log_base,
91             'db_file:s' => \$database_connect_file,
92             'h|help' => \$help
93             );
94              
95             $self->database($database) if ( defined($database) );
96             $self->config_base($config_base) if ( defined($config_base) );
97             $self->root_base($root_base) if ( defined($root_base) );
98             $self->log_base($log_base) if ( defined($log_base) );
99             $self->reference_lookup_file($reference_lookup_file) if ( defined($reference_lookup_file) );
100             $self->reference($reference) if ( defined($reference) );
101             $self->available_references($available_references) if ( defined($available_references) );
102             $self->type($type) if ( defined($type) );
103             $self->id($id) if ( defined($id) );
104             $self->species($species) if ( defined($species) );
105             $self->mapper($mapper) if ( defined($mapper) );
106             $self->protocol($protocol) if ( defined($protocol) );
107             $self->help($help) if ( defined($help) );
108             $self->smalt_index_k($smalt_index_k) if ( defined($smalt_index_k) );
109             $self->smalt_index_s($smalt_index_s) if ( defined($smalt_index_s) );
110             $self->smalt_mapper_r($smalt_mapper_r) if ( defined($smalt_mapper_r) );
111             $self->smalt_mapper_y($smalt_mapper_y) if ( defined($smalt_mapper_y) );
112             $self->smalt_mapper_x($smalt_mapper_x) if ( defined($smalt_mapper_x) );
113             $self->smalt_mapper_l($smalt_mapper_l) if ( defined($smalt_mapper_l) );
114             $self->tophat_mapper_I($tophat_mapper_I) if ( defined($tophat_mapper_I) );
115             $self->tophat_mapper_i($tophat_mapper_i) if ( defined($tophat_mapper_i) );
116             $self->tophat_mapper_g($tophat_mapper_g) if ( defined($tophat_mapper_g) );
117             $self->assembler($assembler) if ( defined($assembler) );
118             $self->database_connect_file($database_connect_file) if ( defined($database_connect_file) );
119              
120             $regeneration_log_file ||= join( '/', ( $self->config_base, 'command_line.log' ) );
121             $self->regeneration_log_file($regeneration_log_file) if ( defined($regeneration_log_file) );
122             $self->overwrite_existing_config_file($overwrite_existing_config_file)
123             if ( defined($overwrite_existing_config_file) );
124              
125             $log_params->log_file( $self->regeneration_log_file );
126             $log_params->create();
127             }
128              
129             sub _construct_smalt_index_params
130             {
131             my ($self) = @_;
132             if(defined($self->smalt_index_k) && defined($self->smalt_index_s) )
133             {
134             return join(' ', ('-k',$self->smalt_index_k,'-s',$self->smalt_index_s));
135             }
136             return undef;
137             }
138              
139             sub _construct_smalt_additional_mapper_params
140             {
141             my ($self) = @_;
142             my $output_param_str = "";
143             if(defined($self->smalt_mapper_r))
144             {
145             $output_param_str = join(' ',($output_param_str,'-r',$self->smalt_mapper_r));
146             }
147             if(defined($self->smalt_mapper_y))
148             {
149             $output_param_str = join(' ',($output_param_str,'-y',$self->smalt_mapper_y));
150             }
151             if(defined($self->smalt_mapper_x))
152             {
153             $output_param_str = join(' ',($output_param_str,'-x'));
154             }
155             if(defined($self->smalt_mapper_l))
156             {
157             my %pairtyp = ('pe' => 1, 'mp' => 1, 'pp' => 1);
158             Bio::VertRes::Config::Exceptions::InvalidType->throw(error => 'Invalid type passed in for smalt_mapper_l, can only be one of pe/mp/pp not '.$self->smalt_mapper_l.".\n") unless exists $pairtyp{$self->smalt_mapper_l};
159             $output_param_str = join(' ',($output_param_str,'-l',$self->smalt_mapper_l));
160             }
161            
162             if($output_param_str eq "")
163             {
164             return undef;
165             }
166            
167             return $output_param_str;
168             }
169              
170             sub _construct_tophat_additional_mapper_params
171             {
172             my ($self) = @_;
173             my $output_param_str = "";
174             if(defined($self->tophat_mapper_I))
175             {
176             $output_param_str = join(' ',($output_param_str,'-I',$self->tophat_mapper_I));
177             }
178             if(defined($self->tophat_mapper_i))
179             {
180             $output_param_str = join(' ',($output_param_str,'-i',$self->tophat_mapper_i));
181             }
182             if(defined($self->tophat_mapper_g))
183             {
184             $output_param_str = join(' ',($output_param_str,'-g',$self->tophat_mapper_g));
185             }
186            
187             if($output_param_str eq "")
188             {
189             return undef;
190             }
191            
192             return $output_param_str;
193             }
194              
195             sub mapping_parameters {
196             my ($self) = @_;
197             my $limits = Bio::VertRes::Config::CommandLine::ConstructLimits->new(
198             input_type => $self->type,
199             input_id => $self->id,
200             species => $self->species
201             )->limits_hash;
202              
203             my %mapping_parameters = (
204             database => $self->database,
205             config_base => $self->config_base,
206             root_base => $self->root_base,
207             log_base => $self->log_base,
208             limits => $limits,
209             reference_lookup_file => $self->reference_lookup_file,
210             reference => $self->reference,
211             overwrite_existing_config_file => $self->overwrite_existing_config_file,
212             protocol => $self->protocol,
213             database_connect_file => $self->database_connect_file
214             );
215            
216             if(defined($self->_construct_smalt_index_params))
217             {
218             $mapping_parameters{mapper_index_params} = $self->_construct_smalt_index_params;
219             }
220             if(defined($self->_construct_smalt_additional_mapper_params))
221             {
222             $mapping_parameters{additional_mapper_params} = $self->_construct_smalt_additional_mapper_params;
223             }
224             if(defined($self->_construct_tophat_additional_mapper_params))
225             {
226             $mapping_parameters{additional_mapper_params} = $self->_construct_tophat_additional_mapper_params;
227             }
228            
229             return \%mapping_parameters;
230             }
231              
232             # Overwrite this method
233             sub retrieving_results_text {
234             my ($self) = @_;
235             }
236              
237             # Overwrite this method
238             sub usage_text {
239             my ($self) = @_;
240             }
241              
242             sub retrieving_rnaseq_results_text {
243             my ($self) = @_;
244             print "Once the data is available you can run these commands:\n\n";
245              
246             print "Create symlinks to all your data\n";
247             print " rnaseqfind -t " . $self->type . " -i " . $self->id . " -symlink\n\n";
248              
249             print "Symlink to the spreadsheets of statistics per gene\n";
250             print " rnaseqfind -t " . $self->type . " -i " . $self->id . " -symlink -f spreadsheet\n\n";
251              
252             print "Symlink to the BAM files (corrected for the protocol)\n";
253             print " rnaseqfind -t " . $self->type . " -i " . $self->id . " -symlink -f bam\n\n";
254              
255             print "Symlink to the annotation for the intergenic regions\n";
256             print " rnaseqfind -t " . $self->type . " -i " . $self->id . " -symlink -f intergenic\n\n";
257              
258             print "Symlink to the coverage plots\n";
259             print " rnaseqfind -t " . $self->type . " -i " . $self->id . " -symlink -f coverage\n\n";
260              
261             print "More details\n";
262             print " rnaseqfind -h\n";
263             }
264              
265             sub retrieving_mapping_results_text {
266             my ($self) = @_;
267             print "Once the data is available you can run these commands:\n\n";
268              
269             print "Symlink to the BAM files\n";
270             print " mapfind -t " . $self->type . " -i " . $self->id . " -symlink\n\n";
271              
272             print "Find out which mapper and reference was used\n";
273             print " mapfind -t " . $self->type . " -i " . $self->id . " -d\n\n";
274              
275             print "More details\n";
276             print " mapfind -h\n\n";
277             }
278              
279             sub retrieving_snp_calling_results_text {
280             my ($self) = @_;
281             print "Once the data is available you can run these commands:\n\n";
282              
283             print "Create a multifasta alignment file of your data\n";
284             print " snpfind -t " . $self->type . " -i " . $self->id . " -p \n\n";
285              
286             print "Create symlinks to the unfiltered variants in VCF format\n";
287             print " snpfind -t " . $self->type . " -i " . $self->id . " -symlink\n\n";
288              
289             print "Symlink to the BAM files\n";
290             print " mapfind -t " . $self->type . " -i " . $self->id . " -symlink\n\n";
291              
292             print "More details\n";
293             print " snpfind -h\n";
294             print " mapfind -h\n\n";
295             }
296              
297             __PACKAGE__->meta->make_immutable;
298             no Moose;
299             1;
300              
301             __END__
302              
303             =pod
304              
305             =head1 NAME
306              
307             Bio::VertRes::Config::CommandLine::Common - Create config scripts
308              
309             =head1 VERSION
310              
311             version 1.133090
312              
313             =head1 SYNOPSIS
314              
315             Create config scripts
316              
317             =head1 AUTHOR
318              
319             Andrew J. Page <ap13@sanger.ac.uk>
320              
321             =head1 COPYRIGHT AND LICENSE
322              
323             This software is Copyright (c) 2013 by Wellcome Trust Sanger Institute.
324              
325             This is free software, licensed under:
326              
327             The GNU General Public License, Version 3, June 2007
328              
329             =cut