G'day mashuk,

Welcome to the Monastery.

[I appreciate this is your first post here. For future reference, please read "How do I post a question effectively?". Also consider the comments others have made in this thread.]

For demonstration purposes, I've truncated your DNA sequences to 20 characters. I believe what you're after is code something like this (pm_11131708_fasta_rev_comp.pl):

#!/usr/bin/env perl use strict; use warnings; use autodie; my $in_file = 'pm_11131708_in'; my $out_file = 'pm_11131708_out'; { open my $in_fh, '<', $in_file; open my $out_fh, '>', $out_file; while (<$in_fh>) { if (0 == index $_, '>') { print $out_fh $_; } else { chomp; my $rev = scalar reverse; $rev =~ y/ATGC/TACG/; print $out_fh "$rev\n"; } } }

Sample run:

$ cat pm_11131708_in >adbca3e TGCTCCCCACGCTTGCCTCT >4c2a958 TCCCCACGCTTTCGCGCTTC >0639b5b TCGCGCCTCAGTGTCCAACG $ ./pm_11131708_fasta_rev_comp.pl $ cat pm_11131708_out >adbca3e AGAGGCAAGCGTGGGGAGCA >4c2a958 GAAGCGCGAAAGCGTGGGGA >0639b5b CGTTGGACACTGAGGCGCGA

See also: autodie, open, index and reverse.

— Ken


In reply to Re: Perl code for reverse complement of DNA sequence by kcott
in thread Perl code for reverse complement of DNA sequence by mashuk

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.