Skip to content

Commit

Permalink
explicitly convert chromosome and basepairs to int for df indices
Browse files Browse the repository at this point in the history
  • Loading branch information
omerwe committed Nov 22, 2024
1 parent 3e657a1 commit 9a99a8a
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 3 deletions.
4 changes: 3 additions & 1 deletion ldsc_polyfun/parse.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,9 @@ def set_snpid_index(df):
df.loc[df['A1_first'], 'A1s'] = df.loc[df['A1_first'], 'A1'].copy()
df['A2s'] = df['A1'].copy()
df.loc[df['A1_first'], 'A2s'] = df.loc[df['A1_first'], 'A2'].copy()
df.index = df['CHR'].astype(str) + '.' + df['BP'].astype(str) + '.' + df['A1s'] + '.' + df['A2s']
s_chr = df['CHR'].map(lambda c: int(c) if str(c)[0] in ['0','1','2','3','4','5,','6','7','8','9'] else c).astype(str)
s_bp = df['BP'].astype(int).astype(str)
df.index = s_chr + '.' + s_bp + '.' + df['A1s'] + '.' + df['A2s']
df.index.name = 'snpid'
df.drop(columns=['A1_first', 'A1s', 'A2s'], inplace=True)
return df
Expand Down
4 changes: 3 additions & 1 deletion polyfun_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,9 @@ def set_snpid_index(df, copy=False, allow_duplicates=False, allow_swapped_indel_
df.loc[df['A1_first'], 'A1s'] = df.loc[df['A1_first'], 'A1'].copy()
df['A2s'] = df['A1'].copy()
df.loc[df['A1_first'], 'A2s'] = df.loc[df['A1_first'], 'A2'].copy()
df.index = df['CHR'].astype(int).astype(str) + '.' + df['BP'].astype(str) + '.' + df['A1s'] + '.' + df['A2s']
s_chr = df['CHR'].map(lambda c: int(c) if str(c)[0] in ['0','1','2','3','4','5,','6','7','8','9'] else c).astype(str)
s_bp = df['BP'].astype(int).astype(str)
df.index = s_chr + '.' + s_bp + '.' + df['A1s'] + '.' + df['A2s']
df.index.name = 'snpid'
df.drop(columns=['A1_first', 'A1s', 'A2s'], inplace=True)

Expand Down
2 changes: 1 addition & 1 deletion test_polyfun.py
Original file line number Diff line number Diff line change
Expand Up @@ -249,7 +249,7 @@ def test_finemapper_susie(tmpdir, python3_exe):
#print(finemapper_cmd)
retval = os.system(finemapper_cmd)
if retval != 0:
raise ValueError('finemapper command failed when running the following command:\n%s'%(cmd))
raise ValueError('finemapper command failed when running the following command:\n%s'%(finemapper_cmd))
compare_dfs(tmpdir, gold_dir, outfile, sort_column='SNP')


Expand Down

0 comments on commit 9a99a8a

Please sign in to comment.