| 1 | package App::Sandy::Command::Variation::Add; | ||
| 2 | # ABSTRACT: variation subcommand class. Add structural variation to the database. | ||
| 3 | |||
| 4 | 1 | ▶ | use App::Sandy::Base 'class'; |
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||
| 5 | |||
| 6 | extends 'App::Sandy::Command::Variation'; | ||
| 7 | |||
| 8 | our $VERSION = '0.25'; # VERSION | ||
| 9 | |||
| 10 | use constant { | ||
| 11 | TYPE_OPT => ['raw', 'vcf'] | ||
| 12 | }; | ||
| 13 | |||
| 14 | override 'opt_spec' => sub { | ||
| 15 | super, | ||
| 16 | 'verbose|v', | ||
| 17 | 'structural-variation|a=s', | ||
| 18 | 'source|s=s', | ||
| 19 | 'sample-name|n=s' | ||
| 20 | }; | ||
| 21 | |||
| 22 | sub _default_opt { | ||
| 23 | 'verbose' => 0, | ||
| 24 | 'type' => 'raw', | ||
| 25 | 'source' => 'not defined' | ||
| 26 | } | ||
| 27 | |||
| 28 | sub validate_args { | ||
| 29 | my ($self, $args) = @_; | ||
| 30 | my $file = shift @$args; | ||
| 31 | |||
| 32 | # Mandatory file | ||
| 33 | if (not defined $file) { | ||
| 34 | die "Missing file (a variation file or vcf file)\n"; | ||
| 35 | } | ||
| 36 | |||
| 37 | # Is it really a file? | ||
| 38 | if (not -f $file) { | ||
| 39 | die "'$file' is not a file. Please, give me a valid file\n"; | ||
| 40 | } | ||
| 41 | |||
| 42 | die "Too many arguments: '@$args'\n" if @$args; | ||
| 43 | } | ||
| 44 | |||
| 45 | sub validate_opts { | ||
| 46 | my ($self, $opts) = @_; | ||
| 47 | my %default_opt = $self->_default_opt; | ||
| 48 | $self->fill_opts($opts, \%default_opt); | ||
| 49 | |||
| 50 | if (not exists $opts->{'structural-variation'}) { | ||
| 51 | die "Mandatory option 'structural-variation' not defined\n"; | ||
| 52 | } | ||
| 53 | } | ||
| 54 | |||
| 55 | sub execute { | ||
| 56 | my ($self, $opts, $args) = @_; | ||
| 57 | my $file = shift @$args; | ||
| 58 | |||
| 59 | my %default_opt = $self->_default_opt; | ||
| 60 | $self->fill_opts($opts, \%default_opt); | ||
| 61 | |||
| 62 | # Set the type of file | ||
| 63 | if ($file =~ /^.+\.vcf(\.gz)?$/) { | ||
| 64 | $opts->{'type'} = 'vcf'; | ||
| 65 | } | ||
| 66 | |||
| 67 | # Set if user wants a verbose log | ||
| 68 | $LOG_VERBOSE = $opts->{verbose}; | ||
| 69 | |||
| 70 | # Go go go | ||
| 71 | log_msg ":: Inserting $opts->{'structural-variation'} from $file ..."; | ||
| 72 | $self->insertdb( | ||
| 73 | $file, | ||
| 74 | $opts->{'structural-variation'}, | ||
| 75 | $opts->{'source'}, | ||
| 76 | 1, | ||
| 77 | $opts->{'type'}, | ||
| 78 | $opts->{'sample-name'} | ||
| 79 | ); | ||
| 80 | |||
| 81 | log_msg ":: Done!"; | ||
| 82 | } | ||
| 83 | |||
| 84 | __END__ | ||