Skip to content

Commit 9a99a8a

Browse files
committed
explicitly convert chromosome and basepairs to int for df indices
1 parent 3e657a1 commit 9a99a8a

File tree

3 files changed

+7
-3
lines changed

3 files changed

+7
-3
lines changed

ldsc_polyfun/parse.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,9 @@ def set_snpid_index(df):
3737
df.loc[df['A1_first'], 'A1s'] = df.loc[df['A1_first'], 'A1'].copy()
3838
df['A2s'] = df['A1'].copy()
3939
df.loc[df['A1_first'], 'A2s'] = df.loc[df['A1_first'], 'A2'].copy()
40-
df.index = df['CHR'].astype(str) + '.' + df['BP'].astype(str) + '.' + df['A1s'] + '.' + df['A2s']
40+
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)
41+
s_bp = df['BP'].astype(int).astype(str)
42+
df.index = s_chr + '.' + s_bp + '.' + df['A1s'] + '.' + df['A2s']
4143
df.index.name = 'snpid'
4244
df.drop(columns=['A1_first', 'A1s', 'A2s'], inplace=True)
4345
return df

polyfun_utils.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,9 @@ def set_snpid_index(df, copy=False, allow_duplicates=False, allow_swapped_indel_
6767
df.loc[df['A1_first'], 'A1s'] = df.loc[df['A1_first'], 'A1'].copy()
6868
df['A2s'] = df['A1'].copy()
6969
df.loc[df['A1_first'], 'A2s'] = df.loc[df['A1_first'], 'A2'].copy()
70-
df.index = df['CHR'].astype(int).astype(str) + '.' + df['BP'].astype(str) + '.' + df['A1s'] + '.' + df['A2s']
70+
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)
71+
s_bp = df['BP'].astype(int).astype(str)
72+
df.index = s_chr + '.' + s_bp + '.' + df['A1s'] + '.' + df['A2s']
7173
df.index.name = 'snpid'
7274
df.drop(columns=['A1_first', 'A1s', 'A2s'], inplace=True)
7375

test_polyfun.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -249,7 +249,7 @@ def test_finemapper_susie(tmpdir, python3_exe):
249249
#print(finemapper_cmd)
250250
retval = os.system(finemapper_cmd)
251251
if retval != 0:
252-
raise ValueError('finemapper command failed when running the following command:\n%s'%(cmd))
252+
raise ValueError('finemapper command failed when running the following command:\n%s'%(finemapper_cmd))
253253
compare_dfs(tmpdir, gold_dir, outfile, sort_column='SNP')
254254

255255

0 commit comments

Comments
 (0)