0
|
1 package Bio::Roary::Output::BlastIdentityFrequency;
|
|
2
|
|
3 # ABSTRACT: Take in blast results and find the percentage identity graph
|
|
4
|
|
5 =head1 SYNOPSIS
|
|
6
|
|
7 Take in blast results and find the percentage identity graph
|
|
8 use Bio::Roary::Output::BlastIdentityFrequency;
|
|
9
|
|
10 my $obj = Bio::Roary::Output::BlastIdentityFrequency->new(
|
|
11 input_filename => '_blast_results',
|
|
12 output_filename => 'blast_identity_frequency.Rtab',
|
|
13 );
|
|
14 $obj->create_file();
|
|
15
|
|
16 =cut
|
|
17
|
|
18 use Moose;
|
|
19 use Bio::SeqIO;
|
|
20 use Bio::Roary::Exceptions;
|
|
21
|
|
22 has 'input_filename' => ( is => 'ro', isa => 'Str', default => '_blast_results' );
|
|
23 has 'output_filename' => ( is => 'ro', isa => 'Str', default => 'blast_identity_frequency.Rtab' );
|
|
24
|
|
25 has '_output_fh' => ( is => 'ro', lazy => 1, builder => '_build__output_fh' );
|
|
26 has '_input_fh' => ( is => 'ro', lazy => 1, builder => '_build__input_fh' );
|
|
27
|
|
28 sub _build__output_fh
|
|
29 {
|
|
30 my ($self) = @_;
|
|
31 open( my $fh, '>', $self->output_filename )
|
|
32 or Bio::Roary::Exceptions::CouldntWriteToFile->throw(
|
|
33 error => "Couldnt write output file:" . $self->output_filename );
|
|
34 return $fh;
|
|
35 }
|
|
36
|
|
37 sub _build__input_fh
|
|
38 {
|
|
39 my ($self) = @_;
|
|
40 my $input_string = 'awk \'{print $3}\' '.$self->input_filename.' | awk \'BEGIN {FS="."}; {print $1}\'| sort | uniq -c | awk \'{print $2"\t"$1}\'';
|
|
41
|
|
42 open( my $fh, '-|', $input_string ) or die "Couldnt open results file";
|
|
43 return $fh;
|
|
44 }
|
|
45
|
|
46 sub create_file
|
|
47 {
|
|
48 my ($self) = @_;
|
|
49
|
|
50 my $input_fh = $self->_input_fh;
|
|
51 while(<$input_fh>)
|
|
52 {
|
|
53 print {$self->_output_fh} $_;
|
|
54 }
|
|
55 close($self->_input_fh);
|
|
56 close($self->_output_fh);
|
|
57 }
|
|
58
|
|
59 no Moose;
|
|
60 __PACKAGE__->meta->make_immutable;
|
|
61
|
|
62 1;
|