File Coverage

lib/Bio/Roary/PrepareInputFiles.pm
Criterion Covered Total %
statement 64 69 92.7
branch 5 8 62.5
condition n/a
subroutine 16 17 94.1
pod 0 2 0.0
total 85 96 88.5


line stmt bran cond sub pod time code
1             package Bio::Roary::PrepareInputFiles;
2             $Bio::Roary::PrepareInputFiles::VERSION = '3.10.1';
3             # ABSTRACT: Take in a mixture of FASTA and GFF input files and output FASTA proteomes only
4              
5              
6 4     4   106562 use Moose;
  4         396867  
  4         30  
7 4     4   27998 use Bio::Roary::Exceptions;
  4         11  
  4         100  
8 4     4   1491 use Bio::Roary::ExtractProteomeFromGFFs;
  4         14  
  4         174  
9 4     4   1737 use Bio::Roary::FilterUnknownsFromFasta;
  4         16  
  4         173  
10 4     4   35 use Cwd qw(getcwd);
  4         7  
  4         231  
11 4     4   25 use File::Temp;
  4         9  
  4         276  
12 4     4   24 use Log::Log4perl qw(:easy);
  4         7  
  4         40  
13              
14             has 'input_files' => ( is => 'ro', isa => 'ArrayRef', required => 1 );
15             has 'job_runner' => ( is => 'ro', isa => 'Str', default => 'Local' );
16             has 'cpus' => ( is => 'ro', isa => 'Int', default => 1 );
17             has '_input_gff_files' => ( is => 'ro', isa => 'Maybe[ArrayRef]', lazy => 1, builder => '_build__input_gff_files' );
18             has '_input_fasta_files' => ( is => 'ro', isa => 'Maybe[ArrayRef]', lazy => 1, builder => '_build__input_fasta_files' );
19             has '_input_fasta_files_filtered' => ( is => 'ro', isa => 'Maybe[ArrayRef]', lazy => 1, builder => '_build__input_fasta_files_filtered' );
20             has '_input_fasta_files_filtered_obj' =>
21             ( is => 'ro', isa => 'Bio::Roary::FilterUnknownsFromFasta', lazy => 1, builder => '_build__input_fasta_files_filtered_obj' );
22              
23             has '_derived_fasta_files' => ( is => 'ro', isa => 'Maybe[ArrayRef]', lazy => 1, builder => '_build__derived_fasta_files' );
24             has '_extract_proteome_obj' => (
25             is => 'ro',
26             isa => 'Bio::Roary::ExtractProteomeFromGFFs',
27             lazy => 1,
28             builder => '_build__extract_proteome_obj'
29             );
30             has 'apply_unknowns_filter' => ( is => 'rw', isa => 'Bool', default => 1 );
31             has 'translation_table' => ( is => 'rw', isa => 'Int', default => 11 );
32             has 'verbose' => ( is => 'rw', isa => 'Bool', default => 0 );
33             has '_fasta_filter_obj' => ( is => 'ro', isa => 'Bio::Roary::FilterUnknowsFromFasta', lazy => 1, builder => '_fasta_filter_obj' );
34             has 'working_directory' => ( is => 'ro', isa => 'File::Temp::Dir', default => sub { File::Temp->newdir( DIR => getcwd, CLEANUP => 1 ); } );
35             has 'logger' => ( is => 'ro', lazy => 1, builder => '_build_logger' );
36              
37             sub _build_logger {
38 0     0   0 my ($self) = @_;
39 0         0 Log::Log4perl->easy_init($ERROR);
40 0         0 my $logger = get_logger();
41 0         0 return $logger;
42             }
43              
44             sub _build__input_gff_files {
45 19     19   50 my ($self) = @_;
46 19         40 my @gff_files = grep( /\.gff$/, @{ $self->input_files } );
  19         566  
47 19         561 return \@gff_files;
48             }
49              
50             sub _build__input_fasta_files {
51 19     19   55 my ($self) = @_;
52 19         46 my @fasta_files = grep( !/\.gff$/, @{ $self->input_files } );
  19         676  
53              
54 19         45 my @validated_fasta_files;
55              
56 19         55 for my $fasta_file (@fasta_files) {
57 44         82 eval {
58 44         460 my $inseq = Bio::SeqIO->new(
59             -file => $fasta_file,
60             -format => 'fasta',
61             -alphabet => 'protein'
62             );
63 44         47250 while ( my $seq = $inseq->next_seq ) {
64              
65             # do something to force the reading.
66 183         32093 $seq->seq;
67             }
68             };
69 44 50       7278 if ($@) {
70 0         0 $self->logger->warn(
71             "Input file doesnt have a .gff extension and isnt a protein FASTA file so excluding it from further analysis: $fasta_file"
72             );
73             }
74             else {
75 44         146 push( @validated_fasta_files, $fasta_file );
76             }
77              
78             }
79              
80 19         941 return \@fasta_files;
81             }
82              
83             sub _build__input_fasta_files_filtered_obj {
84 19     19   49 my ($self) = @_;
85 19         541 return Bio::Roary::FilterUnknownsFromFasta->new( fasta_files => $self->_input_fasta_files );
86             }
87              
88             sub _build__input_fasta_files_filtered {
89 19     19   52 my ($self) = @_;
90 19 50       775 return undef if ( !defined( $self->_input_fasta_files ) );
91 19         684 return $self->_input_fasta_files_filtered_obj->filtered_fasta_files();
92             }
93              
94             sub _build__extract_proteome_obj {
95 19     19   113 my ($self) = @_;
96 19         505 return Bio::Roary::ExtractProteomeFromGFFs->new(
97             gff_files => $self->_input_gff_files,
98             job_runner => $self->job_runner,
99             apply_unknowns_filter => $self->apply_unknowns_filter,
100             translation_table => $self->translation_table,
101             cpus => $self->cpus,
102             verbose => $self->verbose,
103             working_directory => $self->working_directory,
104             );
105             }
106              
107             sub _build__derived_fasta_files {
108 19     19   57 my ($self) = @_;
109 19 50       607 return undef if ( !defined( $self->_input_gff_files ) );
110 19         595 return $self->_extract_proteome_obj->fasta_files();
111             }
112              
113             sub fasta_files {
114 59     59 0 219 my ($self) = @_;
115 59         180 my @output_fasta_files = ( @{ $self->_input_fasta_files_filtered }, @{ $self->_derived_fasta_files } );
  59         2509  
  59         2571  
116 59         2092 return \@output_fasta_files;
117             }
118              
119             sub lookup_fasta_files_from_unknown_input_files {
120 15     15 0 1478 my ( $self, $input_files ) = @_;
121 15         79 $self->fasta_files;
122              
123 15         92 my @output_fasta_files;
124 15         42 for my $input_file ( @{$input_files} ) {
  15         73  
125 23 100       817 if ( defined( $self->_extract_proteome_obj->fasta_files_to_gff_files->{$input_file} ) ) {
126 4         170 push( @output_fasta_files, $self->_extract_proteome_obj->fasta_files_to_gff_files->{$input_file} );
127             }
128             else {
129 19         800 push( @output_fasta_files, $self->_input_fasta_files_filtered_obj->input_fasta_to_output_fasta->{$input_file} );
130             }
131             }
132 15         743 return \@output_fasta_files;
133             }
134              
135 4     4   6257 no Moose;
  4         8  
  4         28  
136             __PACKAGE__->meta->make_immutable;
137              
138             1;
139              
140             __END__
141              
142             =pod
143              
144             =encoding UTF-8
145              
146             =head1 NAME
147              
148             Bio::Roary::PrepareInputFiles - Take in a mixture of FASTA and GFF input files and output FASTA proteomes only
149              
150             =head1 VERSION
151              
152             version 3.10.1
153              
154             =head1 SYNOPSIS
155              
156             Take in a mixture of FASTA and GFF input files and output FASTA proteomes only
157             use Bio::Roary::PrepareInputFiles;
158              
159             my $obj = Bio::Roary::PrepareInputFiles->new(
160             input_files => ['abc.gff','ddd.faa'],
161             );
162             $obj->fasta_files;
163              
164             =head1 AUTHOR
165              
166             Andrew J. Page <ap13@sanger.ac.uk>
167              
168             =head1 COPYRIGHT AND LICENSE
169              
170             This software is Copyright (c) 2013 by Wellcome Trust Sanger Institute.
171              
172             This is free software, licensed under:
173              
174             The GNU General Public License, Version 3, June 2007
175              
176             =cut