<s> """<STR_LIT>""" <EOL> import copy <EOL> import random <EOL> import sys <EOL> import re <EOL> import pandas as pd <EOL> import numpy as np <EOL> import CGAT . Experiment as E <EOL> def groupMappers ( design_table , spike_regex , shuffle_suffix , keep_suffix ) : <EOL> '''<STR_LIT>''' <EOL> design_table = design_table . ix [ design_table [ '<STR_LIT>' ] == <NUM_LIT:1> , ] <EOL> design_table = design_table . ix [ design_table [ '<STR_LIT>' ] == <NUM_LIT:1> , ] <EOL> keep = [ ix for ix in design_table . index if <EOL> re . match ( spike_regex , design_table [ '<STR_LIT>' ] [ ix ] ) ] <EOL> design_table = design_table . ix [ keep ] <EOL> groups = list ( set ( [ design_table [ '<STR_LIT>' ] [ ix ] for <EOL> ix in design_table . index ] ) ) <EOL> groups_to_keep_ix = { } <EOL> groups_to_keep_tracks = { } <EOL> groups_to_spike_tracks = { } <EOL> keep_suffix = keep_suffix . split ( "<STR_LIT:U+002C>" ) <EOL> for group in groups : <EOL> groups_to_keep_ix [ group ] = [ <EOL> ix for ix in design_table . index <EOL> if re . match ( group , design_table [ '<STR_LIT>' ] [ ix ] ) ] <EOL> groups_to_spike_tracks [ group ] = [ <EOL> x + shuffle_suffix <EOL> for x in design_table . ix [ <EOL> groups_to_keep_ix [ group ] , "<STR_LIT>" ] . tolist ( ) ] <EOL> groups_to_keep_tracks [ group ] = copy . copy ( groups_to_spike_tracks [ group ] ) <EOL> groups_to_keep_tracks [ group ] . extend ( [ <EOL> x + y for <EOL> x in design_table . ix [ groups_to_keep_ix [ group ] , "<STR_LIT>" ] . tolist ( ) <EOL> for y in keep_suffix ] ) <EOL> return ( groups , groups_to_keep_tracks , groups_to_spike_tracks ) <EOL> def means2idxarrays ( g1 , g2 , i_bins , c_bins , difference ) : <EOL> '''<STR_LIT>''' <EOL> if difference == "<STR_LIT>" : <EOL> change = [ g2 [ x ] - g1 [ x ] for x in range ( <NUM_LIT:0> , len ( g1 ) ) ] <EOL> initial = g1 <EOL> elif difference == "<STR_LIT>" : <EOL> change = [ np . log2 ( ( g2 [ x ] + <NUM_LIT:1.0> ) / <EOL> ( g1 [ x ] + <NUM_LIT:1.0> ) ) for x in range ( <NUM_LIT:0> , len ( g1 ) ) ] <EOL> initial = [ np . log2 ( g1 [ x ] + <NUM_LIT:1.0> ) for x in range ( <NUM_LIT:0> , len ( g1 ) ) ] <EOL> change_idx = np . digitize ( change , c_bins ) <EOL> initial_idx = np . digitize ( initial , i_bins ) <EOL> return ( change_idx , initial_idx ) <EOL> def findClusters ( df , distance , size , tracks_map , groups ) : <EOL> '''<STR_LIT>''' <EOL> positions = df [ '<STR_LIT>' ] . tolist ( ) <EOL> contigs = df [ '<STR_LIT>' ] . tolist ( ) <EOL> current_pos = <NUM_LIT:0> <EOL> cluster_ix = [ ] <EOL> current_contig = "<STR_LIT>" <EOL> cluster_dfs = { } <EOL> n = <NUM_LIT:0> <EOL> for ix in range ( <NUM_LIT:0> , len ( positions ) ) : <EOL> next_pos = positions [ ix ] <EOL> next_contig = contigs [ ix ] <EOL> if ( ( ( next_pos < current_pos + distance ) & <EOL> ( next_contig == current_contig ) ) ) : <EOL> cluster_ix . append ( ix ) <EOL> else : <EOL> if len ( cluster_ix ) >= size : <EOL> start , end = ( cluster_ix [ <NUM_LIT:0> ] , cluster_ix [ - <NUM_LIT:1> ] ) <EOL> cluster_dfs [ n ] = df . loc [ start : end ] <EOL> n += <NUM_LIT:1> <EOL> cluster_ix = [ ] <EOL> current_pos = next_pos <EOL> current_contig = next_contig <EOL> E . info ( "<STR_LIT>" % n ) <EOL> return ( cluster_dfs ) <EOL> def shuffleCluster ( i_bins , c_bins , tracks_map , groups , <EOL> difference , s_max , i , clusters_dict , <EOL> s_bins_max , s_bins_min , s_bins_width ) : <EOL> s_bins = range ( s_bins_min , s_bins_max + <NUM_LIT:1> , s_bins_width , ) <EOL> counts = np . zeros ( ( len ( i_bins ) + <NUM_LIT:1> , len ( c_bins ) + <NUM_LIT:1> , len ( s_bins ) + <NUM_LIT:1> ) ) <EOL> indices = { ( key1 , key2 , key3 ) : [ ] <EOL> for key1 in np . digitize ( i_bins , i_bins ) <EOL> for key2 in np . digitize ( c_bins , c_bins ) <EOL> for key3 in np . digitize ( s_bins , s_bins ) } <EOL> for iteration in range ( <NUM_LIT:0> , i ) : <EOL> E . info ( "<STR_LIT>" % ( iteration + <NUM_LIT:1> ) ) <EOL> for size in s_bins : <EOL> group1_mean = [ ] <EOL> group2_mean = [ ] <EOL> g1_rand_s = [ ] <EOL> g2_rand_s = [ ] <EOL> g1_rand = np . random . permutation ( clusters_dict . keys ( ) ) <EOL> g2_rand = np . random . permutation ( clusters_dict . keys ( ) ) <EOL> for perm in range ( <NUM_LIT:0> , len ( g1_rand ) ) : <EOL> cluster1 = clusters_dict [ g1_rand [ perm ] ] . ix [ <EOL> : , tracks_map [ groups [ <NUM_LIT:0> ] ] ] <EOL> cluster2 = clusters_dict [ g2_rand [ perm ] ] . ix [ <EOL> : , tracks_map [ groups [ <NUM_LIT:1> ] ] ] <EOL> c1_rand_s = random . randint ( <EOL> min ( cluster1 . index ) , max ( cluster1 . index ) - size ) <EOL> c1_e = int ( c1_rand_s + size ) <EOL> c2_rand_s = random . randint ( <EOL> min ( cluster2 . index ) , max ( cluster2 . index ) - size ) <EOL> c2_e = int ( c2_rand_s + size ) <EOL> c1_mean = np . mean ( np . mean ( cluster1 . ix [ c1_rand_s : c1_e ] ) ) <EOL> c2_mean = np . mean ( np . mean ( cluster2 . ix [ c2_rand_s : c2_e ] ) ) <EOL> group1_mean . append ( c1_mean ) <EOL> group2_mean . append ( c2_mean ) <EOL> g1_rand_s . append ( c1_rand_s ) <EOL> g2_rand_s . append ( c2_rand_s ) <EOL> change_idx , initial_idx , = means2idxarrays ( <EOL> group1_mean , group2_mean , i_bins , <EOL> c_bins , difference ) <EOL> size_idx = np . digitize ( [ size ] * len ( initial_idx ) , s_bins ) <EOL> for idx , coord in enumerate ( zip ( <EOL> initial_idx , change_idx , size_idx ) ) : <EOL> if counts [ coord ] < s_max : <EOL> counts [ coord ] += <NUM_LIT:1> <EOL> cluster1_ix = clusters_dict [ g1_rand [ idx ] ] . index . values <EOL> cluster1_start = cluster1_ix [ <NUM_LIT:0> ] <EOL> cluster1_end = cluster1_ix [ - <NUM_LIT:1> ] <EOL> cluster2_ix = clusters_dict [ g2_rand [ idx ] ] . index . values <EOL> cluster2_start = cluster2_ix [ <NUM_LIT:0> ] <EOL> cluster2_end = cluster2_ix [ - <NUM_LIT:1> ] <EOL> c1_rand_s = g1_rand_s [ idx ] <EOL> c1_rand_e = int ( c1_rand_s + size ) <EOL> c2_rand_s = g2_rand_s [ idx ] <EOL> c2_rand_e = int ( c2_rand_s + size ) <EOL> indices [ coord ] . append ( ( <EOL> cluster1_start , cluster1_end , cluster2_start , <EOL> cluster2_end , c1_rand_s , c1_rand_e , c2_rand_s , <EOL> c2_rand_e ) ) <EOL> return indices , counts <EOL> def shuffleRows ( df , i_bins , c_bins , tracks_map , groups , <EOL> difference , s_max = <NUM_LIT:100> , i = <NUM_LIT:1> ) : <EOL> counts = np . zeros ( ( len ( i_bins ) + <NUM_LIT:1> , len ( c_bins ) + <NUM_LIT:1> ) ) <EOL> E . info ( "<STR_LIT>" ) <EOL> E . info ( counts ) <EOL> indices = { ( key1 , key2 ) : [ ] <EOL> for key1 in np . digitize ( i_bins , i_bins ) <EOL> for key2 in np . digitize ( c_bins , c_bins ) } <EOL> min_occup = min ( counts . flatten ( ) ) <EOL> for iteration in range ( <NUM_LIT:0> , i ) : <EOL> E . info ( "<STR_LIT>" % ( iteration + <NUM_LIT:1> ) ) <EOL> if min_occup < s_max : <EOL> group1_rand = np . random . permutation ( df . index ) <EOL> group2_rand = np . random . permutation ( df . index ) <EOL> group1_mean = df . ix [ group1_rand , <EOL> tracks_map [ groups [ <NUM_LIT:0> ] ] ] . apply ( <EOL> np . mean , axis = <NUM_LIT:1> ) . tolist ( ) <EOL> group2_mean = df . ix [ group2_rand , <EOL> tracks_map [ groups [ <NUM_LIT:1> ] ] ] . apply ( <EOL> np . mean , axis = <NUM_LIT:1> ) . tolist ( ) <EOL> change_idx , initial_idx = means2idxarrays ( <EOL> group1_mean , group2_mean , i_bins , c_bins , difference ) <EOL> E . info ( "<STR_LIT>" % str ( initial_idx . max ( ) ) ) <EOL> for idx , coord in enumerate ( zip ( initial_idx , change_idx ) ) : <EOL> if coord in indices . keys ( ) : <EOL> if counts [ coord ] < s_max : <EOL> counts [ coord ] += <NUM_LIT:1> <EOL> indices [ coord ] . append ( ( group1_rand [ idx ] , <EOL> group2_rand [ idx ] ) ) <EOL> min_occup = min ( counts . flatten ( ) ) <EOL> E . info ( "<STR_LIT>" ) <EOL> E . info ( counts ) <EOL> return indices , counts <EOL> def thresholdBins ( indices , counts , s_min ) : <EOL> output_indices_keep = copy . copy ( indices ) <EOL> for key in indices . keys ( ) : <EOL> if counts [ key ] < s_min : <EOL> output_indices_keep . pop ( key ) <EOL> E . info ( "<STR_LIT>" % len ( output_indices_keep . keys ( ) ) ) <EOL> E . info ( "<STR_LIT>" % <EOL> ( max ( counts . flatten ( ) ) ) ) <EOL> return output_indices_keep <EOL> def outputSpikes ( df , id_column , indices , tracks_map , groups , <EOL> method , spike_type , <EOL> min_cbin , width_cbin , min_ibin , width_ibin , <EOL> min_sbin , width_sbin ) : <EOL> def printHeader ( keep_columns , groups ) : <EOL> header = keep_columns <EOL> header . extend ( tracks_map [ groups [ <NUM_LIT:0> ] ] ) <EOL> header . extend ( tracks_map [ groups [ <NUM_LIT:1> ] ] ) <EOL> sys . stdout . write ( "<STR_LIT>" % "<STR_LIT:\t>" . join ( map ( str , header ) ) ) <EOL> return header <EOL> if spike_type == "<STR_LIT>" : <EOL> keep_cols = printHeader ( [ id_column ] , groups ) <EOL> elif spike_type == "<STR_LIT>" : <EOL> keep_cols = printHeader ( [ "<STR_LIT>" , "<STR_LIT>" ] , groups ) <EOL> if method == "<STR_LIT>" : <EOL> df = df . ix [ : , keep_cols ] <EOL> df . to_csv ( sys . stdout , index = False , header = False , sep = "<STR_LIT:\t>" , <EOL> dtype = { '<STR_LIT>' : int } ) <EOL> def getInitialChangeSize ( key , width_ibin , min_ibin , width_cbin , min_cbin , <EOL> width_s_bin , min_s_bin ) : <EOL> initial_bin , change_bin , size_bin = key <EOL> initial = ( ( initial_bin * width_ibin ) + min_ibin - ( width_ibin * <NUM_LIT:0.5> ) ) <EOL> change = ( ( change_bin * width_cbin ) + min_cbin - ( width_cbin * <NUM_LIT:0.5> ) ) <EOL> size = ( ( size_bin * width_sbin ) + min_sbin - <NUM_LIT:1> ) <EOL> return initial , change , size <EOL> def getInitialChange ( key , width_ibin , min_ibin , width_cbin , min_cbin ) : <EOL> initial_bin , change_bin = key <EOL> initial = ( ( initial_bin * width_ibin ) + min_ibin - ( width_ibin * <NUM_LIT:0.5> ) ) <EOL> change = ( ( change_bin * width_cbin ) + min_cbin - ( width_cbin * <NUM_LIT:0.5> ) ) <EOL> return initial , change <EOL> n = <NUM_LIT:0> <EOL> if spike_type == "<STR_LIT>" : <EOL> for key in indices : <EOL> for pair in indices [ key ] : <EOL> initial , change = getInitialChange ( key , width_ibin , min_ibin , <EOL> width_cbin , min_cbin ) <EOL> row = [ "<STR_LIT:_>" . join ( map ( str , <EOL> ( "<STR_LIT>" , initial , change , n ) ) ) ] <EOL> row . extend ( df . ix [ pair [ <NUM_LIT:0> ] , tracks_map [ groups [ <NUM_LIT:0> ] ] ] ) <EOL> row . extend ( df . ix [ pair [ <NUM_LIT:1> ] , tracks_map [ groups [ <NUM_LIT:1> ] ] ] ) <EOL> sys . stdout . write ( "<STR_LIT>" % "<STR_LIT:\t>" . join ( map ( str , row ) ) ) <EOL> n += <NUM_LIT:1> <EOL> elif spike_type == "<STR_LIT>" : <EOL> for key in indices . keys ( ) : <EOL> initial , change , size = getInitialChangeSize ( <EOL> key , width_ibin , min_ibin , width_cbin , <EOL> min_cbin , width_sbin , min_sbin ) <EOL> for values in indices [ key ] : <EOL> ( c1s , c1e , c2s , c2e , c1rs , c1re , <EOL> c2rs , c2re ) = values <EOL> cluster_id = "<STR_LIT:_>" . join ( map ( str , ( "<STR_LIT>" , initial , <EOL> change , size , c1rs - c1s , n ) ) ) <EOL> temp_cluster_df = df . ix [ c1s : c1e , keep_cols ] <EOL> temp_cluster_df [ '<STR_LIT>' ] = cluster_id <EOL> temp_cluster_swap = df . ix [ c2rs : c2re , tracks_map [ groups [ <NUM_LIT:1> ] ] ] <EOL> temp_cluster_swap . set_index ( df . ix [ c1rs : c1re ] . index , <EOL> drop = True , inplace = True ) <EOL> temp_cluster_df . ix [ c1rs : c1re , tracks_map [ <EOL> groups [ <NUM_LIT:1> ] ] ] = temp_cluster_swap <EOL> temp_cluster_df . to_csv ( sys . stdout , index = False , <EOL> header = False , sep = "<STR_LIT:\t>" , <EOL> dtype = { '<STR_LIT>' : int } ) <EOL> n += <NUM_LIT:1> <EOL> def main ( argv = None ) : <EOL> """<STR_LIT>""" <EOL> if not argv : <EOL> argv = sys . argv <EOL> parser = E . OptionParser ( <EOL> version = "<STR_LIT>" , <EOL> usage = globals ( ) [ "<STR_LIT>" ] ) <EOL> parser . add_option ( "<STR_LIT>" , "<STR_LIT>" , dest = "<STR_LIT>" , <EOL> type = "<STR_LIT:string>" , <EOL> help = "<STR_LIT>" ) <EOL> parser . add_option ( "<STR_LIT>" , "<STR_LIT>" , dest = "<STR_LIT>" , <EOL> type = "<STR_LIT:float>" , <EOL> help = "<STR_LIT>" ) <EOL> parser . add_option ( "<STR_LIT>" , "<STR_LIT>" , dest = "<STR_LIT>" , <EOL> type = "<STR_LIT:float>" , <EOL> help = "<STR_LIT>" ) <EOL> parser . add_option ( "<STR_LIT>" , "<STR_LIT>" , dest = "<STR_LIT>" , <EOL> type = "<STR_LIT:float>" , <EOL> help = "<STR_LIT>" ) <EOL> parser . add_option ( "<STR_LIT>" , "<STR_LIT>" , dest = "<STR_LIT>" , <EOL> type = "<STR_LIT:float>" , <EOL> help = "<STR_LIT>" ) <EOL> parser . add_option ( "<STR_LIT>" , "<STR_LIT>" , dest = "<STR_LIT>" , <EOL> type = "<STR_LIT:float>" , <EOL> help = "<STR_LIT>" ) <EOL> parser . add_option ( "<STR_LIT>" , "<STR_LIT>" , dest = "<STR_LIT>" , <EOL> type = "<STR_LIT:float>" , <EOL> help = "<STR_LIT>" ) <EOL> parser . add_option ( "<STR_LIT>" , "<STR_LIT>" , dest = "<STR_LIT>" , <EOL> type = "<STR_LIT:int>" , <EOL> help = "<STR_LIT>" ) <EOL> parser . add_option ( "<STR_LIT>" , "<STR_LIT>" , dest = "<STR_LIT>" , <EOL> type = "<STR_LIT:int>" , <EOL> help = "<STR_LIT>" ) <EOL> parser . add_option ( "<STR_LIT>" , "<STR_LIT>" , dest = "<STR_LIT>" , <EOL> type = "<STR_LIT>" , choices = ( "<STR_LIT>" , "<STR_LIT>" ) , <EOL> help = "<STR_LIT>" ) <EOL> parser . add_option ( "<STR_LIT>" , "<STR_LIT>" , dest = "<STR_LIT>" , type = "<STR_LIT:int>" , <EOL> help = "<STR_LIT>" ) <EOL> parser . add_option ( "<STR_LIT>" , "<STR_LIT>" , dest = "<STR_LIT:id>" , action = "<STR_LIT>" , <EOL> help = "<STR_LIT>" ) <EOL> parser . add_option ( "<STR_LIT:-c>" , "<STR_LIT>" , <EOL> dest = "<STR_LIT>" , type = "<STR_LIT:int>" , <EOL> help = "<STR_LIT>" ) <EOL> parser . add_option ( "<STR_LIT>" , "<STR_LIT>" , <EOL> dest = "<STR_LIT>" , type = "<STR_LIT:int>" , <EOL> help = "<STR_LIT>" ) <EOL> parser . add_option ( "<STR_LIT>" , "<STR_LIT>" , <EOL> dest = "<STR_LIT>" , type = "<STR_LIT>" , <EOL> choices = ( "<STR_LIT>" , "<STR_LIT>" ) , <EOL> help = "<STR_LIT>" ) <EOL> parser . add_option ( "<STR_LIT>" , "<STR_LIT>" , <EOL> dest = "<STR_LIT>" , type = "<STR_LIT:int>" , <EOL> help = "<STR_LIT>" ) <EOL> parser . add_option ( "<STR_LIT>" , "<STR_LIT>" , <EOL> dest = "<STR_LIT>" , type = "<STR_LIT:int>" , <EOL> help = "<STR_LIT>" ) <EOL> parser . add_option ( "<STR_LIT>" , "<STR_LIT>" , <EOL> dest = "<STR_LIT>" , type = "<STR_LIT:int>" , <EOL> help = "<STR_LIT>" ) <EOL> parser . add_option ( "<STR_LIT>" , "<STR_LIT>" , <EOL> dest = "<STR_LIT>" , type = "<STR_LIT>" , <EOL> choices = ( "<STR_LIT>" , "<STR_LIT>" ) , <EOL> help = "<STR_LIT>" ) <EOL> parser . add_option ( "<STR_LIT>" , "<STR_LIT>" , <EOL> dest = "<STR_LIT>" , type = "<STR_LIT:string>" , <EOL> help = "<STR_LIT>" ) <EOL> parser . add_option ( "<STR_LIT>" , "<STR_LIT>" , <EOL> dest = "<STR_LIT>" , type = "<STR_LIT:string>" , <EOL> help = "<STR_LIT>" ) <EOL> parser . add_option ( "<STR_LIT>" , "<STR_LIT>" , <EOL> dest = "<STR_LIT>" , type = "<STR_LIT:string>" , action = "<STR_LIT>" , <EOL> help = "<STR_LIT>" ) <EOL> parser . set_defaults ( <EOL> design_file = None , <EOL> output_method = "<STR_LIT>" , <EOL> difference = "<STR_LIT>" , <EOL> spike_type = "<STR_LIT>" , <EOL> genome_file = None , <EOL> min_cbin = None , <EOL> max_cbin = None , <EOL> width_cbin = None , <EOL> min_ibin = None , <EOL> max_ibin = None , <EOL> width_ibin = None , <EOL> id_columns = None , <EOL> max_spike = <NUM_LIT:100> , <EOL> min_spike = None , <EOL> iterations = <NUM_LIT:1> , <EOL> cluster_max_distance = <NUM_LIT:100> , <EOL> cluster_min_size = <NUM_LIT:10> , <EOL> min_sbin = <NUM_LIT:1> , <EOL> max_sbin = <NUM_LIT:9> , <EOL> width_sbin = <NUM_LIT:2> , <EOL> id_column = None , <EOL> shuffle_suffix = None , <EOL> keep_suffix = None , <EOL> spike_regex = "<STR_LIT>" ) <EOL> ( options , args ) = E . Start ( parser , argv = argv , add_output_options = True ) <EOL> df = pd . read_table ( sys . stdin , sep = "<STR_LIT:\t>" ) <EOL> if options . spike_type == "<STR_LIT>" : <EOL> df_sort = df . sort ( columns = [ "<STR_LIT>" , "<STR_LIT>" ] ) <EOL> df_sort . set_index ( df . index , inplace = True ) <EOL> else : <EOL> df_sort = df <EOL> if not options . design_file : <EOL> raise ValueError ( "<STR_LIT>" ) <EOL> if options . spike_type == "<STR_LIT>" : <EOL> if options . max_sbin > options . cluster_min_size : <EOL> raise ValueError ( "<STR_LIT>" % ( <EOL> options . max_sbin , options . cluster_min_size ) ) <EOL> df_columns = set ( df . columns . values . tolist ( ) ) <EOL> msg = "<STR_LIT>" <EOL> assert "<STR_LIT>" in df_columns and "<STR_LIT>" in df_columns , msg <EOL> msg2 = '''<STR_LIT>''' % ( options . cluster_min_size , <EOL> options . max_sbin ) <EOL> assert options . max_sbin < options . cluster_min_size , msg2 <EOL> df_sort = df . sort ( columns = [ "<STR_LIT>" , "<STR_LIT>" ] ) <EOL> df_sort . set_index ( df . index , inplace = True ) <EOL> if not options . id_column : <EOL> if options . output_method == "<STR_LIT>" and options . spike_type == "<STR_LIT>" : <EOL> raise ValueError ( "<STR_LIT>" ) <EOL> elif options . output_method != "<STR_LIT>" : <EOL> options . id_column = "<STR_LIT:id>" <EOL> if not options . min_spike : <EOL> options . min_spike = options . max_spike <EOL> design_table = pd . read_table ( options . design_file , sep = "<STR_LIT:\t>" ) <EOL> groups , g_to_keep_tracks , g_to_spike_tracks = groupMappers ( <EOL> design_table , options . spike_regex , <EOL> options . shuffle_suffix , options . keep_suffix ) <EOL> change_bins = np . arange ( options . min_cbin , options . max_cbin , <EOL> options . width_cbin ) <EOL> E . info ( "<STR_LIT>" % str ( change_bins ) ) <EOL> initial_bins = np . arange ( options . min_ibin , options . max_ibin , <EOL> options . width_ibin ) <EOL> E . info ( "<STR_LIT>" % str ( initial_bins ) ) <EOL> if options . spike_type == "<STR_LIT>" : <EOL> E . info ( "<STR_LIT>" ) <EOL> clusters_dict = findClusters ( df_sort , options . cluster_max_distance , <EOL> options . cluster_min_size , <EOL> g_to_spike_tracks , groups ) <EOL> if len ( clusters_dict ) == <NUM_LIT:0> : <EOL> raise Exception ( "<STR_LIT>" ) <EOL> E . info ( "<STR_LIT>" ) <EOL> output_indices , counts = shuffleCluster ( <EOL> initial_bins , change_bins , g_to_spike_tracks , groups , <EOL> options . difference , options . max_spike , <EOL> options . iterations , clusters_dict , <EOL> options . max_sbin , options . min_sbin , options . width_sbin ) <EOL> elif options . spike_type == "<STR_LIT>" : <EOL> E . info ( "<STR_LIT>" ) <EOL> output_indices , counts = shuffleRows ( <EOL> df , initial_bins , change_bins , g_to_spike_tracks , groups , <EOL> options . difference , options . max_spike , options . iterations ) <EOL> filled_bins = thresholdBins ( output_indices , counts , options . min_spike ) <EOL> if len ( filled_bins ) == <NUM_LIT:0> : <EOL> raise Exception ( "<STR_LIT>" ) <EOL> E . info ( "<STR_LIT>" ) <EOL> outputSpikes ( df_sort , options . id_column , filled_bins , g_to_keep_tracks , <EOL> groups , method = options . output_method , <EOL> spike_type = options . spike_type , <EOL> min_cbin = options . min_cbin , width_cbin = options . width_cbin , <EOL> min_ibin = options . min_ibin , width_ibin = options . width_ibin , <EOL> min_sbin = options . min_sbin , width_sbin = options . width_sbin ) <EOL> E . Stop ( ) <EOL> if __name__ == "<STR_LIT:__main__>" : <EOL> sys . exit ( main ( sys . argv ) ) </s>
