File Coverage

lib/App/Sandy/Command/Quality/Add.pm
Criterion Covered Total %
statement 6 31 19.3
branch 0 12 0.0
condition 0 3 0.0
subroutine 2 6 33.3
pod 3 3 100.0
total 11 55 20.0


line stmt bran cond sub pod time code
1             package App::Sandy::Command::Quality::Add;
2             # ABSTRACT: quality subcommand class. Add a quality profile to the database.
3              
4 1     1   3123 use App::Sandy::Base 'class';
  1         4  
  1         6  
5              
6             extends 'App::Sandy::Command::Quality';
7              
8             our $VERSION = '0.24'; # VERSION
9              
10             use constant {
11 1         764 TYPE_OPT => ['raw', 'fastq']
12 1     1   11 };
  1         10  
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 0     0     '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 0     0 1   my ($self, $args) = @_;
33 0           my $file = shift @$args;
34              
35             # Mandatory file
36 0 0         if (not defined $file) {
37 0           die "Missing file (a quality file or fastq file)\n";
38             }
39              
40             # Is it really a file?
41 0 0         if (not -f $file) {
42 0           die "<$file> is not a file. Please, give me a valid quality or fastq file\n";
43             }
44              
45 0 0         die "Too many arguments: '@$args'\n" if @$args;
46             }
47              
48             sub validate_opts {
49 0     0 1   my ($self, $opts) = @_;
50 0           my %default_opt = $self->_default_opt;
51 0           $self->fill_opts($opts, \%default_opt);
52              
53 0 0         if (not exists $opts->{'quality-profile'}) {
54 0           die "Option 'quality-profile' not defined\n";
55             }
56              
57 0 0 0       if (0 > $opts->{'sequencing-error'} || $opts->{'sequencing-error'} > 1) {
58 0           die "Option 'sequencing-error' requires a value between zero and one, not $opts->{'sequencing-error'}\n";
59             }
60             }
61              
62             sub execute {
63 0     0 1   my ($self, $opts, $args) = @_;
64 0           my $file = shift @$args;
65              
66 0           my %default_opt = $self->_default_opt;
67 0           $self->fill_opts($opts, \%default_opt);
68              
69             # Set if user wants a verbose log
70 0           $LOG_VERBOSE = $opts->{verbose};
71              
72             # Set the type of file
73 0 0         if ($file !~ /.+\.(fastq)(\.gz)?$/) {
74 0           $opts->{type} = 'raw';
75             }
76              
77             # Go go go
78 0           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 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::Sandy::Command::Quality::Add - quality subcommand class. Add a quality profile to the database.
101              
102             =head1 VERSION
103              
104             version 0.24
105              
106             =head1 SYNOPSIS
107              
108             sandy quality add -q <entry name> [-s <source>] [-e <error>] [-1] FILE
109              
110             Arguments:
111             a file (fastq or a file with quality entries only)
112              
113             Mandatory options:
114             -q, --quality-profile a quality-profile name
115              
116             Options:
117             -h, --help brief help message
118             -H, --man full documentation
119             -v, --verbose print log messages
120             -s, --source quality-profile source detail for database
121             -1, --single-molecule constraint to single-molecule sequencing
122             (as Pacbio and Nanopore)
123             -e, --sequencing-error sequencing error rate
124             [default:"0.001"; Number]
125              
126             =head1 DESCRIPTION
127              
128             Add a new quality-profile to the database. The profile will be generated
129             from the quality strings, which encode the phred-score in ASCII characters
130             from 0x21 to 0x7e (lowest and highest qualities). So the valid characters
131             are:
132              
133             !"#$%&'()*+,-./0123456789:;<=>?@ABCDEFGHIJKLMNOPQRSTUVWXYZ[\]^_`abcdefghijklmnopqrstuvwxyz{|}~
134              
135             =head2 INPUT
136              
137             The user must pass a file in fastq format or a file containing only the
138             ASCII-encoded phred-scores, as in this example:
139              
140             ===> my_qualities.txt
141             BECGF@F@DEBIDBE@DCC?HFH?BBB?H@FEEIFDCCECCCIGDIDI?@?CCC?AE?EC?F?@FB;<9<>9:599=>7:57614,30,440&"!***)#
142             @DCGIDBDECIHIG@FII?G?GCAD@BFECDCEF?H?GIHE?@GEECBCIHCABAFHDFAHBEBEB:5575678=75>657673-14,.113#"()#&)$
143             F?B@@DFAHIDD?EBFADICBFABCBBAHFCGF@@@?DEIAIEAFCEADC?B@IB?BIEABIBG@C<:;96<968:>::;778,+0203-3,#&'$$#&!
144             HAAAB@AGAEHC@CHE?EGI?@GFDFFAABDEBHBCDEAA?@IHEBCD@A@HDGFBA?@GHEGIE?5>;>8=75;5<6:<:76,.23-3141#("$"'%"
145             CDHC@ADAF?ED?GFFCFBDEE?BDACCEE??DA@?F@ABI@BHGIGFGBBDDBCHHEAIACC@GH<5577:><88;95>9:7///++24.2)"(#%&%$
146             ...
147              
148             =head1 AUTHORS
149              
150             =over 4
151              
152             =item *
153              
154             Thiago L. A. Miller <tmiller@mochsl.org.br>
155              
156             =item *
157              
158             J. Leonel Buzzo <lbuzzo@mochsl.org.br>
159              
160             =item *
161              
162             Felipe R. C. dos Santos <fsantos@mochsl.org.br>
163              
164             =item *
165              
166             Helena B. Conceição <hconceicao@mochsl.org.br>
167              
168             =item *
169              
170             Rodrigo Barreiro <rbarreiro@mochsl.org.br>
171              
172             =item *
173              
174             Gabriela Guardia <gguardia@mochsl.org.br>
175              
176             =item *
177              
178             Fernanda Orpinelli <forpinelli@mochsl.org.br>
179              
180             =item *
181              
182             Rafael Mercuri <rmercuri@mochsl.org.br>
183              
184             =item *
185              
186             Rodrigo Barreiro <rbarreiro@mochsl.org.br>
187              
188             =item *
189              
190             Pedro A. F. Galante <pgalante@mochsl.org.br>
191              
192             =back
193              
194             =head1 COPYRIGHT AND LICENSE
195              
196             This software is Copyright (c) 2023 by Teaching and Research Institute from Sírio-Libanês Hospital.
197              
198             This is free software, licensed under:
199              
200             The GNU General Public License, Version 3, June 2007
201              
202             =cut