annotate vcf2gvf.sh @ 6:f201e8c6e004 draft default tip

Uploaded
author ben-warren
date Mon, 07 Jul 2014 19:28:17 -0400
parents b321e0517be3
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
5
b321e0517be3 Uploaded
ben-warren
parents:
diff changeset
1 #!/bin/sh
b321e0517be3 Uploaded
ben-warren
parents:
diff changeset
2 ##convert vcf to gvf
b321e0517be3 Uploaded
ben-warren
parents:
diff changeset
3 ##NOTE This is a very simple basic parser for a complex format.
b321e0517be3 Uploaded
ben-warren
parents:
diff changeset
4 #It is intended for use with mpileup output where -g or -u flags are NOT used.
b321e0517be3 Uploaded
ben-warren
parents:
diff changeset
5
b321e0517be3 Uploaded
ben-warren
parents:
diff changeset
6 ##usage vcf2gvf.sh <vcf file> <outputfile>
b321e0517be3 Uploaded
ben-warren
parents:
diff changeset
7
b321e0517be3 Uploaded
ben-warren
parents:
diff changeset
8 #Copyright 2012 John McCallum & Leshi Chen
b321e0517be3 Uploaded
ben-warren
parents:
diff changeset
9 #New Zealand Institute for Plant and Food Research
b321e0517be3 Uploaded
ben-warren
parents:
diff changeset
10
b321e0517be3 Uploaded
ben-warren
parents:
diff changeset
11 #New Zealand Institute for Plant and Food Research
b321e0517be3 Uploaded
ben-warren
parents:
diff changeset
12 #This program is free software: you can redistribute it and/or modify
b321e0517be3 Uploaded
ben-warren
parents:
diff changeset
13 # it under the terms of the GNU General Public License as published by
b321e0517be3 Uploaded
ben-warren
parents:
diff changeset
14 # the Free Software Foundation, either version 3 of the License, or
b321e0517be3 Uploaded
ben-warren
parents:
diff changeset
15 # (at your option) any later version.
b321e0517be3 Uploaded
ben-warren
parents:
diff changeset
16 #
b321e0517be3 Uploaded
ben-warren
parents:
diff changeset
17 # This program is distributed in the hope that it will be useful,
b321e0517be3 Uploaded
ben-warren
parents:
diff changeset
18 # but WITHOUT ANY WARRANTY; without even the implied warranty of
b321e0517be3 Uploaded
ben-warren
parents:
diff changeset
19 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
b321e0517be3 Uploaded
ben-warren
parents:
diff changeset
20 # GNU General Public License for more details.
b321e0517be3 Uploaded
ben-warren
parents:
diff changeset
21 #
b321e0517be3 Uploaded
ben-warren
parents:
diff changeset
22 # You should have received a copy of the GNU General Public License
b321e0517be3 Uploaded
ben-warren
parents:
diff changeset
23 # along with this program. If not, see <http://www.gnu.org/licenses/>.
b321e0517be3 Uploaded
ben-warren
parents:
diff changeset
24
b321e0517be3 Uploaded
ben-warren
parents:
diff changeset
25
b321e0517be3 Uploaded
ben-warren
parents:
diff changeset
26
b321e0517be3 Uploaded
ben-warren
parents:
diff changeset
27 inputfile=$1
b321e0517be3 Uploaded
ben-warren
parents:
diff changeset
28 outputfile=$2
b321e0517be3 Uploaded
ben-warren
parents:
diff changeset
29
b321e0517be3 Uploaded
ben-warren
parents:
diff changeset
30 echo "##gvf-version 1.05" > $outputfile
b321e0517be3 Uploaded
ben-warren
parents:
diff changeset
31
b321e0517be3 Uploaded
ben-warren
parents:
diff changeset
32 awk '
b321e0517be3 Uploaded
ben-warren
parents:
diff changeset
33 BEGIN {OFS="\t"}
b321e0517be3 Uploaded
ben-warren
parents:
diff changeset
34
b321e0517be3 Uploaded
ben-warren
parents:
diff changeset
35 ##get feature type
b321e0517be3 Uploaded
ben-warren
parents:
diff changeset
36 {if (index($8,"INDEL")== 1) {type="INDEL"} else {type="SNP"} }
b321e0517be3 Uploaded
ben-warren
parents:
diff changeset
37 ##get feature length
b321e0517be3 Uploaded
ben-warren
parents:
diff changeset
38 {if (type=="SNP")
b321e0517be3 Uploaded
ben-warren
parents:
diff changeset
39 {feat_length=1}
b321e0517be3 Uploaded
ben-warren
parents:
diff changeset
40 else {feat_length=length($4)}
b321e0517be3 Uploaded
ben-warren
parents:
diff changeset
41 }
b321e0517be3 Uploaded
ben-warren
parents:
diff changeset
42 {end=($2+feat_length)}
b321e0517be3 Uploaded
ben-warren
parents:
diff changeset
43
b321e0517be3 Uploaded
ben-warren
parents:
diff changeset
44 !/^#/ { print $1 ,"SAMTOOLS",type,$2,end,$6,".",".","ID="$1":SAMTOOLS:"type":"$2";Variant_seq="$5";Reference_seq="$4";"$8}
b321e0517be3 Uploaded
ben-warren
parents:
diff changeset
45
b321e0517be3 Uploaded
ben-warren
parents:
diff changeset
46 END {print ""}
b321e0517be3 Uploaded
ben-warren
parents:
diff changeset
47 ' "$inputfile" > "$outputfile"