def continuous_enrichment(pheno, data, covariate, node_labels='node_name_not_specificed'): sub_mask = find_subset(pheno, covariate) sub_pheno = pheno.loc[sub_mask] sub_data = data[sub_mask, :] n_data = sub_data.shape[1] results = {key: list() for key in ['node', 'pearson_r', 'p_value']} for node_id in range(n_data): r, p = stats.pearsonr(sub_pheno[covariate], sub_data[:, node_id]) # Store the results results['node'].append(node_id + 1) results['pearson_r'].append(r) results['p_value'].append(p) results_table = pd.DataFrame(data=results) # Correct for multiple comparisons (fdr_pass, qval, _, _) = stm(results_table.p_value, alpha=0.05, method='fdr_bh') results_table['q_value'] = qval # Add the node_names results_table['node_name'] = node_labels return results_table
def summarize_glm(glm_table, conn_mask, roi_labels): out_table = glm_table.copy() (fdr_pass, qval, _, _) = stm(glm_table.pvals, alpha=0.05, method='fdr_bh') out_table['qval'] = qval # Return to matrix form stand_beta_table = pd.DataFrame(conn2mat(out_table.stand_betas.values, conn_mask), index=roi_labels, columns=roi_labels) qval_table = pd.DataFrame(conn2mat(out_table.pvals.values, conn_mask), index=roi_labels, columns=roi_labels) return out_table, stand_beta_table, qval_table
# Determine if cases > controls or reverse case_gt_con = u_right > u_min if not case_gt_con: r_b = -r_b # Store the results results['node'].append(node_id + 1) results['U'].append(u_min) results['p_value'].append(p) results[f'median_{group}_{case}'].append(median_case) results[f'median_{group}_{control}'].append(median_control) results['rank_biserial_correlation'].append(r_b) results_table = pd.DataFrame(data=results) # Correct for multiple comparisons (fdr_pass, qval, _, _) = stm(results_table.p_value, alpha=0.05, method='fdr_bh') results_table['q_value'] = qval # Add the node_names results_table['node_name'] = node_labels return results_table def continuous_enrichment(pheno, data, covariate, node_labels='node_name_not_specificed'): sub_mask = find_subset(pheno, covariate) sub_pheno = pheno.loc[sub_mask] sub_data = data[sub_mask, :]