From fd935ad8e5b9e43aab97e0e4dbeb43bd137b35ac Mon Sep 17 00:00:00 2001 From: Hanna JULIENNE <hanna.julienne@pasteur.fr> Date: Mon, 19 Jul 2021 09:41:16 +0000 Subject: [PATCH] Update save_output.py --- jass_preprocessing/save_output.py | 29 ++++++++++++++++------------- 1 file changed, 16 insertions(+), 13 deletions(-) diff --git a/jass_preprocessing/save_output.py b/jass_preprocessing/save_output.py index c66dc90..1379859 100644 --- a/jass_preprocessing/save_output.py +++ b/jass_preprocessing/save_output.py @@ -12,19 +12,22 @@ def save_output_by_chromosome(mgwas, ImpG_output_Folder, my_study): mgwas_copy.dropna(subset=["computed_z"], how="any", inplace=True) print(mgwas_copy.index.unique()) for chrom in mgwas_copy.index.unique(): - print(mgwas_copy.loc[chrom]) - mgwas_chr = pd.DataFrame({ - 'rsID': mgwas_copy.loc[chrom].snp_id, - 'pos': mgwas_copy.loc[chrom].pos, - 'A0': mgwas_copy.loc[chrom].ref, - 'A1':mgwas_copy.loc[chrom].alt, - 'Z': mgwas_copy.loc[chrom].computed_z, - 'P': mgwas_copy.loc[chrom].pval - }, columns= ['rsID', 'pos', 'A0', "A1", "Z", "P" ]) - - impg_output_file = ImpG_output_Folder + 'z_'+ my_study +'_chr'+str(chrom)+".txt" - print("WRITING CHR {} results for {} to: {}".format(chrom, my_study, ImpG_output_Folder)) - mgwas_chr.sort_values(by="pos").to_csv(impg_output_file, sep="\t", index=False) + if type(mgwas_copy.loc[chrom]) is pd.core.frame.DataFrame: + print(mgwas_copy.loc[chrom]) + mgwas_chr = pd.DataFrame({ + 'rsID': mgwas_copy.loc[chrom].snp_id, + 'pos': mgwas_copy.loc[chrom].pos, + 'A0': mgwas_copy.loc[chrom].ref, + 'A1':mgwas_copy.loc[chrom].alt, + 'Z': mgwas_copy.loc[chrom].computed_z, + 'P': mgwas_copy.loc[chrom].pval + }, columns= ['rsID', 'pos', 'A0', "A1", "Z", "P" ]) + + impg_output_file = ImpG_output_Folder + 'z_'+ my_study +'_chr'+str(chrom)+".txt" + print("WRITING CHR {} results for {} to: {}".format(chrom, my_study, ImpG_output_Folder)) + mgwas_chr.sort_values(by="pos").to_csv(impg_output_file, sep="\t", index=False) + else: + print("NO or 1 value for CHR {} results for {} to: {}".format(chrom, my_study, ImpG_output_Folder)) def save_output(mgwas, ImpG_output_Folder, my_study): -- GitLab