annotate TV-vs-background.sh @ 0:1209f18a5a83 draft

Uploaded
author saskia-hiltemann
date Mon, 03 Aug 2015 05:01:15 -0400
parents
children 885ba15c2564
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
0
1209f18a5a83 Uploaded
saskia-hiltemann
parents:
diff changeset
1 #!/bin/bash
1209f18a5a83 Uploaded
saskia-hiltemann
parents:
diff changeset
2
1209f18a5a83 Uploaded
saskia-hiltemann
parents:
diff changeset
3 #TV-vs-background.sh $variants $genomes ${reference.fields.crr_path} ${reference.fields.31G_var_paths} ${reference.54G_var_paths} $threshold $output_all $output_filtered
1209f18a5a83 Uploaded
saskia-hiltemann
parents:
diff changeset
4
1209f18a5a83 Uploaded
saskia-hiltemann
parents:
diff changeset
5 echo $@
1209f18a5a83 Uploaded
saskia-hiltemann
parents:
diff changeset
6
1209f18a5a83 Uploaded
saskia-hiltemann
parents:
diff changeset
7 set -- `getopt -n$0 -u -a --longoptions="variants: reference: VN_varfiles: outputfile_filtered: outputfile_all: threshold: thresholdhc:" "h:" "$@"` || usage
1209f18a5a83 Uploaded
saskia-hiltemann
parents:
diff changeset
8 [ $# -eq 0 ] && usage
1209f18a5a83 Uploaded
saskia-hiltemann
parents:
diff changeset
9
1209f18a5a83 Uploaded
saskia-hiltemann
parents:
diff changeset
10 while [ $# -gt 0 ]
1209f18a5a83 Uploaded
saskia-hiltemann
parents:
diff changeset
11 do
1209f18a5a83 Uploaded
saskia-hiltemann
parents:
diff changeset
12 case "$1" in
1209f18a5a83 Uploaded
saskia-hiltemann
parents:
diff changeset
13 --variants) variants=$2;shift;;
1209f18a5a83 Uploaded
saskia-hiltemann
parents:
diff changeset
14 --reference) crr=$2;shift;;
1209f18a5a83 Uploaded
saskia-hiltemann
parents:
diff changeset
15 --VN_varfiles) VN_varfiles_list=$2;shift;;
1209f18a5a83 Uploaded
saskia-hiltemann
parents:
diff changeset
16 --outputfile_filtered) output_filtered=$2;shift;;
1209f18a5a83 Uploaded
saskia-hiltemann
parents:
diff changeset
17 --outputfile_all) output_all=$2;shift;;
1209f18a5a83 Uploaded
saskia-hiltemann
parents:
diff changeset
18 --threshold) threshold=$2;shift;;
1209f18a5a83 Uploaded
saskia-hiltemann
parents:
diff changeset
19 --thresholdhc) thresholdhc=$2;shift;;
1209f18a5a83 Uploaded
saskia-hiltemann
parents:
diff changeset
20 -h) shift;;
1209f18a5a83 Uploaded
saskia-hiltemann
parents:
diff changeset
21 --) shift;break;;
1209f18a5a83 Uploaded
saskia-hiltemann
parents:
diff changeset
22 -*) usage;;
1209f18a5a83 Uploaded
saskia-hiltemann
parents:
diff changeset
23 *) break;;
1209f18a5a83 Uploaded
saskia-hiltemann
parents:
diff changeset
24 esac
1209f18a5a83 Uploaded
saskia-hiltemann
parents:
diff changeset
25 shift
1209f18a5a83 Uploaded
saskia-hiltemann
parents:
diff changeset
26 done
1209f18a5a83 Uploaded
saskia-hiltemann
parents:
diff changeset
27
1209f18a5a83 Uploaded
saskia-hiltemann
parents:
diff changeset
28 # replace newline chars with spaces for input to testvariants
1209f18a5a83 Uploaded
saskia-hiltemann
parents:
diff changeset
29 tr '\n' ' ' < $VN_varfiles_list > VN_varfiles.txt
1209f18a5a83 Uploaded
saskia-hiltemann
parents:
diff changeset
30
1209f18a5a83 Uploaded
saskia-hiltemann
parents:
diff changeset
31
1209f18a5a83 Uploaded
saskia-hiltemann
parents:
diff changeset
32 ### run TestVariants against 31G, 54G or 85G
1209f18a5a83 Uploaded
saskia-hiltemann
parents:
diff changeset
33
1209f18a5a83 Uploaded
saskia-hiltemann
parents:
diff changeset
34 echo "number of normals: $VNsetsize"
1209f18a5a83 Uploaded
saskia-hiltemann
parents:
diff changeset
35 echo "list of normals: ($VN_varfiles_list)"
1209f18a5a83 Uploaded
saskia-hiltemann
parents:
diff changeset
36 cat VN_varfiles.txt
1209f18a5a83 Uploaded
saskia-hiltemann
parents:
diff changeset
37
1209f18a5a83 Uploaded
saskia-hiltemann
parents:
diff changeset
38
1209f18a5a83 Uploaded
saskia-hiltemann
parents:
diff changeset
39 echo "running TV against Virtual Normal set"
1209f18a5a83 Uploaded
saskia-hiltemann
parents:
diff changeset
40 echo "command: cgatools testvariants\
1209f18a5a83 Uploaded
saskia-hiltemann
parents:
diff changeset
41 --beta \
1209f18a5a83 Uploaded
saskia-hiltemann
parents:
diff changeset
42 --reference $crr \
1209f18a5a83 Uploaded
saskia-hiltemann
parents:
diff changeset
43 --input $variants \
1209f18a5a83 Uploaded
saskia-hiltemann
parents:
diff changeset
44 --output $output_all \
1209f18a5a83 Uploaded
saskia-hiltemann
parents:
diff changeset
45 --variants `cat VN_varfiles.txt`"
1209f18a5a83 Uploaded
saskia-hiltemann
parents:
diff changeset
46
1209f18a5a83 Uploaded
saskia-hiltemann
parents:
diff changeset
47 cgatools testvariants \
1209f18a5a83 Uploaded
saskia-hiltemann
parents:
diff changeset
48 --beta \
1209f18a5a83 Uploaded
saskia-hiltemann
parents:
diff changeset
49 --reference $crr \
1209f18a5a83 Uploaded
saskia-hiltemann
parents:
diff changeset
50 --input $variants \
1209f18a5a83 Uploaded
saskia-hiltemann
parents:
diff changeset
51 --output $output_all \
1209f18a5a83 Uploaded
saskia-hiltemann
parents:
diff changeset
52 --variants `cat VN_varfiles.txt`
1209f18a5a83 Uploaded
saskia-hiltemann
parents:
diff changeset
53
1209f18a5a83 Uploaded
saskia-hiltemann
parents:
diff changeset
54
1209f18a5a83 Uploaded
saskia-hiltemann
parents:
diff changeset
55
1209f18a5a83 Uploaded
saskia-hiltemann
parents:
diff changeset
56 VNsetsize=`cat $VN_varfiles_list | wc -l`
1209f18a5a83 Uploaded
saskia-hiltemann
parents:
diff changeset
57
1209f18a5a83 Uploaded
saskia-hiltemann
parents:
diff changeset
58
1209f18a5a83 Uploaded
saskia-hiltemann
parents:
diff changeset
59
1209f18a5a83 Uploaded
saskia-hiltemann
parents:
diff changeset
60 ### filter file based on occurrence in background genomes
1209f18a5a83 Uploaded
saskia-hiltemann
parents:
diff changeset
61 cp $output_all $output_filtered
1209f18a5a83 Uploaded
saskia-hiltemann
parents:
diff changeset
62 cp $output_all output_expanded
1209f18a5a83 Uploaded
saskia-hiltemann
parents:
diff changeset
63
1209f18a5a83 Uploaded
saskia-hiltemann
parents:
diff changeset
64 ### condens file to columns with counts for all background genomes
1209f18a5a83 Uploaded
saskia-hiltemann
parents:
diff changeset
65 echo "Counting..."
1209f18a5a83 Uploaded
saskia-hiltemann
parents:
diff changeset
66 awk 'BEGIN{
1209f18a5a83 Uploaded
saskia-hiltemann
parents:
diff changeset
67 FS="\t";
1209f18a5a83 Uploaded
saskia-hiltemann
parents:
diff changeset
68 OFS="\t";
1209f18a5a83 Uploaded
saskia-hiltemann
parents:
diff changeset
69 totalnormals="'"$VNsetsize"'"+0
1209f18a5a83 Uploaded
saskia-hiltemann
parents:
diff changeset
70 count["00"]="0";
1209f18a5a83 Uploaded
saskia-hiltemann
parents:
diff changeset
71 count["01"]="0";
1209f18a5a83 Uploaded
saskia-hiltemann
parents:
diff changeset
72 count["11"]="0";
1209f18a5a83 Uploaded
saskia-hiltemann
parents:
diff changeset
73 count["0N"]="0";
1209f18a5a83 Uploaded
saskia-hiltemann
parents:
diff changeset
74 count["1N"]="0";
1209f18a5a83 Uploaded
saskia-hiltemann
parents:
diff changeset
75 count["NN"]="0";
1209f18a5a83 Uploaded
saskia-hiltemann
parents:
diff changeset
76 count["0"]="0";
1209f18a5a83 Uploaded
saskia-hiltemann
parents:
diff changeset
77 count["1"]="0";
1209f18a5a83 Uploaded
saskia-hiltemann
parents:
diff changeset
78 count["N"]="0";
1209f18a5a83 Uploaded
saskia-hiltemann
parents:
diff changeset
79 }{
1209f18a5a83 Uploaded
saskia-hiltemann
parents:
diff changeset
80 if(FNR==1) # header
1209f18a5a83 Uploaded
saskia-hiltemann
parents:
diff changeset
81 print $1,$2,$3,$4,$5,$6,$7,$8,"VN_occurrences","VN_frequency","VN_fullycalled_count","VN_fullycalled_frequency","VN_00","VN_01","VN_11","VN_0N","VN_1N","VN_NN","VN_0","VN_1","VN_N"
1209f18a5a83 Uploaded
saskia-hiltemann
parents:
diff changeset
82 else{
1209f18a5a83 Uploaded
saskia-hiltemann
parents:
diff changeset
83 #count entries in reference genomes
1209f18a5a83 Uploaded
saskia-hiltemann
parents:
diff changeset
84 for (c in count)
1209f18a5a83 Uploaded
saskia-hiltemann
parents:
diff changeset
85 count[c]=0;
1209f18a5a83 Uploaded
saskia-hiltemann
parents:
diff changeset
86 for (i=9; i<=NF; i++){
1209f18a5a83 Uploaded
saskia-hiltemann
parents:
diff changeset
87 count[$i]++;
1209f18a5a83 Uploaded
saskia-hiltemann
parents:
diff changeset
88 }
1209f18a5a83 Uploaded
saskia-hiltemann
parents:
diff changeset
89 occurrences=count["11"]+count["01"]+count["1N"]+count["1"]
1209f18a5a83 Uploaded
saskia-hiltemann
parents:
diff changeset
90 fullycalled=count["11"]+count["01"]+count["00"]+count["1"]+count["0"]
1209f18a5a83 Uploaded
saskia-hiltemann
parents:
diff changeset
91 print $1,$2,$3,$4,$5,$6,$7,$8,occurrences,occurrences/totalnormals,fullycalled,fullycalled/totalnormals,count["00"],count["01"],count["11"],count["0N"],count["1N"],count["NN"],count["0"],count["1"],count["N"]
1209f18a5a83 Uploaded
saskia-hiltemann
parents:
diff changeset
92 }
1209f18a5a83 Uploaded
saskia-hiltemann
parents:
diff changeset
93 }END{
1209f18a5a83 Uploaded
saskia-hiltemann
parents:
diff changeset
94
1209f18a5a83 Uploaded
saskia-hiltemann
parents:
diff changeset
95
1209f18a5a83 Uploaded
saskia-hiltemann
parents:
diff changeset
96 }' $output_all > "${output_all}-counted"
1209f18a5a83 Uploaded
saskia-hiltemann
parents:
diff changeset
97
1209f18a5a83 Uploaded
saskia-hiltemann
parents:
diff changeset
98
1209f18a5a83 Uploaded
saskia-hiltemann
parents:
diff changeset
99 # this counted file is the final output file
1209f18a5a83 Uploaded
saskia-hiltemann
parents:
diff changeset
100 rm $output_all
1209f18a5a83 Uploaded
saskia-hiltemann
parents:
diff changeset
101 mv "${output_all}-counted" $output_all
1209f18a5a83 Uploaded
saskia-hiltemann
parents:
diff changeset
102
1209f18a5a83 Uploaded
saskia-hiltemann
parents:
diff changeset
103
1209f18a5a83 Uploaded
saskia-hiltemann
parents:
diff changeset
104
1209f18a5a83 Uploaded
saskia-hiltemann
parents:
diff changeset
105 ### filter out variants occurring in more than <threshold> of the background genomes
1209f18a5a83 Uploaded
saskia-hiltemann
parents:
diff changeset
106 # if total of columns containing a 1 (01,11,1N,1) is >= threshold
1209f18a5a83 Uploaded
saskia-hiltemann
parents:
diff changeset
107 awk 'BEGIN{
1209f18a5a83 Uploaded
saskia-hiltemann
parents:
diff changeset
108 FS="\t";
1209f18a5a83 Uploaded
saskia-hiltemann
parents:
diff changeset
109 OFS="\t";
1209f18a5a83 Uploaded
saskia-hiltemann
parents:
diff changeset
110 }{
1209f18a5a83 Uploaded
saskia-hiltemann
parents:
diff changeset
111 if(FNR==1){
1209f18a5a83 Uploaded
saskia-hiltemann
parents:
diff changeset
112 print $0
1209f18a5a83 Uploaded
saskia-hiltemann
parents:
diff changeset
113 }
1209f18a5a83 Uploaded
saskia-hiltemann
parents:
diff changeset
114 if(FNR>1){
1209f18a5a83 Uploaded
saskia-hiltemann
parents:
diff changeset
115 if($9 < "'"$threshold"'" )
1209f18a5a83 Uploaded
saskia-hiltemann
parents:
diff changeset
116 print $0
1209f18a5a83 Uploaded
saskia-hiltemann
parents:
diff changeset
117 }
1209f18a5a83 Uploaded
saskia-hiltemann
parents:
diff changeset
118 }END{}' $output_all > $output_filtered
1209f18a5a83 Uploaded
saskia-hiltemann
parents:
diff changeset
119
1209f18a5a83 Uploaded
saskia-hiltemann
parents:
diff changeset
120
1209f18a5a83 Uploaded
saskia-hiltemann
parents:
diff changeset
121 awk 'BEGIN{
1209f18a5a83 Uploaded
saskia-hiltemann
parents:
diff changeset
122 FS="\t";
1209f18a5a83 Uploaded
saskia-hiltemann
parents:
diff changeset
123 OFS="\t";
1209f18a5a83 Uploaded
saskia-hiltemann
parents:
diff changeset
124 threshold="'"${thresholdhc}"'"+0
1209f18a5a83 Uploaded
saskia-hiltemann
parents:
diff changeset
125 }{
1209f18a5a83 Uploaded
saskia-hiltemann
parents:
diff changeset
126 if(FNR==1)
1209f18a5a83 Uploaded
saskia-hiltemann
parents:
diff changeset
127 print $0
1209f18a5a83 Uploaded
saskia-hiltemann
parents:
diff changeset
128 else if($11 >= threshold)
1209f18a5a83 Uploaded
saskia-hiltemann
parents:
diff changeset
129 print $0
1209f18a5a83 Uploaded
saskia-hiltemann
parents:
diff changeset
130
1209f18a5a83 Uploaded
saskia-hiltemann
parents:
diff changeset
131 }END{}' $output_filtered > "output_filtered_highconf.tsv"
1209f18a5a83 Uploaded
saskia-hiltemann
parents:
diff changeset
132
1209f18a5a83 Uploaded
saskia-hiltemann
parents:
diff changeset
133
1209f18a5a83 Uploaded
saskia-hiltemann
parents:
diff changeset
134
1209f18a5a83 Uploaded
saskia-hiltemann
parents:
diff changeset
135
1209f18a5a83 Uploaded
saskia-hiltemann
parents:
diff changeset
136
1209f18a5a83 Uploaded
saskia-hiltemann
parents:
diff changeset
137
1209f18a5a83 Uploaded
saskia-hiltemann
parents:
diff changeset
138
1209f18a5a83 Uploaded
saskia-hiltemann
parents:
diff changeset
139