def make_table(model, gene): table = summary_table(model) # annotate table if table.shape[0] > 0: v2r = load_var2rsid(gene) table.loc[:, 'rsid'] = table.variant_id.apply(lambda x: v2r.get(x, '-')) table.loc[:, 'chr'] = table.variant_id.apply(lambda x: (x.split('_')[0])) table.loc[:, 'start'] = table.variant_id.apply(lambda x: int(x.split('_')[1])) table.loc[:, 'end'] = table.start + 1 table.loc[:, 'gene'] = gene table = table.loc[:, ['chr', 'start', 'end', 'variant_id', 'rsid', 'study', 'pip', 'top_component', 'p_active', 'pi', 'alpha', 'rank', 'effect', 'effect_var']] return table
def make_table(model, gene, rsid2variant_id): table = summary_table(model) # annotate table table.loc[:, 'rsid'] = table.variant_id table.loc[:, 'variant_id'] = table.rsid.apply(lambda x: rsid2variant_id.get(x, 'chr0_0_A_B_n')) table.loc[:, 'chr'] = table.variant_id.apply(lambda x: (x.split('_')[0])) table.loc[:, 'start'] = table.variant_id.apply(lambda x: int(x.split('_')[1])) table.loc[:, 'end'] = table.start + 1 table.loc[:, 'gene'] = gene table = table.loc[:, ['chr', 'start', 'end', 'gene', 'variant_id', 'rsid', 'study', 'pip', 'top_component', 'p_active', 'pi', 'alpha', 'rank', 'effect', 'effect_var']] return table
'LD': sample_ld(gtex_genotype.loc[:, variants]), 'B': B, 'S': S, 'K': K, 'snp_ids': variants, 'study_ids': studies, 'tolerance': 1e-8 } css = CSS(**init_args) css.prior_activity = np.ones(K) * 0.1 css.weight_precision_b = np.ones_like(css.weight_precision_b) * 10 weight_ard_active_fit_procedure(css, max_iter=10, verbose=True) fit_all(css, max_iter=30, verbose=True) table = summary_table(css) tables.append(table) coloc_table.append(c(css, study=study, gene=gene, phenotye=phenotype, tissue=tissue)) # format results table = pd.concat(tables) table.loc[:, 'rsid'] = table.variant_id table.loc[:, 'variant_id'] = table.rsid.apply(lambda x: rsid2variant_id.get(x)) table.loc[:, 'chr'] = table.variant_id.apply(lambda x: (x.split('_')[0])) table.loc[:, 'start'] = table.variant_id.apply(lambda x: int(x.split('_')[1])) table.loc[:, 'end'] = table.start + 1 table.loc[:, 'gene'] = gene table = table.loc[:, [ 'chr', 'start', 'end', 'gene', 'variant_id', 'rsid', 'study', 'pip', 'top_component', 'p_active', 'pi', 'alpha', 'rank', 'effect', 'effect_var']]