#NEWLINE# def tx_stat( transcript_id , exons , threshold = None ) : #NEWLINE# #INDENT# 'Calculate metrics for transcript stats model.\n\n    Args:\n        transcript_id (str): unqiue transcript id\n        exons (List[dict]): list of exon transcripts\n        threshold (Optional[int]): completeness level to disqualify exons\n\n    Returns:\n        dict: aggregated stats over all exons\n    ' #NEWLINE# sums = { #NEWLINE# #INDENT# 'bases' : 0 , #NEWLINE# 'mean_coverage' : 0 , #NEWLINE# #UNINDENT# } #NEWLINE# incomplete_exons = [ ] #NEWLINE# for exon in exons : #NEWLINE# #INDENT# exon_length = ( exon [ 'chromEnd' ] - exon [ 'chromStart' ] ) #NEWLINE# sums [ 'bases' ] += exon_length #NEWLINE# sums [ 'mean_coverage' ] += ( exon [ 'meanCoverage' ] * exon_length ) #NEWLINE# for comp_key in [ 10 , 15 , 20 , 50 , 100 ] : #NEWLINE# #INDENT# if ( comp_key in exon [ 'thresholds' ] ) : #NEWLINE# #INDENT# sums_key = 'completeness_{}' . format ( comp_key ) #NEWLINE# if ( sums_key not in sums ) : #NEWLINE# #INDENT# sums [ sums_key ] = 0 #NEWLINE# #UNINDENT# completeness = exon [ 'thresholds' ] [ comp_key ] #NEWLINE# sums [ sums_key ] += ( completeness * exon_length ) #NEWLINE# if ( ( threshold == comp_key ) and ( completeness < 100 ) ) : #NEWLINE# #INDENT# exon_obj = Exon ( exon [ 'chrom' ] , exon [ 'chromStart' ] , exon [ 'chromEnd' ] , completeness ) #NEWLINE# incomplete_exons . append ( exon_obj ) #NEWLINE# #UNINDENT# #UNINDENT# #UNINDENT# #UNINDENT# fields = { key : ( value / sums [ 'bases' ] ) for ( key , value ) in iteritems ( sums ) if ( key != 'bases' ) } #NEWLINE# fields [ 'incomplete_exons' ] = incomplete_exons #NEWLINE# fields [ 'threshold' ] = threshold #NEWLINE# return fields