annotate TV-vs-background.sh @ 4:58815aed4ec3 draft default tip

few bugfixes in VCF-2-variantlist
author saskia-hiltemann
date Wed, 04 Nov 2015 05:06:12 -0500
parents 885ba15c2564
children
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
2
885ba15c2564 Uploaded
saskia-hiltemann
parents: 0
diff changeset
29 echo "varfiles list: $VN_varfiles_list"
885ba15c2564 Uploaded
saskia-hiltemann
parents: 0
diff changeset
30
0
1209f18a5a83 Uploaded
saskia-hiltemann
parents:
diff changeset
31 tr '\n' ' ' < $VN_varfiles_list > VN_varfiles.txt
1209f18a5a83 Uploaded
saskia-hiltemann
parents:
diff changeset
32
1209f18a5a83 Uploaded
saskia-hiltemann
parents:
diff changeset
33
1209f18a5a83 Uploaded
saskia-hiltemann
parents:
diff changeset
34 ### run TestVariants against 31G, 54G or 85G
1209f18a5a83 Uploaded
saskia-hiltemann
parents:
diff changeset
35
1209f18a5a83 Uploaded
saskia-hiltemann
parents:
diff changeset
36 echo "number of normals: $VNsetsize"
1209f18a5a83 Uploaded
saskia-hiltemann
parents:
diff changeset
37 echo "list of normals: ($VN_varfiles_list)"
1209f18a5a83 Uploaded
saskia-hiltemann
parents:
diff changeset
38 cat VN_varfiles.txt
1209f18a5a83 Uploaded
saskia-hiltemann
parents:
diff changeset
39
1209f18a5a83 Uploaded
saskia-hiltemann
parents:
diff changeset
40
1209f18a5a83 Uploaded
saskia-hiltemann
parents:
diff changeset
41 echo "running TV against Virtual Normal set"
1209f18a5a83 Uploaded
saskia-hiltemann
parents:
diff changeset
42 echo "command: cgatools testvariants\
1209f18a5a83 Uploaded
saskia-hiltemann
parents:
diff changeset
43 --beta \
1209f18a5a83 Uploaded
saskia-hiltemann
parents:
diff changeset
44 --reference $crr \
1209f18a5a83 Uploaded
saskia-hiltemann
parents:
diff changeset
45 --input $variants \
1209f18a5a83 Uploaded
saskia-hiltemann
parents:
diff changeset
46 --output $output_all \
1209f18a5a83 Uploaded
saskia-hiltemann
parents:
diff changeset
47 --variants `cat VN_varfiles.txt`"
1209f18a5a83 Uploaded
saskia-hiltemann
parents:
diff changeset
48
1209f18a5a83 Uploaded
saskia-hiltemann
parents:
diff changeset
49 cgatools testvariants \
1209f18a5a83 Uploaded
saskia-hiltemann
parents:
diff changeset
50 --beta \
1209f18a5a83 Uploaded
saskia-hiltemann
parents:
diff changeset
51 --reference $crr \
1209f18a5a83 Uploaded
saskia-hiltemann
parents:
diff changeset
52 --input $variants \
1209f18a5a83 Uploaded
saskia-hiltemann
parents:
diff changeset
53 --output $output_all \
1209f18a5a83 Uploaded
saskia-hiltemann
parents:
diff changeset
54 --variants `cat VN_varfiles.txt`
1209f18a5a83 Uploaded
saskia-hiltemann
parents:
diff changeset
55
1209f18a5a83 Uploaded
saskia-hiltemann
parents:
diff changeset
56
1209f18a5a83 Uploaded
saskia-hiltemann
parents:
diff changeset
57
1209f18a5a83 Uploaded
saskia-hiltemann
parents:
diff changeset
58 VNsetsize=`cat $VN_varfiles_list | wc -l`
1209f18a5a83 Uploaded
saskia-hiltemann
parents:
diff changeset
59
1209f18a5a83 Uploaded
saskia-hiltemann
parents:
diff changeset
60
1209f18a5a83 Uploaded
saskia-hiltemann
parents:
diff changeset
61
1209f18a5a83 Uploaded
saskia-hiltemann
parents:
diff changeset
62 ### filter file based on occurrence in background genomes
1209f18a5a83 Uploaded
saskia-hiltemann
parents:
diff changeset
63 cp $output_all $output_filtered
1209f18a5a83 Uploaded
saskia-hiltemann
parents:
diff changeset
64 cp $output_all output_expanded
1209f18a5a83 Uploaded
saskia-hiltemann
parents:
diff changeset
65
1209f18a5a83 Uploaded
saskia-hiltemann
parents:
diff changeset
66 ### condens file to columns with counts for all background genomes
1209f18a5a83 Uploaded
saskia-hiltemann
parents:
diff changeset
67 echo "Counting..."
1209f18a5a83 Uploaded
saskia-hiltemann
parents:
diff changeset
68 awk 'BEGIN{
1209f18a5a83 Uploaded
saskia-hiltemann
parents:
diff changeset
69 FS="\t";
1209f18a5a83 Uploaded
saskia-hiltemann
parents:
diff changeset
70 OFS="\t";
1209f18a5a83 Uploaded
saskia-hiltemann
parents:
diff changeset
71 totalnormals="'"$VNsetsize"'"+0
1209f18a5a83 Uploaded
saskia-hiltemann
parents:
diff changeset
72 count["00"]="0";
1209f18a5a83 Uploaded
saskia-hiltemann
parents:
diff changeset
73 count["01"]="0";
1209f18a5a83 Uploaded
saskia-hiltemann
parents:
diff changeset
74 count["11"]="0";
1209f18a5a83 Uploaded
saskia-hiltemann
parents:
diff changeset
75 count["0N"]="0";
1209f18a5a83 Uploaded
saskia-hiltemann
parents:
diff changeset
76 count["1N"]="0";
1209f18a5a83 Uploaded
saskia-hiltemann
parents:
diff changeset
77 count["NN"]="0";
1209f18a5a83 Uploaded
saskia-hiltemann
parents:
diff changeset
78 count["0"]="0";
1209f18a5a83 Uploaded
saskia-hiltemann
parents:
diff changeset
79 count["1"]="0";
1209f18a5a83 Uploaded
saskia-hiltemann
parents:
diff changeset
80 count["N"]="0";
1209f18a5a83 Uploaded
saskia-hiltemann
parents:
diff changeset
81 }{
1209f18a5a83 Uploaded
saskia-hiltemann
parents:
diff changeset
82 if(FNR==1) # header
1209f18a5a83 Uploaded
saskia-hiltemann
parents:
diff changeset
83 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
84 else{
1209f18a5a83 Uploaded
saskia-hiltemann
parents:
diff changeset
85 #count entries in reference genomes
1209f18a5a83 Uploaded
saskia-hiltemann
parents:
diff changeset
86 for (c in count)
1209f18a5a83 Uploaded
saskia-hiltemann
parents:
diff changeset
87 count[c]=0;
1209f18a5a83 Uploaded
saskia-hiltemann
parents:
diff changeset
88 for (i=9; i<=NF; i++){
1209f18a5a83 Uploaded
saskia-hiltemann
parents:
diff changeset
89 count[$i]++;
1209f18a5a83 Uploaded
saskia-hiltemann
parents:
diff changeset
90 }
1209f18a5a83 Uploaded
saskia-hiltemann
parents:
diff changeset
91 occurrences=count["11"]+count["01"]+count["1N"]+count["1"]
1209f18a5a83 Uploaded
saskia-hiltemann
parents:
diff changeset
92 fullycalled=count["11"]+count["01"]+count["00"]+count["1"]+count["0"]
1209f18a5a83 Uploaded
saskia-hiltemann
parents:
diff changeset
93 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
94 }
1209f18a5a83 Uploaded
saskia-hiltemann
parents:
diff changeset
95 }END{
1209f18a5a83 Uploaded
saskia-hiltemann
parents:
diff changeset
96
1209f18a5a83 Uploaded
saskia-hiltemann
parents:
diff changeset
97
1209f18a5a83 Uploaded
saskia-hiltemann
parents:
diff changeset
98 }' $output_all > "${output_all}-counted"
1209f18a5a83 Uploaded
saskia-hiltemann
parents:
diff changeset
99
1209f18a5a83 Uploaded
saskia-hiltemann
parents:
diff changeset
100
1209f18a5a83 Uploaded
saskia-hiltemann
parents:
diff changeset
101 # this counted file is the final output file
1209f18a5a83 Uploaded
saskia-hiltemann
parents:
diff changeset
102 rm $output_all
1209f18a5a83 Uploaded
saskia-hiltemann
parents:
diff changeset
103 mv "${output_all}-counted" $output_all
1209f18a5a83 Uploaded
saskia-hiltemann
parents:
diff changeset
104
1209f18a5a83 Uploaded
saskia-hiltemann
parents:
diff changeset
105
1209f18a5a83 Uploaded
saskia-hiltemann
parents:
diff changeset
106
1209f18a5a83 Uploaded
saskia-hiltemann
parents:
diff changeset
107 ### filter out variants occurring in more than <threshold> of the background genomes
1209f18a5a83 Uploaded
saskia-hiltemann
parents:
diff changeset
108 # if total of columns containing a 1 (01,11,1N,1) is >= threshold
1209f18a5a83 Uploaded
saskia-hiltemann
parents:
diff changeset
109 awk 'BEGIN{
1209f18a5a83 Uploaded
saskia-hiltemann
parents:
diff changeset
110 FS="\t";
1209f18a5a83 Uploaded
saskia-hiltemann
parents:
diff changeset
111 OFS="\t";
1209f18a5a83 Uploaded
saskia-hiltemann
parents:
diff changeset
112 }{
1209f18a5a83 Uploaded
saskia-hiltemann
parents:
diff changeset
113 if(FNR==1){
1209f18a5a83 Uploaded
saskia-hiltemann
parents:
diff changeset
114 print $0
1209f18a5a83 Uploaded
saskia-hiltemann
parents:
diff changeset
115 }
1209f18a5a83 Uploaded
saskia-hiltemann
parents:
diff changeset
116 if(FNR>1){
1209f18a5a83 Uploaded
saskia-hiltemann
parents:
diff changeset
117 if($9 < "'"$threshold"'" )
1209f18a5a83 Uploaded
saskia-hiltemann
parents:
diff changeset
118 print $0
1209f18a5a83 Uploaded
saskia-hiltemann
parents:
diff changeset
119 }
1209f18a5a83 Uploaded
saskia-hiltemann
parents:
diff changeset
120 }END{}' $output_all > $output_filtered
1209f18a5a83 Uploaded
saskia-hiltemann
parents:
diff changeset
121
1209f18a5a83 Uploaded
saskia-hiltemann
parents:
diff changeset
122
1209f18a5a83 Uploaded
saskia-hiltemann
parents:
diff changeset
123 awk 'BEGIN{
1209f18a5a83 Uploaded
saskia-hiltemann
parents:
diff changeset
124 FS="\t";
1209f18a5a83 Uploaded
saskia-hiltemann
parents:
diff changeset
125 OFS="\t";
1209f18a5a83 Uploaded
saskia-hiltemann
parents:
diff changeset
126 threshold="'"${thresholdhc}"'"+0
1209f18a5a83 Uploaded
saskia-hiltemann
parents:
diff changeset
127 }{
1209f18a5a83 Uploaded
saskia-hiltemann
parents:
diff changeset
128 if(FNR==1)
1209f18a5a83 Uploaded
saskia-hiltemann
parents:
diff changeset
129 print $0
1209f18a5a83 Uploaded
saskia-hiltemann
parents:
diff changeset
130 else if($11 >= threshold)
1209f18a5a83 Uploaded
saskia-hiltemann
parents:
diff changeset
131 print $0
1209f18a5a83 Uploaded
saskia-hiltemann
parents:
diff changeset
132
1209f18a5a83 Uploaded
saskia-hiltemann
parents:
diff changeset
133 }END{}' $output_filtered > "output_filtered_highconf.tsv"
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
1209f18a5a83 Uploaded
saskia-hiltemann
parents:
diff changeset
140
1209f18a5a83 Uploaded
saskia-hiltemann
parents:
diff changeset
141
2
885ba15c2564 Uploaded
saskia-hiltemann
parents: 0
diff changeset
142