| 1 | package Bio::Roary::Output::DifferenceBetweenSets; | ||
| 2 | 2 | $Bio::Roary::Output::DifferenceBetweenSets::VERSION = '3.13.0'; | |
| 3 | # ABSTRACT: Given two sets of isolates and a group file, output whats unique in each and whats in common | ||
| 4 | |||
| 5 | |||
| 6 | 2 | ▶ | use Moose; |
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||
| 7 | 2 | ▶ | use Bio::SeqIO; |
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||
| 8 | 2 | ▶ | use Bio::Roary::Exceptions; |
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||
| 9 | 2 | ▶ | use Bio::Roary::AnalyseGroups; |
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||
| 10 | 2 | ▶ | use Bio::Roary::Output::QueryGroups; |
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||
| 11 | |||
| 12 | 2 | has 'analyse_groups' => ( is => 'ro', isa => 'Bio::Roary::AnalyseGroups', required => 1 ); | |
| 13 | 2 | has 'input_filenames_sets' => ( is => 'ro', isa => 'ArrayRef[ArrayRef]', required => 1 ); | |
| 14 | 2 | has 'output_filename_base' => ( is => 'ro', isa => 'Str', default => 'set_difference' ); | |
| 15 | |||
| 16 | 2 | has '_query_groups_objs' => ( is => 'ro', isa => 'ArrayRef', lazy => 1, builder => '_build__query_groups_objs' ); | |
| 17 | |||
| 18 | # TODO: update to handle more than 2 input sets | ||
| 19 | |||
| 20 | 8 | ▶ | sub _build__query_groups_objs { |
|
Subroutine
_build__query_groups_objs: called CC=2 SCAR=6.9
| |||
| 21 | 8 | my ($self) = @_; | |
| 22 | 8 | my @query_groups_objs; | |
| 23 | 8 | for my $file_name_set ( @{ $self->input_filenames_sets } ) { | |
| 24 | 16 | push( | |
| 25 | @query_groups_objs, | ||
| 26 | Bio::Roary::Output::QueryGroups->new( | ||
| 27 | analyse_groups => $self->analyse_groups, | ||
| 28 | input_filenames => $file_name_set | ||
| 29 | ) | ||
| 30 | ); | ||
| 31 | } | ||
| 32 | |||
| 33 | 8 | my @all_input_files = (@{ $self->input_filenames_sets->[0] },@{ $self->input_filenames_sets->[1] }); | |
| 34 | 8 | push( | |
| 35 | @query_groups_objs, | ||
| 36 | Bio::Roary::Output::QueryGroups->new( | ||
| 37 | analyse_groups => $self->analyse_groups, | ||
| 38 | input_filenames => \@all_input_files | ||
| 39 | ) | ||
| 40 | ); | ||
| 41 | |||
| 42 | |||
| 43 | 8 | return \@query_groups_objs; | |
| 44 | } | ||
| 45 | |||
| 46 | 48 | ▶ | sub _subtract_arrays { |
|
Subroutine
_subtract_arrays: called CC=1 SCAR=0.0
| |||
| 47 | 48 | my ( $self, $array_1, $array_2 ) = @_; | |
| 48 | 48 | my %array_1 = map { $_ => 1 } @{$array_1}; | |
| 49 | 48 | my @difference = grep { not $array_1{$_} } @{$array_2}; | |
| 50 | 48 | return \@difference; | |
| 51 | } | ||
| 52 | |||
| 53 | 16 | ▶ | sub _groups_unique { |
|
Subroutine
_groups_unique: called CC=1 SCAR=0.0
| |||
| 54 | 16 | my ( $self, $output_filename, $query_group1, $query_group2 ) = @_; | |
| 55 | 16 | my $unique_groups = $self->_subtract_arrays( $query_group2->_groups, $query_group1->_groups ); | |
| 56 | 16 | $query_group1->groups_with_external_inputs( $output_filename, $unique_groups ); | |
| 57 | } | ||
| 58 | |||
| 59 | sub groups_set_one_unique_filename | ||
| 60 | 15 | ▶ | { |
|
Subroutine
groups_set_one_unique_filename: called CC=1 SCAR=0.0
Pod
undocumented
| |||
| 61 | 15 | my ($self) = @_; | |
| 62 | 15 | return $self->output_filename_base . '_unique_set_one'; | |
| 63 | } | ||
| 64 | |||
| 65 | sub groups_set_two_unique_filename | ||
| 66 | 15 | ▶ | { |
|
Subroutine
groups_set_two_unique_filename: called CC=1 SCAR=0.0
Pod
undocumented
| |||
| 67 | 15 | my ($self) = @_; | |
| 68 | 15 | return $self->output_filename_base . '_unique_set_two'; | |
| 69 | } | ||
| 70 | |||
| 71 | sub groups_in_common_filename | ||
| 72 | 15 | ▶ | { |
|
Subroutine
groups_in_common_filename: called CC=1 SCAR=0.0
Pod
undocumented
| |||
| 73 | 15 | my ($self) = @_; | |
| 74 | 15 | return $self->output_filename_base . '_common_set'; | |
| 75 | } | ||
| 76 | |||
| 77 | |||
| 78 | 8 | ▶ | sub groups_set_one_unique { |
|
Subroutine
groups_set_one_unique: called CC=1 SCAR=0.0
Pod
undocumented
| |||
| 79 | 8 | my ($self) = @_; | |
| 80 | 8 | $self->_groups_unique( | |
| 81 | $self->groups_set_one_unique_filename, | ||
| 82 | $self->_query_groups_objs->[0], | ||
| 83 | $self->_query_groups_objs->[1] | ||
| 84 | ); | ||
| 85 | } | ||
| 86 | |||
| 87 | 8 | ▶ | sub groups_set_two_unique { |
|
Subroutine
groups_set_two_unique: called CC=1 SCAR=0.0
Pod
undocumented
| |||
| 88 | 8 | my ($self) = @_; | |
| 89 | 8 | $self->_groups_unique( | |
| 90 | $self->groups_set_two_unique_filename, | ||
| 91 | $self->_query_groups_objs->[1], | ||
| 92 | $self->_query_groups_objs->[0] | ||
| 93 | ); | ||
| 94 | } | ||
| 95 | |||
| 96 | 8 | ▶ | sub groups_in_common { |
|
Subroutine
groups_in_common: called CC=1 SCAR=0.0
Pod
undocumented
| |||
| 97 | 8 | my ($self) = @_; | |
| 98 | 8 | my $unique_group_1 = $self->_subtract_arrays( $self->_query_groups_objs->[0]->_groups, $self->_query_groups_objs->[1]->_groups ); | |
| 99 | 8 | my $unique_group_2 = $self->_subtract_arrays( $self->_query_groups_objs->[1]->_groups, $self->_query_groups_objs->[0]->_groups ); | |
| 100 | 8 | my $common_groups_1 = $self->_subtract_arrays( $unique_group_1,$self->_query_groups_objs->[2]->_groups); | |
| 101 | 8 | my $common_groups_2 = $self->_subtract_arrays( $unique_group_2,$common_groups_1); | |
| 102 | 8 | $self->_query_groups_objs->[2]->groups_with_external_inputs( $self->groups_in_common_filename, $common_groups_2 ); | |
| 103 | } | ||
| 104 | |||
| 105 | 2 | ▶ | no Moose; |
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||
| 106 | 2 | __PACKAGE__->meta->make_immutable; | |
| 107 | |||
| 108 | 2 | 1; | |
| 109 | |||
| 110 | __END__ | ||