2015-10-12 07:15:08 -03:00
|
|
|
#!/bin/bash
|
|
|
|
#
|
|
|
|
# Reverse complement a fasta formated alignment
|
|
|
|
#
|
|
|
|
#========================================================================================
|
|
|
|
|
|
|
|
# -- CAUTION -- Works as long than the script
|
|
|
|
# is not called through a symlink
|
2015-11-08 14:28:57 +01:00
|
|
|
THIS_DIR="$(dirname ${BASH_SOURCE[0]})"
|
|
|
|
source "${THIS_DIR}/../../../scripts/bash_init.sh"
|
2015-10-12 07:15:08 -03:00
|
|
|
|
|
|
|
|
|
|
|
function revcomp {
|
2025-03-01 16:15:28 +01:00
|
|
|
$AwkCmd 'function printfasta(seq) { \
|
2015-10-12 07:15:08 -03:00
|
|
|
seqlen=length(seq); \
|
|
|
|
for (i=1; i <= seqlen; i+=60) \
|
|
|
|
print substr(seq,i,60); \
|
|
|
|
} \
|
|
|
|
function comp(seq) { \
|
|
|
|
"echo "seq" | tr acgtACGT tgcaTGCA " | getline res; \
|
|
|
|
close("echo "seq" | tr acgtACGT tgcaTGCA "); \
|
|
|
|
return res; \
|
|
|
|
} \
|
|
|
|
function rev(seq) { \
|
|
|
|
"echo "seq" | rev " | getline res; \
|
|
|
|
close("echo "seq" | rev "); \
|
|
|
|
return res; \
|
|
|
|
} \
|
|
|
|
function revcomp(seq) { \
|
|
|
|
res=rev(comp(seq)); \
|
|
|
|
return res; \
|
|
|
|
} \
|
|
|
|
\
|
|
|
|
(seq) && /^>/ {print head; \
|
|
|
|
printfasta(revcomp(seq)); \
|
|
|
|
seq=""} \
|
|
|
|
/^>/ {head=$0} \
|
|
|
|
! /^>/ {seq=seq$0} \
|
|
|
|
END { print head; \
|
|
|
|
printfasta(revcomp(seq)); \
|
|
|
|
}' $*
|
|
|
|
}
|
|
|
|
|
|
|
|
revcomp $*
|