Skip to content
Snippets Groups Projects
Commit 1a6d0f05 authored by Hanna  JULIENNE's avatar Hanna JULIENNE
Browse files

module to save preprocessing results

parent d2f5af12
No related branches found
No related tags found
No related merge requests found
...@@ -2,3 +2,4 @@ import jass_preprocessing.map_gwas.map_gwas as map_gwas ...@@ -2,3 +2,4 @@ import jass_preprocessing.map_gwas.map_gwas as map_gwas
import jass_preprocessing.dna_utils.dna_utils as dna_utils import jass_preprocessing.dna_utils.dna_utils as dna_utils
import jass_preprocessing.map_reference.map_reference as map_reference import jass_preprocessing.map_reference.map_reference as map_reference
import jass_preprocessing.compute_score.compute as compute_score import jass_preprocessing.compute_score.compute as compute_score
import jass_preprocessing.save_output.save_output as save_output
...@@ -57,13 +57,10 @@ def compute_snp_alignement(mgwas): ...@@ -57,13 +57,10 @@ def compute_snp_alignement(mgwas):
""" """
Add a column to mgwas indicating if the reference and coded Add a column to mgwas indicating if the reference and coded
allele is flipped compared to the reference panel. allele is flipped compared to the reference panel.
If it is, the sign of the statistic must be flipped If it is, the sign of the statistic must be flipped
Args: Args:
mgwas: a pandas dataframe of the GWAS data merged mgwas: a pandas dataframe of the GWAS data merged
with the reference panel with the reference panel
""" """
mgwas['a1c'] = dna_u.dna_complement(mgwas.a1) mgwas['a1c'] = dna_u.dna_complement(mgwas.a1)
......
import pandas as pd
def save_output_by_chromosome(mgwas, ImpG_output_Folder, my_study):
"""
Write the preprocessed Gwas
"""
mgwas.reset_index(inplace=True)
mgwas = pd.DataFrame({
'rsID': mgwas_chr.snp_id,
'pos': mgwas_chr.pos,
'A0': mgwas_chr.ref,
'A1':mgwas_chr.alt,
'Z': mgwas_chr.computed_z
}, columns= ['rsID', 'pos', 'A0', "A1", "Z" ])
mgwas.set_index("chr", inplace=True)
mgwas.dropna(subset=["Z"], how="any", inplace=True)
for chrom in mgwas.index.unique:
impg_output_file = ImpG_output_Folder + 'z_'+ my_study +'_chr_'+str(chrom)+".txt"
print("WRITING CHR {} results for {} to:".format(chrom, my_study))
mgwas.loc[chrom].to_csv(impg_output_file, sep="\t", index=False)
...@@ -10,6 +10,6 @@ setup(name='jass_preprocessing', ...@@ -10,6 +10,6 @@ setup(name='jass_preprocessing',
#package_dir = {'': 'jass_preprocessing'}, #package_dir = {'': 'jass_preprocessing'},
packages= ['jass_preprocessing', "jass_preprocessing.map_gwas", packages= ['jass_preprocessing', "jass_preprocessing.map_gwas",
"jass_preprocessing.dna_utils", "jass_preprocessing.map_reference", "jass_preprocessing.dna_utils", "jass_preprocessing.map_reference",
"jass_preprocessing.compute_score" "jass_preprocessing.compute_score", "jass_preprocessing.save_output"
], ],
zip_safe=False) zip_safe=False)
...@@ -16,58 +16,52 @@ import pandas as pd ...@@ -16,58 +16,52 @@ import pandas as pd
import seaborn as sns import seaborn as sns
perSS = 0.7 perSS = 0.7
netPath = "/mnt/atlas/" # '/home/genstat/ATLAS/' netPath = "/mnt/atlas/"
#netPath = '/pasteur/projets/policy01/'
GWAS_labels = netPath+'PCMA/1._DATA/RAW.GWAS/GWAS_labels.csv' GWAS_labels = netPath+'PCMA/1._DATA/RAW.GWAS/GWAS_labels.csv'
GWAS_path = netPath+'PCMA/1._DATA/RAW.GWAS/' GWAS_path = netPath+'PCMA/1._DATA/RAW.GWAS/'
diagnostic_folder= "/mnt/atlas/PCMA/1._DATA/sample_size_distribution/"
REF_filename = netPath+'PCMA/0._REF/1KGENOME/summary_genome_Filter_part2.out' REF_filename = netPath+'PCMA/0._REF/1KGENOME/summary_genome_Filter_part2.out'
pathOUT = netPath+'PCMA/1._DATA/RAW.summary/' pathOUT = netPath+'PCMA/1._DATA/RAW.summary/'
outFileName = netPath+'PCMA/1._DATA/ZSCORE_merged_ALL_NO_strand_ambiguous.hdf5' outFileName = netPath+'PCMA/1._DATA/ZSCORE_merged_ALL_NO_strand_ambiguous.hdf5'
def_missing = ['', '#N/A', '#N/A', 'N/A', '#NA', '-1.#IND', '-1.#QNAN', '-NaN', def_missing = ['', '#N/A', '#N/A', 'N/A', '#NA', '-1.#IND', '-1.#QNAN', '-NaN',
'-nan', '1.#IND', '1.#QNAN', 'N/A', 'NA', 'NULL', 'NaN', 'nan', 'na', '.'] '-nan', '1.#IND', '1.#QNAN', 'N/A', 'NA', 'NULL', 'NaN', 'nan',
'na', '.']
out_summary = "summary_GWAS.csv" out_summary = "summary_GWAS.csv"
ImpG_output_Folder = netPath+ 'PCMA/1._DATA/preprocessing_test/' ImpG_output_Folder = netPath+ 'PCMA/1._DATA/preprocessing_test/'
GWAS_labels GWAS_labels
gwas_map = pd.read_csv(GWAS_labels, sep="\t", index_col=0, nrows=10) gwas_map = pd.read_csv(GWAS_labels, sep="\t", index_col=0)
GWAS_table = ["GWAS_DBP_recoded.txt","GWAS_MAP_recoded.txt", "GWAS_PP_recoded.txt","GWAS_SBP_recoded_dummy.txt"]
gwas = jp.map_gwas.gwas_internal_link(GWAS_table, GWAS_path)
gwas
column_dict = pd.read_csv(GWAS_labels, sep='\t', na_values='na')
my_labels = column_dict[column_dict['filename'] == gwas.iloc[0,0]] GWAS_table = ["GWAS_SBP_recoded_dummy.txt"]#["GWAS_DBP_recoded.txt","GWAS_MAP_recoded.txt",
column_dict[['freq']] #"GWAS_PP_recoded.txt","GWAS_SBP_recoded_dummy.txt"]
# READ GWAS
GWAS_filename = GWAS_table[3]
GWAS_link = jp.map_gwas.walkfs(GWAS_path, GWAS_filename)[2] for GWAS_filename in GWAS_table:
GWAS_link
mapgw = jp.map_gwas.map_columns_position(GWAS_link, GWAS_labels)
gw_df = jp.map_gwas.read_gwas(GWAS_link, mapgw) tag = "{0}_{1}".format(gwas_map.loc[GWAS_filename, 'consortia'], gwas_map.loc[GWAS_filename, 'outcome'])
gw_df.head() print('processing GWAS: {}'.format(tag))
ref = pd.read_csv(REF_filename, header=None, sep= "\t", gwas = jp.map_gwas.gwas_internal_link(GWAS_table, GWAS_path)
names =['chr', "pos", "snp_id", "ref", "alt", "MAF"], column_dict = pd.read_csv(GWAS_labels, sep='\t', na_values='na')
index_col="snp_id")
inter_index = ref.index.intersection(gw_df.index)
test_merge = pd.merge(ref.loc[inter_index], gw_df.loc[inter_index], how='inner', GWAS_link = jp.map_gwas.walkfs(GWAS_path, GWAS_filename)[2]
indicator=True, left_index=True, right_index=True) mapgw = jp.map_gwas.map_columns_position(GWAS_link, GWAS_labels)
gw_df = jp.map_gwas.read_gwas(GWAS_link, mapgw)
ref = pd.read_csv(REF_filename, header=None, sep= "\t",
names =['chr', "pos", "snp_id", "ref", "alt", "MAF"],
index_col="snp_id")
print(jp.map_reference.map_on_ref_panel) inter_index = ref.index.intersection(gw_df.index)
mgwas = jp.map_reference.map_on_ref_panel(gw_df, ref) test_merge = pd.merge(ref.loc[inter_index], gw_df.loc[inter_index], how='inner',
mgwas indicator=True, left_index=True, right_index=True)
mgwas = jp.map_reference.compute_snp_alignement(mgwas)
mgwas = jp.compute_score.compute_z_score(mgwas) print(jp.map_reference.map_on_ref_panel)
mgwas = jp.compute_score.compute_sample_size(mgwas, "/mnt/atlas/PCMA/1._DATA/RAW.GWAS/ICPB_bloodPress/", "test_samp") mgwas = jp.map_reference.map_on_ref_panel(gw_df, ref)
mgwas.reset_index(inplace=True) mgwas = jp.map_reference.compute_snp_alignement(mgwas)
mgwas.set_index("chr", inplace=True)
jp. mgwas = jp.compute_score.compute_z_score(mgwas)
mgwas = jp.compute_score.compute_sample_size(mgwas, diagnostic_folder, tag)
jp.save_output.save_output_by_chromosome(mgwas, ImpG_output_Folder, tag)
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment