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


In reply to Re: Switching the Order of Lines by kcott
in thread Switching the Order of Lines by BeckyLynn

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.