Skip to content

Commit 3e3bca7

Browse files
committed
PolyLoc no longer requires --bfile-chr
1 parent 3af19e9 commit 3e3bca7

File tree

1 file changed

+30
-25
lines changed

1 file changed

+30
-25
lines changed

polyloc.py

Lines changed: 30 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -56,14 +56,15 @@ def check_args(args):
5656
#partitionining-related parameters
5757
if args.compute_partitions:
5858
if args.bfile_chr is None:
59-
raise ValueError('You must specify --bfile-chr when you specify --compute-partitions')
59+
#raise ValueError('You must specify --bfile-chr when you specify --compute-partitions')
60+
logging.warning('You did not specify --bfile-chr with --compute-partitions. PolyLoc will only use SNPs provided in the posterior files')
6061
if args.posterior is None:
6162
raise ValueError('--posterior must be specified when using --compute-partitions')
6263

6364
#verify LD-score related parameters
6465
if args.compute_ldscores:
65-
if args.bfile_chr is None:
66-
raise ValueError('You must specify --bfile-chr when you specify --compute-ldscores')
66+
if not not args.ld_ukb and args.bfile_chr is None:
67+
raise ValueError('You must specify either --ld-ukb or --bfile-chr when using --compute-ldscores')
6768
if not args.ld_ukb and (args.ld_wind_cm is None and args.ld_wind_kb is None and args.ld_wind_snps is None):
6869
args.ld_wind_cm = 1.0
6970
logging.warning('no ld-wind argument specified. PolyLoc will use --ld-cm 1.0')
@@ -96,8 +97,11 @@ def check_files(args):
9697
else: chr_range = range(args.chr, args.chr+1)
9798

9899
for chr_num in chr_range:
99-
get_file_name(args, 'bim', chr_num, verify_exists=True)
100+
if args.bfile_chr is not None:
101+
get_file_name(args, 'bim', chr_num, verify_exists=True)
100102
if args.compute_ldscores and not args.ld_ukb:
103+
if args.bfile_chr is None:
104+
raise ValueError('--bfile-chr not provided')
101105
get_file_name(args, 'fam', chr_num, verify_exists=True)
102106
get_file_name(args, 'bed', chr_num, verify_exists=True)
103107
if not args.compute_partitions:
@@ -143,30 +147,31 @@ def polyloc_partitions(self, args):
143147

144148
self.load_posterior_betas(args)
145149
self.partition_snps_to_bins(args, use_ridge=False)
146-
147-
#add another partition for all SNPs not in the posterior file
148-
df_bim_list = []
149-
for chr_num in range(1,23):
150-
df_bim_chr = pd.read_table(args.bfile_chr+'%d.bim'%(chr_num), sep='\s+', names=['CHR', 'SNP', 'CM', 'BP', 'A1', 'A2'], header=None)
151-
df_bim_list.append(df_bim_chr)
152-
df_bim = pd.concat(df_bim_list, axis=0)
153-
df_bim = set_snpid_index(df_bim)
154150
self.df_bins = set_snpid_index(self.df_bins)
155151

156-
#make sure that all variants in the posterior file are also in the plink files
157-
if np.any(~self.df_bins.index.isin(df_bim.index)):
158-
raise ValueError('Found variants in posterior file that are not found in the plink files')
152+
#add another partition for all SNPs not in the posterior file
153+
if args.bfile_chr is not None:
154+
df_bim_list = []
155+
for chr_num in range(1,23):
156+
df_bim_chr = pd.read_table(args.bfile_chr+'%d.bim'%(chr_num), sep='\s+', names=['CHR', 'SNP', 'CM', 'BP', 'A1', 'A2'], header=None)
157+
df_bim_list.append(df_bim_chr)
158+
df_bim = pd.concat(df_bim_list, axis=0)
159+
df_bim = set_snpid_index(df_bim)
159160

160-
#add a new bin for SNPs that are not found in the posterior file (if there are any)
161-
if df_bim.shape[0] > self.df_bins.shape[0]:
162-
new_snps = df_bim.index[~df_bim.index.isin(self.df_bins.index)]
163-
df_bins_new = df_bim.loc[new_snps, SNP_COLUMNS].copy()
164-
for colname in self.df_bins.drop(columns=SNP_COLUMNS).columns:
165-
df_bins_new[colname] = False
166-
new_colname = 'snpvar_bin%d'%(df_bins_new.shape[1] - len(SNP_COLUMNS)+1)
167-
self.df_bins[new_colname] = False
168-
df_bins_new[new_colname] = True
169-
self.df_bins = pd.concat([self.df_bins, df_bins_new], axis=0)
161+
#make sure that all variants in the posterior file are also in the plink files
162+
if np.any(~self.df_bins.index.isin(df_bim.index)):
163+
raise ValueError('Found variants in posterior file that are not found in the plink files')
164+
165+
#add a new bin for SNPs that are not found in the posterior file (if there are any)
166+
if df_bim.shape[0] > self.df_bins.shape[0]:
167+
new_snps = df_bim.index[~df_bim.index.isin(self.df_bins.index)]
168+
df_bins_new = df_bim.loc[new_snps, SNP_COLUMNS].copy()
169+
for colname in self.df_bins.drop(columns=SNP_COLUMNS).columns:
170+
df_bins_new[colname] = False
171+
new_colname = 'snpvar_bin%d'%(df_bins_new.shape[1] - len(SNP_COLUMNS)+1)
172+
self.df_bins[new_colname] = False
173+
df_bins_new[new_colname] = True
174+
self.df_bins = pd.concat([self.df_bins, df_bins_new], axis=0)
170175

171176
#save the bins to disk
172177
self.save_bins_to_disk(args)

0 commit comments

Comments
 (0)