-
Notifications
You must be signed in to change notification settings - Fork 15
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
1 changed file
with
74 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,74 @@ | ||
#!/usr/bin/perl | ||
use warnings; | ||
use strict; | ||
|
||
## fastx-rc -- reverse complement a sequence | ||
|
||
use Getopt::Long qw(:config auto_help pass_through); | ||
|
||
my $quiet = 0; | ||
|
||
sub rc { | ||
my ($seq) = @_; | ||
$seq =~ tr/ACGTUYRSWMKDVHBXN-/TGCAARYSWKMHBDVXN-/; | ||
# work on masked sequences as well | ||
$seq =~ tr/acgtuyrswmkdvhbxn/tgcaaryswkmhbdvxn/; | ||
return(scalar(reverse($seq))); | ||
} | ||
|
||
GetOptions("quiet!" => \$quiet) or | ||
die("Error in command line arguments"); | ||
|
||
# unknown commands are treated as identifiers | ||
my @files = (); | ||
while(@ARGV){ | ||
my $arg = shift(@ARGV); | ||
if(-f $arg){ | ||
push(@files, $arg); | ||
} | ||
} | ||
@ARGV = @files; | ||
|
||
my $inQual = 0; # false | ||
my $seqID = ""; | ||
my $qualID = ""; | ||
my $seq = ""; | ||
my $qual = ""; | ||
while(<>){ | ||
chomp; | ||
chomp; | ||
if(!$inQual){ | ||
if(/^(>|@)((.+?)( .*?\s*)?)$/){ | ||
my $newSeqID = $2; | ||
my $newShortID = $3; | ||
if($seqID){ | ||
if($qual){ | ||
printf("@%s [RC]\n%s\n+\n%s\n", $seqID, rc($seq), scalar(reverse($qual))); | ||
} else { | ||
printf(">%s [RC]\n%s\n", $seqID, rc($seq)); | ||
} | ||
} | ||
$seq = ""; | ||
$qual = ""; | ||
$seqID = $newSeqID; | ||
} elsif(/^\+(.*)$/) { | ||
$inQual = 1; # true | ||
$qualID = $1; | ||
} else { | ||
$seq .= $_; | ||
} | ||
} else { | ||
$qual .= $_; | ||
if(length($qual) >= length($seq)){ | ||
$inQual = 0; # false | ||
} | ||
} | ||
} | ||
|
||
if($seqID){ | ||
if($qual){ | ||
printf("@%s [rc]\n%s\n+\n%s\n", $seqID, rc($seq), scalar(reverse($qual))); | ||
} else { | ||
printf(">%s [rc]\n%s\n", $seqID, rc($seq)); | ||
} | ||
} |