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

Annotation of /FigKernelScripts/run_glimmer3.pl

Parent Directory Parent Directory | Revision Log Revision Log


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

MCS Webmaster
ViewVC Help
Powered by ViewVC 1.0.3