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

Annotation of /FigKernelScripts/run_glimmer3.pl

Parent Directory Parent Directory | Revision Log Revision Log


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

MCS Webmaster
ViewVC Help
Powered by ViewVC 1.0.3