pcgr icon indicating copy to clipboard operation
pcgr copied to clipboard

grantham_distance type error

Open ridwan-shaikh opened this issue 10 months ago • 2 comments

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

ridwan-shaikh avatar Jun 25 '25 14:06 ridwan-shaikh

Hi Ridwan, Thanks for detecting this. I will incorporate this fix in the next version.

Kind regards, Sigve

sigven avatar Jun 27 '25 17:06 sigven

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

cornejoem avatar Jun 27 '25 19:06 cornejoem

Thanks a lot for the follow-up, Elena. Fix in the making! 😊

Kind regards, Sigve

sigven avatar Jun 28 '25 10:06 sigven

@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

sigven avatar Jul 01 '25 08:07 sigven

Shared via email. Let me know if you have any issues with it

ridwan-shaikh avatar Jul 02 '25 11:07 ridwan-shaikh

Fixed in v2.2.2

sigven avatar Jul 15 '25 12:07 sigven