in reply to Switching the Order of Lines
G'day BeckyLynn,
Welcome to the monastery.
I was unable to determine, from either your code or description, whether your input file contained one or many ">Sequence n" lines. The following code handles any number of such lines.
#!/usr/bin/env perl use strict; use warnings; use autodie; my ($in_file, $out_file) = qw{temp_in.txt temp_out.txt}; open my $in_fh, '<', $in_file; open my $out_fh, '>', $out_file; my @protein; while (<$in_fh>) { chomp; if (/^>(.*)$/) { print_reverse_decoy(\@protein, $out_fh); print $out_fh ">Reverse Decoy $1\n"; } else { push @protein, $_; } } print_reverse_decoy(\@protein, $out_fh); sub print_reverse_decoy { my ($protein, $out_fh) = @_; print $out_fh "$_\n" for map { scalar reverse split '' } reverse @ +$protein; @$protein = (); return; }
A test run with this input:
$ cat temp_in.txt >Sequence 1 ABCDEFG HIJKLMN >Sequence 2 OPQRST UVWXYZ >Sequence N 1234567890 !@#$%^&*()
Produces this output:
$ cat temp_out.txt >Reverse Decoy Sequence 1 NMLKJIH GFEDCBA >Reverse Decoy Sequence 2 ZYXWVU TSRQPO >Reverse Decoy Sequence N )(*&^%$#@! 0987654321
Notes:
-- Ken
|
|---|