Hi Perlmonks,

Recently, I posted a question about creating a column of frequencies for the unique entries of other column (http://www.perlmonks.com/?node_id=934469). Thanks for the valuable inputs. In the same script, I did some tweaking to reverse complement the sequence under $1 and then print it like before. I am able to get the results, but I am curious if there is another neat way to do the step.

#!usr/bin/perl use strict; use warnings; my $sequence='ABCD'; my @headings= qw/ Tags Frequency /; my $headings=join("\t",@headings); my @input_files=<*.seq>; foreach my $input_file (@input_files) { open INPUT, "<", $input_file or die "Cannot open file \"$input_fil +e\". $!"; (my $outfile = $input_file) =~ s/.seq/\.tag\.txt/i; my %freq; while (my $line=<INPUT>) { if ($line=~m/$sequence(.{11})(.{11})$sequence/i){ my $revcomp=reverse($1); $revcomp=~tr/ACGTacgt/TGCAtgca/; $freq{$_}++ for $revcomp, $2; } } close INPUT or die "Cannot close file \"$input_file\". $!"; open OUTPUT, ">", $outfile or die "Cannot open file \"$outfile\". + $!"; print OUTPUT $headings, "\n"; for my $tag (sort {$freq{$b} <=> $freq{$a}} keys %freq) { print OUTPUT $tag,"\t",$freq{$tag},"\n"; } close OUTPUT or die "Unable to close \"$outfile\". $!"; }

In reply to Reverse complement by bluray

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.