Bio-Roary
view release on metacpan or search on metacpan
lib/Bio/Roary/OrderGenes.pm view on Meta::CPAN
package Bio::Roary::OrderGenes;
$Bio::Roary::OrderGenes::VERSION = '3.13.0';
# ABSTRACT: Take in GFF files and create a matrix of what genes are beside what other genes
use Moose;
use Bio::Roary::Exceptions;
use Bio::Roary::AnalyseGroups;
use Bio::Roary::ContigsToGeneIDsFromGFF;
use Graph;
use Graph::Writer::Dot;
use File::Basename;
has 'gff_files' => ( is => 'ro', isa => 'ArrayRef', required => 1 );
has 'analyse_groups_obj' => ( is => 'ro', isa => 'Bio::Roary::AnalyseGroups', required => 1 );
has 'core_definition' => ( is => 'ro', isa => 'Num', default => 1.0 );
has 'pan_graph_filename' => ( is => 'ro', isa => 'Str', default => 'core_accessory_graph.dot' );
has 'accessory_graph_filename' => ( is => 'ro', isa => 'Str', default => 'accessory_graph.dot' );
has 'sample_weights' => ( is => 'ro', isa => 'Maybe[HashRef]' );
has 'samples_to_clusters' => ( is => 'ro', isa => 'Maybe[HashRef]' );
has 'group_order' => ( is => 'ro', isa => 'HashRef', lazy => 1, builder => '_build_group_order' );
has 'groups_to_sample_names' => ( is => 'rw', isa => 'HashRef', default => sub { {} } );
has 'group_graphs' => ( is => 'ro', isa => 'Graph', lazy => 1, builder => '_build_group_graphs' );
has 'groups_to_contigs' => ( is => 'ro', isa => 'HashRef', lazy => 1, builder => '_build_groups_to_contigs' );
has '_groups_to_file_contigs' => ( is => 'ro', isa => 'HashRef', lazy => 1, builder => '_build__groups_to_file_contigs' );
has '_groups' => ( is => 'ro', isa => 'HashRef', lazy => 1, builder => '_build_groups' );
has 'number_of_files' => ( is => 'ro', isa => 'Int', lazy => 1, builder => '_build_number_of_files' );
has '_groups_qc' => ( is => 'ro', isa => 'HashRef', default => sub { {} } );
has '_percentage_of_largest_weak_threshold' => ( is => 'ro', isa => 'Num', default => 0.9 );
sub _build_number_of_files {
my ($self) = @_;
return @{ $self->gff_files };
}
sub _build_groups {
my ($self) = @_;
my %groups;
for my $group_name ( @{ $self->analyse_groups_obj->_groups } ) {
$groups{$group_name}++;
}
return \%groups;
}
sub _build__groups_to_file_contigs {
my ($self) = @_;
my @overlapping_hypothetical_gene_ids;
my %samples_to_groups_contigs;
# Open each GFF file
for my $filename ( @{ $self->gff_files } ) {
my @groups_to_contigs;
my $contigs_to_ids_obj = Bio::Roary::ContigsToGeneIDsFromGFF->new( gff_file => $filename );
my ( $sample_name, $directories, $suffix ) = fileparse($filename);
$sample_name =~ s/\.gff//gi;
# Loop over each contig in the GFF file
for my $contig_name ( keys %{ $contigs_to_ids_obj->contig_to_ids } ) {
my @groups_on_contig;
#Â loop over each gene in each contig in the GFF file
for my $gene_id ( @{ $contigs_to_ids_obj->contig_to_ids->{$contig_name} } ) {
#Â convert to group name
my $group_name = $self->analyse_groups_obj->_genes_to_groups->{$gene_id};
next unless ( defined($group_name) );
if ( $contigs_to_ids_obj->overlapping_hypothetical_protein_ids->{$gene_id} ) {
$self->_groups_qc->{$group_name} =
'Hypothetical protein with no hits to refseq/uniprot/clusters/cdd/tigrfams/pfam overlapping another protein with hits';
}
push( @groups_on_contig, $group_name );
}
push( @groups_to_contigs, \@groups_on_contig );
}
$samples_to_groups_contigs{$sample_name} = \@groups_to_contigs;
}
return \%samples_to_groups_contigs;
}
sub _build_group_order {
my ($self) = @_;
my %group_order;
my %groups_to_sample_names;
( run in 1.153 second using v1.01-cache-2.11-cpan-9789f410c06 )