-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathmerge.sh
executable file
·61 lines (47 loc) · 1.33 KB
/
merge.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
#!/usr/bin/env sh
set -e
if [[ $# -ne 1 ]]
then
echo 'usage: merge.sh <results_dir>'
exit 1
fi
input_dir=$1
test -d "${input_dir}" || (echo "${input_dir} not found"; exit 1)
study="study"
echo Build text files
prefix="FS6.0.${study}"
for b in 10 11 12 13 17 18 26 49 50 51 52 53 54 58
do
for m in "thick" "LogJacs"
do
out="${prefix}.${m}.${b}.txt"
\rm -f $out
for s in "${input_dir}"/*
do
od -f "${s}"/*/${m}_${b}.raw | gawk 'BEGIN{a="'$s'"}{for(i=2;i<NF+1;i++)a=a" "$i}END{print a}' >> $out
done
done
done
echo Add header and remove NAs
for f in "${prefix}".*.txt
do
gawk 'BEGIN{f="'$f'";gsub(".txt",".clean.txt.gz",f)}{if(a<NF)a=NF;b[$1]=$0;c[$1]=NF}END{for(i=0;i<a;i++)if(i==0){h="bigrfullname"}else h=h" Vert_"i;print h | "gzip -9c > "f; for (d in b) if (c[d]==a) print b[d] | "gzip -9c > "f}' "$f"
done
echo Build and run R script
cat << EOF > merge.R
gzfiles=system("ls ${prefix}.*.clean.txt.gz",intern=T)
for (f in gzfiles){
fX=gsub(".gz","",f)
fR=gsub(".txt",".Rdata",fX)
system(paste("zcat ",f," > ",fX,sep=""),intern=T)
out=as.data.frame(read.table(fX, header=T))
rownames(out) <- out[,1]
out[,1] <- NULL
save(out,file=fR)
system(paste("rm ",fX,sep=""),intern=T)
}
EOF
Rscript merge.R
echo cleanup
#\rm -f ${prefix}*
\rm -f merge.R