<s> import logging <EOL> from tabix import TabixError <EOL> logger = logging . getLogger ( __name__ ) <EOL> def get_tabix_records ( tabix_reader , chrom , start ) : <EOL> """<STR_LIT>""" <EOL> records = [ ] <EOL> logger . debug ( "<STR_LIT>" % ( tabix_reader ) ) <EOL> logger . debug ( "<STR_LIT>" % ( chrom , start ) ) <EOL> tabix_key = int ( start ) <EOL> try : <EOL> records = tabix_reader . query ( chrom , tabix_key - <NUM_LIT:1> , tabix_key ) <EOL> except TypeError : <EOL> records = tabix_reader . query ( str ( chrom ) , tabix_key - <NUM_LIT:1> , tabix_key ) <EOL> except TabixError : <EOL> logger . warning ( "<STR_LIT>" . format ( <EOL> chrom , tabix_reader ) ) <EOL> except : <EOL> pass <EOL> return records <EOL> def get_frequencies ( tabix_reader , chrom , start , alt ) : <EOL> """<STR_LIT>""" <EOL> freq = None <EOL> records = get_tabix_records ( tabix_reader , chrom , start ) <EOL> frequencies = { } <EOL> for record in records : <EOL> logger . debug ( "<STR_LIT>" . format ( '<STR_LIT:\t>' . join ( record ) ) ) <EOL> for i , alternative in enumerate ( record [ <NUM_LIT:4> ] . split ( '<STR_LIT:U+002C>' ) ) : <EOL> if alternative == alt : <EOL> for info in record [ <NUM_LIT:7> ] . split ( '<STR_LIT:;>' ) : <EOL> info = info . split ( '<STR_LIT:=>' ) <EOL> if info [ <NUM_LIT:0> ] in [ '<STR_LIT>' , '<STR_LIT>' ] : <EOL> freqs = info [ - <NUM_LIT:1> ] . split ( '<STR_LIT:U+002C>' ) <EOL> frequencies [ info [ <NUM_LIT:0> ] ] = freqs [ i ] <EOL> return frequencies <EOL> def get_spidex_score ( tabix_reader , chrom , start , alt ) : <EOL> """<STR_LIT>""" <EOL> records = get_tabix_records ( tabix_reader , chrom , start ) <EOL> spidex_score = None <EOL> for record in records : <EOL> if record [ <NUM_LIT:3> ] == alt : <EOL> spidex_score = float ( record [ <NUM_LIT:5> ] ) <EOL> logger . debug ( "<STR_LIT>" . format ( spidex_score ) ) <EOL> return spidex_score <EOL> def get_cosmic ( tabix_reader , chrom , start , alt ) : <EOL> """<STR_LIT>""" <EOL> records = get_tabix_records ( tabix_reader , chrom , start ) <EOL> in_cosmic = False <EOL> for record in records : <EOL> if record [ <NUM_LIT:4> ] == alt : <EOL> in_cosmic = True <EOL> if in_cosmic : <EOL> logger . debug ( "<STR_LIT>" ) <EOL> else : <EOL> logger . debug ( "<STR_LIT>" ) <EOL> return in_cosmic <EOL> def get_cadd_scores ( tabix_reader , chrom , start , alt ) : <EOL> """<STR_LIT>""" <EOL> cadd_scores = { <EOL> '<STR_LIT>' : None , <EOL> '<STR_LIT>' : None , <EOL> } <EOL> records = get_tabix_records ( tabix_reader , chrom , start ) <EOL> for record in records : <EOL> if record [ <NUM_LIT:3> ] == alt : <EOL> cadd_scores [ '<STR_LIT>' ] = record [ - <NUM_LIT:2> ] <EOL> cadd_scores [ '<STR_LIT>' ] = record [ - <NUM_LIT:1> ] <EOL> return cadd_scores <EOL> def annotate_cadd_score ( variant , cadd_raw , cadd_file , cadd_1000g , cadd_exac , <EOL> cadd_ESP , cadd_InDels ) : <EOL> """<STR_LIT>""" <EOL> cadd_score = None <EOL> cadd_relative = None <EOL> cadd_absolute = None <EOL> cadd_relative_scores = [ ] <EOL> cadd_absolute_scores = [ ] <EOL> for alt in variant [ '<STR_LIT>' ] . split ( '<STR_LIT:U+002C>' ) : <EOL> if cadd_file : <EOL> cadd_scores = get_cadd_scores ( <EOL> cadd_file , <EOL> variant [ '<STR_LIT>' ] , <EOL> variant [ '<STR_LIT>' ] , <EOL> alt <EOL> ) <EOL> cadd_relative = cadd_scores [ '<STR_LIT>' ] <EOL> cadd_absolute = cadd_scores [ '<STR_LIT>' ] <EOL> if not ( cadd_relative and cadd_absolute ) and cadd_1000g : <EOL> cadd_scores = get_cadd_scores ( <EOL> cadd_1000g , <EOL> variant [ '<STR_LIT>' ] , <EOL> variant [ '<STR_LIT>' ] , <EOL> alt <EOL> ) <EOL> cadd_relative = cadd_scores [ '<STR_LIT>' ] <EOL> cadd_absolute = cadd_scores [ '<STR_LIT>' ] <EOL> if not ( cadd_relative and cadd_absolute ) and cadd_exac : <EOL> cadd_scores = get_cadd_scores ( <EOL> cadd_exac , <EOL> variant [ '<STR_LIT>' ] , <EOL> variant [ '<STR_LIT>' ] , <EOL> alt <EOL> ) <EOL> cadd_relative = cadd_scores [ '<STR_LIT>' ] <EOL> cadd_absolute = cadd_scores [ '<STR_LIT>' ] <EOL> if not ( cadd_relative and cadd_absolute ) and cadd_ESP : <EOL> cadd_scores = get_cadd_scores ( <EOL> cadd_ESP , <EOL> variant [ '<STR_LIT>' ] , <EOL> variant [ '<STR_LIT>' ] , <EOL> alt <EOL> ) <EOL> cadd_relative = cadd_scores [ '<STR_LIT>' ] <EOL> cadd_absolute = cadd_scores [ '<STR_LIT>' ] <EOL> if not ( cadd_relative and cadd_absolute ) and cadd_InDels : <EOL> cadd_scores = get_cadd_scores ( <EOL> cadd_ESP , <EOL> variant [ '<STR_LIT>' ] , <EOL> variant [ '<STR_LIT>' ] , <EOL> alt <EOL> ) <EOL> cadd_relative = cadd_scores [ '<STR_LIT>' ] <EOL> cadd_absolute = cadd_scores [ '<STR_LIT>' ] <EOL> if cadd_relative : <EOL> cadd_relative_scores . append ( str ( cadd_relative ) ) <EOL> else : <EOL> cadd_relative_scores . append ( '<STR_LIT:->' ) <EOL> if cadd_absolute : <EOL> cadd_absolute_scores . append ( str ( cadd_absolute ) ) <EOL> else : <EOL> cadd_absolute_scores . append ( '<STR_LIT:->' ) <EOL> any_annotation = False <EOL> for annotation in cadd_relative_scores : <EOL> if annotation != '<STR_LIT:->' : <EOL> any_annotation = True <EOL> if any_annotation : <EOL> variant [ '<STR_LIT>' ] = '<STR_LIT:U+002C>' . join ( cadd_relative_scores ) <EOL> if cadd_raw : <EOL> variant [ '<STR_LIT>' ] = '<STR_LIT:U+002C>' . join ( cadd_absolute_scores ) <EOL> return variant </s>
