|
0
|
1 package Bio::Roary::SpreadsheetRole;
|
|
|
2
|
|
|
3 # ABSTRACT: Read and write a spreadsheet
|
|
|
4
|
|
|
5 =head1 SYNOPSIS
|
|
|
6
|
|
|
7 with 'Bio::Roary::SpreadsheetRole';
|
|
|
8
|
|
|
9 =cut
|
|
|
10 use Moose::Role;
|
|
|
11
|
|
|
12 has 'spreadsheet' => ( is => 'ro', isa => 'Str', required => 1 );
|
|
|
13 has '_fixed_headers' => ( is => 'ro', isa => 'ArrayRef', lazy => 1, builder => '_build__fixed_headers' );
|
|
|
14 has '_input_spreadsheet_fh' => ( is => 'ro', lazy => 1, builder => '_build__input_spreadsheet_fh' );
|
|
|
15 has '_output_spreadsheet_fh' => ( is => 'ro', lazy => 1, builder => '_build__output_spreadsheet_fh' );
|
|
|
16 has '_fixed_headers' => ( is => 'ro', isa => 'ArrayRef', lazy => 1, builder => '_build__fixed_headers' );
|
|
|
17 has '_num_fixed_headers' => ( is => 'ro', isa => 'Int', lazy => 1, builder => '_build__num_fixed_headers' );
|
|
|
18 has '_csv_parser' => ( is => 'ro', isa => 'Text::CSV',lazy => 1, builder => '_build__csv_parser' );
|
|
|
19 has '_csv_output' => ( is => 'ro', isa => 'Text::CSV',lazy => 1, builder => '_build__csv_output' );
|
|
|
20
|
|
|
21 sub BUILD
|
|
|
22 {
|
|
|
23 my ($self) = @_;
|
|
|
24 $self->_input_spreadsheet_fh;
|
|
|
25 }
|
|
|
26
|
|
|
27 sub _build__fixed_headers
|
|
|
28 {
|
|
|
29 my ($self) = @_;
|
|
|
30 my @fixed_headers = @{Bio::Roary::GroupStatistics->fixed_headers()};
|
|
|
31 return \@fixed_headers;
|
|
|
32 }
|
|
|
33
|
|
|
34 sub _build__csv_parser
|
|
|
35 {
|
|
|
36 my ($self) = @_;
|
|
|
37 return Text::CSV->new( { binary => 1, always_quote => 1} );
|
|
|
38 }
|
|
|
39
|
|
|
40 sub _build__csv_output
|
|
|
41 {
|
|
|
42 my ($self) = @_;
|
|
|
43 return Text::CSV->new( { binary => 1, always_quote => 1, eol => "\r\n"} );
|
|
|
44 }
|
|
|
45
|
|
|
46 sub _build__input_spreadsheet_fh {
|
|
|
47 my ($self) = @_;
|
|
|
48 open( my $fh, $self->spreadsheet ) or die "Couldnt open input spreadsheet: ".$self->spreadsheet ;
|
|
|
49 return $fh;
|
|
|
50 }
|
|
|
51
|
|
|
52 sub _build__output_spreadsheet_fh {
|
|
|
53 my ($self) = @_;
|
|
|
54 open( my $fh, '>', $self->output_filename );
|
|
|
55 return $fh;
|
|
|
56 }
|
|
|
57
|
|
|
58 sub _build__num_fixed_headers
|
|
|
59 {
|
|
|
60 my ($self) = @_;
|
|
|
61 return @{$self->_fixed_headers};
|
|
|
62 }
|
|
|
63
|
|
|
64
|
|
|
65
|
|
|
66 1;
|