def main(): _simulations = load.structured() _simulations = filtering.by_time_points_amount(_simulations, TIME_POINTS) _simulations = filtering.by_categories( _simulations, _is_single_cell=False, _is_heterogeneity=True, _is_low_connectivity=False, _is_causality=False, _is_dominant_passive=False, _is_fibrin=False ) _simulations = filtering.by_pair_distance(_simulations, _distance=PAIR_DISTANCE) _simulations = filtering.by_heterogeneity(_simulations, _std=STD) print('Total simulations:', len(_simulations)) _fiber_densities = compute_fiber_densities(_simulations) _window_distances_communicating = [[] for _i in OFFSETS_X] _window_distances_non_communicating = [[] for _i in OFFSETS_X] # window distances loop for _window_distance_index, _window_distance in enumerate(OFFSETS_X): print('Window distance:', _window_distance) # communicating loop for _simulation in tqdm(_simulations, desc='Communicating loop'): _left_cell_fiber_densities = _fiber_densities[(_simulation, _window_distance, 'left_cell')] _right_cell_fiber_densities = _fiber_densities[(_simulation, _window_distance, 'right_cell')] _correlation = compute_lib.correlation( compute_lib.derivative(_left_cell_fiber_densities, _n=DERIVATIVE), compute_lib.derivative(_right_cell_fiber_densities, _n=DERIVATIVE) ) _window_distances_communicating[_window_distance_index].append(_correlation) # non-communicating loop _simulations_indices = range(len(_simulations)) for _simulation_1_index in tqdm(_simulations_indices, desc='Non-communicating pairs loop'): _simulation_1 = _simulations[_simulation_1_index] for _simulation_2_index in _simulations_indices[_simulation_1_index + 1:]: _simulation_2 = _simulations[_simulation_2_index] for _simulation_1_cell_id, _simulation_2_cell_id in product(['left_cell', 'right_cell'], ['left_cell', 'right_cell']): _simulation_1_fiber_densities = \ _fiber_densities[(_simulation_1, _window_distance, _simulation_1_cell_id)] _simulation_2_fiber_densities = \ _fiber_densities[(_simulation_2, _window_distance, _simulation_2_cell_id)] _correlation = compute_lib.correlation( compute_lib.derivative(_simulation_1_fiber_densities, _n=DERIVATIVE), compute_lib.derivative(_simulation_2_fiber_densities, _n=DERIVATIVE) ) _window_distances_non_communicating[_window_distance_index].append(_correlation) # rank sums print('Wilcoxon rank-sum tests between communicating and non-communicating:', ranksums(_window_distances_communicating[_window_distance_index], _window_distances_non_communicating[_window_distance_index])) # plot _data = [] _colors_array = config.colors(2) for _communicating, _communicating_text, _pair_distances, _color in \ zip([True, False], ['Communicating', 'Non-communicating'], [_window_distances_communicating, _window_distances_non_communicating], _colors_array): _y = [] _x = [] for _window_distance_index, _window_distance in enumerate(OFFSETS_X): _y += _pair_distances[_window_distance_index] _x += [_window_distance for _i in _pair_distances[_window_distance_index]] _data.append( go.Box( y=_y, x=_x, name=_communicating_text, boxpoints='all' if _communicating else False, jitter=1, pointpos=0, line={ 'width': 1 }, fillcolor='white', marker={ 'size': 10, 'color': _color }, opacity=0.7 ) ) _fig = go.Figure( data=_data, layout={ 'xaxis': { 'title': 'Window distance (cell diameter)', 'zeroline': False, 'tickmode': 'array', 'tickvals': OFFSETS_X, 'type': 'category' }, 'yaxis': { 'title': 'Correlation', 'range': [-1, 1], 'zeroline': False, 'tickmode': 'array', 'tickvals': [-1, -0.5, 0, 0.5, 1] }, 'boxmode': 'group', 'legend': { 'xanchor': 'right', 'yanchor': 'top', 'bordercolor': 'black', 'borderwidth': 2 } } ) save.to_html( _fig=_fig, _path=os.path.join(paths.PLOTS, save.get_module_name()), _filename='plot' )
def main(_type='alpha', _low_connectivity=False, _plots=None, _plot_types=None): if _plots is None: _plots = ['same', 'different'] if _plot_types is None: _plot_types = ['stacked_bar', 'box', 'bar'] _same_arrays = [] _different_arrays = [] _same_highest = [] _different_highest = [] if _type == 'alpha': _alphas = ALPHAS _betas = [BETA] * len(ALPHAS) _names = _alphas elif _type == 'beta': _alphas = [ALPHA] * len(BETAS) _betas = BETAS _names = _betas else: raise Exception( 'No such type. Only \'alpha\' or \'beta\' are acceptable.') for _alpha, _beta in zip(_alphas, _betas): print('Alpha:', _alpha, 'beta:', _beta) _, _same_time_lags_arrays, _different_time_lags_arrays, _same_time_lags_highest, \ _different_time_lags_highest = same_inner_correlation_vs_different_inner_correlation_cross_correlation.compute_fiber_densities( _alpha=_alpha, _beta=_beta, _low_connectivity=_low_connectivity) _same_arrays.append(_same_time_lags_arrays[TIME_LAG_INDEX]) _different_arrays.append(_different_time_lags_arrays[TIME_LAG_INDEX]) _same_highest.append(_same_time_lags_highest) _different_highest.append(_different_time_lags_highest) if _plots is not None: # stacked bar plot if 'stacked_bar' in _plot_types: for _name, _sums in zip(['same', 'different'], [_same_highest, _different_highest]): if _name in _plots: _y_arrays = [[], [], []] for _type_sums in _sums: _left_wins, _none_wins, _right_wins = 0, 0, 0 for _time_lag, _type_sum in zip( same_inner_correlation_vs_different_inner_correlation_cross_correlation .TIME_LAGS, _type_sums): if _time_lag > 0: _left_wins += _type_sum elif _time_lag < 0: _right_wins += _type_sum else: _none_wins += _type_sum _total = sum(_type_sums) _y_arrays[0].append(_left_wins / _total) _y_arrays[1].append(_none_wins / _total) _y_arrays[2].append(_right_wins / _total) _colors_array = config.colors(3) _fig = go.Figure(data=[ go.Bar(x=_names, y=_y_array, name=_name, marker={'color': _color}) for _name, _y_array, _color in zip(['Leader', 'None', 'Follower'], _y_arrays, _colors_array) ], layout={ 'xaxis': { 'title': _type.capitalize(), 'zeroline': False, 'tickmode': 'array', 'tickvals': _names, 'type': 'category' }, 'yaxis': { 'title': 'Highest correlation fraction', 'range': [0, 1.1], 'zeroline': False, 'tickmode': 'array', 'tickvals': [0, 0.5, 1] }, 'barmode': 'stack', 'legend': { 'xanchor': 'right', 'yanchor': 'top', 'bordercolor': 'black', 'borderwidth': 2 }, }) save.to_html(_fig=_fig, _path=os.path.join(paths.PLOTS, save.get_module_name()), _filename='plot_stacked_bar_' + _type + '_low_con_' + str(_low_connectivity) + '_' + _name) # box plot if 'box' in _plot_types: for _name, _arrays in zip(['same', 'different'], [_same_arrays, _different_arrays]): if _name in _plots: _fig = go.Figure( data=[ go.Box(y=_y, name=_name, boxpoints=False, line={'width': 1}, marker={ 'size': 10, 'color': '#2e82bf' }, showlegend=False) for _y, _name in zip(_arrays, _names) ], layout={ 'xaxis': { 'title': _type.capitalize(), 'zeroline': False, 'tickmode': 'array', 'tickvals': _names, 'type': 'category' }, 'yaxis': { 'title': 'Inner correlation' if _name == 'same' else 'Different network correlation', 'range': [-1, 1.1], 'zeroline': False, 'tickmode': 'array', 'tickvals': [-1, -0.5, 0, 0.5, 1] } }) save.to_html(_fig=_fig, _path=os.path.join(paths.PLOTS, save.get_module_name()), _filename='plot_box_' + _type + '_low_con_' + str(_low_connectivity) + '_' + _name) # bar plot if 'bar' in _plot_types: for _name, _sums in zip(['same', 'different'], [_same_highest, _different_highest]): if _name in _plots: _fig = go.Figure(data=go.Bar( x=_names, y=[ _type_sums[TIME_LAG_INDEX] / sum(_type_sums) for _type_sums in _sums ], marker={'color': '#2e82bf'}), layout={ 'xaxis': { 'title': _type.capitalize(), 'zeroline': False, 'tickmode': 'array', 'tickvals': _names, 'type': 'category' }, 'yaxis': { 'title': 'Lag ' + str(TIME_LAG) + ' highest correlation fraction', 'range': [0, 1.1], 'zeroline': False, 'tickmode': 'array', 'tickvals': [0, 0.5, 1] } }) save.to_html(_fig=_fig, _path=os.path.join(paths.PLOTS, save.get_module_name()), _filename='plot_bar_' + _type + '_low_con_' + str(_low_connectivity) + '_' + _name)
def main(): _simulations = load.structured() _simulations = filtering.by_time_points_amount( _simulations, _time_points=SIMULATIONS_TIME_POINTS) _simulations = filtering.by_categories(_simulations, _is_single_cell=False, _is_heterogeneity=True, _is_low_connectivity=False, _is_causality=False, _is_dominant_passive=False, _is_fibrin=False) _simulations = filtering.by_heterogeneity(_simulations, _std=STD) _simulations = filtering.by_pair_distances(_simulations, _distances=PAIR_DISTANCE) print('Total simulations:', len(_simulations)) _fiber_densities = compute_fiber_densities(_simulations) _x_arrays = [[] for _i in PAIR_DISTANCE] _y_arrays = [[] for _i in PAIR_DISTANCE] for _distance_index, _distance in enumerate(PAIR_DISTANCE): _distance_simulations = filtering.by_pair_distance(_simulations, _distance=_distance) print('Distance:', _distance, 'Total simulations:', len(_distance_simulations)) for _simulation in tqdm(_distance_simulations, desc='Simulations loop'): for _direction in ['inside', 'outside']: _left_cell_fiber_densities = _fiber_densities[(_simulation, 'left_cell', _direction)] _right_cell_fiber_densities = _fiber_densities[(_simulation, 'right_cell', _direction)] _correlation = compute_lib.correlation( compute_lib.derivative(_left_cell_fiber_densities, _n=DERIVATIVE), compute_lib.derivative(_right_cell_fiber_densities, _n=DERIVATIVE)) if _direction == 'inside': _x_arrays[_distance_index].append(_correlation) else: _y_arrays[_distance_index].append(_correlation) print('Wilcoxon of insides minus outsides around the zero:') print( wilcoxon( np.array(_x_arrays[_distance_index]) - np.array(_y_arrays[_distance_index]))) # 2d plots _colors_array = config.colors(4) _legendgroup_array = ['group_1', 'group_1', 'group_2', 'group_2'] _fig = go.Figure(data=[ go.Scatter(x=_x, y=_y, name='Dist. ' + str(_distance), mode='markers', marker={ 'size': 10, 'color': _color }, legendgroup=_legendgroup) for _x, _y, _distance, _color, _legendgroup in zip( _x_arrays, _y_arrays, PAIR_DISTANCE, _colors_array, _legendgroup_array) ], layout={ 'xaxis': { 'title': 'Inner correlation', 'zeroline': False, 'range': [-1.1, 1.2], 'tickmode': 'array', 'tickvals': [-1, -0.5, 0, 0.5, 1] }, 'yaxis': { 'title': 'Outer correlation', 'zeroline': False, 'range': [-1.1, 1.2], 'tickmode': 'array', 'tickvals': [-1, -0.5, 0, 0.5, 1] }, 'legend': { 'x': 0.1, 'y': 1, 'xanchor': 'left', 'yanchor': 'top', 'bordercolor': 'black', 'borderwidth': 2, 'bgcolor': 'white', 'orientation': 'h' }, 'shapes': [{ 'type': 'line', 'x0': -1, 'y0': -1, 'x1': -1, 'y1': 1, 'line': { 'color': 'black', 'width': 2 } }, { 'type': 'line', 'x0': -1, 'y0': -1, 'x1': 1, 'y1': -1, 'line': { 'color': 'black', 'width': 2 } }, { 'type': 'line', 'x0': -1, 'y0': -1, 'x1': 1, 'y1': 1, 'line': { 'color': 'red', 'width': 2 } }] }) save.to_html(_fig=_fig, _path=os.path.join(paths.PLOTS, save.get_module_name()), _filename='plot') for _x, _y, _distance, _color in zip(_x_arrays, _y_arrays, PAIR_DISTANCE, _colors_array): _fig = go.Figure(data=go.Scatter(x=_x, y=_y, name='Dist. ' + str(_distance), mode='markers', marker={ 'size': 10, 'color': _color }, showlegend=True), layout={ 'xaxis': { 'title': 'Inner correlation', 'zeroline': False, 'range': [-1.1, 1.2], 'tickmode': 'array', 'tickvals': [-1, -0.5, 0, 0.5, 1] }, 'yaxis': { 'title': 'Outer correlation', 'zeroline': False, 'range': [-1.1, 1.2], 'tickmode': 'array', 'tickvals': [-1, -0.5, 0, 0.5, 1] }, 'legend': { 'xanchor': 'left', 'x': 0.1, 'yanchor': 'top', 'bordercolor': 'black', 'borderwidth': 2, 'bgcolor': 'white' }, 'shapes': [{ 'type': 'line', 'x0': -1, 'y0': -1, 'x1': -1, 'y1': 1, 'line': { 'color': 'black', 'width': 2 } }, { 'type': 'line', 'x0': -1, 'y0': -1, 'x1': 1, 'y1': -1, 'line': { 'color': 'black', 'width': 2 } }, { 'type': 'line', 'x0': -1, 'y0': -1, 'x1': 1, 'y1': 1, 'line': { 'color': 'red', 'width': 2 } }] }) save.to_html(_fig=_fig, _path=os.path.join(paths.PLOTS, save.get_module_name()), _filename='plot_distance_' + str(_distance)) # box plot _box_y_arrays = [[] for _i in PAIR_DISTANCE] for _x_array, _y_array, _distance_index in zip(_x_arrays, _y_arrays, range(len(PAIR_DISTANCE))): for _x, _y in zip(_x_array, _y_array): _point_distance = compute_lib.distance_from_a_point_to_a_line( _line=[-1, -1, 1, 1], _point=[_x, _y]) if _x > _y: _box_y_arrays[_distance_index].append(_point_distance) else: _box_y_arrays[_distance_index].append(-_point_distance) _fig = go.Figure(data=[ go.Box(y=_y, name=str(_distance), boxpoints='all', jitter=1, pointpos=0, line={'width': 1}, fillcolor='white', marker={ 'size': 10, 'color': _color }, showlegend=False) for _y, _distance, _color in zip( _box_y_arrays, PAIR_DISTANCE, _colors_array) ], layout={ 'xaxis': { 'title': 'Pair distance (cell diameter)', 'zeroline': False, 'tickmode': 'array', 'tickvals': PAIR_DISTANCE, 'type': 'category' }, 'yaxis': { 'title': 'Inner minus outer correlation', 'zeroline': False, 'tickmode': 'array', 'tickvals': [-0.2, 0, 0.2, 0.4] } }) save.to_html(_fig=_fig, _path=os.path.join(paths.PLOTS, save.get_module_name()), _filename='plot_box')
def main(_low_connectivity=False): _names_array, _x_array, _y_array = compute_cell_pairs(_low_connectivity) # plot _colors_array = config.colors(3) _fig = go.Figure(data=[ go.Scatter(x=_x, y=[np.mean(_array) for _array in _y], name=_name, error_y={ 'type': 'data', 'array': [np.std(_array) for _array in _y], 'thickness': 1, 'color': _color }, mode='markers', marker={ 'size': 15, 'color': _color }, opacity=0.7) for _x, _y, _name, _color in zip( _x_array, _y_array, _names_array, _colors_array) ], layout={ 'xaxis': { 'title': 'Window distance (cell diameter)', 'zeroline': False }, 'yaxis': { 'title': 'Fiber density (z-score)', 'range': [-1.7, 13], 'zeroline': False, 'tickmode': 'array', 'tickvals': [0, 4, 8, 12] }, 'legend': { 'xanchor': 'right', 'yanchor': 'top', 'bordercolor': 'black', 'borderwidth': 2 }, 'shapes': [{ 'type': 'line', 'x0': -0.2, 'y0': -1.5, 'x1': 3.4, 'y1': -1.5, 'line': { 'color': 'black', 'width': 2 } }, { 'type': 'line', 'x0': -0.2, 'y0': -1.5, 'x1': -0.2, 'y1': 13, 'line': { 'color': 'black', 'width': 2 } }] }) save.to_html(_fig=_fig, _path=os.path.join(paths.PLOTS, save.get_module_name()), _filename='plot_low_con_' + str(_low_connectivity))
def main(_low_connectivity=False): _simulations = load.structured() _simulations = filtering.by_time_points_amount( _simulations, TIME_POINT[_low_connectivity]) _simulations = filtering.by_categories( _simulations, _is_single_cell=False, _is_heterogeneity=True, _is_low_connectivity=_low_connectivity, _is_causality=False, _is_dominant_passive=False, _is_fibrin=False) _simulations = filtering.by_heterogeneity(_simulations, _std=STD) _simulations = filtering.by_pair_distances(_simulations, _distances=PAIR_DISTANCE) print('Total simulations:', len(_simulations)) _fiber_densities = compute_fiber_densities(_simulations, _low_connectivity) _y_arrays = [[] for _i in PAIR_DISTANCE] for _distance_index, _distance in enumerate(PAIR_DISTANCE): _distance_simulations = filtering.by_pair_distance(_simulations, _distance=_distance) print('Distance:', _distance, 'Total simulations:', len(_distance_simulations)) _higher_same_counter = 0 for _same_index in tqdm(range(len(_distance_simulations)), desc='Main loop'): _same_simulation = _distance_simulations[_same_index] _same_left_cell_fiber_densities = _fiber_densities[( _same_simulation, 'left_cell')] _same_right_cell_fiber_densities = _fiber_densities[( _same_simulation, 'right_cell')] _same_correlation = compute_lib.correlation( compute_lib.derivative(_same_left_cell_fiber_densities, _n=DERIVATIVE), compute_lib.derivative(_same_right_cell_fiber_densities, _n=DERIVATIVE)) for _different_index in range(len(_distance_simulations)): if _same_index != _different_index: _different_simulation = _distance_simulations[ _different_index] for _same_cell_id, _different_cell_id in product( ['left_cell', 'right_cell'], ['left_cell', 'right_cell']): _same_fiber_densities = \ _fiber_densities[(_same_simulation, _same_cell_id)] _different_fiber_densities = \ _fiber_densities[(_different_simulation, _different_cell_id)] _different_correlation = compute_lib.correlation( compute_lib.derivative(_same_fiber_densities, _n=DERIVATIVE), compute_lib.derivative(_different_fiber_densities, _n=DERIVATIVE)) _point_distance = compute_lib.distance_from_a_point_to_a_line( _line=[-1, -1, 1, 1], _point=[_same_correlation, _different_correlation]) if _same_correlation > _different_correlation: _y_arrays[_distance_index].append(_point_distance) _higher_same_counter += 1 else: _y_arrays[_distance_index].append(-_point_distance) print('Total points:', len(_y_arrays[_distance_index])) print('Wilcoxon around the zero:') print(wilcoxon(_y_arrays[_distance_index])) print('Higher same amount:', _higher_same_counter / len(_y_arrays[_distance_index])) # plot _colors_array = config.colors(4) _fig = go.Figure(data=[ go.Box(y=_y, name=str(_distance), boxpoints=False, line={'width': 1}, marker={ 'size': 10, 'color': _color }, showlegend=False) for _y, _distance, _color in zip( _y_arrays, PAIR_DISTANCE, _colors_array) ], layout={ 'xaxis': { 'title': 'Pair distance (cell diameter)', 'zeroline': False, 'tickmode': 'array', 'tickvals': PAIR_DISTANCE, 'type': 'category' }, 'yaxis': { 'title': 'Same minus different correlation', 'range': [-1, 1.1], 'zeroline': False, 'tickmode': 'array', 'tickvals': [-1, -0.5, 0, 0.5, 1] } }) save.to_html(_fig=_fig, _path=os.path.join(paths.PLOTS, save.get_module_name()), _filename='plot')
def main(): _simulations = load.structured() _simulations = filtering.by_time_points_amount( _simulations, _time_points=SIMULATIONS_TIME_POINTS) _simulations = filtering.by_categories(_simulations, _is_single_cell=False, _is_heterogeneity=False, _is_low_connectivity=False, _is_causality=False, _is_dominant_passive=False, _is_fibrin=False) _simulations = filtering.by_pair_distance(_simulations, _distance=PAIR_DISTANCE) print('Total simulations:', len(_simulations)) _fiber_densities = compute_fiber_densities(_simulations) _kpss_y_arrays = [[] for _i in DERIVATIVES] _adf_y_arrays = [[] for _i in DERIVATIVES] for _simulation in tqdm(_simulations, desc='Simulations loop'): for _cell_id in ['left_cell', 'right_cell']: _cell_fiber_densities = _fiber_densities[(_simulation, _cell_id)] for _derivative_index, _derivative in enumerate(DERIVATIVES): _cell_fiber_densities_derivative = compute_lib.derivative( _cell_fiber_densities, _n=_derivative) with warnings.catch_warnings(): warnings.simplefilter('ignore', category=InterpolationWarning) _, _kpss_p_value, _, _ = kpss( _cell_fiber_densities_derivative, nlags='legacy') _kpss_y_arrays[_derivative_index].append(_kpss_p_value) _, _adf_p_value, _, _, _, _ = adfuller( _cell_fiber_densities_derivative) _adf_y_arrays[_derivative_index].append(_adf_p_value) # print results print('KPSS:') for _derivative_index, _derivative in enumerate(DERIVATIVES): _stationary_count = len([ _value for _value in _kpss_y_arrays[_derivative_index] if _value > 0.05 ]) print( 'Derivative:', _derivative, 'Stationary:', str(_stationary_count / len(_kpss_y_arrays[_derivative_index]) * 100) + '%') print('ADF:') for _derivative_index, _derivative in enumerate(DERIVATIVES): _stationary_count = len([ _value for _value in _adf_y_arrays[_derivative_index] if _value < 0.05 ]) print( 'Derivative:', _derivative, 'Stationary:', str(_stationary_count / len(_adf_y_arrays[_derivative_index]) * 100) + '%') # plot _colors_array = config.colors(3) for _test_name, _y_title, _y_tickvals, _p_value_line, _y_arrays in \ zip( ['kpss', 'adf'], ['KPSS test p-value', 'ADF test p-value'], [[0.05, 0.1], [0.05, 1]], [0.05, 0.05], [_kpss_y_arrays, _adf_y_arrays] ): _fig = go.Figure(data=[ go.Box(y=_y, name=_derivative, boxpoints='all', jitter=1, pointpos=0, line={'width': 1}, fillcolor='white', marker={ 'size': 10, 'color': _color }, opacity=0.7, showlegend=False) for _y, _derivative, _color in zip( _y_arrays, DERIVATIVES_TEXT, _colors_array) ], layout={ 'xaxis': { 'title': 'Fiber density derivative', 'zeroline': False }, 'yaxis': { 'title': _y_title, 'zeroline': False, 'tickmode': 'array', 'tickvals': _y_tickvals }, 'shapes': [{ 'type': 'line', 'x0': DERIVATIVES[0] - 0.75, 'y0': _p_value_line, 'x1': DERIVATIVES[-1] + 0.75, 'y1': _p_value_line, 'line': { 'color': 'red', 'width': 2, 'dash': 'dash' } }] }) save.to_html(_fig=_fig, _path=os.path.join(paths.PLOTS, save.get_module_name()), _filename='plot_' + _test_name)
def main(): _simulations = load.structured() _simulations = filtering.by_time_points_amount(_simulations, _time_points=TIME_POINTS) _simulations = filtering.by_categories(_simulations, _is_single_cell=True, _is_heterogeneity=False, _is_low_connectivity=False, _is_causality=False, _is_dominant_passive=False, _is_fibrin=False) print('Total simulations:', len(_simulations)) _fiber_densities = compute_simulations_fiber_densities(_simulations) _y_arrays = [[] for _i in DERIVATIVES] for _index_1 in tqdm(range(len(_simulations)), desc='Simulations loop'): _simulation_1 = _simulations[_index_1] _cell_1_fiber_densities = \ [_fiber_densities[(_simulation_1, _direction)] for _direction in ['left', 'right', 'up', 'down']] _cell_1_fiber_densities = np.mean(_cell_1_fiber_densities, axis=0) for _index_2 in range(_index_1 + 1, len(_simulations)): _simulation_2 = _simulations[_index_2] _cell_2_fiber_densities = \ [_fiber_densities[(_simulation_2, _direction)] for _direction in ['left', 'right', 'up', 'down']] _cell_2_fiber_densities = np.mean(_cell_2_fiber_densities, axis=0) for _derivative_index, _derivative in enumerate(DERIVATIVES): _y_arrays[_derivative_index].append( compute_lib.correlation( compute_lib.derivative(_cell_1_fiber_densities, _n=_derivative), compute_lib.derivative(_cell_2_fiber_densities, _n=_derivative))) print('Total points:', len(_y_arrays[0])) print('Wilcoxon around the zero') for _y_array, _derivative in zip(_y_arrays, DERIVATIVES): print('Derivative:', _derivative, wilcoxon(_y_array)) # plot _colors_array = config.colors(3) _fig = go.Figure(data=[ go.Box(y=_y, name=_derivative, boxpoints='all', jitter=1, pointpos=0, line={'width': 1}, fillcolor='white', marker={ 'size': 10, 'color': _color }, opacity=0.7, showlegend=False) for _y, _derivative, _color in zip( _y_arrays, DERIVATIVES_TEXT, _colors_array) ], layout={ 'xaxis': { 'title': 'Fiber density derivative', 'zeroline': False }, 'yaxis': { 'title': 'Correlation', 'range': [-1, 1], 'zeroline': False, 'tickmode': 'array', 'tickvals': [-1, -0.5, 0, 0.5, 1] } }) save.to_html(_fig=_fig, _path=os.path.join(paths.PLOTS, save.get_module_name()), _filename='plot')
def main(): _simulations = load.structured() _simulations = filtering.by_time_points_amount(_simulations, TIME_POINT) _simulations = filtering.by_categories( _simulations, _is_single_cell=False, _is_heterogeneity=None, _is_low_connectivity=False, _is_causality=False, _is_dominant_passive=False, _is_fibrin=False ) _simulations = filtering.by_heterogeneities(_simulations, _stds=STDS) _simulations = filtering.by_pair_distance(_simulations, _distance=PAIR_DISTANCE) print('Total simulations:', len(_simulations)) _fiber_densities = compute_fiber_densities(_simulations) # stds loop _std_communicating = [[] for _i in STDS] _std_non_communicating = [[] for _i in STDS] for _std_index, _std in enumerate(STDS): print('Std:', _std) _simulations_std = filtering.by_heterogeneity(_simulations, _std=_std) print('Total simulations:', len(_simulations_std)) # communicating loop for _simulation in tqdm(_simulations_std, desc='Communicating pairs loop'): _left_cell_fiber_densities = _fiber_densities[(_simulation, 'left_cell')] _right_cell_fiber_densities = _fiber_densities[(_simulation, 'right_cell')] _correlation = compute_lib.correlation( compute_lib.derivative(_left_cell_fiber_densities, _n=DERIVATIVE), compute_lib.derivative(_right_cell_fiber_densities, _n=DERIVATIVE) ) _std_communicating[_std_index].append(_correlation) # non-communicating loop _simulations_indices = range(len(_simulations_std)) for _simulation_1_index in tqdm(_simulations_indices, desc='Non-communicating pairs loop'): _simulation_1 = _simulations_std[_simulation_1_index] for _simulation_2_index in _simulations_indices[_simulation_1_index + 1:]: _simulation_2 = _simulations_std[_simulation_2_index] for _simulation_1_cell_id, _simulation_2_cell_id in product(['left_cell', 'right_cell'], ['left_cell', 'right_cell']): _simulation_1_fiber_densities = _fiber_densities[(_simulation_1, _simulation_1_cell_id)] _simulation_2_fiber_densities = _fiber_densities[(_simulation_2, _simulation_2_cell_id)] _correlation = compute_lib.correlation( compute_lib.derivative(_simulation_1_fiber_densities, _n=DERIVATIVE), compute_lib.derivative(_simulation_2_fiber_densities, _n=DERIVATIVE) ) _std_non_communicating[_std_index].append(_correlation) print('Wilcoxon rank-sum test:', ranksums(_std_communicating[_std_index], _std_non_communicating[_std_index])) # histogram plot, once with and once without the legend _colors_array = config.colors(len(STDS)) for _show_legend in [True, False]: _fig = go.Figure( data=[ *[ go.Histogram( x=_non_communicating, name='STD ' + str(_std), marker={ 'color': _color }, nbinsx=10, histnorm='probability', showlegend=_show_legend ) for _std, _non_communicating, _color in zip(STDS, _std_non_communicating, _colors_array) ], *[ go.Scatter( x=_communicating, y=[0.5 - 0.02 * _std_index for _i in range(len(_communicating))], mode='text', text='●', textfont={ 'color': _color, 'size': 15 }, showlegend=False ) for _std_index, _communicating, _color in zip(range(len(STDS)), _std_communicating, _colors_array) ] ], layout={ 'xaxis': { 'title': 'Correlation', 'zeroline': False }, 'yaxis': { 'title': 'Fraction', 'zeroline': False }, 'legend': { 'xanchor': 'right', 'yanchor': 'top', 'bordercolor': 'black', 'borderwidth': 2 }, 'bargap': 0.1 } ) save.to_html( _fig=_fig, _path=os.path.join(paths.PLOTS, save.get_module_name()), _filename='plot_legend_' + str(_show_legend) )
def main(_directions=None): if _directions is None: _directions = ['inside', 'outside'] _simulations = load.structured() _simulations = filtering.by_time_points_amount( _simulations, _time_points=SIMULATIONS_TIME_POINTS) _simulations = filtering.by_categories(_simulations, _is_single_cell=False, _is_heterogeneity=False, _is_low_connectivity=False, _is_causality=False, _is_dominant_passive=False, _is_fibrin=False) _simulations = filtering.by_pair_distance(_simulations, _distance=PAIR_DISTANCE) print('Total simulations:', len(_simulations)) _fiber_densities = compute_fiber_densities(_simulations, _directions) for _direction in _directions: _y_arrays = [[] for _i in DERIVATIVES] for _simulation in tqdm(_simulations, desc='Simulations loop'): _left_cell_fiber_densities = _fiber_densities[(_simulation, 'left_cell', _direction)] _right_cell_fiber_densities = _fiber_densities[(_simulation, 'right_cell', _direction)] for _derivative_index, _derivative in enumerate(DERIVATIVES): _y_arrays[_derivative_index].append( compute_lib.correlation( compute_lib.derivative(_left_cell_fiber_densities, _n=_derivative), compute_lib.derivative(_right_cell_fiber_densities, _n=_derivative))) print('Direction:', _direction) print('Total pairs:', len(_y_arrays[0])) print('Wilcoxon around the zero') for _y_array, _derivative in zip(_y_arrays, DERIVATIVES): print('Derivative:', _derivative, wilcoxon(_y_array)) # plot _y_title = 'Inner correlation' if _direction == 'inside' else 'Outer correlation' _colors_array = config.colors(3) _fig = go.Figure(data=[ go.Box(y=_y, name=_derivative, boxpoints='all', jitter=1, pointpos=0, line={'width': 1}, fillcolor='white', marker={ 'size': 10, 'color': _color }, opacity=0.7, showlegend=False) for _y, _derivative, _color in zip( _y_arrays, DERIVATIVES_TEXT, _colors_array) ], layout={ 'xaxis': { 'title': 'Fiber density derivative', 'zeroline': False }, 'yaxis': { 'title': _y_title, 'range': [-1, 1], 'zeroline': False, 'tickmode': 'array', 'tickvals': [-1, -0.5, 0, 0.5, 1] } }) save.to_html(_fig=_fig, _path=os.path.join(paths.PLOTS, save.get_module_name()), _filename='plot_direction_' + _direction)