-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathget_sample_annot_fantom5.awk
61 lines (51 loc) · 1.54 KB
/
get_sample_annot_fantom5.awk
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
### FANTOM5 hg38 のファイルに適用
### 上部の ## 行に記載されているサンプルアノテーションを、サンプル名のカラムの下に取り込む
### awk -f get_sample_annot_fantom5.awk -v field=4 input
### ヒトのデータではフィールドは最大で4つ。マウスでは6。field 引数で指定のこと。満たないものは NA で埋める
BEGIN {
OFS = "\t"
FS = "\t"
if(!field) {
print "'-v field=NUM' is missing." > "/dev/stderr"
exit(-1)
}
}
/^#/ && /tpm/ {
left = index($0, "[")+1
right = index($0, "]")-1
sample = substr($0, left, right-left+1)
left = index($0, ") of ")+5
right = index(substr($0, left), ".CNhs")-1
ann = substr($0, left, right)
# print ann
# ", "区切りで入力されているアノテーション情報を分解して配列に格納する
prev = 0
for(i=1; i<=field; i++) {
comma = index(substr(ann, prev+1), ", ")
if(comma==0) {
ann_of[sample, i] = substr(ann, prev+1)
for(i=i+1; i<=field; i++)
ann_of[sample, i] = "NA"
}
else
ann_of[sample, i] = substr(ann, prev+1, comma-1)
prev = prev+comma+1
}
# for(i=1;i<=field;i++)
# printf ann_of[sample, i] "\t"
# printf "\n"
}
/^00Annotation/ {
print
for(i=1; i<=field; i++) {
printf "annotation" i
for(j=2; j<=NF; j++)
printf "\t" ann_of[$j, i]
printf "\n"
}
}
!/^#/ && !/^00Annotation/ {
print
}
END {
}