-
Notifications
You must be signed in to change notification settings - Fork 0
/
rc
62 lines (56 loc) · 1.32 KB
/
rc
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
#!/bin/env bash
set -e
helpstr="RC - reverse-complement a nucleotide sequence or FASTA file.
Can handle base ambiguity codes.
Usage:
rc SEQUENCE
rc -f FILE
Options:
-f: Treat input as a filepath rather than a nucleotide sequence.
-h: Print this help message and exit.
"
unset filein input
while [ $OPTIND -le $# ]; do
while getopts "fh" opt; do
case "$opt" in
f)
filein="true"
;;
h)
echo "$helpstr"
exit
;;
*)
echo "Invalid argument:" $opt >&2
echo "$helpstr"
exit 1
esac
done
if [[ -z "$input" ]]; then
input=${@:$OPTIND:1}
OPTIND=$(expr $OPTIND + 1)
fi
done
shift $((OPTIND-1))
# Argument errors and warnings:
if [[ -z $input ]]; then
>&2 echo "Error: Input file or sequence required."
echo "$helpstr"
exit 1
fi
# Script:
in="[ATUGCatugcNnKMRYSWkmryswBVHDbvhdXx]"
to="[TAACGtaacgNnMKYRWSmkyrwsVBDHvbdhXx]"
if [[ -z $filein ]]; then
echo $input | tr "$in" "$to" | rev
else
while read line; do
nhead=$(echo "$line" | egrep '^>' | wc -l)
if [[ $nhead -ge 1 ]]; then
echo ${line}\|RC
else
echo $line | tr "$in" "$to" | rev
fi
done < $input
fi
exit