| 1 | package App::Sandy::Command::Quality::Add; | ||
| 2 | # ABSTRACT: quality subcommand class. Add a quality profile 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::Quality'; | ||
| 7 | |||
| 8 | our $VERSION = '0.25'; # VERSION | ||
| 9 | |||
| 10 | use constant { | ||
| 11 | TYPE_OPT => ['raw', 'fastq'] | ||
| 12 | }; | ||
| 13 | |||
| 14 | override 'opt_spec' => sub { | ||
| 15 | super, | ||
| 16 | 'verbose|v', | ||
| 17 | 'quality-profile|q=s', | ||
| 18 | 'source|s=s', | ||
| 19 | 'sequencing-error|e=f', | ||
| 20 | 'single-molecule|1' | ||
| 21 | }; | ||
| 22 | |||
| 23 | sub _default_opt { | ||
| 24 | 'verbose' => 0, | ||
| 25 | 'type' => 'fastq', | ||
| 26 | 'source' => 'not defined', | ||
| 27 | 'sequencing-error' => 0.001, | ||
| 28 | 'single-molecule' => 0 | ||
| 29 | } | ||
| 30 | |||
| 31 | sub validate_args { | ||
| 32 | my ($self, $args) = @_; | ||
| 33 | my $file = shift @$args; | ||
| 34 | |||
| 35 | # Mandatory file | ||
| 36 | if (not defined $file) { | ||
| 37 | die "Missing file (a quality file or fastq file)\n"; | ||
| 38 | } | ||
| 39 | |||
| 40 | # Is it really a file? | ||
| 41 | if (not -f $file) { | ||
| 42 | die "<$file> is not a file. Please, give me a valid quality or fastq file\n"; | ||
| 43 | } | ||
| 44 | |||
| 45 | die "Too many arguments: '@$args'\n" if @$args; | ||
| 46 | } | ||
| 47 | |||
| 48 | sub validate_opts { | ||
| 49 | my ($self, $opts) = @_; | ||
| 50 | my %default_opt = $self->_default_opt; | ||
| 51 | $self->fill_opts($opts, \%default_opt); | ||
| 52 | |||
| 53 | if (not exists $opts->{'quality-profile'}) { | ||
| 54 | die "Option 'quality-profile' not defined\n"; | ||
| 55 | } | ||
| 56 | |||
| 57 | if (0 > $opts->{'sequencing-error'} || $opts->{'sequencing-error'} > 1) { | ||
| 58 | die "Option 'sequencing-error' requires a value between zero and one, not $opts->{'sequencing-error'}\n"; | ||
| 59 | } | ||
| 60 | } | ||
| 61 | |||
| 62 | sub execute { | ||
| 63 | my ($self, $opts, $args) = @_; | ||
| 64 | my $file = shift @$args; | ||
| 65 | |||
| 66 | my %default_opt = $self->_default_opt; | ||
| 67 | $self->fill_opts($opts, \%default_opt); | ||
| 68 | |||
| 69 | # Set if user wants a verbose log | ||
| 70 | $LOG_VERBOSE = $opts->{verbose}; | ||
| 71 | |||
| 72 | # Set the type of file | ||
| 73 | if ($file !~ /.+\.(fastq)(\.gz)?$/) { | ||
| 74 | $opts->{type} = 'raw'; | ||
| 75 | } | ||
| 76 | |||
| 77 | # Go go go | ||
| 78 | log_msg ":: Inserting $opts->{'quality-profile'} from $file ..."; | ||
| 79 | $self->insertdb( | ||
| 80 | $file, | ||
| 81 | $opts->{'quality-profile'}, | ||
| 82 | $opts->{'source'}, | ||
| 83 | 1, | ||
| 84 | $opts->{'sequencing-error'}, | ||
| 85 | $opts->{'single-molecule'}, | ||
| 86 | $opts->{'type'} | ||
| 87 | ); | ||
| 88 | |||
| 89 | log_msg ":: Done!"; | ||
| 90 | } | ||
| 91 | |||
| 92 | __END__ | ||