blib/lib/Bio/Tools/Run/Phrap.pm

filter: Statementstmt 100% 9 / 9 Branchbran n/a Conditioncond n/a MC/DCmcdc n/a Subroutinesub 100% 3 / 3 Podpod n/a totaltotal 100% 12 / 12 CC 1 SCAR 0.0
CC
1
Cov
100%
BEGIN
1.0
BEGIN
1.0
BEGIN
1.0
CRAP 1.0
« blib/lib/Bio/Tools/Run/Newbler.pm ↑ Summary blib/lib/Bio/Tools/Run/Phylo/Phylip/PhylipConf.pm »
1 # $Id$
2 #
3 # Phrap wraper module
4 #
5 # Please direct questions and support issues to <bioperl-l@bioperl.org>
6 #
7 # Cared for by Shawn Hoon
8 #
9 # Copyright Shawn Hoon
10 #
11 # You may distribute this module under the same terms as perl itself
12 #
13 # POD documentation - main docs before the code
14  
15 =head1 NAME
16  
17 Bio::Tools::Run::Phrap - a wrapper for running Phrap
18  
19 =head1 SYNOPSIS
20  
21 use Bio::Tools::Run::Phrap;
22 # Run Phrap using an input FASTA file
23 my $factory = Bio::Tools::Run::Phrap->new( -penalty => -2, -raw => 1 );
24 my $asm_obj = $factory->run($fasta_file, $qual_file);
25 # An assembly object is returned by default
26 for my $contig ($assembly->all_contigs) {
27 ... do something ...
28 }
29  
30 # Read some sequences
31 use Bio::SeqIO;
32 my $sio = Bio::SeqIO->new(-file => $fasta_file, -format => 'fasta');
33 my @seqs;
34 while (my $seq = $sio->next_seq()) {
35 push @seqs,$seq;
36 }
37  
38 # Run Phrap using input sequence objects and returning an assembly file
39 my $asm_file = 'results.phrap';
40 $factory->out_type($asm_file);
41 $factory->run(\@seqs);
42  
43  
44 =head1 DESCRIPTION
45  
46 Wrapper module for the Phrap assembly program
47 Phrap is available at: http://www.phrap.org/
48  
49 =head1 FEEDBACK
50  
51 =head2 Mailing Lists
52  
53 User feedback is an integral part of the evolution of this and other
54 Bioperl modules. Send your comments and suggestions preferably to one
55 of the Bioperl mailing lists. Your participation is much appreciated.
56  
57 bioperl-l@bioperl.org - General discussion
58 http://bioperl.org/wiki/Mailing_lists - About the mailing lists
59  
60 =head2 Support
61  
62 Please direct usage questions or support issues to the mailing list:
63  
64 I<bioperl-l@bioperl.org>
65  
66 rather than to the module maintainer directly. Many experienced and
67 reponsive experts will be able look at the problem and quickly
68 address it. Please include a thorough description of the problem
69 with code and data examples if at all possible.
70  
71 =head2 Reporting Bugs
72  
73 Report bugs to the Bioperl bug tracking system to help us keep track
74 the bugs and their resolution. Bug reports can be submitted via the
75 web:
76  
77 http://redmine.open-bio.org/projects/bioperl/
78  
79 =head1 AUTHOR - Shawn Hoon
80  
81 Email shawnh-at-stanford.edu
82  
83 =head1 APPENDIX
84  
85 The rest of the documentation details each of the object
86 methods. Internal methods are usually preceded with a _
87  
88 =cut
89  
90 package Bio::Tools::Run::Phrap;
91  
92 1 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
93 1 ▶use File::Copy;
Subroutine BEGIN: called CC=1 SCAR=0.0
94  
95 1 ▶use base qw(Bio::Root::Root Bio::Tools::Run::AssemblerBase);
Subroutine BEGIN: called CC=1 SCAR=0.0
96  
97 our $program_name = 'phrap';
98 our @program_params = (qw(penalty gap_init gap_ext ins_gap_ext del_gap_ext
99 matrix minmatch maxmatch max_group_size bandwidth minscore vector_bound masklevel
100 default_qual subclone_delim n_delim group_delim trim_start forcelevel
101 bypasslevel maxgap repeat_stringency node_seg node_space max_subclone_size
102 trim_penalty trim_score trim_qual confirm_length confirm_trim confirm_penalty
103 confirm_score indexwordsize));
104 our @program_switches = (qw(raw word_raw revise_greedy shatter_greedy preassemble
105 force_high retain_duplicates));
106 our %param_translation;
107 our $qual_param;
108 our $use_dash = 1;
109 our $join = ' ';
110 our $asm_format = 'phrap';
111  
112  
113 =head2 new
114  
115 Title : new
116 Usage : $factory = Bio::Tools::Run::Phrap->new(
117 -penalty => -2, # parameter option and value
118 -raw => 1 # flag (1=yes, 0=no)
119 );
120 Function: Create a new Phrap factory
121 Returns : A Bio::Tools::Run::Phrap object
122 Args : Phrap options available in this module:
123  
124 Option names & default values taken from the PHRAP manual:
125  
126 1. Scoring of pairwise alignments
127  
128 -penalty -2
129 Mismatch (substitution) penalty for SWAT comparisons.
130  
131 -gap_init penalty-2
132 Gap initiation penalty for SWAT comparisons.
133  
134 -gap_ext penalty-1
135 Gap extension penalty for SWAT comparisons.
136  
137 -ins_gap_ext gap_ext
138 Insertion gap extension penalty for SWAT comparisons (insertion in
139 subject relative to query).
140  
141 -del_gap_ext gap_ext
142 Deletion gap extension penalty for SWAT comparisons (deletion in
143 subject relative to query).
144  
145 -matrix [None]
146 Score matrix for SWAT comparisons (if present, supersedes -penalty)
147  
148 -raw *
149 Use raw rather than complexity-adjusted Smith-Waterman scores.
150  
151 2. Banded search
152  
153 -maxmatch 30
154 Maximum length of matching word. For cross_match, the default value
155 is equal to minmatch, instead of 30.
156  
157 -max_group_size 20
158 Group size (query file, forward strand words)
159  
160 -word_raw *
161 Use raw rather than complexity-adjusted word length, in testing
162 against minmatch (N.B. maxmatch always refer to raw lengths). (The
163 default is to adjust word length to reflect complexity of matching
164 sequence).
165  
166 -bandwidth 14
167 1/2 band width for banded SWAT searches (full width is 2 times
168 bandwidth + 1). Decreasing bandwidth also decreases running time at
169 the expense of sensitivity. Phrap assemblies of clones containing long
170 tandem repeats of a short repeat unit (< 30 bp) may be more accurately
171 assembled by decreasing -bandwidth; -bandwidth should be set such that
172 2 bandwidth + 1 is less than the length of a repeat unit. -bandwidth 0
173 can be used to find gap-free alignments.
174  
175 3. Filtering of matches
176  
177 -minscore 30
178 Minimum alignment score.
179  
180 -vector_bound 80
181 Number of potential vector bases at beginning of each read. Matches
182 that lie entirely within this region are assumed to represent vector
183 matches and are ignored. For cross_match, the default value is 0
184 instead of 80.
185  
186 -masklevel 80
187 (cross_match only). A match is reported only if at least (100 -
188 masklevel)% of the bases in its "domain" (the part of the query that
189 is aligned) are not contained within the domain of any higher-scoring
190 match.
191 Special cases:
192 -masklevel 0 report only the single highest scoring match for each query
193 -masklevel 100 report any match whose domain is not completely contained
194 within a higher scoring match
195 -masklevel 101 report all matches
196  
197 4. Input data interpretation
198  
199 -default_qual 15
200 Quality value to be used for each base, when no input .qual file is
201 provided. Note that a quality value of 15 corresponds to an error rate
202 of approximately 1 in 30 bases, i.e. relatively accurate sequence. If
203 you are using sequence that is substantially less accurate than this
204 and do not have phred-generated quality values you should be sure to
205 decrease the value of this parameter.
206  
207 -subclone_delim .
208 (phrap only). Subclone name delimiter: Character used to indicate end
209 of that part of the read name that corresponds to the subclone name
210  
211 -n_delim 1
212 (phrap only). Indicates which occurrence of the subclone delimiter
213 character denotes the end of the subclone name (so for example
214 -subclone_delim _ -n_delim 2
215 means that the end of the subclone name occurs at the
216 second occurrence of the character '_'). Must be the same for all
217 reads!
218  
219 -group_delim _
220 (phrap only). Group name delimiter: Character used to indicate end of
221 that part of the read name that corresponds to the group name
222 (relevant only if option -preassemble is used); this character must
223 occur before the subclone delimiter (else it has no effect, and the
224 read is not assigned to a group).
225  
226 -trim_start 0
227 (phrap only). No. of bases to be removed at beginning of each read.
228  
229 5. Assembly
230  
231 -forcelevel 0
232 (phrap only). Relaxes stringency to varying degree during final
233 contig merge pass. Allowed values are integers from 0 (most
234 stringent) to 10 (least stringent), inclusive.
235  
236 -bypasslevel 1
237 (phrap only). Controls treatment of inconsistent reads in merge.
238 Currently allowed values are 0 (no bypasses allowed; most stringent)
239 and 1 (a single conflicting read may be bypassed).
240  
241 -maxgap 30
242 (phrap only). Maximum permitted size of an unmatched region in
243 merging contigs, during first (most stringent) merging pass.
244  
245 -repeat_stringency .95
246 (phrap only). Controls stringency of match required for joins. Must
247 be less than 1 (highest stringency), and greater than 0 (lowest
248 stringency).
249  
250 -revise_greedy *
251 (phrap only). Splits initial greedy assembly into pieces at "weak
252 joins", and then tries to reattach them to give higher overall score.
253 Use of this option should correct some types of missassembly.
254  
255 -shatter_greedy *
256 (phrap only). Breaks assembly at weak joins (as with -revise_greedy)
257 but does not try to reattach pieces.
258  
259 -preassemble *
260 (phrap only). Preassemble reads within groups, prior to merging with
261 other groups. This is useful for example when the input data set
262 consists of reads from two distinct but overlapping clones, and it is
263 desired to assemble the reads from each clone separately before
264 merging in order to reduce the risk of incorrect joins due to
265 repeats. The preassemble merging pass is relatively stringent and not
266 guaranteed to merge all of the reads from a group.
267 Groups are indicated by the first part of the read name, up to the
268 character specified by -group_delim.
269  
270 -force_high *
271 (phrap only). Causes edited high-quality discrepancies to be ignored
272 during final contig merge pass. This option may be useful when it is
273 suspected that incorrect edits are causing a misassembly.
274  
275 6. Consensus sequence construction
276  
277 -node_seg 8
278 (phrap only). Minimum segment size (for purposes of traversing
279 weighted directed graph).
280  
281 -node_space 4
282 (phrap only). Spacing between nodes (in weighted directed graph).
283  
284 7. Output
285  
286 Not implemented in this Perl module.
287  
288 8. Miscellaneous
289  
290 -retain_duplicates *
291 (phrap only). Retain exact duplicate reads, rather than eliminating
292 them.
293  
294 -max_subclone_size 5000
295 (phrap only). Maximum subclone size -- for forward-reverse read pair
296 consistency checks.
297  
298 -trim_penalty -2
299 (phrap only). Penalty used for identifying degenerate sequence at
300 beginning & end of read.
301  
302 -trim_score 20
303 (phrap only). Minimum score for identifying degenerate sequence at
304 beginning & end of read.
305  
306 -trim_qual 13
307 (phrap only). Quality value used in to define the "high-quality" part
308 of a read, (the part which should overlap; this is used to adjust
309 qualities at ends of reads.
310  
311 -confirm_length 8
312 (phrap only). Minimum size of confirming segment (segment starts at
313 3d distinct nuc following discrepancy).
314  
315 -confirm_trim 1
316 (phrap only). Amount by which confirming segments are trimmed at
317 edges.
318  
319 -confirm_penalty -5
320 (phrap only). Penalty used in aligning against "confirming" reads.
321  
322 -confirm_score 30
323 (phrap only). Minimum alignment score for a read to be allowed to
324 "confirm" part of another read.
325  
326 -indexwordsize 10
327 Size of indexing (hashing) words, used in finding word matches
328 between sequences. The value of this parameter has a generally minor
329 effect on run time and memory usage.
330  
331 =cut
332  
333 sub new {
334 my ($class,@args) = @_;
335 my $self = $class->SUPER::new(@args);
336 $self->_set_program_options(\@args, \@program_params, \@program_switches, \%param_translation,
337 $qual_param, $use_dash, $join);
338 $self->program_name($program_name) if not defined $self->program_name();
339 $self->_assembly_format($asm_format);
340 return $self;
341 }
342  
343 =head2 out_type
344  
345 Title : out_type
346 Usage : $assembler->out_type('Bio::Assembly::ScaffoldI')
347 Function: Get/set the desired type of output
348 Returns : The type of results to return
349 Args : Desired type of results to return (optional):
350 'Bio::Assembly::IO' object
351 'Bio::Assembly::ScaffoldI' object (default)
352 The name of a file to save the results in
353  
354 =cut
355  
356  
357 =head2 run
358  
359 Title : run
360 Usage : $asm = $factory->run($fasta_file)
361 Function: Run Phrap
362 Returns : Assembly results (file, IO object or assembly object)
363 Args : - sequence input (FASTA file or sequence object arrayref)
364 - optional quality score input (QUAL file or quality score object
365 arrayref)
366 =cut
367  
368  
369 =head2 _run
370  
371 Title : _run
372 Usage : $factory->_run()
373 Function: Make a system call and run Phrap
374 Returns : An assembly file
375 Args : - FASTA file
376 - optional QUAL file
377  
378 =cut
379  
380 sub _run {
381 my ($self, $fasta_file, $qual_file) = @_;
382  
383 # Move quality file to proper place
384 my $tmp_qual_file = "$fasta_file.qual";
385 if ($qual_file && not -f $tmp_qual_file) {
386 $tmp_qual_file = "$fasta_file.qual"; # by Cap3 convention
387 link ($qual_file, $tmp_qual_file) or copy ($qual_file, $tmp_qual_file) or
388 $self->throw("Could not copy file '$qual_file' to '$tmp_qual_file': $!");
389 }
390  
391 # Setup needed files and filehandles
392 my ($output_fh, $output_file) = $self->_prepare_output_file( );
393  
394 # Get program executable
395 my $exe = $self->executable;
396  
397 # Get command-line options
398 my $options = join ' ', @{$self->_translate_params()};
399  
400 # Usage: phrap seq_file1 [seq_file2 ...] [-option value] [-option value] ...
401 my $str = "$exe $options $fasta_file 1> $output_file 2> /dev/null";
402 if ($self->verbose() >= 0) {
403 $self->debug( "$exe command = $str\n" );
404 };
405 my $status = system($str);
406 $self->throw( "Phrap call ($str) crashed: $? \n") unless $status==0;
407 close($output_fh);
408  
409 # Result files
410 my $log_file = "$fasta_file.log";
411 my $contigs_file = "$fasta_file.contigs";
412 my $problems_file = "$fasta_file.problems";
413 my $problems_qual_file = "$fasta_file.problems.qual";
414 my $contigs_qual_file = "$fasta_file.contigs.qual";
415 my $singlets_file = "$fasta_file.singlets";
416  
417 # Remove all files except for the PHRAP file
418 for my $file ($log_file, $contigs_file, $problems_file, $problems_qual_file,
419 $contigs_qual_file, $singlets_file, $tmp_qual_file) {
420 unlink $file;
421 }
422  
423 return $output_file;
424 }
425  
426 1;
« blib/lib/Bio/Tools/Run/Newbler.pm ↑ Summary blib/lib/Bio/Tools/Run/Phylo/Phylip/PhylipConf.pm »