diff --git a/examples/test_vcf.vcf b/examples/test_vcf.vcf index b1dd5bc..9ff8f40 100644 --- a/examples/test_vcf.vcf +++ b/examples/test_vcf.vcf @@ -1,4 +1,4 @@ -##fileformat=VCFv4.1 +##fileformat=VCFv4.2 ##INFO= ##INFO= ##contig= diff --git a/vcf_parser/parser.py b/vcf_parser/parser.py index 69e08e9..34c01d0 100755 --- a/vcf_parser/parser.py +++ b/vcf_parser/parser.py @@ -569,10 +569,16 @@ def make_splitted_variants(self, variant_dict): except KeyError: print(""""\nOne of the FILTER lines is missing in vcf header: %s \n""" % info, file=sys.stderr) - raise + raise + if info == 'CSQ': + try: + vep_dict[alternative] = variant_dict['vep_info'][alternative] + info_dict['CSQ'] = [self.build_new_vep_string(variant_dict['vep_info'][alternative])] + except KeyError: + pass # If there if one value per allele we need to split it in # the proper way - if number_of_values == 'A': + elif number_of_values == 'A': try: # When we split the alleles we only want to annotate with the correct number info_dict[info] = [variant_dict['info_dict'][info][alternative_number]] @@ -580,12 +586,17 @@ def make_splitted_variants(self, variant_dict): # If there is only one annotation we choose that one info_dict[info] = [variant_dict['info_dict'][info][0]] # Choose the right vep info from the old variant - elif info == 'CSQ': + elif number_of_values == 'R': + reference_value = variant_dict['info_dict'][info][0] + new_info = [reference_value] try: - vep_dict[alternative] = variant_dict['vep_info'][alternative] - info_dict['CSQ'] = [self.build_new_vep_string(variant_dict['vep_info'][alternative])] - except KeyError: + # When we split the alleles we only want to annotate with the correct number + new_info.append(variant_dict['info_dict'][info][alternative_number + 1]) + info_dict[info] = new_info + except IndexError: + # If annotation is missing we keep the original annotation pass + else: info_dict[info] = variant_dict['info_dict'][info]