« lib/Bio/Roary/CommandLine/RoaryReorderSpreadsheet.pm
↑ Summary
lib/Bio/Roary/CommandLine/TransferAnnotationToGroups.pm »
| 1 | 1 | undef $VERSION; | |||||||||||||||||||||||||||
| 2 | package Bio::Roary::CommandLine::RoaryCoreAlignment; | ||||||||||||||||||||||||||||
| 3 | 1 | $Bio::Roary::CommandLine::RoaryCoreAlignment::VERSION = '3.13.0'; | |||||||||||||||||||||||||||
| 4 | # ABSTRACT: Take in the group statistics spreadsheet and the location of the gene multifasta files and create a core alignment. | ||||||||||||||||||||||||||||
| 5 | |||||||||||||||||||||||||||||
| 6 | |||||||||||||||||||||||||||||
| 7 | 1 | ▶ | use Moose; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 8 | 1 | ▶ | use Getopt::Long qw(GetOptionsFromArray); | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 9 | 1 | ▶ | use Cwd 'abs_path'; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 10 | 1 | ▶ | use File::Path qw(remove_tree); | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 11 | 1 | ▶ | use Bio::Roary::ExtractCoreGenesFromSpreadsheet; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 12 | 1 | ▶ | use Bio::Roary::LookupGeneFiles; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 13 | 1 | ▶ | use Bio::Roary::MergeMultifastaAlignments; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 14 | 1 | extends 'Bio::Roary::CommandLine::Common'; | |||||||||||||||||||||||||||
| 15 | |||||||||||||||||||||||||||||
| 16 | 1 | has 'args' => ( is => 'ro', isa => 'ArrayRef', required => 1 ); | |||||||||||||||||||||||||||
| 17 | 1 | has 'script_name' => ( is => 'ro', isa => 'Str', required => 1 ); | |||||||||||||||||||||||||||
| 18 | 1 | has 'help' => ( is => 'rw', isa => 'Bool', default => 0 ); | |||||||||||||||||||||||||||
| 19 | |||||||||||||||||||||||||||||
| 20 | 1 | has 'multifasta_base_directory' => ( is => 'rw', isa => 'Str', default => 'pan_genome_sequences' ); | |||||||||||||||||||||||||||
| 21 | 1 | has 'spreadsheet_filename' => ( is => 'rw', isa => 'Str', default => 'gene_presence_absence.csv' ); | |||||||||||||||||||||||||||
| 22 | 1 | has 'output_filename' => ( is => 'rw', isa => 'Str', default => 'core_gene_alignment.aln' ); | |||||||||||||||||||||||||||
| 23 | 1 | has 'core_definition' => ( is => 'rw', isa => 'Num', default => 0.99 ); | |||||||||||||||||||||||||||
| 24 | 1 | has 'dont_delete_files' => ( is => 'rw', isa => 'Bool', default => 0 ); | |||||||||||||||||||||||||||
| 25 | 1 | has 'allow_paralogs' => ( is => 'rw', isa => 'Bool', default => 0 ); | |||||||||||||||||||||||||||
| 26 | 1 | has '_error_message' => ( is => 'rw', isa => 'Str' ); | |||||||||||||||||||||||||||
| 27 | 1 | has 'verbose' => ( is => 'rw', isa => 'Bool', default => 0 ); | |||||||||||||||||||||||||||
| 28 | |||||||||||||||||||||||||||||
| 29 | 3 | ▶ | sub BUILD { | ||||||||||||||||||||||||||
|
Subroutine
BUILD: called CC=14 SCAR=27.5
Pod
undocumented
| |||||||||||||||||||||||||||||
| 30 | 3 | my ($self) = @_; | |||||||||||||||||||||||||||
| 31 | |||||||||||||||||||||||||||||
| 32 | 3 | my ( $multifasta_base_directory, $spreadsheet_filename, $output_filename, $core_definition,$verbose, $help, $mafft, $allow_paralogs, $dont_delete_files ); | |||||||||||||||||||||||||||
| 33 | |||||||||||||||||||||||||||||
| 34 | 3 | GetOptionsFromArray( | |||||||||||||||||||||||||||
| 35 | $self->args, | ||||||||||||||||||||||||||||
| 36 | 'm|multifasta_base_directory=s' => \$multifasta_base_directory, | ||||||||||||||||||||||||||||
| 37 | 's|spreadsheet_filename=s' => \$spreadsheet_filename, | ||||||||||||||||||||||||||||
| 38 | 'o|output_filename=s' => \$output_filename, | ||||||||||||||||||||||||||||
| 39 | 'cd|core_definition=f' => \$core_definition, | ||||||||||||||||||||||||||||
| 40 | 'z|dont_delete_files' => \$dont_delete_files, | ||||||||||||||||||||||||||||
| 41 | 'p|allow_paralogs' => \$allow_paralogs, | ||||||||||||||||||||||||||||
| 42 | 'v|verbose' => \$verbose, | ||||||||||||||||||||||||||||
| 43 | 'h|help' => \$help, | ||||||||||||||||||||||||||||
| 44 | ); | ||||||||||||||||||||||||||||
| 45 | |||||||||||||||||||||||||||||
| 46 | 3 | ▶ | if ( defined($verbose) ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 47 | 0 | $self->verbose($verbose); | |||||||||||||||||||||||||||
| 48 | 0 | $self->logger->level(10000); | |||||||||||||||||||||||||||
| 49 | } | ||||||||||||||||||||||||||||
| 50 | 3 | ▶ | $self->help($help) if(defined($help)); | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 51 | 3 | ▶ | $self->allow_paralogs($allow_paralogs) if(defined($allow_paralogs)); | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 52 | |||||||||||||||||||||||||||||
| 53 | 3 | ▶ | if ( defined($multifasta_base_directory) && ( -d $multifasta_base_directory ) ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
defined $multifasta_base_directory and -d $multifasta_base_directory
MC/DC50%1/2
defined $multifasta_base_directory and -d $multifasta_base_directory
defined $multifasta_base_directory
-d $multifasta_base_directory
Truth table66%2/3
A and B
A= defined $multifasta_base_directoryB= -d $multifasta_base_directory
| |||||||||||||||||||||||||||||
| 54 | 2 | $self->multifasta_base_directory( abs_path($multifasta_base_directory)); | |||||||||||||||||||||||||||
| 55 | } | ||||||||||||||||||||||||||||
| 56 | 3 | ▶ | if(! -d $self->multifasta_base_directory ) | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 57 | { | ||||||||||||||||||||||||||||
| 58 | 1 | $self->_error_message("Error: Cant access the multifasta base directory: ".$self->multifasta_base_directory); | |||||||||||||||||||||||||||
| 59 | } | ||||||||||||||||||||||||||||
| 60 | |||||||||||||||||||||||||||||
| 61 | 3 | ▶ | if ( defined($spreadsheet_filename) && ( -e $spreadsheet_filename ) ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
defined $spreadsheet_filename and -e $spreadsheet_filename
MC/DC50%1/2
defined $spreadsheet_filename and -e $spreadsheet_filename
defined $spreadsheet_filename
-e $spreadsheet_filename
Truth table66%2/3
A and B
A= defined $spreadsheet_filenameB= -e $spreadsheet_filename
| |||||||||||||||||||||||||||||
| 62 | 2 | $self->spreadsheet_filename( abs_path($spreadsheet_filename)); | |||||||||||||||||||||||||||
| 63 | } | ||||||||||||||||||||||||||||
| 64 | 3 | ▶ | if(! -e $self->spreadsheet_filename ) | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 65 | { | ||||||||||||||||||||||||||||
| 66 | 1 | $self->_error_message("Error: Cant access the spreadsheet: ".$self->spreadsheet_filename); | |||||||||||||||||||||||||||
| 67 | } | ||||||||||||||||||||||||||||
| 68 | 3 | ▶ | $self->output_filename( $output_filename ) if ( defined($output_filename) ); | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 69 | 3 | ▶ | if ( defined($core_definition) ) | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 70 | { | ||||||||||||||||||||||||||||
| 71 | 1 | ▶ | if($core_definition > 1) | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 72 | { | ||||||||||||||||||||||||||||
| 73 | 0 | $self->core_definition( $core_definition/100 ); | |||||||||||||||||||||||||||
| 74 | } | ||||||||||||||||||||||||||||
| 75 | else | ||||||||||||||||||||||||||||
| 76 | { | ||||||||||||||||||||||||||||
| 77 | 1 | $self->core_definition( $core_definition ); | |||||||||||||||||||||||||||
| 78 | } | ||||||||||||||||||||||||||||
| 79 | } | ||||||||||||||||||||||||||||
| 80 | 3 | ▶ | $self->dont_delete_files($dont_delete_files) if ( defined($dont_delete_files) ); | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 81 | |||||||||||||||||||||||||||||
| 82 | } | ||||||||||||||||||||||||||||
| 83 | |||||||||||||||||||||||||||||
| 84 | 3 | ▶ | sub run { | ||||||||||||||||||||||||||
|
Subroutine
run: called CC=4 SCAR=14.2
Pod
undocumented
| |||||||||||||||||||||||||||||
| 85 | 3 | my ($self) = @_; | |||||||||||||||||||||||||||
| 86 | |||||||||||||||||||||||||||||
| 87 | 3 | ▶ | ( !$self->help ) or die $self->usage_text; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 88 | 2 | ▶ | if ( defined( $self->_error_message ) ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 89 | 0 | print $self->_error_message . "\n"; | |||||||||||||||||||||||||||
| 90 | 0 | die $self->usage_text; | |||||||||||||||||||||||||||
| 91 | } | ||||||||||||||||||||||||||||
| 92 | |||||||||||||||||||||||||||||
| 93 | 2 | $self->logger->info("Extract core genes from spreadsheet"); | |||||||||||||||||||||||||||
| 94 | 2 | my $core_genes_obj = Bio::Roary::ExtractCoreGenesFromSpreadsheet->new( | |||||||||||||||||||||||||||
| 95 | spreadsheet => $self->spreadsheet_filename, | ||||||||||||||||||||||||||||
| 96 | core_definition => $self->core_definition, | ||||||||||||||||||||||||||||
| 97 | allow_paralogs => $self->allow_paralogs | ||||||||||||||||||||||||||||
| 98 | ); | ||||||||||||||||||||||||||||
| 99 | |||||||||||||||||||||||||||||
| 100 | 2 | $self->logger->info("Looking up genes in files"); | |||||||||||||||||||||||||||
| 101 | 2 | my $gene_files = Bio::Roary::LookupGeneFiles->new( | |||||||||||||||||||||||||||
| 102 | multifasta_directory => $self->multifasta_base_directory, | ||||||||||||||||||||||||||||
| 103 | ordered_genes => $core_genes_obj->ordered_core_genes, | ||||||||||||||||||||||||||||
| 104 | ); | ||||||||||||||||||||||||||||
| 105 | |||||||||||||||||||||||||||||
| 106 | 2 | $self->logger->info("Merge multifasta alignments"); | |||||||||||||||||||||||||||
| 107 | 2 | my $merge_alignments_obj = Bio::Roary::MergeMultifastaAlignments->new( | |||||||||||||||||||||||||||
| 108 | sample_names => $core_genes_obj->sample_names, | ||||||||||||||||||||||||||||
| 109 | multifasta_files => $gene_files->ordered_gene_files(), | ||||||||||||||||||||||||||||
| 110 | output_filename => $self->output_filename, | ||||||||||||||||||||||||||||
| 111 | sample_names_to_genes => $core_genes_obj->sample_names_to_genes | ||||||||||||||||||||||||||||
| 112 | ); | ||||||||||||||||||||||||||||
| 113 | 2 | $merge_alignments_obj->merge_files; | |||||||||||||||||||||||||||
| 114 | |||||||||||||||||||||||||||||
| 115 | 2 | ▶ | if($self->dont_delete_files == 0) | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 116 | { | ||||||||||||||||||||||||||||
| 117 | 2 | remove_tree('pan_genome_sequences'); | |||||||||||||||||||||||||||
| 118 | } | ||||||||||||||||||||||||||||
| 119 | } | ||||||||||||||||||||||||||||
| 120 | |||||||||||||||||||||||||||||
| 121 | 1 | ▶ | sub usage_text { | ||||||||||||||||||||||||||
|
Subroutine
usage_text: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||||||||||||||||||||
| 122 | 1 | my ($self) = @_; | |||||||||||||||||||||||||||
| 123 | |||||||||||||||||||||||||||||
| 124 | 1 | return <<USAGE; | |||||||||||||||||||||||||||
| 125 | Usage: pan_genome_core_alignment [options] | ||||||||||||||||||||||||||||
| 126 | Create an alignment of core genes from the spreadsheet and the directory of gene multi-FASTAs. | ||||||||||||||||||||||||||||
| 127 | |||||||||||||||||||||||||||||
| 128 | Options: -o STR output filename [core_gene_alignment.aln] | ||||||||||||||||||||||||||||
| 129 | -cd FLOAT percentage of isolates a gene must be in to be core [99] | ||||||||||||||||||||||||||||
| 130 | -m STR directory containing gene multi-FASTAs [pan_genome_sequences] | ||||||||||||||||||||||||||||
| 131 | -s STR gene presence and absence spreadsheet [gene_presence_absence.csv] | ||||||||||||||||||||||||||||
| 132 | -p allow paralogs | ||||||||||||||||||||||||||||
| 133 | -z dont delete intermediate files | ||||||||||||||||||||||||||||
| 134 | -v verbose output to STDOUT | ||||||||||||||||||||||||||||
| 135 | -h this help message | ||||||||||||||||||||||||||||
| 136 | |||||||||||||||||||||||||||||
| 137 | For further info see: http://sanger-pathogens.github.io/Roary/ | ||||||||||||||||||||||||||||
| 138 | USAGE | ||||||||||||||||||||||||||||
| 139 | } | ||||||||||||||||||||||||||||
| 140 | |||||||||||||||||||||||||||||
| 141 | 1 | __PACKAGE__->meta->make_immutable; | |||||||||||||||||||||||||||
| 142 | 1 | ▶ | no Moose; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 143 | 1 | 1; | |||||||||||||||||||||||||||
| 144 | |||||||||||||||||||||||||||||
| 145 | __END__ | ||||||||||||||||||||||||||||