lib/Bio/MUST/Drivers/Cap3.pm

filter: Statementstmt 54.9% 50 / 91 Branchbran 0.0% 0 / 12 Conditioncond 0.0% 0 / 3 MC/DCmcdc 0.0% 0 / 2 Subroutinesub 87.5% 14 / 16 Podpod 0.0% 0 / 1 totaltotal 51.2% 64 / 125 CC 9 SCAR 35.4
CC
9
Cov
47%
BUILD
90.0
__ANON__
2.0
BEGIN
1.0
CRAP 34.4
« lib/Bio/MUST/Drivers/Roles/Hmmerable.pm ↑ Summary lib/Bio/MUST/Drivers/Blast/Database.pm »
1 package Bio::MUST::Drivers::Cap3;
2 # ABSTRACT: Bio::MUST driver for running the CAP3 assembly program
3 5 $Bio::MUST::Drivers::Cap3::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 # use Smart::Comments;
11  
12 5 ▶use Carp;
Subroutine BEGIN: called CC=1 SCAR=0.0
13 5 ▶use IPC::System::Simple qw(system);
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 5 ▶use Tie::IxHash;
Subroutine BEGIN: called CC=1 SCAR=0.0
17  
18 5 ▶use Bio::MUST::Core;
Subroutine BEGIN: called CC=1 SCAR=0.0
19 5 extends 'Bio::MUST::Core::Ali::Temporary';
20  
21 5 ▶use Bio::MUST::Core::Constants qw(:files);
Subroutine BEGIN: called CC=1 SCAR=0.0
22 5 ▶use aliased 'Bio::MUST::Core::Ali';
Subroutine BEGIN: called CC=1 SCAR=0.0
23 5 ▶use aliased 'Bio::MUST::Core::SeqId';
Subroutine BEGIN: called CC=1 SCAR=0.0
24  
25 5 ▶use Bio::MUST::Drivers::Utils qw(stringify_args);
Subroutine BEGIN: called CC=1 SCAR=0.0
26  
27  
28 has 'cap3_args' => (
29 is => 'ro',
30 isa => 'HashRef',
31 0 ▶ default => sub { {} },
Subroutine __ANON__: not called CC=1 SCAR=6.9
32 5 );
33  
34 5 has '_contig_seq_ids' => (
35 traits => ['Hash'],
36 is => 'ro',
37 isa => 'HashRef[ArrayRef[Bio::MUST::Core::SeqId]]',
38 init_arg => undef,
39 writer => '_set_contig_seq_ids',
40 handles => {
41 all_contig_names => 'keys',
42 all_contig_seq_ids => 'values',
43 seq_ids_for => 'get',
44 },
45 );
46  
47 5 has '_contigs' => (
48 is => 'ro',
49 isa => 'Bio::MUST::Core::Ali',
50 init_arg => undef,
51 writer => '_set_contigs',
52 handles => {
53 all_contigs => 'all_seqs',
54 count_contigs => 'count_seqs',
55 },
56 );
57  
58 5 has '_singlets' => (
59 is => 'ro',
60 isa => 'Bio::MUST::Core::Ali',
61 init_arg => undef,
62 writer => '_set_singlets',
63 handles => {
64 all_singlets => 'all_seqs',
65 count_singlets => 'count_seqs',
66 },
67 );
68  
69  
70 0 ▶sub BUILD {
Subroutine BUILD: not called CC=9 SCAR=45.0
Pod undocumented
71 0 my $self = shift;
72  
73 # provision executable
74 0 my $app = use_module('Bio::MUST::Provision::Cap3')->new;
75 0 $app->meet();
76  
77 # setup output files
78 0 my $infile = $self->filename;
79 0 my $basename = $infile . '.cap';
80 0 my $outfile = $basename . '.out';
81 0 my $outfile_contigs = $basename . '.contigs';
82 0 my $outfile_singlets = $basename . '.singlets';
83  
84 # format CAP3 (optional) arguments
85 0 my $args = $self->cap3_args;
86 0 my $args_str = stringify_args($args);
87  
88 # create CAP3 command
89 0 my $pgm = 'cap3';
90 0 my $cmd = "$pgm $infile $args_str > $outfile 2> /dev/null";
91 #### $cmd
92  
93 # try to robustly execute CAP3
94 0 my $ret_code = system( [ 0, 127 ], $cmd);
95 0 ▶ if ($ret_code == 127) {
Branch: 1 branch
BranchTrueFalseTotal
if ($ret_code == 127) 0 0 0
96 0 carp "[BMD] Warning: cannot execute $pgm command;"
97 . ' returning without contigs!';
98 0 return;
99 }
100 # TODO: try to bypass shell (need for absolute path to executable then)
101  
102 # parse output file
103 0 open my $out, '<', $outfile;
104 0 tie my %ids_for, 'Tie::IxHash';
105 0 my $contig_id;
106  
107 # CAP3 output file extract
108 #
109 # Number of segment pairs = 342; number of pairwise comparisons = 8
110 # '+' means given segment; '-' means reverse complement
111 #
112 # Overlaps Containments No. of Constraints Supporting Overlap
113 #
114 # ******************* Contig 1 ********************
115 # seq8+
116 # seq9+ is in seq8+
117 # ******************* Contig 2 ********************
118 # seq10+
119 # seq11+
120 # ******************* Contig 3 ********************
121 # seq12+
122 # seq13+ is in seq12+
123 # seq14+ is in seq13+
124 # ******************* Contig 4 ********************
125 # seq15+
126 # seq16+
127 # ******************* Contig 5 ********************
128 # seq17+
129 # seq18+
130 # seq19+ is in seq18+
131 #
132 # DETAILED DISPLAY OF CONTIGS
133 # ******************* Contig 1 ********************
134 # . : . : . : . : . : . :
135 # seq8+ CTGGACGAGCTGCAGGAGGAGGCGCTGGCGCTGGTGGCGCAGGCCCGACGAGAGGGCGAC
136 # ____________________________________________________________
137 # consensus CTGGACGAGCTGCAGGAGGAGGCGCTGGCGCTGGTGGCGCAGGCCCGACGAGAGGGCGAC
138 #
139 # ...
140  
141 LINE:
142 0 ▶ while (my $line = <$out>) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined(my $line = readline $out)) 0 0 0
143 0 chomp $line;
144  
145 0 ▶ next LINE if $line =~ $EMPTY_LINE;
Branch: 1 branch
BranchTrueFalseTotal
if $line =~ /$Bio::MUST::Drivers::Cap3::EMPTY_LINE/ 0 0 0
146 0 ▶ last LINE if $line =~ m{\A DETAILED \s+ DISPLAY \s+ OF \s+ CONTIGS}xms;
Branch: 1 branch
BranchTrueFalseTotal
if $line =~ /\A DETAILED \s+ DISPLAY \s+ OF \s+ CONTIGS/msx 0 0 0
147  
148 # capture next contig id
149 0 ▶ if ($line =~ m{\A \*+ \s+ (Contig\s+\d+) \s+ \*+}xms) {
Branch: 2 branches
BranchTrueFalseTotal
if ($line =~ /\A \*+ \s+ (Contig\s+\d+) \s+ \*+/msx) { } 0 0 0
elsif ($line =~ /\A ([^\'\+\-\ ]+)[+-]/msx or $line =~ /\A \s+ (\S+?)[+-]/msx) { } 0 0 0
150 0 ($contig_id = $1) =~ tr/ //d;
151 }
152  
153 # capture fragment ids for current contig...
154 ▶ elsif ($line =~ m{\A ([^\'\+\-\ ]+)[+-]}xms
Condition0%0/3
$line =~ /\A ([^\'\+\-\ ]+)[+-]/msx or $line =~ /\A \s+ (\S+?)[+-]/msx
l!l&&r!l&&!r
000
MC/DC0%0/2
$line =~ /\A ([^\'\+\-\ ]+)[+-]/msx or $line =~ /\A \s+ (\S+?)[+-]/msx
$line =~ /\A ([^\'\+\-\ ]+)[+-]/msx $line =~ /\A \s+ (\S+?)[+-]/msx
Truth table0%0/3
A or B
A= $line =~ /\A ([^\'\+\-\ ]+)[+-]/msxB= $line =~ /\A \s+ (\S+?)[+-]/msx
ABresult
1X1
011
000
155 || $line =~ m{\A \s+ (\S+?)[+-]}xms) {
156 0 my $fragment_id = $1;
157 0 push @{ $ids_for{$contig_id} },
158 SeqId->new( full_id => $self->long_id_for($fragment_id) );
159 } # ... and restore original id on the fly from IdMapper
160 }
161  
162 # store contig and fragment ids
163 0 $self->_set_contig_seq_ids(\%ids_for);
164  
165 # read and store contig seqs
166 0 my $contigs = Ali->load($outfile_contigs);
167 0 $contigs->dont_guess;
168 0 $self->_set_contigs($contigs);
169  
170 # read and store singlet seqs...
171 0 my $singlets = Ali->load($outfile_singlets);
172 0 $singlets->dont_guess;
173 0 $singlets->restore_ids($self->mapper); # ... restoring original ids
174 0 $self->_set_singlets($singlets);
175  
176 # unlink temp files
177 my @files2rm = (
178 $outfile, $outfile_contigs, $outfile_singlets,
179 0 map { $basename . '.' . $_ } qw(info ace contigs.links contigs.qual)
180 );
181 0 file($_)->remove for @files2rm;
182  
183 0 return;
184 }
185  
186 5 __PACKAGE__->meta->make_immutable;
187 5 1;
188  
189 __END__
« lib/Bio/MUST/Drivers/Roles/Hmmerable.pm ↑ Summary lib/Bio/MUST/Drivers/Blast/Database.pm »