Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixes #23 KeyError: ['beta', 'SE'] when using Z #37

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 6 additions & 1 deletion popcorn/sumstats.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ def __init__(self,scores,args):
"compliment SNPs.")

def parse_input(self, sfile):
print('Parse', sfile, '...')
DF = pd.read_table(sfile)
data = pd.DataFrame()
try:
Expand All @@ -58,6 +59,7 @@ def parse_input(self, sfile):
try:
data['id'] = 'chr'+DF['chr'].map(str)+':'+DF['pos'].map(str)
id_type = 'pos'
print('Note: CHR:POS will be used as SNP identifier')
except KeyError:
raise ValueError('Must provide either "rsid", "SNP"'
' or "chr" and "pos"')
Expand Down Expand Up @@ -85,6 +87,8 @@ def parse_input(self, sfile):
try:
data['beta'] = DF['beta']
data['SE'] = DF['SE']
if 'Z' in data.columns:
print('Note: Z column will be re-calculated from beta and SE')
data['Z'] = data['beta']/data['SE']
except KeyError:
try:
Expand All @@ -96,6 +100,7 @@ def parse_input(self, sfile):
data['beta'] = beta
data['SE'] = SE
data['Z'] = Z
print('Note: beta, SE and Z will be calculated from OR and p-value columns')
except KeyError:
raise ValueError(
'Must provide either signed Z-scores 1) "Z", 2) "beta" and "SE",'
Expand All @@ -105,7 +110,7 @@ def parse_input(self, sfile):
valid_alleles = np.logical_and(has_comp['a1'], has_comp['a2'])
data=data.loc[valid_alleles]
data.replace([np.inf, -np.inf], np.nan, inplace=True)
data.dropna(subset=['id', 'a1', 'a2', 'N', 'beta', 'SE', 'Z'], inplace=True)
data.dropna(subset={'id', 'a1', 'a2', 'N', 'beta', 'SE', 'Z'}.intersection(data.columns), inplace=True)
# else:
# data = pd.read_table(sfile,sep='\t',header=None,
# names=['chr','id','pos','af','a1','a2',
Expand Down