-
Notifications
You must be signed in to change notification settings - Fork 5
/
reverse-complement.sh
61 lines (52 loc) · 1.7 KB
/
reverse-complement.sh
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
#!/bin/bash
#print the options
usage () {
echo ""
echo "This bash script can generate complement nucleotides in FASTA files - does not work on multi-fasta"
echo ""
echo "Usage: $0 [options] FASTAFILE > NEWFILENAME"
echo "Option:"
echo " -h print usage and exit"
echo " -a print author and exit"
echo " -v print version and exit"
echo ""
echo "Version 1.0"
echo "Author: Raymond Kiu [email protected]"
echo "";
}
version () { echo "version 1.0";}
author () { echo "Author: Raymond Kiu [email protected]";}
while getopts ':hav' opt;
do
case $opt in
h) usage; exit;;
a) author; exit;;
v) version; exit;;
\?) echo "Invalid option: -$OPTARG" >&2; exit 1;;
:) echo "Missing option argument for -$OPTARG" >&2; exit 1;;
*) echo "Unimplemented option: -$OPTARG" >&2; exit 1;;
esac
done
# skip over the processed options
shift $((OPTIND-1))
#check for mandatory positional parameters
if [ $# -lt 1 ]; then
echo ""
echo "This bash script can generate complement nucleotides in FASTA files"
echo ""
echo "Usage: $0 [options] FASTAFILE > NEWFILENAME"
echo "Option:"
echo " -h print usage and exit"
echo " -a print author and exit"
echo " -v print version and exit"
echo ""
echo "Version 1.0
echo "Author: Raymond Kiu [email protected]"
echo "";
exit 1
fi
#cat $1|grep "^[ATGCatgc]" |tr ACGTacgt TGCAtgca | rev
#cat $1 | while read L; do echo $L; read L; echo "$L" | tr "ATGC" "TACG"|tr "atgc" "tacg"|rev ; done
awk 'BEGIN{RS=">";FS="\n";a["T"]="A";a["A"]="T";a["C"]="G";a["G"]="C";a["N"]="N"}NR>1{for (i=2;i<=NF;i++) seq=seq""$i;for(i=length(seq);i!=0;i--) {k=substr(seq,i,1);x=x a[k]}; printf ">%s\n%s\n",$1,x}' $1
#cat $complement > $output
exit 1;