-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathadd_id.sh
33 lines (28 loc) · 1.06 KB
/
add_id.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
#---------------------- Insert ID -------------------------#
awk 'BEGIN{FS=","; OFS=","}
function custom_sort(i1,v1,i2,v2){
l1=length(v1); l2=length(v2);
if (l1 == l2) {
return (v1 > v2)? 1:-1
} else {
return l2 - l1
}
} NR==1 { $0=$0 FS "ID" }
NR>1 { a[1]=$11; a[2]=$12; asort(a,b,"custom_sort");
$(NF+1) = sprintf("%s:%s_%s_%s",$1,$2,b[1],b[2])
}1' T2D_european_noID.txt > T2D_european.txt | column -t
#------------------ Insert ID in multiple files ---------------------#
for i in basalganglia-EUR-30 cortex-AFR-40 cortex-EAS-30 cortex-EUR-80 hippocampus-EUR-30;
do awk 'BEGIN{FS=","; OFS=","}
function custom_sort(i1,v1,i2,v2){
l1=length(v1); l2=length(v2);
if (l1 == l2) {
return (v1 > v2)? 1:-1
} else {
return l2 - l1
}
} NR==1 { $0=$0 FS "ID" }
NR>1 { a[1]=$8; a[2]=$9; asort(a,b,"custom_sort");
$(NF+1) = sprintf("%s:%s_%s_%s",$10,$11,b[1],b[2])
}1' eQTL_${i}_hg19.csv > eQTL_${i}.csv;
done