-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathbb.revcomp
executable file
·80 lines (68 loc) · 1.99 KB
/
bb.revcomp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
#!/usr/bin/perl
use strict;
use warnings;
#----------------------------------------------------------#
# Author: Douglas Senalik dsenalik@wisc.edu #
#----------------------------------------------------------#
# "Black Box" program series
=bb
pipe to reverse complement a raw sequence stream
=cut bb
my @stream = <>;
my $rc = revcompfasta ( join ( '', @stream ) );
print $rc;
exit 0;
############################################################
sub revcompfasta { my ( $dna ) = @_;
############################################################
# if stream is in fasta format, split on headers and only
# reverse complement the sequence. If in raw format, entire
# stream is reverse complemented
my @lines = split( /[\n\r]+/, $dna );
my $tmpseq = '';
my $outseq = '';
my $wasfasta = 0;
foreach my $aline ( split( /[\n\r]+/, $dna ) )
{
if ( $aline =~ m/^>/ )
{
if ( $tmpseq )
{
my $tmp = revcomp( $tmpseq );
$tmp =~ s/^\n+//;
$tmp =~ s/\n+$//;
$outseq .= $tmp;
$tmpseq = '';
}
if ( $outseq )
{ $outseq .= "\n"; }
$outseq .= $aline . "rc\n";
$wasfasta = 1;
}
else
{
if ( $tmpseq )
{ $tmpseq .= "\n"; }
$tmpseq .= $aline;
}
}
if ( $tmpseq )
{
my $tmp = revcomp( $tmpseq );
$tmp =~ s/^\n+//;
$tmp =~ s/\n+$//;
$outseq .= $tmp;
# no return at end of final sequence unless was in fasta format
if ( $wasfasta ) { $outseq .= "\n"; }
}
return( $outseq );
} # sub revcompfasta
############################################################
sub revcomp { my ( $dna ) = @_;
############################################################
# standard DNA reverse complement, including degenerate bases
my $revcomp = reverse ( $dna );
$revcomp =~ tr/AaCcTtGgMmRrYyKkVvHhDdBb/TtGgAaCcKkYyRrMmBbDdHhVv/;
return $revcomp;
} # sub revcomp
#eof