-
Notifications
You must be signed in to change notification settings - Fork 1
/
revcomp
50 lines (41 loc) · 1.02 KB
/
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
#! /usr/bin/env bash
usage() {
cat <<EOF
[Usage] revcomp [mode] textfile > outfile
By default, outputs the reverse-complement. Use the first argument to specify a different mode of operation:
[r] or [reverse] for reverse only
[c] or [complement] for complement only
[Example] revcomp oligos.txt > revcomp_oligos.txt
[Example] revcomp reverse oligots.txt > reverse_oligos.txt
EOF
}
if [[ -z "$1" ]]; then
echo -e "\n Returns the reverse-complement of DNA bases in a text file."
usage
exit
fi
if [[ -z "$2" ]]; then
while IFS= read -r line
do
echo "$line" | tr 'ATCG' 'TAGC' | rev
done < "$1"
else
case "$1" in
reverse | r )
while IFS= read -r line
do
echo "$line" | rev
done < "$2"
;;
complement | c )
while IFS= read -r line
do
echo "$line" | tr 'ATCG' 'TAGC'
done < "$2"
;;
*)
echo "Invalid mode of operation: $1"
usage
;;
esac
fi