Beefy Boxes and Bandwidth Generously Provided by pair Networks
Don't ask to ask, just ask
 
PerlMonks  

Re: default option

by kevbot (Vicar)
on Apr 13, 2016 at 06:54 UTC ( [id://1160295]=note: print w/replies, xml ) Need Help??


in reply to default option

If you don't mind introducing Moose and its dependencies, then MooseX::Getopt is a good way of setting up command-line options (some of the features that I'm using here are documented in MooseX::Getopt::Meta::Attribute)

For example, in MyApp.pm

package MyApp; use Moose; with 'MooseX::Getopt'; has 'extension' => ( traits => ['Getopt'], is => 'rw', isa => 'Str', cmd_aliases => 'b', documentation => 'Short description of extension' ); has 'liste_snp' => ( traits => ['Getopt'], is => 'rw', isa => 'Str', cmd_aliases => 'l' ); has 'min_snp_per_cds' => ( traits => ['Getopt'], is => 'rw', isa => 'Bool', cmd_aliases => 's', default => 1 ); has 'liste_geno' => ( traits => ['Getopt'], is => 'rw', isa => 'Str', cmd_aliases => 'g' ); has 'reference_cds_fasta' => ( traits => ['Getopt'], is => 'rw', isa => 'Str', cmd_aliases => 'r' ); has 'prefixe' => ( traits => ['Getopt'], is => 'rw', isa => 'Str', cmd_aliases => 'p' ); has 'min_read_classe' => ( traits => ['Getopt'], is => 'rw', isa => 'Int', cmd_aliases => 'mc', default => 30 ); has 'max_read_per_cent_ambi' => ( traits => ['Getopt'], is => 'rw', isa => 'Num', cmd_aliases => 'a', default => 1 ); sub print_options { my $self = shift; my $bam = $self->extension // 'undefined'; my $liste_snp = $self->liste_snp // 'undefined'; my $min_snp_cds = $self->min_snp_per_cds // 'undefined'; my $list_geno = $self->liste_geno // 'undefined'; my $ref_cds = $self->reference_cds_fasta // 'undefined'; my $prefixe = $self->prefixe // 'undefined'; my $seuil_min_classe = $self->min_read_classe // 'undefined'; my $seuil_max_amb = $self->max_read_per_cent_ambi // 'undefined'; print "extension: $bam\n"; print "liste_snp: $liste_snp\n"; print "min_snp_per_cds: $min_snp_cds\n"; print "list_geno: $list_geno\n"; print "reference_cds_fasta: $ref_cds\n"; print "prefixe: $prefixe\n"; print "min_read_classe: $seuil_min_classe\n"; print "max_read_per_cent_ambi: $seuil_max_amb\n"; } 1;
Then in runapp.pl,
#!/usr/bin/env perl use MyApp; my $app = MyApp->new_with_options(); $app->print_options; # ... rest of the script here exit;
Here are some examples of running the script...
The output of runapp.pl is:
extension: undefined liste_snp: undefined min_snp_per_cds: 1 list_geno: undefined reference_cds_fasta: undefined prefixe: undefined min_read_classe: 30 max_read_per_cent_ambi: 1
The output of runapp.pl --extention myext --mc 40 is:
extension: myext liste_snp: undefined min_snp_per_cds: 1 list_geno: undefined reference_cds_fasta: undefined prefixe: undefined min_read_classe: 40 max_read_per_cent_ambi: 1
The output of runapp.pl -? is:
usage: runapp.pl [-?abghlprs] [long options...] -h -? --usage --help Prints this usage informati +on. -b STR --extension STR Short description of extens +ion -l STR --liste_snp STR -s --min_snp_per_cds -g STR --liste_geno STR -r STR --reference_cds_fasta STR -p STR --prefixe STR --mc INT --min_read_classe INT -a NUM --max_read_per_cent_ambi NUM

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://1160295]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others having an uproarious good time at the Monastery: (6)
As of 2024-04-19 02:32 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found