Skip to content

Commit

Permalink
Raise error about column types (#59)
Browse files Browse the repository at this point in the history
  • Loading branch information
ofrei authored and tpoterba committed May 7, 2018
1 parent 9c7040e commit 1b0e2f0
Showing 1 changed file with 6 additions and 0 deletions.
6 changes: 6 additions & 0 deletions munge_sumstats.py
Expand Up @@ -120,6 +120,7 @@
'NSTUDY': 'Number of studies in which the SNP was genotyped.'
}

numeric_cols = ['P', 'N', 'N_CAS', 'N_CON', 'Z', 'OR', 'BETA', 'LOG_ODDS', 'INFO', 'FRQ', 'SIGNED_SUMSTAT', 'NSTUDY']

def read_header(fh):
'''Read the first line of a file and returns a list with the column names.'''
Expand Down Expand Up @@ -242,6 +243,11 @@ def parse_dat(dat_gen, convert_colname, merge_alleles, log, args):
lambda x: x != 'INFO', dat.columns)).reset_index(drop=True)
drops['NA'] += old - len(dat)
dat.columns = map(lambda x: convert_colname[x], dat.columns)

wrong_types = [c for c in dat.columns if c in numeric_cols and not np.issubdtype(dat[c].dtype, np.number)]
if len(wrong_types) > 0:
raise ValueError('Columns {} are expected to be numeric'.format(wrong_types))

ii = np.array([True for i in xrange(len(dat))])
if args.merge_alleles:
old = ii.sum()
Expand Down

0 comments on commit 1b0e2f0

Please sign in to comment.