-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathdrawHelix.sh
executable file
·123 lines (110 loc) · 3.18 KB
/
drawHelix.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
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
#!/bin/bash
#
# drawHelix.sh <input.fa>
#
# Reads a fasta input file and stream a B-Form DNA
# helix with the sequence to STDOUT
#
## __ __ __ ___
### |__) | / \ /__` \ / |\ | | /\ \_/
#### |__) | \__/ .__/ | | \| | /~~\ / \
#####=======================================
## biosyntax.org v0.1
#
# ABabaian -- artem@rRNA.ca
#
# Props to @darokin for the gif-spiration
#
# TODO
# - Add B- and Z-form DNA helices [-dna B|Z]
# INITIALIZE ----------------------------------------------
# Input Fasta
FASTA=$1
LINENUMBER=$(wc -l $FASTA | cut -f1 -d ' ' -)
DELAY='0.1s' # Delay between bases
# DNA Helix Type
IDX=1 # Initialize print index
# Terminal Color Palette
if [[ $(tput colors) == '256' ]]; then
# Color Definitions (ANSI_256 Supported)
colA="$(tput setaf 10)"
colT="$(tput setaf 33)"
colG="$(tput setaf 214)"
colC="$(tput setaf 9)"
colN1="$(tput setaf 87)"
colN2="$(tput setaf 205)"
colHelix=$(tput setaf 250)
#colBond1=$colHelix
colBond2="$(tput setaf 0)"
colBg="$(tput setaf 17)"
else # use System colors
# Color Definitions (System Colors)
colA="$(tput setaf 2)"
colT="$(tput setaf 4)"
colG="$(tput setaf 3)"
colC="$(tput setaf 1)"
colN1="$(tput setaf 6)"
colN2="$(tput setaf 5)"
colHelix="$(tput setaf 7)"
#colBond1=$colHelix
colBond2="$(tput setaf 0)"
colBg="$(tput setaf 0)"
fi
# DRAW DNA ------------------------------------------------
for N in $(seq 3 $LINENUMBER) # iterate each line of FA
do
SEQ=$(sed -n "$N"p $FASTA) # extract Nth line
if [[ $SEQ =~ '^N+$' ]]; then # if all N line; skip
sleep 0 # do nothing
else
# Draw Helix - weird linebreak is for mac portability
for BASE in $(echo $SEQ | sed -e 's/\(.\)/\1\
/g')
do
# Declare Watson and Crick bases
#echo $BASE
if [[ $BASE =~ [Aa] ]]; then # A
W="$colA"A"$colHelix"
C="$colT"T"$colHelix"
bond='-' # weak
elif [[ $BASE =~ [TtUu] ]]; then # T or U
W="$colT"T"$colHelix"
C="$colA"A"$colHelix"
bond='-' # weak
elif [[ $BASE =~ [Gg] ]]; then # G
W="$colG"G"$colHelix"
C="$colC"C"$colHelix"
bond='=' # strong
elif [[ $BASE =~ [Cc] ]]; then # C
W="$colC"C"$colHelix"
C="$colG"G"$colHelix"
bond='=' # strong
else # Non-standard base
W="$colN1"O"$colHelix"
C="$colN2"X"$colHelix"
bond='-' # unknown
fi
BP_1="$colBg.... $colHelix\$$W---$C\$$colBg ....."
BP_2="$colBg.... $colHelix\$$W----$C\$$colBg ...."
BP_3="$colBg..... $colHelix\$$W----$C\$$colBg ..."
BP_4="$colBg...... $colHelix\$$W---$C\$$colBg ..."
BP_5="$colBg....... $colHelix\$$W-$C\$$colBg ...."
BP_6="$colBg........ $C\$$colBg ......"
BP_7="$colBg...... $colHelix\$$C$colBond2---$W\$$colBg ..."
BP_8="$colBg..... $colHelix\$$C$colBond2----$W\$$colBg ..."
BP_9="$colBg.... $colHelix\$$C$colBond2----$W\$$colBg ...."
BP_10="$colBg.... $colHelix\$$C$colBond2---$W\$$colBg ....."
BP_11="$colBg...... $colHelix\$$W$colBg ........"
BP_12="$colBg..... $colHelix\$$W-$C\$$colBg ......"
OUTPUT="BP_$IDX"
eval echo -e '$'$OUTPUT
# Move through index
if [ $IDX -eq 12 ]; then
IDX=1
else
IDX=$((IDX + 1))
fi
sleep $DELAY # Delay timer between base-pairs
done # BASE
fi #N
done #SEQ