How to ignore errors when working with multiple variants?

11 views
Skip to first unread message

Tarun karthik kumar Mamidi

unread,
Feb 7, 2020, 6:36:25 PM2/7/20
to hgvs-discuss
Hello all,

I have a column of variants and want to convert them all to genomic co-ordinates. I'm using the following code 

def c2g(hgvs_c):
    var_c = hp.parse_hgvs_variant(hgvs_c)
    g = am.c_to_g(var_c)
    
    return g.posedit.pos.end.base

known['Variant1_pos']  = known.apply(lambda  row: c2g(row.Variant1) if 'NM' in row.Variant1 else '', axis=1)


Error:
HGVSInvalidIntervalError: ('The given coordinate is outside the bounds of the reference sequence.', 'occurred at index 6')


As expected, some of the variants are not formatted well, maybe cause of human error or something. I want to ignore those and print all others in the column. Is there a way to do that? I really hate using loops. Please help!

Thank you,




Reece Hart

unread,
Feb 7, 2020, 9:02:23 PM2/7/20
to hgvs-discuss
You need to catch exceptions. Something like:

import logging
_logger = logging.getLogger(__name__)

def c2g(hgvs_c):
    try:
        var_c = hp.parse_hgvs_variant(hgvs_c)
        g = am.c_to_g(var_c)
    except HGVSError as e:
        _logger.exception(e)
        return None
    return g.posedit.pos.end.base

--
You received this message because you are subscribed to the Google Groups "hgvs-discuss" group.
To unsubscribe from this group and stop receiving emails from it, send an email to hgvs-discuss...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/hgvs-discuss/60762dee-a52b-4ee4-93ee-32f1c54ca0d7%40googlegroups.com.

Tarun karthik kumar Mamidi

unread,
Feb 10, 2020, 11:45:36 AM2/10/20
to hgvs-discuss
Thanks for the help. I still get an error. Please see below.

NameError: ("name 'HGVSError' is not defined", 'occurred at index 6')

So, there was an unrecognized variant in the column at that position. I would like to ignore and convert all others.

Thanks for the help!
To unsubscribe from this group and stop receiving emails from it, send an email to hgvs-d...@googlegroups.com.
Reply all
Reply to author
Forward
0 new messages