-
Notifications
You must be signed in to change notification settings - Fork 0
/
ped2fad.sh
76 lines (60 loc) · 1.36 KB
/
ped2fad.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
#!/bin/bash
# For debugging
#set -o verbose
# Die on unset variables
set -o nounset
# Die on errors
set -o errexit
# Die if any part of a pipe fails
set -o pipefail
OUTBASE="plink"
usage() {
echo -e "usage:\n$0 -b/-f basename [-o outbase] [-- plinkoptions]
-f inbase Base name for map/ped files
-t inbase Base name for tfam/tped files
-b inbase Base name for bim/bed/fam files
-o outbase Base name for output and temporary files files (default ${OUTBASE})
-h Show this message and exit.
The rest of the command line is given to plink for possible data filtering.
" >&2
exit 1
}
while getopts "h:f:t:b:o:-" flag
do
case "$flag" in
o)
OUTBASE="$OPTARG"
;;
f)
INBASE="$OPTARG"
INCMD="--file"
;;
t)
INBASE="$OPTARG"
INCMD="--tfile"
;;
b)
INBASE="$OPTARG"
INCMD="--bfile"
;;
-)
break
;;
*)
# usage;
;;
esac
done
shift $((OPTIND-1)); OPTIND=1
trap usage EXIT
test -s ${OUTBASE}.tfam || plink --noweb ${INCMD} ${INBASE} --out ${OUTBASE} $@ --transpose --recode12
awk --assign OUTBASE=${OUTBASE} '{
outStr=$4 " ";
for(i=5;i<=NF;i+=2) {
j=i+1;
if($i=="0") outStr=outStr "33"
else if($i==$j) outStr=outStr $i-1 $i-1
else outStr=outStr "22";
} print outStr >OUTBASE ".chr" $1 ".fad";
}' ${OUTBASE}.tped
trap EXIT