grantham_distance type error
Hi Sigve (and PCGR team),
I am getting the following error in an attempt to analyse a VCF. So far I've found it only affects three samples from a total of 360 samples I've tested.
Traceback (most recent call last):
File "/opt/mambaforge/envs/pcgr/bin/pcgr_summarise.py", line 308, in <module>
__main__()
File "/opt/mambaforge/envs/pcgr/bin/pcgr_summarise.py", line 47, in __main__
extend_vcf_annotations(arg_dict, logger)
File "/opt/mambaforge/envs/pcgr/bin/pcgr_summarise.py", line 277, in extend_vcf_annotations
match_oncogenic_variants(vep_csq_record_results['all_csq'], oncogenic_variants, rec, principal_csq_properties)
File "/opt/mambaforge/envs/pcgr/lib/python3.12/site-packages/pcgr/oncogenicity.py", line 533, in match_oncogenic_variants
if float(grantham_distance / float(oncogenic_variants[oncogenic_varkey]['grantham_distance'])) > 0.8:
~~~~~~~~~~~~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
TypeError: unsupported operand type(s) for /: 'str' and 'float'
https://github.com/sigven/pcgr/blob/70a3bb4625755f8df1bc2969a830d99a8c03fc11/pcgr/oncogenicity.py#L533
I think the fix just needs to be the following:
if float(float(grantham_distance) / float(oncogenic_variants[oncogenic_varkey]['grantham_distance'])) > 0.8 just to force the Grantham_distance into a float to begin with to prevent a type error.
Happy to share the offending VCFs with you for debugging.
Regards, Ridwan
Hi Ridwan, Thanks for detecting this. I will incorporate this fix in the next version.
Kind regards, Sigve
Hello Sigve & Team,
just wanted to chime in and say that I encountered the same error in 3/50 vcf (PCGR 2.2.1).
Traceback (most recent call last):
File "/Users/cornejocastroe/Software/pcgr_conda/pcgr/bin/pcgr_summarise.py", line 308, in <module>
__main__()
File "/Users/cornejocastroe/Software/pcgr_conda/pcgr/bin/pcgr_summarise.py", line 47, in __main__
extend_vcf_annotations(arg_dict, logger)
File "/Users/cornejocastroe/Software/pcgr_conda/pcgr/bin/pcgr_summarise.py", line 277, in extend_vcf_annotations
match_oncogenic_variants(vep_csq_record_results['all_csq'], oncogenic_variants, rec, principal_csq_properties)
File "/Users/cornejocastroe/Software/pcgr_conda/pcgr/lib/python3.12/site-packages/pcgr/oncogenicity.py", line 533, in match_oncogenic_variants
if float(grantham_distance / float(oncogenic_variants[oncogenic_varkey]['grantham_distance'])) > 0.8:
~~~~~~~~~~~~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
TypeError: unsupported operand type(s) for /: 'str' and 'float'
I tried implementing the solution by Ridwan, unfortunately I now get the following error:
Traceback (most recent call last):
File "/Users/cornejocastroe/Software/pcgr_conda/pcgr/bin/pcgr_summarise.py", line 308, in <module>
__main__()
File "/Users/cornejocastroe/Software/pcgr_conda/pcgr/bin/pcgr_summarise.py", line 47, in __main__
extend_vcf_annotations(arg_dict, logger)
File "/Users/cornejocastroe/Software/pcgr_conda/pcgr/bin/pcgr_summarise.py", line 277, in extend_vcf_annotations
match_oncogenic_variants(vep_csq_record_results['all_csq'], oncogenic_variants, rec, principal_csq_properties)
File "/Users/cornejocastroe/Software/pcgr_conda/pcgr/lib/python3.12/site-packages/pcgr/oncogenicity.py", line 533, in match_oncogenic_variants
if float(float(grantham_distance) / float(oncogenic_variants[oncogenic_varkey]['grantham_distance'])) > 0.8:
^^^^^^^^^^^^^^^^^^^^^^^^
ValueError: could not convert string to float: '.'
Which leads me to believe that it does not know how to handle "." or NA as they cannot be converted to a float.
Regards, Elena
Thanks a lot for the follow-up, Elena. Fix in the making! 😊
Kind regards, Sigve
@ridwan-shaikh , would you able to share a few VCF's where this bug occurs, so I have a test set to work with?
best, Sigve
Shared via email. Let me know if you have any issues with it
Fixed in v2.2.2