From 162a1bce4574a28825f54a578cfda4a1ad109b2e Mon Sep 17 00:00:00 2001 From: costero-e Date: Fri, 8 Nov 2024 16:07:37 +0100 Subject: [PATCH] allowing non AF vcf --- genomicVariations_vcf.py | 50 +++++++++++++++++++++------------------- 1 file changed, 26 insertions(+), 24 deletions(-) diff --git a/genomicVariations_vcf.py b/genomicVariations_vcf.py index 10e4e9f..fc76ddb 100644 --- a/genomicVariations_vcf.py +++ b/genomicVariations_vcf.py @@ -138,9 +138,7 @@ def generate(dict_properties): try: allele_frequency=v.INFO.get('AF') if allele_frequency == None: - i+=1 - pbar.update(1) - continue + pass if isinstance(allele_frequency, tuple): allele_frequency=list(allele_frequency) allele_frequency=allele_frequency[0] @@ -152,8 +150,7 @@ def generate(dict_properties): continue allele_number=v.INFO.get('AN') if allele_number == None: - i+=1 - continue + pass elif isinstance(allele_number, tuple): allele_number=list(allele_number) allele_number[0] @@ -161,39 +158,40 @@ def generate(dict_properties): allele_number = float(allele_number) allele_count=v.INFO.get('AC') if allele_count == None: - i+=1 - pbar.update(1) - continue + pass elif isinstance(allele_count, tuple): allele_count=list(allele_count) - allele_count[0] + allele_count=allele_count[0] else: allele_count = float(allele_count) - ac_hom=v.INFO.get('AC_Hom') - if ac_hom == None: + if allele_count == 0.0: i+=1 + pbar.update(1) continue + ac_hom=v.INFO.get('AC_Hom') + if ac_hom == None: + pass elif isinstance(ac_hom, tuple): ac_hom=list(ac_hom) - ac_hom[0] + ac_hom=ac_hom[0] else: ac_hom = float(v.INFO.get('AC_Hom')) ac_het=v.INFO.get('AC_Het') if ac_het == None: - i+=1 - continue + pass elif isinstance(ac_het, tuple): ac_het=list(ac_het) - ac_het[0] + ac_het=ac_het[0] else: ac_het = float(v.INFO.get('AC_Het')) - dict_to_xls['frequencyInPopulations|sourceReference']=pipeline["frequencyInPopulations|sourceReference"] - dict_to_xls['frequencyInPopulations|source']=pipeline["frequencyInPopulations|source"] - dict_to_xls['frequencyInPopulations|frequencies|population']=conf.datasetId - dict_to_xls['frequencyInPopulations|frequencies|alleleFrequency']=allele_frequency + if allele_frequency is not None: + dict_to_xls['frequencyInPopulations|sourceReference']=pipeline["frequencyInPopulations|sourceReference"] + dict_to_xls['frequencyInPopulations|source']=pipeline["frequencyInPopulations|source"] + dict_to_xls['frequencyInPopulations|frequencies|population']=conf.datasetId + dict_to_xls['frequencyInPopulations|frequencies|alleleFrequency']=allele_frequency except Exception as e: - continue + pass #print(allele_frequency) #print(v) @@ -614,10 +612,14 @@ def generate(dict_properties): GenomicVariations(**definitivedict) definitivedict["datasetId"]=conf.datasetId try: - definitivedict["frequencyInPopulations"][0]["frequencies"][0]["alleleCount"]=allele_count - definitivedict["frequencyInPopulations"][0]["frequencies"][0]["alleleNumber"]=allele_number - definitivedict["frequencyInPopulations"][0]["frequencies"][0]["alleleCountHomozygous"]=ac_hom - definitivedict["frequencyInPopulations"][0]["frequencies"][0]["alleleCountHeterozygous"]=ac_het + if allele_count: + definitivedict["frequencyInPopulations"][0]["frequencies"][0]["alleleCount"]=allele_count + if allele_number: + definitivedict["frequencyInPopulations"][0]["frequencies"][0]["alleleNumber"]=allele_number + if ac_hom: + definitivedict["frequencyInPopulations"][0]["frequencies"][0]["alleleCountHomozygous"]=ac_hom + if ac_het: + definitivedict["frequencyInPopulations"][0]["frequencies"][0]["alleleCountHeterozygous"]=ac_het except Exception: pass total_dict.append(definitivedict)