Mike wrote:
>
> Well this is the final code I put together with everyones help from this
> group:
>
> #!/usr/bin/perl
> use warnings;
> use strict;
>
> print "Enter the path of the INFILE to be processed:\n";
> chomp (my $infile = <STDIN>);
> open(INFILE, $infile)
> or die "Can't open INFILE for input: $!";
> print "Enter in the path of the OUTFILE:\n";
> chomp (my $outfile = <STDIN>);
> open(OUTFILE, ">$outfile")
> or die "Can't open OUTFILE for input: $!";
> print "Enter in the LENGTH you want the sequence to be:\n";
> chomp (my $len = <STDIN>);
>
> my ($name, @seq);
> while ( <INFILE> ) {
> chomp;
> unless ( /^\s*$/ or s/^\s*>(.+)// ) {
> $name = $1;
> my @char = ( split( // ), ( '-' ) x ( $len - length ) );
> push @seq, ' '."@char $name";
> }
> }
>
> {
> local $" ="\n";
> print OUTFILE "R 1 [EMAIL PROTECTED]"; # The top of the file is
> supposed
>
> }
>
> close INFILE;
> close OUTFILE;
>
> [snip]
>
> However, I forgot that sometime the imput data is like this:
>
> >dog
> agatgtagt
> agtggttga
> agggagc
> >cat
> gcatcgatg
> agcatatgc
> >mouse
> actagcatc
> acgtacgat
>
> That is the sequence of letters can span multiple lines. I would like
> the above script to handle input data that can possibly span several
> lines as well as those that do not. and output as mentioned above.
You keep changing the specs Mike. :-) Based on your code and data above, this will
work:
#!/usr/bin/perl
use warnings;
use strict;
print "Enter the path of the INFILE to be processed: ";
chomp( my $infile = <STDIN> );
open INFILE, $infile or die "Can't open $infile for input: $!";
print "Enter in the path of the OUTFILE: ";
chomp( my $outfile = <STDIN> );
open OUTFILE, ">$outfile" or die "Can't open $outfile for output: $!";
print "Enter in the LENGTH you want the sequence to be: ";
my ( $len ) = <STDIN> =~ /(\d+)/ or die "Invalid length parameter";
print OUTFILE "R 1 $len\n\n"; # The top of the file is supposed
$/ = '>'; # Set input record separator
while ( <INFILE> ) {
chomp;
next unless s/^\s*(\S+)//;
my $name = $1;
my @char = ( /[acgt]/g, ( '-' ) x $len )[ 0 .. $len - 1 ];
print OUTFILE " @char $name\n";
}
close INFILE;
close OUTFILE;
__END__
John
--
use Perl;
program
fulfillment
--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]