line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Bio::Roary::InflateClusters; |
2
|
|
|
|
|
|
|
$Bio::Roary::InflateClusters::VERSION = '3.10.2'; |
3
|
|
|
|
|
|
|
# ABSTRACT: Take the clusters file from cd-hit and use it to inflate the output of MCL |
4
|
|
|
|
|
|
|
|
5
|
|
|
|
|
|
|
|
6
|
3
|
|
|
3
|
|
79647
|
use Moose; |
|
3
|
|
|
|
|
385405
|
|
|
3
|
|
|
|
|
18
|
|
7
|
3
|
|
|
3
|
|
17831
|
use Bio::Roary::Exceptions; |
|
3
|
|
|
|
|
6
|
|
|
3
|
|
|
|
|
1463
|
|
8
|
|
|
|
|
|
|
with 'Bio::Roary::ClustersRole'; |
9
|
|
|
|
|
|
|
|
10
|
|
|
|
|
|
|
has 'mcl_filename' => ( is => 'ro', isa => 'Str', required => 1 ); |
11
|
|
|
|
|
|
|
has 'output_file' => ( is => 'ro', isa => 'Str', default => 'inflated_results' ); |
12
|
|
|
|
|
|
|
has '_mcl_fh' => ( is => 'ro',lazy => 1, builder => '_build__mcl_fh' ); |
13
|
|
|
|
|
|
|
has '_output_fh' => ( is => 'ro',lazy => 1, builder => '_build__output_fh' ); |
14
|
|
|
|
|
|
|
has 'cdhit_groups_filename' => ( is => 'ro', isa => 'Maybe[Str]' ); |
15
|
|
|
|
|
|
|
|
16
|
|
|
|
|
|
|
sub _build__output_fh |
17
|
|
|
|
|
|
|
{ |
18
|
2
|
|
|
2
|
|
4
|
my($self) = @_; |
19
|
2
|
50
|
|
|
|
39
|
open(my $fh, '>', $self->output_file) or Bio::Roary::Exceptions::CouldntWriteToFile->throw( error => 'Cant write to file: ' . $self->output_file ); |
20
|
2
|
|
|
|
|
45
|
return $fh; |
21
|
|
|
|
|
|
|
} |
22
|
|
|
|
|
|
|
|
23
|
|
|
|
|
|
|
sub _build__mcl_fh |
24
|
|
|
|
|
|
|
{ |
25
|
2
|
|
|
2
|
|
3
|
my($self) = @_; |
26
|
2
|
50
|
|
|
|
44
|
open(my $fh, $self->mcl_filename) or Bio::Roary::Exceptions::FileNotFound->throw( error => 'Cant open file: ' . $self->mcl_filename ); |
27
|
2
|
|
|
|
|
45
|
return $fh; |
28
|
|
|
|
|
|
|
} |
29
|
|
|
|
|
|
|
|
30
|
|
|
|
|
|
|
sub _inflate_line |
31
|
|
|
|
|
|
|
{ |
32
|
9
|
|
|
9
|
|
17
|
my($self, $line) = @_; |
33
|
9
|
|
|
|
|
9
|
my @inflated_genes; |
34
|
9
|
|
|
|
|
11
|
chomp($line); |
35
|
9
|
|
|
|
|
32
|
my @gene_names = split(/[\t\s]+/, $line); |
36
|
9
|
|
|
|
|
30
|
for my $gene_name (@gene_names) |
37
|
|
|
|
|
|
|
{ |
38
|
21
|
|
|
|
|
36
|
push(@inflated_genes, $self->_inflate_gene($gene_name)); |
39
|
|
|
|
|
|
|
} |
40
|
9
|
|
|
|
|
58
|
return join(' ',@inflated_genes); |
41
|
|
|
|
|
|
|
} |
42
|
|
|
|
|
|
|
|
43
|
|
|
|
|
|
|
sub _inflate_gene |
44
|
|
|
|
|
|
|
{ |
45
|
21
|
|
|
21
|
|
27
|
my($self, $gene_name) = @_; |
46
|
21
|
|
|
|
|
22
|
my $inflated_gene = $gene_name; |
47
|
21
|
100
|
|
|
|
348
|
if(defined($self->_clustered_genes->{$gene_name})) |
48
|
|
|
|
|
|
|
{ |
49
|
5
|
|
|
|
|
9
|
$inflated_gene = $inflated_gene."\t". join("\t",@{$self->_clustered_genes->{$gene_name}}); |
|
5
|
|
|
|
|
82
|
|
50
|
5
|
|
|
|
|
83
|
delete($self->_clustered_genes->{$gene_name}); |
51
|
|
|
|
|
|
|
} |
52
|
21
|
|
|
|
|
39
|
return $inflated_gene; |
53
|
|
|
|
|
|
|
} |
54
|
|
|
|
|
|
|
|
55
|
|
|
|
|
|
|
sub inflate |
56
|
|
|
|
|
|
|
{ |
57
|
2
|
|
|
2
|
0
|
4
|
my($self) = @_; |
58
|
2
|
|
|
|
|
50
|
my $mcl_fh = $self->_mcl_fh; |
59
|
|
|
|
|
|
|
|
60
|
|
|
|
|
|
|
# Inflate genes from cdhit which were sent to mcl |
61
|
2
|
|
|
|
|
20
|
while(<$mcl_fh>) |
62
|
|
|
|
|
|
|
{ |
63
|
9
|
|
|
|
|
14
|
my $line = $_; |
64
|
9
|
|
|
|
|
7
|
print { $self->_output_fh } $self->_inflate_line($line) . "\n"; |
|
9
|
|
|
|
|
162
|
|
65
|
|
|
|
|
|
|
} |
66
|
|
|
|
|
|
|
|
67
|
|
|
|
|
|
|
#Â Inflate any clusters that were in the clusters file but not sent to mcl |
68
|
2
|
|
|
|
|
3
|
for my $gene_name(keys %{$self->_clustered_genes}) |
|
2
|
|
|
|
|
36
|
|
69
|
|
|
|
|
|
|
{ |
70
|
16
|
50
|
|
|
|
258
|
next unless(defined($self->_clustered_genes->{$gene_name})); |
71
|
0
|
|
|
|
|
0
|
print { $self->_output_fh } $gene_name."\t". join("\t",@{$self->_clustered_genes->{$gene_name}})."\n"; |
|
0
|
|
|
|
|
0
|
|
|
0
|
|
|
|
|
0
|
|
72
|
|
|
|
|
|
|
} |
73
|
|
|
|
|
|
|
|
74
|
2
|
50
|
|
|
|
39
|
if(defined($self->cdhit_groups_filename)) |
75
|
|
|
|
|
|
|
{ |
76
|
|
|
|
|
|
|
#Â Add clusters which were excluded because the groups were full at the cdhit stage |
77
|
0
|
0
|
|
|
|
0
|
open(my $cdhit_fh, $self->cdhit_groups_filename) or Bio::Roary::Exceptions::FileNotFound->throw( error => "CD hit group file not found: " . $self->cdhit_groups_filename); |
78
|
0
|
|
|
|
|
0
|
while(<$cdhit_fh>) |
79
|
|
|
|
|
|
|
{ |
80
|
0
|
|
|
|
|
0
|
my $line = $_; |
81
|
|
|
|
|
|
|
|
82
|
0
|
0
|
|
|
|
0
|
if(defined($line)) |
83
|
|
|
|
|
|
|
{ |
84
|
0
|
|
|
|
|
0
|
print { $self->_output_fh } $line ; |
|
0
|
|
|
|
|
0
|
|
85
|
|
|
|
|
|
|
} |
86
|
|
|
|
|
|
|
} |
87
|
|
|
|
|
|
|
} |
88
|
|
|
|
|
|
|
|
89
|
2
|
|
|
|
|
32
|
close($self->_output_fh); |
90
|
2
|
|
|
|
|
14
|
1; |
91
|
|
|
|
|
|
|
} |
92
|
|
|
|
|
|
|
|
93
|
3
|
|
|
3
|
|
18
|
no Moose; |
|
3
|
|
|
|
|
3
|
|
|
3
|
|
|
|
|
17
|
|
94
|
|
|
|
|
|
|
__PACKAGE__->meta->make_immutable; |
95
|
|
|
|
|
|
|
|
96
|
|
|
|
|
|
|
1; |
97
|
|
|
|
|
|
|
|
98
|
|
|
|
|
|
|
__END__ |
99
|
|
|
|
|
|
|
|
100
|
|
|
|
|
|
|
=pod |
101
|
|
|
|
|
|
|
|
102
|
|
|
|
|
|
|
=encoding UTF-8 |
103
|
|
|
|
|
|
|
|
104
|
|
|
|
|
|
|
=head1 NAME |
105
|
|
|
|
|
|
|
|
106
|
|
|
|
|
|
|
Bio::Roary::InflateClusters - Take the clusters file from cd-hit and use it to inflate the output of MCL |
107
|
|
|
|
|
|
|
|
108
|
|
|
|
|
|
|
=head1 VERSION |
109
|
|
|
|
|
|
|
|
110
|
|
|
|
|
|
|
version 3.10.2 |
111
|
|
|
|
|
|
|
|
112
|
|
|
|
|
|
|
=head1 SYNOPSIS |
113
|
|
|
|
|
|
|
|
114
|
|
|
|
|
|
|
Take the clusters file from cd-hit and use it to inflate the output of MCL |
115
|
|
|
|
|
|
|
use Bio::Roary::InflateClusters; |
116
|
|
|
|
|
|
|
|
117
|
|
|
|
|
|
|
my $obj = Bio::Roary::InflateClusters->new( |
118
|
|
|
|
|
|
|
clusters_filename => 'example.clstr', |
119
|
|
|
|
|
|
|
mcl_filename => 'example.mcl', |
120
|
|
|
|
|
|
|
output_file => 'example.output' |
121
|
|
|
|
|
|
|
); |
122
|
|
|
|
|
|
|
$obj->inflate; |
123
|
|
|
|
|
|
|
|
124
|
|
|
|
|
|
|
=head1 AUTHOR |
125
|
|
|
|
|
|
|
|
126
|
|
|
|
|
|
|
Andrew J. Page <ap13@sanger.ac.uk> |
127
|
|
|
|
|
|
|
|
128
|
|
|
|
|
|
|
=head1 COPYRIGHT AND LICENSE |
129
|
|
|
|
|
|
|
|
130
|
|
|
|
|
|
|
This software is Copyright (c) 2013 by Wellcome Trust Sanger Institute. |
131
|
|
|
|
|
|
|
|
132
|
|
|
|
|
|
|
This is free software, licensed under: |
133
|
|
|
|
|
|
|
|
134
|
|
|
|
|
|
|
The GNU General Public License, Version 3, June 2007 |
135
|
|
|
|
|
|
|
|
136
|
|
|
|
|
|
|
=cut |