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

Annotation of /FigKernelScripts/run_glimmer3.pl

Parent Directory Parent Directory | Revision Log Revision Log


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

MCS Webmaster
ViewVC Help
Powered by ViewVC 1.0.3