Skip to content
Snippets Groups Projects
Commit 805f2f78 authored by haibo Huang's avatar haibo Huang
Browse files

replace inf computed_Z score by real Z score or maximum value

parent 57ee2dfb
No related branches found
No related tags found
No related merge requests found
File added
...@@ -12,18 +12,36 @@ def compute_z_score(mgwas): ...@@ -12,18 +12,36 @@ def compute_z_score(mgwas):
""" """
Compute zscore value and sign1 Compute zscore value and sign1
add the corresponding column to the mgwas dataframe add the corresponding column to the mgwas dataframe
the smallest positive value of float
sys.float_info.min
2.2250738585072014e-308
the biggest Z score
np.sqrt(ss.chi2.isf(sys.float_info.min, 1))
37.537836095576054
""" """
print(mgwas.columns)
mgwas["computed_z"] = np.sqrt(ss.chi2.isf(mgwas['pval'], 1))
if 'z' in mgwas.columns:
sign_vect = np.sign(mgwas.z)
mgwas.loc[mgwas["computed_z"].isin([np.inf]), 'computed_z'] = mgwas["z"]
if 'beta_or_Z' in mgwas.columns: elif 'beta' in mgwas.columns:
sign_vect = np.sign(mgwas.beta_or_Z) sign_vect = np.sign(mgwas.beta)
mgwas["computed_z"] = mgwas["computed_z"].replace(np.inf, 37.537836095576054)
else: else:
if "OR" in mgwas.columns: if "OR" in mgwas.columns:
sign_vect = np.sign(mgwas["OR"] - 1.0 + 10**(-8)) sign_vect = np.sign(mgwas["OR"] - 1.0 + 10**(-8))
mgwas["computed_z"] = mgwas["computed_z"].replace(np.inf, 37.537836095576054)
else: else:
raise ValueError( raise ValueError(
'The gwas data frame doesn"t contain effect column') 'The gwas data frame doesn"t contain effect column')
mgwas["computed_z"] = np.sqrt(ss.chi2.isf(mgwas['pval'], 1)) * sign_vect * mgwas["sign_flip"] mgwas["computed_z"] = mgwas["computed_z"] * sign_vect * mgwas["sign_flip"]
return mgwas return mgwas
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment