File Coverage

lib/Bio/Roary/CommandLine/GeneAlignmentFromNucleotides.pm
Criterion Covered Total %
statement 27 65 41.5
branch 0 18 0.0
condition 0 6 0.0
subroutine 9 12 75.0
pod 0 3 0.0
total 36 104 34.6


line stmt bran cond sub pod time code
1             undef $VERSION;
2             package Bio::Roary::CommandLine::GeneAlignmentFromNucleotides;
3             $Bio::Roary::CommandLine::GeneAlignmentFromNucleotides::VERSION = '3.11.0';
4             # ABSTRACT: Take in a multifasta file of nucleotides, convert to proteins and align with PRANK
5              
6              
7 1     1   449240 use Moose;
  1         8  
  1         8  
8 1     1   6341 use Getopt::Long qw(GetOptionsFromArray);
  1         7749  
  1         3  
9 1     1   408 use File::Copy;
  1         1692  
  1         44  
10 1     1   245 use Bio::Roary::AnnotateGroups;
  1         4  
  1         37  
11 1     1   373 use Bio::Roary::External::Prank;
  1         3  
  1         37  
12 1     1   405 use Bio::Roary::Output::GroupsMultifastaProtein;
  1         3  
  1         37  
13 1     1   397 use Bio::Roary::SortFasta;
  1         4  
  1         36  
14 1     1   375 use Bio::Roary::External::Mafft;
  1         3  
  1         484  
15             extends 'Bio::Roary::CommandLine::Common';
16              
17             has 'args' => ( is => 'ro', isa => 'ArrayRef', required => 1 );
18             has 'script_name' => ( is => 'ro', isa => 'Str', required => 1 );
19             has 'help' => ( is => 'rw', isa => 'Bool', default => 0 );
20              
21             has 'nucleotide_fasta_files' => ( is => 'rw', isa => 'ArrayRef' );
22             has '_error_message' => ( is => 'rw', isa => 'Str' );
23             has 'verbose' => ( is => 'rw', isa => 'Bool', default => 0 );
24             has 'mafft' => ( is => 'rw', isa => 'Bool', default => 0 );
25             has '_min_similarity' => ( is => 'rw', isa => 'Num', default => 0.98 );
26              
27             sub BUILD {
28 0     0 0   my ($self) = @_;
29              
30 0           my ( $nucleotide_fasta_files, $help, $verbose,$mafft, );
31              
32 0           GetOptionsFromArray(
33             $self->args,
34             'v|verbose' => \$verbose,
35             'n|mafft' => \$mafft,
36             'h|help' => \$help,
37             );
38              
39 0 0         if ( defined($verbose) ) {
40 0           $self->verbose($verbose);
41 0           $self->logger->level(10000);
42             }
43 0 0         $self->mafft($mafft) if (defined($mafft));
44 0 0         $self->help($help) if ( defined($help) );
45 0 0         if ( @{ $self->args } == 0 ) {
  0            
46 0           $self->_error_message("Error: You need to provide at least 1 FASTA file");
47             }
48              
49 0           for my $filename ( @{ $self->args } ) {
  0            
50 0 0         if ( !-e $filename ) {
51 0           $self->_error_message("Error: Cant access file $filename");
52 0           last;
53             }
54             }
55 0           $self->nucleotide_fasta_files( $self->args );
56             }
57              
58             sub run {
59 0     0 0   my ($self) = @_;
60              
61 0 0         ( !$self->help ) or die $self->usage_text;
62 0 0         if ( defined( $self->_error_message ) ) {
63 0           print $self->_error_message . "\n";
64 0           die $self->usage_text;
65             }
66              
67 0           for my $fasta_file ( @{ $self->nucleotide_fasta_files } ) {
  0            
68              
69 0           my $sort_fasta_before = Bio::Roary::SortFasta->new(
70             input_filename => $fasta_file,
71             make_multiple_of_three => 1,
72             );
73 0           $sort_fasta_before->sort_fasta->replace_input_with_output_file;
74              
75 0 0 0       if ( $sort_fasta_before->sequences_unaligned == 1 || $sort_fasta_before->sequences_unaligned == 0 && $sort_fasta_before->similarity <= $self->_min_similarity) {
      0        
76              
77 0 0         if ( $self->mafft == 1 ) {
78 0           my $mafft_obj = Bio::Roary::External::Mafft->new(
79             input_filename => $fasta_file,
80             output_filename => $fasta_file . '.aln',
81             job_runner => 'Local',
82             logger => $self->logger,
83             verbose => $self->verbose
84             );
85 0           $mafft_obj->run();
86             }
87             else {
88              
89 0           my $prank_obj = Bio::Roary::External::Prank->new(
90             input_filename => $fasta_file,
91             output_filename => $fasta_file . '.aln',
92             job_runner => 'Local',
93             logger => $self->logger,
94             verbose => $self->verbose
95             );
96 0           $prank_obj->run();
97             }
98             }
99             else {
100 0           move( $fasta_file, $fasta_file . '.aln' );
101             }
102              
103 0           my $sort_fasta_after_revtrans = Bio::Roary::SortFasta->new(
104             input_filename => $fasta_file . '.aln',
105             remove_nnn_from_end => 1,
106             );
107 0           $sort_fasta_after_revtrans->sort_fasta->replace_input_with_output_file;
108 0           unlink($fasta_file);
109             }
110             }
111              
112             sub usage_text {
113 0     0 0   my ($self) = @_;
114              
115 0           return <<USAGE;
116             Usage: protein_alignment_from_nucleotides [options] *.fa
117             Take in multi-FASTA files of nucleotides and align each file with PRANK or MAFFT
118              
119             Options: -n nucleotide alignment with MAFFT
120             -v verbose output to STDOUT
121             -h this help message
122              
123             For further info see: http://sanger-pathogens.github.io/Roary/
124             USAGE
125             }
126              
127             __PACKAGE__->meta->make_immutable;
128 1     1   8 no Moose;
  1         2  
  1         7  
129             1;
130              
131             __END__
132              
133             =pod
134              
135             =encoding UTF-8
136              
137             =head1 NAME
138              
139             Bio::Roary::CommandLine::GeneAlignmentFromNucleotides - Take in a multifasta file of nucleotides, convert to proteins and align with PRANK
140              
141             =head1 VERSION
142              
143             version 3.11.0
144              
145             =head1 SYNOPSIS
146              
147             Take in a multifasta file of nucleotides, convert to proteins and align with PRANK or MAFFT, reverse translate back to nucleotides
148              
149             =head1 AUTHOR
150              
151             Andrew J. Page <ap13@sanger.ac.uk>
152              
153             =head1 COPYRIGHT AND LICENSE
154              
155             This software is Copyright (c) 2013 by Wellcome Trust Sanger Institute.
156              
157             This is free software, licensed under:
158              
159             The GNU General Public License, Version 3, June 2007
160              
161             =cut