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
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |