Bio-MLST-Check
view release on metacpan or search on metacpan
lib/Bio/MLST/Spreadsheet/Row.pm view on Meta::CPAN
package Bio::MLST::Spreadsheet::Row;
# ABSTRACT: Create a row representation of the ST results for a single fasta file.
$Bio::MLST::Spreadsheet::Row::VERSION = '2.1.1706216';
use Data::Dumper;
use Text::CSV;
use Bio::MLST::FilterAlleles qw(only_keep_alleles);
use Moose;
has 'sequence_type_obj' => ( is => 'ro', isa => 'Bio::MLST::SequenceType', required => 1 );
has 'compare_alleles' => ( is => 'ro', isa => 'Bio::MLST::CompareAlleles', required => 1 );
has 'show_contamination_instead_of_alt_matches' => ( is => 'ro', isa => 'Bool', default => 1 );
has 'allele_numbers_row' => ( is => 'ro', isa => 'ArrayRef', lazy => 1, builder => '_build_allele_numbers_row');
has 'genomic_row' => ( is => 'ro', isa => 'ArrayRef', lazy => 1, builder => '_build_genomic_row');
has 'header_row' => ( is => 'ro', isa => 'ArrayRef', lazy => 1, builder => '_build_header_row');
has '_common_cells' => ( is => 'ro', isa => 'ArrayRef', lazy => 1, builder => '_build__common_cells');
has '_allele_order' => ( is => 'ro', isa => 'ArrayRef', lazy => 1, builder => '_build__allele_order');
sub _build__common_cells
{
my($self) = @_;
#cause the variable to be built.
$self->sequence_type_obj->sequence_type;
my $new_st_cell = '';
if($self->compare_alleles->new_st )
{
$new_st_cell = "Unknown";
}
elsif($self->sequence_type_obj->nearest_sequence_type)
{
$new_st_cell = "Novel ST";
}
my $contamination_cell;
if($self->show_contamination_instead_of_alt_matches == 1)
{
$contamination_cell = ($self->compare_alleles->contamination ? $self->compare_alleles->contamination_alleles : '');
}
else
{
$contamination_cell = (defined($self->compare_alleles->contamination_sequence_names)) ? join(',',@{$self->compare_alleles->contamination_sequence_names}) : '';
}
# sequence_type_or_nearest is a Maybe[Int]; if it's undefined csv->print skips it so we need to set it to be an empty string
my $sequence_type = $self->sequence_type_obj->sequence_type_or_nearest ? $self->sequence_type_obj->sequence_type_or_nearest : '';
my @common_cells = (
$self->compare_alleles->sequence_filename_root,
$sequence_type,
$new_st_cell,
$contamination_cell,
);
return \@common_cells;
}
sub _build__allele_order {
my $self = shift;
my $profile_path = $self->compare_alleles->profiles_filename;
my $csv = Text::CSV->new({sep_char=>"\t"});
open( my $profile_fh, '<', $profile_path );
my @alleles = @{$csv->getline($profile_fh)};
@alleles = @{only_keep_alleles(\@alleles)};
my @fixed_alleles;
foreach my $allele ( @alleles ){
$allele =~ s/_/-/g;
$allele =~ s/-$//;
push( @fixed_alleles, $allele );
}
#print "ALLELES FROM PROFILE: ";
#print Dumper \@fixed_alleles;
( run in 1.637 second using v1.01-cache-2.11-cpan-39bf76dae61 )