File Coverage

lib/App/Sandy/Role/IO.pm
Criterion Covered Total %
statement 25 29 86.2
branch 5 12 41.6
condition n/a
subroutine 7 8 87.5
pod 0 4 0.0
total 37 53 69.8


line stmt bran cond sub pod time code
1             package App::Sandy::Role::IO;
2             # ABSTRACT: Input and output custom wrappers.
3              
4 6     6   4089 use App::Sandy::Base 'role';
  6         12  
  6         101  
5 6     6   2649 use App::Sandy::BGZF;
  6         40662  
  6         246  
6 6     6   52 use IO::Compress::Gzip '$GzipError';
  6         12  
  6         597  
7 6     6   3188 use PerlIO::gzip;
  6         3607  
  6         2573  
8              
9             our $VERSION = '0.22'; # VERSION
10              
11             sub with_open_r {
12 20     20 0 50 my ($self, $file) = @_;
13              
14 20         40 my $fh;
15 20 50       75 my $mode = $file =~ /\.gz$/ ? "<:gzip" : "<";
16              
17 20 50       855 open $fh, $mode => $file
18             or die "Not possible to read $file: $!\n";
19              
20 20         130 return $fh;
21             }
22              
23             sub with_open_w {
24 10     10 0 151 my ($self, $file, $level) = @_;
25              
26 10         67 my $fh;
27              
28 10 50       51 if ($level) {
29 0 0       0 $fh = IO::Compress::Gzip->new($file, -Level => $level)
30             or die "Not possible to create $file: $GzipError\n";
31             } else {
32 10 50       1850 open $fh, '>' => $file
33             or die "Not possible to create $file: $!\n";
34             }
35              
36 10         91 return $fh;
37             }
38              
39             sub with_open_a {
40 5     5 0 59 my ($self, $file) = @_;
41              
42 5 50       271 open my $fh, '>>' => $file
43             or die "Not possible to append to $file: $!\n";
44              
45 5         42 return $fh;
46             }
47              
48             sub with_open_bam_w {
49 0     0 0   my ($self, $file, $level) = @_;
50 0           my $fh = App::Sandy::BGZF->new_filehandle($file, $level);
51 0           return $fh;
52             }
53              
54             __END__
55              
56             =pod
57              
58             =encoding UTF-8
59              
60             =head1 NAME
61              
62             App::Sandy::Role::IO - Input and output custom wrappers.
63              
64             =head1 VERSION
65              
66             version 0.22
67              
68             =head1 AUTHORS
69              
70             =over 4
71              
72             =item *
73              
74             Thiago L. A. Miller <tmiller@mochsl.org.br>
75              
76             =item *
77              
78             J. Leonel Buzzo <lbuzzo@mochsl.org.br>
79              
80             =item *
81              
82             Felipe R. C. dos Santos <fsantos@mochsl.org.br>
83              
84             =item *
85              
86             Helena B. Conceição <hconceicao@mochsl.org.br>
87              
88             =item *
89              
90             Gabriela Guardia <gguardia@mochsl.org.br>
91              
92             =item *
93              
94             Fernanda Orpinelli <forpinelli@mochsl.org.br>
95              
96             =item *
97              
98             Pedro A. F. Galante <pgalante@mochsl.org.br>
99              
100             =back
101              
102             =head1 COPYRIGHT AND LICENSE
103              
104             This software is Copyright (c) 2018 by Teaching and Research Institute from Sírio-Libanês Hospital.
105              
106             This is free software, licensed under:
107              
108             The GNU General Public License, Version 3, June 2007
109              
110             =cut