#NEWLINE# def outputSpikes( self , indices , tracks_map , groups , output_method , spike_type , min_cbin , width_cbin , max_cbin , min_ibin , width_ibin , max_ibin , min_sbin = 1 , width_sbin = 1 , max_sbin = 1 , append = False ) : #NEWLINE# #INDENT# ' method to output spike-ins generated by shuffling rows\n        (counts.shuffleRows) or clusters of rows (counts.shuffleCluster)\n\n        parameters:\n        * indices - indices for spike-ins\n        * min_i_bins = minimum bins for initial values\n        * width_i_bins = width of bins for initial values\n        * max_i_bins = maximum bin for initial values\n        * min_c_bins = minimum bin for change values\n        * width_c_bins = width of bins for change values\n        * max_c_bins = maximum bin for change values\n        * min_s_bins = minimum bin for size values\n        * width_s_bins = width of bins for size values\n        * max_s_bins = maximum bin for size values\n        * tracks_map = dictionary mapping groups to tracks\n        * spike_type = "relative" or "logfold"\n        * output_method = "append" or "seperate"\n        ' #NEWLINE# def makeHeader( tracks_map , groups , keep_columns = None ) : #NEWLINE# #INDENT# if keep_columns : #NEWLINE# #INDENT# header = keep_columns #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# header = [ ] #NEWLINE# #UNINDENT# header . extend ( tracks_map [ groups [ 0 ] ] ) #NEWLINE# header . extend ( tracks_map [ groups [ 1 ] ] ) #NEWLINE# return header #NEWLINE# #UNINDENT# if ( spike_type == 'row' ) : #NEWLINE# #INDENT# index = True #NEWLINE# keep_columns = None #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# if ( spike_type == 'cluster' ) : #NEWLINE# #INDENT# index = False #NEWLINE# keep_columns = [ 'contig' , 'position' ] #NEWLINE# #UNINDENT# #UNINDENT# header = makeHeader ( tracks_map , groups , keep_columns = keep_columns ) #NEWLINE# if ( output_method == 'append' ) : #NEWLINE# #INDENT# self . table = self . table . ix [ : , header ] #NEWLINE# self . table . to_csv ( sys . stdout , index = index , header = True , sep = '\t' , dtype = { #NEWLINE# #INDENT# 'position' : int , #NEWLINE# #UNINDENT# } ) #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# sys . stdout . write ( ( '%s\t%s\n' % ( 'spike' , '\t' . join ( map ( str , header ) ) ) ) ) #NEWLINE# #UNINDENT# def getInitialChangeSize( key , width_ibin , min_ibin , width_cbin , min_cbin , width_s_bin , min_s_bin ) : #NEWLINE# #INDENT# ( initial_bin , change_bin , size_bin ) = key #NEWLINE# initial = ( ( ( initial_bin * width_ibin ) + min_ibin ) - ( width_ibin * 0.5 ) ) #NEWLINE# change = ( ( ( change_bin * width_cbin ) + min_cbin ) - ( width_cbin * 0.5 ) ) #NEWLINE# size = ( ( ( size_bin * width_sbin ) + min_sbin ) - 1 ) #NEWLINE# return ( initial , change , size ) #NEWLINE# #UNINDENT# def getInitialChange( key , width_ibin , min_ibin , width_cbin , min_cbin ) : #NEWLINE# #INDENT# ( initial_bin , change_bin ) = key #NEWLINE# initial = ( ( ( initial_bin * width_ibin ) + min_ibin ) - ( width_ibin * 0.5 ) ) #NEWLINE# change = ( ( ( change_bin * width_cbin ) + min_cbin ) - ( width_cbin * 0.5 ) ) #NEWLINE# return ( initial , change ) #NEWLINE# #UNINDENT# n = 0 #NEWLINE# if ( spike_type == 'row' ) : #NEWLINE# #INDENT# for key in indices : #NEWLINE# #INDENT# for pair in indices [ key ] : #NEWLINE# #INDENT# ( initial , change ) = getInitialChange ( key , width_ibin , min_ibin , width_cbin , min_cbin ) #NEWLINE# row = [ '_' . join ( map ( str , ( 'spike-in' , initial , change , n ) ) ) ] #NEWLINE# row . extend ( self . table . ix [ ( pair [ 0 ] , tracks_map [ groups [ 0 ] ] ) ] ) #NEWLINE# row . extend ( self . table . ix [ ( pair [ 1 ] , tracks_map [ groups [ 1 ] ] ) ] ) #NEWLINE# sys . stdout . write ( ( '%s\n' % '\t' . join ( map ( str , row ) ) ) ) #NEWLINE# n += 1 #NEWLINE# #UNINDENT# #UNINDENT# #UNINDENT# else : #NEWLINE# #INDENT# if ( spike_type == 'cluster' ) : #NEWLINE# #INDENT# for key in indices . keys ( ) : #NEWLINE# #INDENT# ( initial , change , size ) = getInitialChangeSize ( key , width_ibin , min_ibin , width_cbin , min_cbin , width_sbin , min_sbin ) #NEWLINE# for values in indices [ key ] : #NEWLINE# #INDENT# ( c1s , c1e , c2s , c2e , c1rs , c1re , c2rs , c2re ) = values #NEWLINE# cluster_id = '_' . join ( map ( str , ( 'spike-in' , initial , change , size , ( c1rs - c1s ) , n ) ) ) #NEWLINE# temp_cluster_df = self . table . ix [ min_sbin : c1e , keep_cols ] #NEWLINE# temp_cluster_df [ 'contig' ] = cluster_id #NEWLINE# temp_cluster_swap = self . table . ix [ c2rs : c2re , tracks_map [ groups [ 1 ] ] ] #NEWLINE# temp_cluster_swap . set_index ( self . table . ix [ c1rs : c1re ] . index , drop = True , inplace = True ) #NEWLINE# temp_cluster_df . ix [ c1rs : c1re , tracks_map [ groups [ 1 ] ] ] = temp_cluster_swap #NEWLINE# temp_cluster_df . to_csv ( sys . stdout , index = index , header = False , sep = '\t' , dtype = { #NEWLINE# #INDENT# 'position' : int , #NEWLINE# #UNINDENT# } ) #NEWLINE# n += 1