lib/Bio/MUST/Drivers/Exonerate.pm

filter: Statementstmt 54.5% 54 / 99 Branchbran 0.0% 0 / 10 Conditioncond n/a MC/DCmcdc n/a Subroutinesub 68.1% 15 / 22 Podpod 0.0% 0 / 6 totaltotal 50.3% 69 / 137 CC 8 SCAR 26.9
CC
8
Cov
50%
BUILD
56.0
complete_cds
6.0
__ANON__
2.0
CRAP 14.8
« lib/Bio/MUST/Drivers/ClustalO.pm ↑ Summary lib/Bio/MUST/Drivers/Hmmer/Model/Temporary.pm »
1 package Bio::MUST::Drivers::Exonerate;
2 # ABSTRACT: Bio::MUST driver for running the Exonerate alignment program
3 5 $Bio::MUST::Drivers::Exonerate::VERSION = '0.252830';
4 5 ▶use Moose;
Subroutine BEGIN: called CC=1 SCAR=0.0
5 5 ▶use namespace::autoclean;
Subroutine BEGIN: called CC=1 SCAR=0.0
6  
7 5 ▶use autodie;
Subroutine BEGIN: called CC=1 SCAR=0.0
8 5 ▶use feature qw(say);
Subroutine BEGIN: called CC=1 SCAR=0.0
9  
10 5 ▶use Carp;
Subroutine BEGIN: called CC=1 SCAR=0.0
11 5 ▶use Const::Fast;
Subroutine BEGIN: called CC=1 SCAR=0.0
12 5 ▶use IPC::System::Simple qw(system);
Subroutine BEGIN: called CC=1 SCAR=0.0
13 5 ▶use List::AllUtils qw(mesh);
Subroutine BEGIN: called CC=1 SCAR=0.0
14 5 ▶use Module::Runtime qw(use_module);
Subroutine BEGIN: called CC=1 SCAR=0.0
15 5 ▶use Path::Class qw(file);
Subroutine BEGIN: called CC=1 SCAR=0.0
16  
17 5 ▶use Bio::MUST::Core;
Subroutine BEGIN: called CC=1 SCAR=0.0
18 5 ▶use aliased 'Bio::MUST::Core::Ali';
Subroutine BEGIN: called CC=1 SCAR=0.0
19 5 ▶use aliased 'Bio::MUST::Core::GeneticCode';
Subroutine BEGIN: called CC=1 SCAR=0.0
20 5 ▶use aliased 'Bio::MUST::Core::Seq';
Subroutine BEGIN: called CC=1 SCAR=0.0
21 5 ▶use aliased 'Bio::MUST::Drivers::Exonerate::Sugar';
Subroutine BEGIN: called CC=1 SCAR=0.0
22  
23  
24 5 has 'dna_seq' => (
25 is => 'ro',
26 isa => 'Bio::MUST::Core::Seq',
27 required => 1,
28 );
29  
30 5 has 'pep_seq' => (
31 is => 'ro',
32 isa => 'Bio::MUST::Core::Seq',
33 required => 1,
34 );
35  
36 5 has 'genetic_code' => (
37 is => 'ro',
38 isa => 'Bio::MUST::Core::GeneticCode',
39 required => 1,
40 );
41  
42 5 has '_ali' => (
43 is => 'ro',
44 isa => 'Bio::MUST::Core::Ali',
45 init_arg => undef,
46 writer => '_set_ali',
47 handles => {
48 all_cds => 'all_seqs',
49 count_cds => 'count_seqs',
50 },
51 );
52  
53 has '_sugars' => (
54 traits => ['Array'],
55 is => 'ro',
56 isa => 'ArrayRef[Bio::MUST::Drivers::Exonerate::Sugar]',
57 0 ▶ default => sub { [] },
Subroutine __ANON__: not called CC=1 SCAR=6.9
58 5 handles => {
59 add_sugar => 'push',
60 get_sugar => 'get',
61 },
62 );
63  
64  
65 5 const my @attrs => qw(
66 query_id query_start query_end query_strand
67 target_id target_start target_end target_strand
68 score
69 );
70  
71 0 ▶sub BUILD {
Subroutine BUILD: not called CC=7 SCAR=40.3
Pod undocumented
72 0 my $self = shift;
73  
74 # provision executable
75 0 my $app = use_module('Bio::MUST::Provision::Exonerate')->new;
76 0 $app->meet();
77  
78 # build temp Ali file for input DNA seq
79 0 my $dna = Ali->new(
80 seqs => [ $self->dna_seq ],
81 guessing => 0,
82 );
83 0 my $dnafile = $dna->temp_fasta;
84  
85 # build temp Ali file for input PEP seq
86 0 my $pep = Ali->new(
87 seqs => [ $self->pep_seq ],
88 guessing => 0,
89 );
90 0 my $pepfile = $pep->temp_fasta;
91  
92 # setup output file
93 0 my $outfile = $dnafile . '.exonerate.out';
94 # TODO: make outfile name more robust using File::Temp
95  
96 # create exonerate command
97 0 my $pgm = 'exonerate';
98 0 my $code = $self->genetic_code->ncbi_id;
99 0 my $cmd = qq{$pgm --ryo ">%S\\n%tcs" --showvulgar no}
100 . " --showalignment no --verbose 0 --geneticcode $code"
101 . " --model protein2genome --query $pepfile --target $dnafile"
102 . " > $outfile 2> /dev/null"
103 ;
104  
105 # try to robustly execute exonerate
106 0 my $ret_code = system( [ 0, 127 ], $cmd);
107 0 ▶ if ($ret_code == 127) {
Branch: 1 branch
BranchTrueFalseTotal
if ($ret_code == 127) 0 0 0
108 0 carp "[BMD] Warning: Cannot execute $pgm command; returning nothing!";
109 0 return;
110 }
111 # TODO: try to bypass shell (need for absolute path to executable then)
112  
113 # read output file (FASTA format with special defline)
114 0 my $ali = Ali->load($outfile);
115 0 $self->_set_ali($ali);
116  
117 # parse deflines and store them as Sugar objects
118 # TODO: fix coordinates for consistency with Aligned? (beware of rev_comp)
119 0 for my $id ($ali->all_seq_ids) {
120 0 my @fields = split /\s+/xms, $id->full_id;
121 0 $fields[0] = $self->pep_seq->seq_id->full_id;
122 0 $fields[4] = $self->dna_seq->seq_id->full_id;
123 @fields[3,7] = map {
124 0 ▶ $_ eq '-' ? -1 : # reverse
Branch: 3 branches
BranchTrueFalseTotal
$_ eq '-' ? : 0 0 0
$_ eq '+' ? : 0 0 0
$_ eq '.' ? : 0 0 0
125 $_ eq '+' ? 1 : # forward
126 $_ eq '.' ? 1 : # unknown
127 $_
128 } @fields[3,7];
129 0 $self->add_sugar( Sugar->new( { mesh @attrs, @fields } ) );
130 }
131 # TODO: check value of strands / gene orientation
132  
133 # unlink temp files
134 0 file($_)->remove for ($dnafile, $pepfile, $outfile);
135  
136 0 return;
137 }
138  
139  
140 0 ▶sub cds_order {
Subroutine cds_order: not called CC=1 SCAR=6.9
Pod undocumented
141 0 my $self = shift;
142  
143 # return exon indices according to start pos in protein coordinates
144 my @order = sort {
145 0 $self->get_sugar($a)->query_start <=> $self->get_sugar($b)->query_start
146 } 0..$self->count_cds-1;
147  
148 0 return @order;
149 }
150  
151  
152 0 ▶sub all_exons_in_order {
Subroutine all_exons_in_order: not called CC=1 SCAR=6.9
Pod undocumented
153 0 my $self = shift;
154 0 return @{ $self->_ali->seqs }[ $self->cds_order ];
155 }
156  
157  
158 0 ▶sub complete_cds {
Subroutine complete_cds: not called CC=2 SCAR=17.9
Pod undocumented
159 0 my $self = shift;
160  
161 # splice CDS from sorted exons
162 0 my $full_id = $self->dna_seq->full_id;
163 0 my $new_seq = join q{}, map { $_->seq } $self->all_exons_in_order;
164  
165 # warn of unexpected CDS length
166 0 ▶ carp "[BMD] Warning: spliced CDS length not a multiple of 3 for $full_id!"
Branch: 1 branch
BranchTrueFalseTotal
unless length($new_seq) % 3 == 0 0 0 0
167 unless length($new_seq) % 3 == 0;
168  
169 0 return Seq->new(seq_id => $full_id, seq => $new_seq);
170 }
171  
172  
173 0 ▶sub translation {
Subroutine translation: not called CC=1 SCAR=6.9
Pod undocumented
174 0 my $self = shift;
175  
176 # return translated protein from spliced CDS
177 0 return $self->genetic_code->translate($self->complete_cds);
178 }
179  
180  
181 0 ▶sub all_sugars_in_order {
Subroutine all_sugars_in_order: not called CC=1 SCAR=6.9
Pod undocumented
182 0 my $self = shift;
183 0 return @{ $self->_sugars }[ $self->cds_order ];
184 }
185  
186 5 __PACKAGE__->meta->make_immutable;
187 5 1;
188  
189 __END__
« lib/Bio/MUST/Drivers/ClustalO.pm ↑ Summary lib/Bio/MUST/Drivers/Hmmer/Model/Temporary.pm »