<s> from __future__ import print_function <EOL> import dxpy <EOL> import sys <EOL> import magic <EOL> import subprocess <EOL> import argparse <EOL> parser = argparse . ArgumentParser ( description = '<STR_LIT>' ) <EOL> parser . add_argument ( '<STR_LIT>' , help = '<STR_LIT>' ) <EOL> parser . add_argument ( '<STR_LIT>' , help = '<STR_LIT>' ) <EOL> parser . add_argument ( '<STR_LIT>' , dest = '<STR_LIT>' , default = '<STR_LIT>' , help = '<STR_LIT>' ) <EOL> parser . add_argument ( '<STR_LIT>' , default = None , help = '<STR_LIT>' ) <EOL> parser . add_argument ( '<STR_LIT>' , default = [ ] , action = '<STR_LIT>' , help = '<STR_LIT>' ) <EOL> parser . add_argument ( '<STR_LIT>' , default = [ ] , action = '<STR_LIT>' , help = '<STR_LIT>' ) <EOL> parser . add_argument ( '<STR_LIT>' , default = [ ] , action = '<STR_LIT>' , help = '<STR_LIT>' ) <EOL> parser . add_argument ( '<STR_LIT>' , default = [ ] , action = '<STR_LIT>' , help = '<STR_LIT>' ) <EOL> @ dxpy . entry_point ( '<STR_LIT>' ) <EOL> def importGTF ( ** args ) : <EOL> if len ( args ) == <NUM_LIT:0> : <EOL> command_line_args = parser . parse_args ( sys . argv [ <NUM_LIT:1> : ] ) <EOL> fileName = command_line_args . fileName <EOL> reference = command_line_args . reference <EOL> outputName = command_line_args . outputName <EOL> tag = command_line_args . tag <EOL> property_key = command_line_args . property_key <EOL> property_value = command_line_args . property_value <EOL> additional_type = command_line_args . additional_type <EOL> file_id = command_line_args . file_id <EOL> else : <EOL> fileName = args [ '<STR_LIT>' ] <EOL> reference = args [ '<STR_LIT>' ] <EOL> outputName = '<STR_LIT>' <EOL> if args . get ( '<STR_LIT>' ) != None : <EOL> outputName = args [ '<STR_LIT>' ] <EOL> tag = [ ] <EOL> if args . get ( '<STR_LIT>' ) : <EOL> tag = args [ '<STR_LIT>' ] <EOL> if args . get ( '<STR_LIT>' ) != None : <EOL> property_key = args [ '<STR_LIT>' ] <EOL> if args . get ( '<STR_LIT>' ) != None : <EOL> property_value = args [ '<STR_LIT>' ] <EOL> if args . get ( '<STR_LIT>' ) != None : <EOL> additional_type = args [ '<STR_LIT>' ] <EOL> if args . get ( '<STR_LIT>' ) != None : <EOL> file_id = args [ '<STR_LIT>' ] <EOL> inputFileName = unpack ( fileName ) <EOL> capturedTypes = { "<STR_LIT>" : "<STR_LIT>" , "<STR_LIT>" : "<STR_LIT>" , "<STR_LIT>" : "<STR_LIT>" , "<STR_LIT>" : "<STR_LIT>" , "<STR_LIT>" : "<STR_LIT>" , "<STR_LIT>" : "<STR_LIT>" , "<STR_LIT>" : "<STR_LIT>" , "<STR_LIT>" : "<STR_LIT>" , "<STR_LIT>" : "<STR_LIT>" , "<STR_LIT>" : "<STR_LIT>" , "<STR_LIT>" : "<STR_LIT>" } <EOL> spansTable , additionalColumns = constructTable ( inputFileName ) <EOL> spansTable . add_tags ( tag ) <EOL> types = [ "<STR_LIT>" , "<STR_LIT>" ] <EOL> for x in additional_type : <EOL> types . append ( x ) <EOL> spansTable . add_types ( types ) <EOL> details = { '<STR_LIT>' : dxpy . dxlink ( reference ) } <EOL> if len ( property_key ) != len ( property_value ) : <EOL> raise dxpy . AppError ( "<STR_LIT>" ) <EOL> for i in range ( len ( property_key ) ) : <EOL> details [ property_key [ i ] ] = property_value [ i ] <EOL> for x in additional_type : <EOL> types . append ( x ) <EOL> if file_id != None : <EOL> details [ '<STR_LIT>' ] = dxpy . dxlink ( file_id ) <EOL> spansTable . set_details ( details ) <EOL> if outputName == '<STR_LIT>' : <EOL> spansTable . rename ( fileName ) <EOL> else : <EOL> spansTable . rename ( outputName ) <EOL> genes = { } <EOL> transcripts = { } <EOL> spanId = <NUM_LIT:0> <EOL> frames = { } <EOL> stopCodons = { } <EOL> inputFile = open ( inputFileName , '<STR_LIT:r>' ) <EOL> for line in inputFile : <EOL> if line [ <NUM_LIT:0> ] != "<STR_LIT:#>" : <EOL> values = parseLine ( line , capturedTypes ) <EOL> if values [ "<STR_LIT:type>" ] == "<STR_LIT>" : <EOL> if frames . get ( values [ "<STR_LIT>" ] ) == None : <EOL> frames [ values [ "<STR_LIT>" ] ] = { } <EOL> frames [ values [ "<STR_LIT>" ] ] [ values [ "<STR_LIT>" ] ] = values [ "<STR_LIT>" ] <EOL> for [ element , hashId , elementType ] in [ [ genes , values [ "<STR_LIT>" ] , "<STR_LIT>" ] , [ transcripts , values [ "<STR_LIT>" ] , "<STR_LIT>" ] ] : <EOL> if element . get ( hashId ) == None : <EOL> element [ hashId ] = { values [ "<STR_LIT>" ] : { "<STR_LIT>" : values [ "<STR_LIT>" ] , "<STR_LIT>" : values [ "<STR_LIT>" ] , "<STR_LIT>" : - <NUM_LIT:1> , "<STR_LIT>" : - <NUM_LIT:1> , "<STR_LIT>" : values [ "<STR_LIT>" ] , "<STR_LIT>" : values [ "<STR_LIT>" ] , "<STR_LIT>" : values [ "<STR_LIT>" ] , "<STR_LIT>" : False , "<STR_LIT>" : spanId , "<STR_LIT:name>" : values [ elementType ] , "<STR_LIT>" : values [ "<STR_LIT>" ] [ "<STR_LIT>" ] , "<STR_LIT>" : values [ "<STR_LIT>" ] [ "<STR_LIT>" ] } } <EOL> spanId += <NUM_LIT:1> <EOL> elif element [ hashId ] . get ( values [ "<STR_LIT>" ] ) == None : <EOL> element [ hashId ] [ values [ "<STR_LIT>" ] ] = { "<STR_LIT>" : values [ "<STR_LIT>" ] , "<STR_LIT>" : values [ "<STR_LIT>" ] , "<STR_LIT>" : - <NUM_LIT:1> , "<STR_LIT>" : - <NUM_LIT:1> , "<STR_LIT>" : values [ "<STR_LIT>" ] , "<STR_LIT>" : values [ "<STR_LIT>" ] , "<STR_LIT>" : values [ "<STR_LIT>" ] , "<STR_LIT>" : False , "<STR_LIT>" : spanId , "<STR_LIT:name>" : values [ elementType ] , "<STR_LIT>" : values [ "<STR_LIT>" ] [ "<STR_LIT>" ] , "<STR_LIT>" : values [ "<STR_LIT>" ] [ "<STR_LIT>" ] } <EOL> spanId += <NUM_LIT:1> <EOL> else : <EOL> if values [ "<STR_LIT>" ] < element [ hashId ] [ values [ "<STR_LIT>" ] ] [ "<STR_LIT>" ] : <EOL> element [ hashId ] [ values [ "<STR_LIT>" ] ] [ "<STR_LIT>" ] = values [ "<STR_LIT>" ] <EOL> if values [ "<STR_LIT>" ] > element [ hashId ] [ values [ "<STR_LIT>" ] ] [ "<STR_LIT>" ] : <EOL> element [ hashId ] [ values [ "<STR_LIT>" ] ] [ "<STR_LIT>" ] = values [ "<STR_LIT>" ] <EOL> if values [ "<STR_LIT:type>" ] == "<STR_LIT>" : <EOL> if stopCodons . get ( values [ "<STR_LIT>" ] ) == None : <EOL> stopCodons [ values [ "<STR_LIT>" ] ] = [ [ values [ "<STR_LIT>" ] , values [ "<STR_LIT>" ] ] ] <EOL> else : <EOL> stopCodons [ values [ "<STR_LIT>" ] ] . append ( [ values [ "<STR_LIT>" ] , values [ "<STR_LIT>" ] ] ) <EOL> if values [ "<STR_LIT:type>" ] == "<STR_LIT>" or values [ "<STR_LIT:type>" ] == "<STR_LIT>" or values [ "<STR_LIT:type>" ] == "<STR_LIT>" : <EOL> if values [ "<STR_LIT>" ] > transcripts [ values [ "<STR_LIT>" ] ] [ values [ "<STR_LIT>" ] ] [ "<STR_LIT>" ] : <EOL> transcripts [ values [ "<STR_LIT>" ] ] [ values [ "<STR_LIT>" ] ] [ "<STR_LIT>" ] = values [ "<STR_LIT>" ] <EOL> if values [ "<STR_LIT>" ] < transcripts [ values [ "<STR_LIT>" ] ] [ values [ "<STR_LIT>" ] ] [ "<STR_LIT>" ] or transcripts [ values [ "<STR_LIT>" ] ] [ values [ "<STR_LIT>" ] ] [ "<STR_LIT>" ] == - <NUM_LIT:1> : <EOL> transcripts [ values [ "<STR_LIT>" ] ] [ values [ "<STR_LIT>" ] ] [ "<STR_LIT>" ] = values [ "<STR_LIT>" ] <EOL> genes [ values [ "<STR_LIT>" ] ] [ values [ "<STR_LIT>" ] ] [ "<STR_LIT>" ] = True <EOL> transcripts [ values [ "<STR_LIT>" ] ] [ values [ "<STR_LIT>" ] ] [ "<STR_LIT>" ] = True <EOL> for gId , chrList in genes . iteritems ( ) : <EOL> for k , v in chrList . iteritems ( ) : <EOL> entry = [ k , v [ "<STR_LIT>" ] , v [ "<STR_LIT>" ] , v [ "<STR_LIT:name>" ] , v [ "<STR_LIT>" ] , "<STR_LIT>" , v [ "<STR_LIT>" ] , v [ "<STR_LIT>" ] , v [ "<STR_LIT>" ] , - <NUM_LIT:1> , - <NUM_LIT:1> , '<STR_LIT>' , '<STR_LIT>' , v [ "<STR_LIT>" ] , '<STR_LIT>' ] <EOL> for x in additionalColumns : <EOL> if x != "<STR_LIT>" and x != "<STR_LIT>" : <EOL> entry . append ( '<STR_LIT>' ) <EOL> spansTable . add_rows ( [ entry ] ) <EOL> for gId , chrList in transcripts . iteritems ( ) : <EOL> for k , v in chrList . iteritems ( ) : <EOL> entry = [ k , v [ "<STR_LIT>" ] , v [ "<STR_LIT>" ] , v [ "<STR_LIT:name>" ] , v [ "<STR_LIT>" ] , "<STR_LIT>" , v [ "<STR_LIT>" ] , v [ "<STR_LIT>" ] , genes [ v [ "<STR_LIT>" ] ] [ k ] [ "<STR_LIT>" ] , genes [ v [ "<STR_LIT>" ] ] [ k ] [ "<STR_LIT>" ] , - <NUM_LIT:1> , '<STR_LIT>' , '<STR_LIT>' , v [ "<STR_LIT>" ] , v [ "<STR_LIT>" ] ] <EOL> for x in additionalColumns : <EOL> if x != "<STR_LIT>" and x != "<STR_LIT>" : <EOL> entry . append ( '<STR_LIT>' ) <EOL> spansTable . add_rows ( [ entry ] ) <EOL> exons = { } <EOL> inputFile = open ( inputFileName , '<STR_LIT:r>' ) <EOL> for line in inputFile : <EOL> if line [ <NUM_LIT:0> ] != "<STR_LIT:#>" : <EOL> values = parseLine ( line , capturedTypes ) <EOL> if exons . get ( values [ "<STR_LIT>" ] ) != None : <EOL> if exons [ values [ "<STR_LIT>" ] ] . get ( values [ "<STR_LIT>" ] ) == None : <EOL> exons [ values [ "<STR_LIT>" ] ] [ values [ "<STR_LIT>" ] ] = [ ] <EOL> else : <EOL> exons [ values [ "<STR_LIT>" ] ] = { values [ "<STR_LIT>" ] : [ ] } <EOL> if capturedTypes . get ( values [ "<STR_LIT:type>" ] ) != None : <EOL> if values [ "<STR_LIT:type>" ] == "<STR_LIT>" or values [ "<STR_LIT:type>" ] == "<STR_LIT>" or values [ "<STR_LIT:type>" ] == "<STR_LIT>" or values [ "<STR_LIT:type>" ] == "<STR_LIT>" or values [ "<STR_LIT:type>" ] == "<STR_LIT>" : <EOL> writeEntry ( spansTable , spanId , exons [ values [ "<STR_LIT>" ] ] , additionalColumns , values [ "<STR_LIT>" ] , values [ "<STR_LIT>" ] , values [ "<STR_LIT>" ] , values [ "<STR_LIT>" ] , [ values [ "<STR_LIT>" ] , values [ "<STR_LIT>" ] , values [ "<STR_LIT>" ] , values [ "<STR_LIT:name>" ] , spanId , capturedTypes [ values [ "<STR_LIT:type>" ] ] , values [ "<STR_LIT>" ] , values [ "<STR_LIT>" ] , False , transcripts [ values [ "<STR_LIT>" ] ] [ "<STR_LIT>" ] , values [ "<STR_LIT>" ] , '<STR_LIT>' , values [ "<STR_LIT:source>" ] ] ) <EOL> if "<STR_LIT>" in values [ "<STR_LIT>" ] : <EOL> values [ "<STR_LIT>" ] += "<STR_LIT:.>" + values [ "<STR_LIT>" ] [ "<STR_LIT>" ] <EOL> if values [ "<STR_LIT:type>" ] == "<STR_LIT>" : <EOL> if stopCodons . get ( values [ "<STR_LIT>" ] ) != None : <EOL> for x in stopCodons [ values [ "<STR_LIT>" ] ] : <EOL> if values [ "<STR_LIT>" ] == x [ <NUM_LIT:0> ] : <EOL> values [ "<STR_LIT>" ] = x [ <NUM_LIT:1> ] <EOL> break <EOL> if [ values [ "<STR_LIT>" ] , values [ "<STR_LIT>" ] ] not in exons [ values [ "<STR_LIT>" ] ] [ values [ "<STR_LIT>" ] ] : <EOL> spanId = writeEntry ( spansTable , spanId , exons [ values [ "<STR_LIT>" ] ] , additionalColumns , values [ "<STR_LIT>" ] , values [ "<STR_LIT>" ] , values [ "<STR_LIT>" ] , values [ "<STR_LIT>" ] , [ values [ "<STR_LIT>" ] , values [ "<STR_LIT>" ] , values [ "<STR_LIT>" ] , values [ "<STR_LIT>" ] , spanId , capturedTypes [ values [ "<STR_LIT:type>" ] ] , values [ "<STR_LIT>" ] , values [ "<STR_LIT>" ] , True , transcripts [ values [ "<STR_LIT>" ] ] [ values [ "<STR_LIT>" ] ] [ "<STR_LIT>" ] , values [ "<STR_LIT>" ] , '<STR_LIT>' , values [ "<STR_LIT:source>" ] ] ) <EOL> if values [ "<STR_LIT:type>" ] == "<STR_LIT>" : <EOL> values [ "<STR_LIT:type>" ] = "<STR_LIT>" <EOL> values [ "<STR_LIT>" ] = <NUM_LIT:3> - ( values [ "<STR_LIT>" ] - values [ "<STR_LIT>" ] ) <EOL> if values [ "<STR_LIT:type>" ] == "<STR_LIT>" : <EOL> if ( transcripts [ values [ "<STR_LIT>" ] ] [ values [ "<STR_LIT>" ] ] [ "<STR_LIT>" ] != - <NUM_LIT:1> and transcripts [ values [ "<STR_LIT>" ] ] [ values [ "<STR_LIT>" ] ] [ "<STR_LIT>" ] != - <NUM_LIT:1> ) : <EOL> if frames . get ( values [ "<STR_LIT>" ] ) != None : <EOL> if frames [ values [ "<STR_LIT>" ] ] . get ( values [ "<STR_LIT>" ] ) != None : <EOL> values [ "<STR_LIT>" ] = frames [ values [ "<STR_LIT>" ] ] [ values [ "<STR_LIT>" ] ] <EOL> for x in splitExons ( transcripts [ values [ "<STR_LIT>" ] ] , values [ "<STR_LIT>" ] , values [ "<STR_LIT>" ] , values [ "<STR_LIT>" ] , values [ "<STR_LIT>" ] ) : <EOL> spanId = writeEntry ( spansTable , spanId , exons [ values [ "<STR_LIT>" ] ] , additionalColumns , values [ "<STR_LIT>" ] , x [ <NUM_LIT:1> ] , x [ <NUM_LIT:2> ] , values [ "<STR_LIT>" ] , [ values [ "<STR_LIT>" ] , x [ <NUM_LIT:1> ] , x [ <NUM_LIT:2> ] , values [ "<STR_LIT>" ] , spanId , x [ <NUM_LIT:0> ] , values [ "<STR_LIT>" ] , values [ "<STR_LIT>" ] , x [ <NUM_LIT:3> ] , transcripts [ values [ "<STR_LIT>" ] ] [ values [ "<STR_LIT>" ] ] [ "<STR_LIT>" ] , values [ "<STR_LIT>" ] , '<STR_LIT>' , values [ "<STR_LIT:source>" ] ] ) <EOL> else : <EOL> spanId = writeEntry ( spansTable , spanId , exons [ values [ "<STR_LIT>" ] ] , additionalColumns , values [ "<STR_LIT>" ] , values [ "<STR_LIT>" ] , values [ "<STR_LIT>" ] , values [ "<STR_LIT>" ] , [ values [ "<STR_LIT>" ] , values [ "<STR_LIT>" ] , values [ "<STR_LIT>" ] , values [ "<STR_LIT>" ] , spanId , capturedTypes [ values [ "<STR_LIT:type>" ] ] , values [ "<STR_LIT>" ] , values [ "<STR_LIT>" ] , False , transcripts [ values [ "<STR_LIT>" ] ] [ values [ "<STR_LIT>" ] ] [ "<STR_LIT>" ] , values [ "<STR_LIT>" ] , '<STR_LIT>' , values [ "<STR_LIT:source>" ] ] ) <EOL> spansTable . flush ( ) <EOL> spansTable . close ( ) <EOL> outputFile = open ( "<STR_LIT>" , '<STR_LIT:w>' ) <EOL> outputFile . write ( spansTable . get_id ( ) ) <EOL> outputFile . close ( ) <EOL> print ( spansTable . get_id ( ) ) <EOL> return spansTable . get_id ( ) <EOL> def writeEntry ( spansTable , spanId , exonInfo , additionalColumns , chromosome , lo , hi , attributes , entry ) : <EOL> if [ lo , hi ] not in exonInfo [ chromosome ] and [ lo , hi - <NUM_LIT:2> ] not in exonInfo [ chromosome ] : <EOL> checkOverlap = trimOverlap ( exonInfo [ chromosome ] , lo , hi ) <EOL> if checkOverlap [ "<STR_LIT>" ] - checkOverlap [ "<STR_LIT>" ] > <NUM_LIT:0> : <EOL> entry [ <NUM_LIT:1> ] = checkOverlap [ "<STR_LIT>" ] <EOL> entry [ <NUM_LIT:2> ] = checkOverlap [ "<STR_LIT>" ] <EOL> if entry [ <NUM_LIT:6> ] == "<STR_LIT:->" : <EOL> entry [ <NUM_LIT:10> ] = int ( entry [ <NUM_LIT:10> ] ) + checkOverlap [ "<STR_LIT>" ] % <NUM_LIT:3> <EOL> else : <EOL> entry [ <NUM_LIT:10> ] = int ( entry [ <NUM_LIT:10> ] ) + checkOverlap [ "<STR_LIT>" ] % <NUM_LIT:3> <EOL> exonInfo [ chromosome ] . append ( [ lo , hi ] ) <EOL> spanId += <NUM_LIT:1> <EOL> for x in additionalColumns : <EOL> if attributes . get ( x ) != None : <EOL> entry . append ( attributes [ x ] ) <EOL> else : <EOL> entry . append ( '<STR_LIT>' ) <EOL> spansTable . add_rows ( [ entry ] ) <EOL> return spanId <EOL> def trimOverlap ( exons , lo , hi ) : <EOL> loChange = <NUM_LIT:0> <EOL> hiChange = <NUM_LIT:0> <EOL> for x in exons : <EOL> if lo >= x [ <NUM_LIT:0> ] and lo <= x [ <NUM_LIT:1> ] : <EOL> loChange = x [ <NUM_LIT:1> ] - lo <EOL> lo = x [ <NUM_LIT:1> ] <EOL> if hi >= x [ <NUM_LIT:0> ] and hi <= x [ <NUM_LIT:1> ] : <EOL> hiChange = hi - x [ <NUM_LIT:0> ] <EOL> hi = x [ <NUM_LIT:0> ] <EOL> return { "<STR_LIT>" : lo , "<STR_LIT>" : hi , "<STR_LIT>" : loChange , "<STR_LIT>" : hiChange } <EOL> def splitExons ( transcriptInfo , chromosome , lo , hi , strand ) : <EOL> upstream = "<STR_LIT>" <EOL> downstream = "<STR_LIT>" <EOL> if strand == "<STR_LIT:->" : <EOL> upstream = "<STR_LIT>" <EOL> downstream = "<STR_LIT>" <EOL> result = [ [ "<STR_LIT>" , lo , hi , True ] ] <EOL> if hi < transcriptInfo [ chromosome ] [ "<STR_LIT>" ] : <EOL> result [ <NUM_LIT:0> ] [ <NUM_LIT:0> ] = upstream <EOL> elif lo > transcriptInfo [ chromosome ] [ "<STR_LIT>" ] : <EOL> result [ <NUM_LIT:0> ] [ <NUM_LIT:0> ] = downstream <EOL> if lo < transcriptInfo [ chromosome ] [ "<STR_LIT>" ] : <EOL> result [ <NUM_LIT:0> ] [ <NUM_LIT:1> ] = transcriptInfo [ chromosome ] [ "<STR_LIT>" ] <EOL> result . append ( [ upstream , lo , transcriptInfo [ chromosome ] [ "<STR_LIT>" ] , False ] ) <EOL> if hi > transcriptInfo [ chromosome ] [ "<STR_LIT>" ] : <EOL> result [ <NUM_LIT:0> ] [ <NUM_LIT:2> ] = transcriptInfo [ chromosome ] [ "<STR_LIT>" ] <EOL> result . append ( [ downstream , transcriptInfo [ chromosome ] [ "<STR_LIT>" ] , hi , False ] ) <EOL> return result <EOL> def parseLine ( line , capturedTypes ) : <EOL> tabSplit = line . split ( "<STR_LIT:\t>" ) <EOL> if len ( tabSplit ) == <NUM_LIT:1> : <EOL> tabSplit = line . split ( "<STR_LIT:U+0020>" ) <EOL> if len ( tabSplit ) < <NUM_LIT:9> : <EOL> raise dxpy . AppError ( "<STR_LIT>" + line ) <EOL> tabSplit [ <NUM_LIT:8> ] = "<STR_LIT:U+0020>" . join ( tabSplit [ <NUM_LIT:8> : ] ) <EOL> tabSplit = tabSplit [ : <NUM_LIT:9> ] <EOL> chromosome = tabSplit [ <NUM_LIT:0> ] <EOL> source = tabSplit [ <NUM_LIT:1> ] <EOL> typ = tabSplit [ <NUM_LIT:2> ] <EOL> if capturedTypes . get ( typ ) == None : <EOL> message = '<STR_LIT>' + "<STR_LIT>" . join ( capturedTypes . keys ( ) ) <EOL> raise dxpy . AppError ( "<STR_LIT>" + message + "<STR_LIT>" + line + "<STR_LIT>" + typ ) <EOL> try : <EOL> score = float ( tabSplit [ <NUM_LIT:5> ] ) <EOL> except ValueError : <EOL> if tabSplit [ <NUM_LIT:5> ] == "<STR_LIT:.>" or tabSplit [ <NUM_LIT:5> ] == '<STR_LIT>' : <EOL> score = dxpy . NULL <EOL> else : <EOL> raise dxpy . AppError ( "<STR_LIT>" + "<STR_LIT>" + line + "<STR_LIT>" + tabSplit [ <NUM_LIT:5> ] ) <EOL> if tabSplit [ <NUM_LIT:6> ] != "<STR_LIT:+>" and tabSplit [ <NUM_LIT:6> ] != "<STR_LIT:->" and tabSplit [ <NUM_LIT:6> ] != "<STR_LIT:.>" : <EOL> raise dxpy . AppError ( "<STR_LIT>" + "<STR_LIT>" + line + "<STR_LIT>" + tabSplit [ <NUM_LIT:6> ] ) <EOL> else : <EOL> strand = tabSplit [ <NUM_LIT:6> ] <EOL> try : <EOL> lo = int ( tabSplit [ <NUM_LIT:3> ] ) - <NUM_LIT:1> <EOL> except ValueError : <EOL> raise dxpy . AppError ( "<STR_LIT>" + "<STR_LIT>" + line + "<STR_LIT>" + tabSplit [ <NUM_LIT:3> ] ) <EOL> try : <EOL> hi = int ( tabSplit [ <NUM_LIT:4> ] ) <EOL> except ValueError : <EOL> raise dxpy . AppError ( "<STR_LIT>" + "<STR_LIT>" + line + "<STR_LIT>" + tabSplit [ <NUM_LIT:4> ] ) <EOL> try : <EOL> frame = int ( tabSplit [ <NUM_LIT:7> ] ) <EOL> if frame > <NUM_LIT:2> or frame < <NUM_LIT:0> : <EOL> raise dxpy . AppError ( "<STR_LIT>" + "<STR_LIT>" + line + "<STR_LIT>" + tabSplit [ <NUM_LIT:7> ] ) <EOL> except ValueError : <EOL> if tabSplit [ <NUM_LIT:7> ] == "<STR_LIT:.>" : <EOL> frame = - <NUM_LIT:1> <EOL> else : <EOL> raise dxpy . AppError ( "<STR_LIT>" + "<STR_LIT>" + line + "<STR_LIT>" + tabSplit [ <NUM_LIT:7> ] ) <EOL> lineAttributes = { } <EOL> entrySplit = tabSplit [ <NUM_LIT:8> ] . split ( "<STR_LIT:;>" ) <EOL> result = [ ] <EOL> for x in entrySplit : <EOL> keyValue = x . strip ( ) . split ( "<STR_LIT:U+0020>" ) <EOL> key = keyValue [ <NUM_LIT:0> ] <EOL> if key != '<STR_LIT>' : <EOL> if len ( key ) < <NUM_LIT:100> : <EOL> lineAttributes [ key . strip ( '<STR_LIT:">' ) ] = keyValue [ <NUM_LIT:1> ] . strip ( '<STR_LIT:">' ) <EOL> geneId = lineAttributes [ "<STR_LIT>" ] <EOL> transcriptId = lineAttributes [ "<STR_LIT>" ] <EOL> geneName = geneId <EOL> if "<STR_LIT>" in lineAttributes : <EOL> geneName = lineAttributes [ "<STR_LIT>" ] <EOL> transcriptName = transcriptId <EOL> if "<STR_LIT>" in lineAttributes : <EOL> transcriptName = lineAttributes [ "<STR_LIT>" ] <EOL> values = { "<STR_LIT>" : chromosome , "<STR_LIT>" : lo , "<STR_LIT>" : hi , "<STR_LIT>" : geneName , "<STR_LIT>" : transcriptName , "<STR_LIT:source>" : source , "<STR_LIT:type>" : typ , "<STR_LIT>" : strand , "<STR_LIT>" : score , "<STR_LIT>" : frame , "<STR_LIT>" : geneId , "<STR_LIT>" : transcriptId , "<STR_LIT>" : lineAttributes } <EOL> return values <EOL> def constructTable ( inputFileName ) : <EOL> inputFile = open ( inputFileName , '<STR_LIT:r>' ) <EOL> attributes = { "<STR_LIT>" : True , "<STR_LIT>" : True } <EOL> for line in inputFile : <EOL> if line [ <NUM_LIT:0> ] != "<STR_LIT:#>" : <EOL> tabSplit = line . split ( "<STR_LIT:\t>" ) <EOL> if len ( tabSplit ) == <NUM_LIT:1> : <EOL> tabSplit = line . split ( "<STR_LIT:U+0020>" ) <EOL> if len ( tabSplit ) < <NUM_LIT:9> : <EOL> raise dxpy . AppError ( "<STR_LIT>" + line ) <EOL> tabSplit [ <NUM_LIT:8> ] = "<STR_LIT:U+0020>" . join ( tabSplit [ <NUM_LIT:8> : ] ) <EOL> tabSplit = tabSplit [ : <NUM_LIT:9> ] <EOL> if len ( tabSplit ) != <NUM_LIT:9> : <EOL> raise dxpy . AppError ( "<STR_LIT>" + str ( len ( tabSplit ) ) + "<STR_LIT>" + line ) <EOL> else : <EOL> entrySplit = tabSplit [ <NUM_LIT:8> ] . split ( "<STR_LIT:;>" ) <EOL> geneIdPresent = False <EOL> transcriptIdPresent = False <EOL> result = [ ] <EOL> for x in entrySplit : <EOL> keyValue = x . strip ( ) . split ( "<STR_LIT:U+0020>" ) <EOL> key = keyValue [ <NUM_LIT:0> ] <EOL> if key == "<STR_LIT>" : <EOL> geneIdPresent = True <EOL> elif key == "<STR_LIT>" : <EOL> transcriptIdPresent = True <EOL> attributes [ key ] = True <EOL> if not geneIdPresent : <EOL> raise dxpy . AppError ( "<STR_LIT>" + line ) <EOL> if not transcriptIdPresent : <EOL> raise dxpy . AppError ( "<STR_LIT>" + line ) <EOL> schema = [ <EOL> { "<STR_LIT:name>" : "<STR_LIT>" , "<STR_LIT:type>" : "<STR_LIT:string>" } , <EOL> { "<STR_LIT:name>" : "<STR_LIT>" , "<STR_LIT:type>" : "<STR_LIT>" } , <EOL> { "<STR_LIT:name>" : "<STR_LIT>" , "<STR_LIT:type>" : "<STR_LIT>" } , <EOL> { "<STR_LIT:name>" : "<STR_LIT:name>" , "<STR_LIT:type>" : "<STR_LIT:string>" } , <EOL> { "<STR_LIT:name>" : "<STR_LIT>" , "<STR_LIT:type>" : "<STR_LIT>" } , <EOL> { "<STR_LIT:name>" : "<STR_LIT:type>" , "<STR_LIT:type>" : "<STR_LIT:string>" } , <EOL> { "<STR_LIT:name>" : "<STR_LIT>" , "<STR_LIT:type>" : "<STR_LIT:string>" } , <EOL> { "<STR_LIT:name>" : "<STR_LIT>" , "<STR_LIT:type>" : "<STR_LIT:float>" } , <EOL> { "<STR_LIT:name>" : "<STR_LIT>" , "<STR_LIT:type>" : "<STR_LIT>" } , <EOL> { "<STR_LIT:name>" : "<STR_LIT>" , "<STR_LIT:type>" : "<STR_LIT>" } , <EOL> { "<STR_LIT:name>" : "<STR_LIT>" , "<STR_LIT:type>" : "<STR_LIT>" } , <EOL> { "<STR_LIT:name>" : "<STR_LIT:description>" , "<STR_LIT:type>" : "<STR_LIT:string>" } , <EOL> { "<STR_LIT:name>" : "<STR_LIT:source>" , "<STR_LIT:type>" : "<STR_LIT:string>" } , <EOL> { "<STR_LIT:name>" : "<STR_LIT>" , "<STR_LIT:type>" : "<STR_LIT:string>" } , <EOL> { "<STR_LIT:name>" : "<STR_LIT>" , "<STR_LIT:type>" : "<STR_LIT:string>" } ] <EOL> additionalColumns = [ '<STR_LIT>' , '<STR_LIT>' ] <EOL> for k , v in attributes . iteritems ( ) : <EOL> if k != '<STR_LIT>' and k != '<STR_LIT>' and k != '<STR_LIT>' and len ( k ) < <NUM_LIT:100> : <EOL> schema . append ( { "<STR_LIT:name>" : k , "<STR_LIT:type>" : "<STR_LIT:string>" } ) <EOL> additionalColumns . append ( k ) <EOL> indices = [ dxpy . DXGTable . genomic_range_index ( "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" , '<STR_LIT>' ) , <EOL> dxpy . DXGTable . lexicographic_index ( [ <EOL> dxpy . DXGTable . lexicographic_index_column ( "<STR_LIT:name>" , True , False ) , <EOL> dxpy . DXGTable . lexicographic_index_column ( "<STR_LIT>" ) , <EOL> dxpy . DXGTable . lexicographic_index_column ( "<STR_LIT>" ) , <EOL> dxpy . DXGTable . lexicographic_index_column ( "<STR_LIT>" ) , <EOL> dxpy . DXGTable . lexicographic_index_column ( "<STR_LIT:type>" ) ] , "<STR_LIT>" ) ] <EOL> spansTable = dxpy . new_dxgtable ( columns = schema , indices = indices ) <EOL> return spansTable , additionalColumns <EOL> def unpack ( input ) : <EOL> m = magic . Magic ( ) <EOL> try : <EOL> file_type = m . from_file ( input ) <EOL> except : <EOL> raise dxpy . AppError ( "<STR_LIT>" ) <EOL> if file_type == '<STR_LIT>' : <EOL> raise dxpy . AppError ( "<STR_LIT>" ) <EOL> uncomp_util = None <EOL> if file_type == '<STR_LIT>' : <EOL> uncomp_util = '<STR_LIT>' <EOL> elif file_type [ : <NUM_LIT> ] == '<STR_LIT>' : <EOL> uncomp_util = '<STR_LIT>' <EOL> elif file_type [ : <NUM_LIT:20> ] == '<STR_LIT>' : <EOL> uncomp_util = '<STR_LIT>' <EOL> elif file_type == '<STR_LIT>' or '<STR_LIT>' in file_type : <EOL> raise dxpy . AppError ( "<STR_LIT>" ) <EOL> else : <EOL> return input <EOL> if uncomp_util != None : <EOL> test_util = None <EOL> if uncomp_util == '<STR_LIT>' : <EOL> test_util = '<STR_LIT>' <EOL> elif uncomp_util == '<STR_LIT>' : <EOL> test_util = '<STR_LIT>' <EOL> elif uncomp_util == '<STR_LIT>' : <EOL> test_util = '<STR_LIT>' <EOL> try : <EOL> subprocess . check_call ( "<STR_LIT:U+0020>" . join ( [ test_util , "<STR_LIT>" , input ] ) , shell = True ) <EOL> except subprocess . CalledProcessError : <EOL> raise dxpy . AppError ( "<STR_LIT>" + uncomp_util + "<STR_LIT>" ) <EOL> try : <EOL> with subprocess . Popen ( [ uncomp_util , input ] , stdout = subprocess . PIPE ) . stdout as pipe : <EOL> line = pipe . next ( ) <EOL> uncomp_type = m . from_buffer ( line ) <EOL> except : <EOL> raise dxpy . AppError ( "<STR_LIT>" ) <EOL> if uncomp_type == '<STR_LIT>' or '<STR_LIT>' in uncomp_type : <EOL> raise dxpy . AppError ( "<STR_LIT>" ) <EOL> try : <EOL> subprocess . check_call ( "<STR_LIT:U+0020>" . join ( [ uncomp_util , "<STR_LIT>" , input , "<STR_LIT:>>" , "<STR_LIT>" ] ) , shell = True ) <EOL> return "<STR_LIT>" <EOL> except subprocess . CalledProcessError : <EOL> raise dxpy . AppError ( "<STR_LIT>" ) <EOL> def main ( ** args ) : <EOL> return importGTF ( ** args ) <EOL> if __name__ == '<STR_LIT:__main__>' : <EOL> importGTF ( ) </s>
