<s> from chanjo . store import Exon <EOL> def _exon_kwargs ( data ) : <EOL> """<STR_LIT>""" <EOL> exon_id = data . get ( '<STR_LIT:name>' ) or data [ '<STR_LIT>' ] [ <NUM_LIT:0> ] <EOL> return { '<STR_LIT>' : exon_id , '<STR_LIT>' : data [ '<STR_LIT>' ] , <EOL> '<STR_LIT:start>' : data [ '<STR_LIT>' ] , '<STR_LIT:end>' : data [ '<STR_LIT>' ] } <EOL> def get_or_build_exon ( session , exon_filters ) : <EOL> """<STR_LIT>""" <EOL> exon_obj = session . query ( Exon ) . filter_by ( ** exon_filters ) . first ( ) <EOL> if exon_obj is None : <EOL> exon_obj = Exon ( ** exon_filters ) <EOL> return exon_obj <EOL> def groupby_tx ( exons , sambamba = False ) : <EOL> """<STR_LIT>""" <EOL> transcripts = { } <EOL> for exon in exons : <EOL> if sambamba : <EOL> exon [ '<STR_LIT>' ] = dict ( zip ( exon [ '<STR_LIT>' ] [ - <NUM_LIT:2> ] . split ( '<STR_LIT:U+002C>' ) , <EOL> exon [ '<STR_LIT>' ] [ - <NUM_LIT:1> ] . split ( '<STR_LIT:U+002C>' ) ) ) <EOL> else : <EOL> exon [ '<STR_LIT>' ] = dict ( exon [ '<STR_LIT>' ] ) <EOL> for transcript_id in exon [ '<STR_LIT>' ] : <EOL> if transcript_id not in transcripts : <EOL> transcripts [ transcript_id ] = [ ] <EOL> transcripts [ transcript_id ] . append ( exon ) <EOL> return transcripts </s>
