-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtab-to-nodeclass.sh
executable file
·85 lines (69 loc) · 2.05 KB
/
tab-to-nodeclass.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
#! /bin/bash
while getopts eut: ARG
do
case ${ARG} in
(e) EXONS="1";;
(u) UNIQUIFY="1";;
(t) TAB_FILE="${OPTARG}";;
esac
done
if [ -z "${TAB_FILE}" ];
then
echo "tab file not supplied"
exit 1
fi
SCRIPT_DIR=$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )
BASE_NAME=$(basename "$TAB_FILE")
NO_EXT="${BASE_NAME%.*}"
COLOR="${SCRIPT_DIR}/color.txt"
if [ "${UNIQUIFY}" == "1" ];
then
#create nodeclass
cat ${TAB_FILE} | \
sed -e '1,2d' | \
cut -f3,4 | \
sort -k1 -u | \
sort -k2 | \
uniq -cf1| \
sort -rn > t1
cat ${TAB_FILE} | \
sed -e '1,2d' | \
awk {'print $3"\t "$6"\t" $7"\t "$4'} | \
sort -k4 > t2
awk 'FNR==NR {C[$2]=$1;next}FNR==1 \
{print "Count Read_ID Sequence Exon Transcript_ID"; next}$1 in C \
{print C[$1], $1, $4, $3, $2}' t1 t2 > t3
cat t3 | awk '{print "//NODECLASS\t\"" $2"_"$1 "\"\t\"Exon " $4 "\"\t\"" $5 "\""}'
#create nodesize
cat t1 | \
awk {'print "//NODESIZE\t\""$2"_"$1"\"\t"$1'}
rm t1 t2 t3
#create nodeclasscolor
cat ${TAB_FILE} | \
sed -e '1,2d' | \
cut -f7,6 | \
sort -u | \
sort | \
awk '{print "//NODECLASSCOLOR\t\t\"Exon " $2 "\"\t\"" $1 "\""}' | \
sort > t1
awk 'FNR==NR{B=$NF;$NF="";gsub(/[[:space:]]+$/,X,$0);A[$0]=B;next} \
($2" "$3 in A){print $0 OFS A[$2" "$3]}' ${COLOR} \
OFS="\t" t1
rm t1
else
awk '{print "//NODECLASS\t\"" $3 "\"\t\"Exon " $7 "\"\t\"" $6 "\""}' ${TAB_FILE} | \
sed 's,"readname",\//GENEID,' | sed 's,"Exon exonnumber",\//EXONNUMBER,' | \
sed 's,"transcriptid",\//TRANSCRIPTID,'| sed '2d'
#create nodeclasscolor
cat ${TAB_FILE} | \
sed -e '1,2d' | \
cut -f7,6 | \
sort -u | \
sort | \
awk '{print "//NODECLASSCOLOR\t\t\"Exon " $2 "\"\t\"" $1 "\""}' | \
sort > t1
awk 'FNR==NR{B=$NF;$NF="";gsub(/[[:space:]]+$/,X,$0);A[$0]=B;next} \
($2" "$3 in A){print $0 OFS A[$2" "$3]}' ${COLOR} \
OFS="\t" t1
rm t1
fi