perl_n00b has asked for the wisdom of the Perl Monks concerning the following question:
If ^^ is not present I need to add it in with a new line character before the sequence.use strict; use warnings; my $dir = 'c:\seqs'; opendir(DIR,$dir) or die "unable to open directory $dir:$!"; foreach my $file ( grep{/\.seq$/ && -f "$dir/$_"}readdir DIR) { my $output_path = "$dir/$file.seq"; my $input_path = "$dir/$file"; open (my $in, '<', $input_path) or die "Unable to open $input_path: $!"; open (my $out, '>', $output_path) or die "Unable to open $output_path: $!"; while (<$in>) { my $locus =~ /LOCUS\s*(\w+)/; s/\^\^/>$locus\n^^\n/g; print $out $_; } close ($in); close ($out); unlink ($input_path) or die "unable to unlink $input_path: $!"; rename ($output_path, $input_path) or die "Unable to rename $output_path to $input_path:$!"; }
while (<$in>) { if $in =~ /^^/ { s/\^\^/\n^^/g; print $out $_; else { s/[a]|[c]|[t]|[g]{6}/^^\n }
while (<$in>) { my $locus =~ /LOCUS\s*(\w+)/; s/\^\^/>$locus\n^^\n/g; print $out $_; }
Created: Tuesday, July 12, 2005 4:17 PM LOCUS AJ877263 663 bp DNA linear INV 15 +-APR-2005
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Writing to file part deux
by ikegami (Patriarch) on Jul 23, 2009 at 18:25 UTC | |
by Anonymous Monk on Jul 23, 2009 at 23:25 UTC | |
by ikegami (Patriarch) on Jul 23, 2009 at 23:28 UTC | |
by Anonymous Monk on Jul 24, 2009 at 00:24 UTC | |
by ikegami (Patriarch) on Jul 24, 2009 at 00:31 UTC | |
|
Re: Writing to file part duex
by graff (Chancellor) on Jul 24, 2009 at 03:58 UTC | |
by Anonymous Monk on Jul 24, 2009 at 04:41 UTC |