[Bio] / FigKernelScripts / run_glimmer3.pl Repository:
ViewVC logotype

Annotation of /FigKernelScripts/run_glimmer3.pl

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1.5 - (view) (download) (as text)

1 : overbeek 1.1 # -*- perl -*-
2 :    
3 : gdpusch 1.2 use strict;
4 :     use warnings;
5 : overbeek 1.1
6 : gdpusch 1.2 use FIG;
7 :     my $fig = FIG->new();
8 : overbeek 1.1
9 : gdpusch 1.2 $0 =~ m/([^\/]+)$/;
10 :     my $self = $1;
11 :     my $usage = "$self [-code=genetic_code_num] [-train=training_tbl[,training_contigs]] [-skip_called] Taxon_ID contigs";
12 :    
13 : gdpusch 1.3
14 :     #+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
15 :     #...PATH environment variables
16 :     #-----------------------------------------------------------------------
17 : gdpusch 1.4 my $elph_bin = $ENV{ELPH_BIN} || $FIG_Config::ext_bin;
18 :     my $glimmer_bin = $ENV{GLIMMER_3_BIN} || "$FIG_Config::ext_bin/../apps/glimmer3/bin";
19 :     my $glimmer_scripts = $ENV{GLIMMER_3_SCRIPTS} || "$FIG_Config::ext_bin/../apps/glimmer3/bin";
20 : gdpusch 1.3
21 :     #+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
22 :     #...Defaults for vars set during argument parsing
23 :     #-----------------------------------------------------------------------
24 :     my $genetic_code = 11; #...Default to the "standard" code
25 : gdpusch 1.2
26 :     my $train = qq(); #...Flag associated with '-train' switch
27 :     my $training_tbl = qq();
28 :     my $training_contigs = qq();
29 :    
30 : gdpusch 1.3 my $glimmeropts = qq(-o50 -g110 -t30); #...NOTE: Make these the default for a switch
31 : gdpusch 1.2
32 :     #+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
33 :     # NOTE: '-skip' is an obscure option introduced to handle one job
34 :     # for which new contigs had been added to a set of existing contigs,
35 :     # and it was required that we not re-call the existing contigs,
36 :     # but instead use their calls as the 'training set' for the new contigs.
37 :     # It seems quite unlikely that this option will ever be used again.
38 :     #-----------------------------------------------------------------------
39 :     my %skip; #...Hash storing already-called contig IDs to be skipped.
40 :     my $skip_called = qq(); #...Flag indicating whether '-skip' switch is present.
41 :    
42 :    
43 :     #+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
44 :     #... Parse argument list
45 :     #-----------------------------------------------------------------------
46 :     my $trouble = 0;
47 : overbeek 1.5 for (my $arg=$#ARGV; ($arg >= 0); $arg--)
48 : overbeek 1.1 {
49 : overbeek 1.5 if ($ARGV[$arg] =~ m/^-{1,2}code=(\d+)/) {
50 : gdpusch 1.2 $genetic_code = $1;
51 : overbeek 1.5 splice(@ARGV,$arg,1);
52 : overbeek 1.1 }
53 : overbeek 1.5 elsif ($ARGV[$arg] =~ m/^-{1,2}train=(\S+)/) {
54 : gdpusch 1.2 $train = $1;
55 :     ($training_tbl, $training_contigs) = split /,/, $train;
56 :    
57 :     if (-s $training_tbl) {
58 :     print STDERR "Training features will be taken from $training_tbl\n"
59 :     if $ENV{VERBOSE};
60 :     }
61 :     else {
62 :     $trouble = 1;
63 :     warn "Training tbl $training_tbl does not exist";
64 :     }
65 :    
66 :     if ($training_contigs) {
67 :     if (-s $training_contigs) {
68 :     print STDERR "Training set will be extracted from $training_contigs\n"
69 :     if $ENV{VERBOSE};
70 : overbeek 1.1 }
71 : gdpusch 1.2 else {
72 : overbeek 1.1 $trouble = 1;
73 : gdpusch 1.2 warn "Training contigs $training_contigs do not exist";
74 : overbeek 1.1 }
75 :     }
76 : gdpusch 1.2 else {
77 : overbeek 1.1 $trouble = 1;
78 :     warn "Training argument $train is invalid";
79 :     }
80 : overbeek 1.5 splice(@ARGV,$arg,1);
81 : overbeek 1.1 }
82 : overbeek 1.5 elsif ($ARGV[$arg] =~ m/^-{1,2}skip_called/) {
83 :     $skip_called = $ARGV[$arg];
84 : gdpusch 1.2 print STDERR "Skip option is set\n" if $ENV{VERBOSE};
85 : overbeek 1.5 splice(@ARGV,$arg,1);
86 : overbeek 1.1 }
87 : overbeek 1.5 elsif ($ARGV[$arg] =~ /^-/) {
88 : gdpusch 1.2 $trouble = 1;
89 : overbeek 1.5 warn "Unrecognized argument $ARGV[$arg]";
90 : overbeek 1.1 }
91 :     }
92 :    
93 : gdpusch 1.2 my $genetic_code_switch = qq(-z $genetic_code);
94 : overbeek 1.1
95 :    
96 : gdpusch 1.2 my $taxon_ID = qq();
97 :     my $contigs_file = qq();
98 : overbeek 1.1
99 : gdpusch 1.2 if (@ARGV == 2) {
100 :     ($taxon_ID, $contigs_file) = @ARGV;
101 :    
102 :     if ($taxon_ID && ($taxon_ID =~ m/^\d+\.\d+$/)) {
103 :     print STDERR "Taxon-ID is $taxon_ID\n" if $ENV{VERBOSE};
104 :     } else {
105 :     $trouble = 1;
106 :     warn "Bad Taxon-ID $taxon_ID\n";
107 : overbeek 1.1 }
108 :    
109 : gdpusch 1.2 if (-s $contigs_file) {
110 :     print STDERR "Contigs file is $contigs_file\n" if $ENV{VERBOSE};
111 :     } else {
112 :     $trouble = 1;
113 :     warn "Missing or zero-size contigs file $contigs_file";
114 : overbeek 1.1 }
115 :     }
116 : gdpusch 1.2 die "\n\tusage: $usage\n\n" if $trouble;
117 :    
118 :    
119 :    
120 :     #+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
121 :     # ... Initial Training Pass
122 :     #-----------------------------------------------------------------------
123 :     if (not $training_contigs) {
124 :     $training_contigs = $contigs_file;
125 :     }
126 :    
127 : gdpusch 1.3 my $tmp_prefix = "$FIG_Config::temp/tmp$$";
128 :     $fig->run("rm -f $tmp_prefix.*");
129 :    
130 :     my $tmp_contig = "$tmp_prefix.contig";
131 :     my $tmp_coords = "$tmp_prefix.coords";
132 :     my $tmp_train = "$tmp_prefix.train";
133 :     my $tmp_model = "$tmp_prefix.icm";
134 : gdpusch 1.2
135 :     my ($contig_id, $seqP);
136 :    
137 :     if (not $train) {
138 :     #+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
139 :     print STDERR "\nFinding training ORFs using GLIMMER default procedure\n"
140 :     if $ENV{VERBOSE};
141 :     #-----------------------------------------------------------------------
142 : overbeek 1.1 if (-s "$tmp_train") {
143 :     system("rm -f $tmp_train")
144 :     && die "Could not remove $tmp_train";
145 :     }
146 :    
147 :     open(CONTIGS, "<$training_contigs")
148 :     || die "could not read-open $training_contigs";
149 :    
150 : gdpusch 1.3 $training_tbl = "$tmp_prefix.train.tbl";
151 : gdpusch 1.2 open(TRAINING, ">$training_tbl") || die "Could not write-open $training_tbl";
152 :    
153 :     my $orf_num = 0;
154 :     my %len_of; #...Hash storing training contig lens
155 : overbeek 1.1 while (($contig_id, $seqP) = &read_fasta_record(\*CONTIGS))
156 :     {
157 :     $len_of{$contig_id} = length($$seqP);
158 :    
159 :     open( TMP, ">$tmp_contig") || die "Could not write-open $tmp_contig";
160 :     &display_id_and_seq($contig_id, $seqP, \*TMP);
161 :     close(TMP) || die "Could not close $tmp_contig";
162 :    
163 : gdpusch 1.2 print STDERR "\nScanning contig $contig_id for long orfs\n" if $ENV{VERBOSE};
164 :    
165 : gdpusch 1.3 system("$glimmer_bin/long-orfs -l -n -t 1.15 $genetic_code_switch $tmp_contig $tmp_coords")
166 : overbeek 1.1 && die "Could not extract training ORFs from contig $contig_id";
167 : gdpusch 1.3
168 :     system("$glimmer_bin/extract -t $tmp_contig $tmp_coords >> $tmp_train")
169 : overbeek 1.1 && die "Could not extract training sequences from contig $contig_id";
170 : gdpusch 1.2
171 :     #... Translate GLIMMER $tmp_coords into SEED $training_tbl
172 :     open(TMP_COORDS, "<$tmp_coords") || die "Could not read-open $tmp_coords";
173 :     print TRAINING map { ++$orf_num;
174 :     chomp $_;
175 :     my (undef, $beg, $end) = split /\s+/o, $_;
176 :     die "Bad coords in entry: $_" unless ($beg && $end);
177 :     my $fid = qq(orf) . (qq(0)x(5-length($orf_num))) . $orf_num;
178 :     my $loc = join(qq(_), ($contig_id, $beg, $end));
179 :     $_ = qq($fid\t$loc\n)
180 :     } <TMP_COORDS>;
181 :     }
182 :     close(TRAINING) || die "Could not close $training_tbl";
183 :     close(CONTIGS) || die "Could not close $contigs_file";
184 :     }
185 :    
186 :    
187 :     #+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
188 :     print STDERR ("\n",
189 :     "Training using:\n",
190 :     " contigs --- $training_contigs\n",
191 :     " ORFs --- $training_tbl\n"
192 :     )
193 :     if $ENV{VERBOSE};
194 :     #-----------------------------------------------------------------------
195 :     open(CONTIGS, "<$training_contigs")
196 :     || die "Could not read-open $training_contigs";
197 :    
198 :     my ($len_of, $seq_of);
199 :     while (($contig_id, $seqP) = &read_fasta_record(\*CONTIGS)) {
200 :     $len_of->{$contig_id} = length($$seqP);
201 :     $seq_of->{$contig_id} = $$seqP;
202 :     }
203 :     close(CONTIGS) || die "Could not close $contigs_file";
204 :    
205 :     my $entry;
206 :     my $orf_num;
207 :     my $max_orf_num = 0;
208 :     my %training_tbl;
209 :     open(TBL, "<$training_tbl") || die "Could not read-open $training_tbl";
210 :     open(TRAIN, ">$tmp_train") || die "Could not write-open $tmp_train";
211 :     while (defined($entry = <TBL>)) {
212 :     chomp $entry;
213 :     my ($fid, $locus) = split /\t/, $entry;
214 :    
215 :     if ($fid =~ m/(\d+)$/) {
216 :     $orf_num = $1;
217 :     $max_orf_num = ($orf_num > $max_orf_num) ? $orf_num : $max_orf_num;
218 :     }
219 :     else {
220 :     die "Could not parse FID $fid for training entry $.: $entry";
221 :     }
222 :    
223 :     #...If -skip_called option was selected, record which contigs are in the training set
224 :     if ($skip_called) { $skip{$contig_id} = 1; }
225 :    
226 :     my $training_seq = qq();
227 :     my @exons = split /,/, $locus;
228 :     foreach my $exon (@exons) {
229 :     if ($exon =~ m/^(\S+)_(\d+)_(\d+)/) {
230 :     my ($contig, $beg, $end) = ($1, $2, $3);
231 :    
232 :     my $contig_seq = $seq_of->{$contig};
233 :    
234 :     my $dna = &get_dna_seq($contig, $beg, $end, $len_of, $seq_of);
235 :    
236 :     $training_seq .= lc($dna);
237 :     }
238 :     else {
239 :     die "Could not parse exon $exon for training entry $.: $entry";
240 :     }
241 :    
242 :     my $training_ID = qq(orf) . (qq(0) x (5-length($orf_num))) . $orf_num;
243 :     &display_id_and_seq($training_ID, \$training_seq, \*TRAIN);
244 : overbeek 1.1 }
245 :     }
246 : gdpusch 1.2 close(TRAIN) || die "Could not close $tmp_train";
247 :     close(TBL) || die "Could not close $training_tbl";
248 : overbeek 1.1
249 : gdpusch 1.2 if (($_ = `grep -c "^>" $tmp_train`) && ($_ =~ m/^\s*(\d+)/)) {
250 :     print STDERR "\nExtracted $1 training sequences\n\n" if $ENV{VERBOSE};
251 : overbeek 1.1 }
252 : gdpusch 1.2 else {
253 : overbeek 1.1 die "\nCould not extract any training sequences";
254 :     }
255 :    
256 :    
257 : gdpusch 1.2
258 :     #+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
259 :     #... Build ICM (interpolated context model)
260 :     #-----------------------------------------------------------------------
261 :     print STDERR ("Building interpolated context model ---\n",
262 :     " output in $tmp_model\n\n"
263 :     ) if $ENV{VERBOSE};
264 :    
265 :     if (-s "$tmp_model") {
266 : overbeek 1.1 system("rm -f $tmp_model") && die "Could not remove $tmp_model";
267 :     }
268 :    
269 : gdpusch 1.3 $fig->run("$glimmer_bin/build-icm -r $tmp_model < $tmp_train");
270 : gdpusch 1.2
271 :    
272 :    
273 :     #+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
274 :     #... First GLIMMER pass
275 :     #-----------------------------------------------------------------------
276 :     print STDERR "Running first GLIMMER pass\n" if $ENV{VERBOSE};
277 : gdpusch 1.3 $fig->run("$glimmer_bin/glimmer3 $glimmeropts $contigs_file $tmp_model $tmp_prefix.pass_1");
278 : gdpusch 1.2
279 : overbeek 1.1
280 : gdpusch 1.2
281 :     #+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
282 :     #... Extract upstream regions and START codon counts
283 :     #-----------------------------------------------------------------------
284 : gdpusch 1.3 my $tmp_predictions_pass_1 = "$tmp_prefix.pass_1.predict";
285 : gdpusch 1.2 print STDERR "\nExtracting upstream regions and START counts from $tmp_predictions_pass_1\n"
286 :     if $ENV{VERBOSE};
287 :    
288 :     open(PREDICT, "<$tmp_predictions_pass_1")
289 :     || die "Could not read-open $tmp_predictions_pass_1";
290 :    
291 : gdpusch 1.3 my $tmp_upstream = "$tmp_prefix.upstream";
292 : gdpusch 1.2 open(UPSTREAM, ">$tmp_upstream")
293 :     || die "Could not write-open $tmp_upstream";
294 :    
295 :     my %start_counts; #...Hash to hold START codon counts
296 :    
297 :     $contig_id = qq();
298 :     while(defined($entry = <PREDICT>)) {
299 :     chomp $entry;
300 :    
301 :     if ($entry =~ m/^>(\S+)/) {
302 :     $contig_id = $1;
303 : overbeek 1.1 next;
304 :     }
305 : gdpusch 1.2 elsif ($entry =~ m/^(\S+)\s+(\d+)\s+(\d+)/) {
306 :     my ($id, $beg, $end) = ($1, $2, $3);
307 :    
308 :     my $sign = ($beg < $end) ? +1 : -1;
309 :    
310 :     my $end_start = $beg + $sign * 2;
311 :     my $start_codon = &get_dna_seq($contig_id, $beg, $end_start, $len_of, $seq_of);
312 :    
313 :     ++$start_counts{0};
314 :     ++$start_counts{$start_codon};
315 :    
316 :     my $up_id = $id;
317 :     $up_id =~ s/^orf/ups/o;
318 :     my $up_beg = $beg - $sign * 25;
319 :     my $up_end = $beg - $sign;
320 :    
321 :     my $up_seq;
322 :     if ($up_seq = &get_dna_seq($contig_id, $up_beg, $up_end, $len_of, $seq_of)) {
323 :     &display_id_and_seq($id, \$up_seq, \*UPSTREAM);
324 :     }
325 :     }
326 :     else {
327 :     die "Could not parse prediction $.: $entry";
328 :     }
329 :     }
330 :    
331 :     #+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
332 :     #... Compute pseudocount-stabilized START codon frequencies
333 :     #-----------------------------------------------------------------------
334 :     my $atg_freq = ($start_counts{atg} + 80) / ($start_counts{0} + 100);
335 :     my $gtg_freq = ($start_counts{gtg} + 15) / ($start_counts{0} + 100);
336 :     my $ttg_freq = ($start_counts{ttg} + 5) / ($start_counts{0} + 100);
337 :     my $start_freqs = "$atg_freq,$gtg_freq,$ttg_freq";
338 :    
339 :     print STDERR "start_freqs = $start_freqs\n\n" if $ENV{VERBOSE};
340 :    
341 :    
342 :     #+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
343 :     #... Build Position Weight Matrix for upstream regions using ELPH
344 :     #-----------------------------------------------------------------------
345 : gdpusch 1.4 print STDERR "\nExtracting upstream motifs from $tmp_predictions_pass_1\n";
346 :    
347 :     my $motif_width = 6;
348 :     my $tmp_motifs = "$tmp_prefix.motifs";
349 :     system("$elph_bin/elph $tmp_upstream LEN=$motif_width > $tmp_motifs")
350 :     && ((-s $tmp_motifs)
351 :     || die("Could not extract upstream motifs")
352 :     );
353 :    
354 :    
355 :     print STDERR "\nBuilding PWM from upstream motifs in $tmp_motifs\n";
356 :    
357 :     open( MOTIFS, "<$tmp_motifs") || die "Could not read-open $tmp_motifs";
358 :     my @motifs = <MOTIFS>;
359 :     close(MOTIFS) || die "Could not close $tmp_motifs";
360 :     while ($motifs[0] !~ m/^Motif counts/) { shift @motifs };
361 :     shift @motifs;
362 :     my $last = 0;
363 :     for (my $i=0; $i < @motifs; ++$i) {
364 :     last unless ($motifs[$i] =~ m/\S+/);
365 :     if ($motifs[$i] =~ m/^[acgt]:((\s+\d+){$motif_width})/) {
366 :     $last = $i;
367 :     }
368 :     }
369 :     $#motifs = $last;
370 : gdpusch 1.2
371 : gdpusch 1.3 my $tmp_matrix = "$tmp_prefix.pwm";
372 : gdpusch 1.4 open( MATRIX, ">$tmp_matrix") || die "Could not write-open $tmp_matrix";
373 :     print MATRIX "$motif_width\n";
374 :     foreach my $line (@motifs) {
375 :     chomp $line;
376 :     my @fields = split /\s+/, $line;
377 :     my $base = substr((shift @fields), 0, 1);
378 :     print MATRIX ($base, (map { sprintf(qq(%7u), $_) } @fields), qq(\n));
379 :     }
380 :     close(MATRIX) || die "Could not close $tmp_matrix";
381 :    
382 :     (-s $tmp_matrix) || die "Could not construct PWM --- empty file $tmp_matrix";
383 : gdpusch 1.2
384 :    
385 :    
386 :     #+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
387 :     #... Re-call PEGs using ICM and PWM
388 :     #-----------------------------------------------------------------------
389 :     print STDERR "Re-calling PEGs using trained ICM\n" if $ENV{VERBOSE};
390 :    
391 : gdpusch 1.3 $fig->run("$glimmer_bin/glimmer3 $glimmeropts -b $tmp_matrix -P $start_freqs $tmp_contig $tmp_model $tmp_prefix");
392 :    
393 : gdpusch 1.2
394 :    
395 :     #+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
396 :     #... Parse and write final predictions
397 :     # NOTE: Does not yet handle '-skip' option
398 :     #-----------------------------------------------------------------------
399 :     my $tmp_predictions = "$tmp_prefix.predict";
400 :     print STDERR "\nParsing $tmp_predictions\n"
401 :     if $ENV{VERBOSE};
402 :    
403 :     open(PREDICT, "<$tmp_predictions")
404 :     || die "Could not read-open $tmp_predictions";
405 :    
406 :     my $fid_num = 0;
407 :    
408 :     $contig_id = qq();
409 :     while(defined($entry = <PREDICT>)) {
410 :     chomp $entry;
411 : overbeek 1.1
412 : gdpusch 1.2 if ($entry =~ m/^>(\S+)/) {
413 :     $contig_id = $1;
414 :     next;
415 :     }
416 :     elsif ($entry =~ m/^(\S+)\s+(\d+)\s+(\d+)/) {
417 :     my ($id, $beg, $end) = ($1, $2, $3);
418 : overbeek 1.1
419 : gdpusch 1.2 if ($beg && $end) {
420 :     ++$fid_num;
421 :     my $fid = qq(fig|$taxon_ID.peg.) . $fid_num;
422 :     print STDOUT (qq($fid\t), join(qq(_), ($contig_id, $beg, $end)), qq(\n));
423 : overbeek 1.1 }
424 : gdpusch 1.2 else {
425 :     die "Error in $tmp_predictions line $.: $entry";
426 : overbeek 1.1 }
427 :     }
428 : gdpusch 1.2 else {
429 :     die "Could not parse prediction $.: $entry";
430 :     }
431 : overbeek 1.1 }
432 :    
433 : gdpusch 1.4 if (not $ENV{VERBOSE}) {
434 : gdpusch 1.3 $fig->run("rm -f $tmp_prefix.*");
435 :     }
436 : gdpusch 1.4 else {
437 :     print STDERR "\nKeeping tmp files\n\n";
438 :     }
439 : overbeek 1.1
440 :     exit 0;
441 :    
442 :    
443 : gdpusch 1.2 ########################################################################
444 :     sub get_dna_seq {
445 :     my ($contig, $beg, $end, $len_of, $seq_of) = @_;
446 :     my $dna = qq();
447 :    
448 :     my $contig_len = $len_of->{$contig};
449 :     my $contig_seq = $seq_of->{$contig};
450 :    
451 :     return undef if (&max($beg, $end) > $contig_len);
452 :     return undef if (&min($beg, $end) < 1);
453 :    
454 :     if ($beg < $end) {
455 :     $dna = substr($contig_seq, ($beg-1), ($end+1-$beg));
456 :     }
457 :     else {
458 :     $dna = substr($contig_seq, ($end-1), ($beg+1-$end));
459 :     $dna = $ { &rev_comp(\$dna) };
460 :     }
461 :    
462 :     return lc($dna);
463 :     }
464 :    
465 : overbeek 1.1
466 :     sub read_fasta_record
467 :     {
468 :     my ($file_handle) = @_;
469 :     my ( $old_end_of_record, $fasta_record, @lines, $head, $sequence, $seq_id, $comment, @parsed_fasta_record );
470 :    
471 :     if (not defined($file_handle)) { $file_handle = \*STDIN; }
472 :    
473 :     $old_end_of_record = $/;
474 :     $/ = "\n>";
475 :    
476 :     if (defined($fasta_record = <$file_handle>))
477 :     {
478 :     chomp $fasta_record;
479 :     @lines = split( /\n/, $fasta_record );
480 :     $head = shift @lines;
481 :     $head =~ s/^>?//;
482 :     $head =~ m/^(\S+)/;
483 :     $seq_id = $1;
484 :    
485 :     if ($head =~ m/^\S+\s+(.*)$/) { $comment = $1; } else { $comment = ""; }
486 :    
487 :     $sequence = join( "", @lines );
488 :    
489 :     @parsed_fasta_record = ( $seq_id, \$sequence, $comment );
490 :     }
491 :     else
492 :     {
493 :     @parsed_fasta_record = ();
494 :     }
495 :    
496 :     $/ = $old_end_of_record;
497 :    
498 :     return @parsed_fasta_record;
499 :     }
500 :    
501 :     sub display_id_and_seq
502 :     {
503 :     my( $id, $seq, $fh ) = @_;
504 :    
505 :     if (! defined($fh) ) { $fh = \*STDOUT; }
506 :    
507 :     print $fh ">$id\n";
508 :     &display_seq($seq, $fh);
509 :     }
510 :    
511 :     sub display_seq
512 :     {
513 :     my ( $seq, $fh ) = @_;
514 :     my ( $i, $n, $ln );
515 :    
516 :     if (! defined($fh) ) { $fh = \*STDOUT; }
517 :    
518 :     $n = length($$seq);
519 :     # confess "zero-length sequence ???" if ( (! defined($n)) || ($n == 0) );
520 :     for ($i=0; ($i < $n); $i += 60)
521 :     {
522 :     if (($i + 60) <= $n)
523 :     {
524 :     $ln = substr($$seq,$i,60);
525 :     }
526 :     else
527 :     {
528 :     $ln = substr($$seq,$i,($n-$i));
529 :     }
530 :     print $fh "$ln\n";
531 :     }
532 :     }
533 :    
534 :     sub rev_comp
535 :     {
536 :     my( $seqP ) = @_;
537 :     my( $rev );
538 :    
539 :     $rev = reverse( $$seqP );
540 :     $rev =~ tr/a-z/A-Z/;
541 :     $rev =~ tr/ACGTUMRWSYKBDHV/TGCAAKYWSRMVHDB/;
542 :     return \$rev;
543 :     }
544 :    
545 :     sub min { my ($x, $y) = @_; return (($x < $y) ? $x : $y); }
546 :    
547 :     sub max { my ($x, $y) = @_; return (($x > $y) ? $x : $y); }

MCS Webmaster
ViewVC Help
Powered by ViewVC 1.0.3