comparison ivar_variants_to_vcf.py @ 17:0893a1dbb807 draft

planemo upload for repository https://github.com/galaxyproject/tools-iuc/tree/master/tools/ivar/ commit 9d25797b06335056930bddede98a2f3f9a303470
author iuc
date Tue, 27 Jun 2023 17:13:02 +0000
parents c3f9b8720d37
children
comparison
equal deleted inserted replaced
16:28e4bcbc86e7 17:0893a1dbb807
64 '##INFO=<ID=ALT_DP,Number=1,Type=Integer,Description="Depth of alternate base">\n' 64 '##INFO=<ID=ALT_DP,Number=1,Type=Integer,Description="Depth of alternate base">\n'
65 '##INFO=<ID=ALT_RV,Number=1,Type=Integer,Description="Deapth of alternate base on reverse reads">\n' 65 '##INFO=<ID=ALT_RV,Number=1,Type=Integer,Description="Deapth of alternate base on reverse reads">\n'
66 '##INFO=<ID=ALT_QUAL,Number=1,Type=Integer,Description="Mean quality of alternate base">\n' 66 '##INFO=<ID=ALT_QUAL,Number=1,Type=Integer,Description="Mean quality of alternate base">\n'
67 '##INFO=<ID=AF,Number=1,Type=Float,Description="Frequency of alternate base">\n' 67 '##INFO=<ID=AF,Number=1,Type=Float,Description="Frequency of alternate base">\n'
68 '##INFO=<ID=INDEL,Number=0,Type=Flag,Description="Indicates that the variant is an INDEL.">\n' 68 '##INFO=<ID=INDEL,Number=0,Type=Flag,Description="Indicates that the variant is an INDEL.">\n'
69 '##INFO=<ID=DP4,Number=4,Type=Integer,Description="Counts for ref-forward bases, ref-reverse, alt-forward and alt-reverse bases">'
69 '##FILTER=<ID=PASS,Description="Result of p-value <= 0.05">\n' 70 '##FILTER=<ID=PASS,Description="Result of p-value <= 0.05">\n'
70 '##FILTER=<ID=FAIL,Description="Result of p-value > 0.05">\n' 71 '##FILTER=<ID=FAIL,Description="Result of p-value > 0.05">\n'
71 ) 72 )
72 info_keys = [ 73 info_keys = [
73 re.match(r'##INFO=<ID=([^,]+),', line).group(1) 74 re.match(r'##INFO=<ID=([^,]+),', line).group(1)
86 fout.write(header) 87 fout.write(header)
87 for line in f: 88 for line in f:
88 if line.startswith("REGION"): 89 if line.startswith("REGION"):
89 continue 90 continue
90 91
92 # fields:
93 # 0 REGION
94 # 1 POS
95 # 2 REF
96 # 3 ALT
97 # 4 REF_DP
98 # 5 REF_RV
99 # 6 REF_QUAL
100 # 7 ALT_DP
101 # 8 ALT_RV
102 # 9 ALT_QUAL
103 # 10 ALT_FREQ
104 # 11 TOTAL_DP
105 # 12 PVAL
106 # 13 PASS
107 # 14 GFF_FEATURE
108 # 15 REF_CODON
109 # 16 REF_AA
110 # 17 ALT_CODON
111 # 18 ALT_AA
112 # 19 POS_AA
91 line = line.split("\t") 113 line = line.split("\t")
92 CHROM = line[0] 114 CHROM = line[0]
93 POS = line[1] 115 POS = line[1]
94 ID = "." 116 ID = "."
95 REF = line[2] 117 REF = line[2]
114 continue 136 continue
115 var = (CHROM, POS, REF, ALT) 137 var = (CHROM, POS, REF, ALT)
116 if var in vars_seen: 138 if var in vars_seen:
117 continue 139 continue
118 140
141 ref_dp = int(line[4])
142 ref_dp_rev = int(line[5])
143 ref_dp_fwd = ref_dp - ref_dp_rev
144
145 alt_dp = int(line[7])
146 alt_dp_rev = int(line[8])
147 alt_dp_fwd = alt_dp - alt_dp_rev
148
149 dp4 = f'{ref_dp_fwd},{ref_dp_rev},{alt_dp_fwd},{alt_dp_rev}'
119 info_elements = { 150 info_elements = {
120 'DP': line[11], 151 'DP': line[11],
121 'REF_DP': line[4], 152 'REF_DP': ref_dp,
122 'REF_RV': line[5], 153 'REF_RV': ref_dp_rev,
123 'REF_QUAL': line[6], 154 'REF_QUAL': line[6],
124 'ALT_DP': line[7], 155 'ALT_DP': alt_dp,
125 'ALT_RV': line[8], 156 'ALT_RV': alt_dp_rev,
126 'ALT_QUAL': line[9], 157 'ALT_QUAL': line[9],
127 'AF': line[10] 158 'AF': line[10],
159 'DP4': dp4
128 } 160 }
129 if var_type in ['INS', 'DEL']: 161 if var_type in ['INS', 'DEL']:
130 # add INDEL FLAG 162 # add INDEL FLAG
131 info_elements['INDEL'] = True 163 info_elements['INDEL'] = True
132 else: 164 else: