| 1 | package Bio::Roary::ClustersRole; | ||||||||||
| 2 | # ABSTRACT: A role to read a clusters file from CD hit | ||||||||||
| 3 | 5 | $Bio::Roary::ClustersRole::VERSION = '3.13.0'; | |||||||||
| 4 | |||||||||||
| 5 | 5 | ▶ | use Moose::Role; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 6 | 5 | ▶ | use Bio::Roary::Exceptions; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 7 | |||||||||||
| 8 | 5 | has 'clusters_filename' => ( is => 'ro', isa => 'Str', required => 1 ); | |||||||||
| 9 | 5 | has '_clustered_genes' => ( is => 'ro',lazy => 1, builder => '_build__clustered_genes' ); | |||||||||
| 10 | 5 | has '_clusters_fh' => ( is => 'ro',lazy => 1, builder => '_build__clusters_fh' ); | |||||||||
| 11 | |||||||||||
| 12 | sub _build__clusters_fh | ||||||||||
| 13 | 4 | ▶ | { | ||||||||
|
Subroutine
_build__clusters_fh: called CC=2 SCAR=6.9
| |||||||||||
| 14 | 4 | my($self) = @_; | |||||||||
| 15 | 4 | ▶ | open(my $fh, $self->clusters_filename) or Bio::Roary::Exceptions::FileNotFound->throw( error => 'Cant open file: ' . $self->clusters_filename ); | ||||||||
|
Branch: 1 branch
| |||||||||||
| 16 | 3 | return $fh; | |||||||||
| 17 | } | ||||||||||
| 18 | |||||||||||
| 19 | sub _build__clustered_genes | ||||||||||
| 20 | 4 | ▶ | { | ||||||||
|
Subroutine
_build__clustered_genes: called CC=6 SCAR=17.9
| |||||||||||
| 21 | 4 | my($self) = @_; | |||||||||
| 22 | 4 | my $fh = $self->_clusters_fh; | |||||||||
| 23 | 3 | my %clustered_genes ; | |||||||||
| 24 | |||||||||||
| 25 | my %raw_clusters; | ||||||||||
| 26 | 3 | my $current_cluster_name; | |||||||||
| 27 | 3 | ▶ | while(<$fh>) | ||||||||
|
Branch: 1 branch
| |||||||||||
| 28 | { | ||||||||||
| 29 | 113 | my $line = $_; | |||||||||
| 30 | 113 | ▶ | if($line =~ /^>(.+)$/) | ||||||||
|
Branch: 1 branch
| |||||||||||
| 31 | { | ||||||||||
| 32 | 31 | $current_cluster_name = $1; | |||||||||
| 33 | } | ||||||||||
| 34 | |||||||||||
| 35 | #>Cluster 5 | ||||||||||
| 36 | #0 4201aa, >6630_4#9_00008... * | ||||||||||
| 37 | #1 4201aa, >6631_1#23_00379... at 100.00% | ||||||||||
| 38 | |||||||||||
| 39 | 113 | ▶ | if($line =~ /[\d]+\t[\w]+, >(.+)\.\.\. (.+)$/) | ||||||||
|
Branch: 1 branch
| |||||||||||
| 40 | { | ||||||||||
| 41 | 82 | my $gene_name = $1; | |||||||||
| 42 | 82 | my $identity = $2; | |||||||||
| 43 | |||||||||||
| 44 | 82 | ▶ | if($identity eq '*') | ||||||||
|
Branch: 1 branch
| |||||||||||
| 45 | { | ||||||||||
| 46 | 31 | $raw_clusters{$current_cluster_name}{representative_gene_name} = $gene_name; | |||||||||
| 47 | } | ||||||||||
| 48 | else | ||||||||||
| 49 | { | ||||||||||
| 50 | 51 | push(@{$raw_clusters{$current_cluster_name}{gene_names}}, $gene_name); | |||||||||
| 51 | } | ||||||||||
| 52 | } | ||||||||||
| 53 | } | ||||||||||
| 54 | |||||||||||
| 55 | # iterate over the raw clusters and convert to a simple hash | ||||||||||
| 56 | 3 | for my $cluster_name (keys %raw_clusters) | |||||||||
| 57 | { | ||||||||||
| 58 | 31 | $clustered_genes{$raw_clusters{$cluster_name}{representative_gene_name}} = $raw_clusters{$cluster_name}{gene_names}; | |||||||||
| 59 | } | ||||||||||
| 60 | |||||||||||
| 61 | 3 | return \%clustered_genes; | |||||||||
| 62 | } | ||||||||||
| 63 | |||||||||||
| 64 | 5 | 1; | |||||||||
| 65 | |||||||||||
| 66 | __END__ | ||||||||||