| line | stmt | bran | cond | sub | pod | time | code | 
| 1 |  |  |  |  |  |  | package App::SimulateReads::Command::QualityDB::Add; | 
| 2 |  |  |  |  |  |  | # ABSTRACT: qualitydb subcommand class. Add a quality profile to the database. | 
| 3 |  |  |  |  |  |  |  | 
| 4 | 1 |  |  | 1 |  | 1398 | use App::SimulateReads::Base 'class'; | 
|  | 1 |  |  |  |  | 2 |  | 
|  | 1 |  |  |  |  | 8 |  | 
| 5 |  |  |  |  |  |  |  | 
| 6 |  |  |  |  |  |  | extends 'App::SimulateReads::Command::QualityDB'; | 
| 7 |  |  |  |  |  |  |  | 
| 8 |  |  |  |  |  |  | our $VERSION = '0.05'; # VERSION | 
| 9 |  |  |  |  |  |  |  | 
| 10 |  |  |  |  |  |  | use constant { | 
| 11 | 1 |  |  |  |  | 501 | TYPE_OPT => ['raw', 'fastq'] | 
| 12 | 1 |  |  | 1 |  | 8 | }; | 
|  | 1 |  |  |  |  | 2 |  | 
| 13 |  |  |  |  |  |  |  | 
| 14 |  |  |  |  |  |  | override 'opt_spec' => sub { | 
| 15 |  |  |  |  |  |  | super, | 
| 16 |  |  |  |  |  |  | 'verbose|v', | 
| 17 |  |  |  |  |  |  | 'quality-profile|q=s', | 
| 18 |  |  |  |  |  |  | 'read-size|r=i', | 
| 19 |  |  |  |  |  |  | 'source|s=s' | 
| 20 |  |  |  |  |  |  | }; | 
| 21 |  |  |  |  |  |  |  | 
| 22 |  |  |  |  |  |  | sub _default_opt { | 
| 23 | 0 |  |  | 0 |  |  | 'verbose' => 0, | 
| 24 |  |  |  |  |  |  | 'type'    => 'fastq', | 
| 25 |  |  |  |  |  |  | 'source'  => 'not defined' | 
| 26 |  |  |  |  |  |  | } | 
| 27 |  |  |  |  |  |  |  | 
| 28 |  |  |  |  |  |  | sub validate_args { | 
| 29 | 0 |  |  | 0 | 1 |  | my ($self, $args) = @_; | 
| 30 | 0 |  |  |  |  |  | my $file = shift @$args; | 
| 31 |  |  |  |  |  |  |  | 
| 32 |  |  |  |  |  |  | # Mandatory file | 
| 33 | 0 | 0 |  |  |  |  | if (not defined $file) { | 
| 34 | 0 |  |  |  |  |  | die "Missing file (a quality file or fastq file)\n"; | 
| 35 |  |  |  |  |  |  | } | 
| 36 |  |  |  |  |  |  |  | 
| 37 |  |  |  |  |  |  | # Is it really a file? | 
| 38 | 0 | 0 |  |  |  |  | if (not -f $file) { | 
| 39 | 0 |  |  |  |  |  | die "<$file> is not a file. Please, give me a valid quality or fastq file\n"; | 
| 40 |  |  |  |  |  |  | } | 
| 41 |  |  |  |  |  |  |  | 
| 42 | 0 | 0 |  |  |  |  | die "Too many arguments: '@$args'\n" if @$args; | 
| 43 |  |  |  |  |  |  | } | 
| 44 |  |  |  |  |  |  |  | 
| 45 |  |  |  |  |  |  | sub validate_opts { | 
| 46 | 0 |  |  | 0 | 1 |  | my ($self, $opts) = @_; | 
| 47 | 0 |  |  |  |  |  | my %default_opt = $self->_default_opt; | 
| 48 | 0 |  |  |  |  |  | $self->fill_opts($opts, \%default_opt); | 
| 49 |  |  |  |  |  |  |  | 
| 50 | 0 | 0 |  |  |  |  | if (not exists $opts->{'quality-profile'}) { | 
| 51 | 0 |  |  |  |  |  | die "Option 'quality-profile' not defined\n"; | 
| 52 |  |  |  |  |  |  | } | 
| 53 |  |  |  |  |  |  |  | 
| 54 | 0 | 0 |  |  |  |  | if (not exists $opts->{'read-size'}) { | 
| 55 | 0 |  |  |  |  |  | die "Option 'read-size' not defined\n"; | 
| 56 |  |  |  |  |  |  | } | 
| 57 |  |  |  |  |  |  |  | 
| 58 | 0 | 0 |  |  |  |  | if ($opts->{'read-size'} <= 0) { | 
| 59 | 0 |  |  |  |  |  | die "Option 'read-size' requires an integer greater than zero\n"; | 
| 60 |  |  |  |  |  |  | } | 
| 61 |  |  |  |  |  |  | } | 
| 62 |  |  |  |  |  |  |  | 
| 63 |  |  |  |  |  |  | sub execute { | 
| 64 | 0 |  |  | 0 | 1 |  | my ($self, $opts, $args) = @_; | 
| 65 | 0 |  |  |  |  |  | my $file = shift @$args; | 
| 66 |  |  |  |  |  |  |  | 
| 67 | 0 |  |  |  |  |  | my %default_opt = $self->_default_opt; | 
| 68 | 0 |  |  |  |  |  | $self->fill_opts($opts, \%default_opt); | 
| 69 |  |  |  |  |  |  |  | 
| 70 |  |  |  |  |  |  | # Set if user wants a verbose log | 
| 71 | 0 |  |  |  |  |  | $LOG_VERBOSE = $opts->{verbose}; | 
| 72 |  |  |  |  |  |  |  | 
| 73 |  |  |  |  |  |  | # Set the type of file | 
| 74 | 0 | 0 |  |  |  |  | if ($file !~ /.+\.(fastq)(\.gz)?$/) { | 
| 75 | 0 |  |  |  |  |  | $opts->{type} = 'raw'; | 
| 76 |  |  |  |  |  |  | } | 
| 77 |  |  |  |  |  |  |  | 
| 78 |  |  |  |  |  |  | # Go go go | 
| 79 | 0 |  |  |  |  |  | log_msg "Inserting $opts->{'quality-profile'}:$opts->{'read-size'} from $file ..."; | 
| 80 |  |  |  |  |  |  | $self->insertdb( | 
| 81 |  |  |  |  |  |  | $file, | 
| 82 |  |  |  |  |  |  | $opts->{'quality-profile'}, | 
| 83 |  |  |  |  |  |  | $opts->{'read-size'}, | 
| 84 |  |  |  |  |  |  | $opts->{'source'}, | 
| 85 |  |  |  |  |  |  | 1, | 
| 86 | 0 |  |  |  |  |  | $opts->{'type'} | 
| 87 |  |  |  |  |  |  | ); | 
| 88 |  |  |  |  |  |  |  | 
| 89 | 0 |  |  |  |  |  | log_msg "Done!"; | 
| 90 |  |  |  |  |  |  | } | 
| 91 |  |  |  |  |  |  |  | 
| 92 |  |  |  |  |  |  | __END__ | 
| 93 |  |  |  |  |  |  |  | 
| 94 |  |  |  |  |  |  | =pod | 
| 95 |  |  |  |  |  |  |  | 
| 96 |  |  |  |  |  |  | =encoding UTF-8 | 
| 97 |  |  |  |  |  |  |  | 
| 98 |  |  |  |  |  |  | =head1 NAME | 
| 99 |  |  |  |  |  |  |  | 
| 100 |  |  |  |  |  |  | App::SimulateReads::Command::QualityDB::Add - qualitydb subcommand class. Add a quality profile to the database. | 
| 101 |  |  |  |  |  |  |  | 
| 102 |  |  |  |  |  |  | =head1 VERSION | 
| 103 |  |  |  |  |  |  |  | 
| 104 |  |  |  |  |  |  | version 0.05 | 
| 105 |  |  |  |  |  |  |  | 
| 106 |  |  |  |  |  |  | =head1 SYNOPSIS | 
| 107 |  |  |  |  |  |  |  | 
| 108 |  |  |  |  |  |  | simulate_reads qualitydb add -q <entry name> -r <size> [-s <source>] FILE | 
| 109 |  |  |  |  |  |  |  | 
| 110 |  |  |  |  |  |  | Arguments: | 
| 111 |  |  |  |  |  |  | a quality-profile file (fastq or a matrix with only quality entries) | 
| 112 |  |  |  |  |  |  |  | 
| 113 |  |  |  |  |  |  | Options: | 
| 114 |  |  |  |  |  |  | -h, --help               brief help message | 
| 115 |  |  |  |  |  |  | -M, --man                full documentation | 
| 116 |  |  |  |  |  |  | -v, --verbose            print log messages | 
| 117 |  |  |  |  |  |  | -q, --quality-profile    quality-profile name for the database [required] | 
| 118 |  |  |  |  |  |  | -r, --read-size          the read-size to be used for the quality [required, Integer] | 
| 119 |  |  |  |  |  |  | -s, --source             qaulity-profile source detail for database | 
| 120 |  |  |  |  |  |  |  | 
| 121 |  |  |  |  |  |  | =head1 DESCRIPTION | 
| 122 |  |  |  |  |  |  |  | 
| 123 |  |  |  |  |  |  | B<simulate_reads> will read the given input file and do something | 
| 124 |  |  |  |  |  |  | useful with the contents thereof. | 
| 125 |  |  |  |  |  |  |  | 
| 126 |  |  |  |  |  |  | =head1 AUTHOR | 
| 127 |  |  |  |  |  |  |  | 
| 128 |  |  |  |  |  |  | Thiago L. A. Miller <tmiller@mochsl.org.br> | 
| 129 |  |  |  |  |  |  |  | 
| 130 |  |  |  |  |  |  | =head1 COPYRIGHT AND LICENSE | 
| 131 |  |  |  |  |  |  |  | 
| 132 |  |  |  |  |  |  | This software is Copyright (c) 2017 by Teaching and Research Institute from SÃrio-Libanês Hospital. | 
| 133 |  |  |  |  |  |  |  | 
| 134 |  |  |  |  |  |  | This is free software, licensed under: | 
| 135 |  |  |  |  |  |  |  | 
| 136 |  |  |  |  |  |  | The GNU General Public License, Version 3, June 2007 | 
| 137 |  |  |  |  |  |  |  | 
| 138 |  |  |  |  |  |  | =cut |