@@ -56,14 +56,15 @@ def check_args(args):
56
56
#partitionining-related parameters
57
57
if args .compute_partitions :
58
58
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' )
60
61
if args .posterior is None :
61
62
raise ValueError ('--posterior must be specified when using --compute-partitions' )
62
63
63
64
#verify LD-score related parameters
64
65
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' )
67
68
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 ):
68
69
args .ld_wind_cm = 1.0
69
70
logging .warning ('no ld-wind argument specified. PolyLoc will use --ld-cm 1.0' )
@@ -96,8 +97,11 @@ def check_files(args):
96
97
else : chr_range = range (args .chr , args .chr + 1 )
97
98
98
99
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 )
100
102
if args .compute_ldscores and not args .ld_ukb :
103
+ if args .bfile_chr is None :
104
+ raise ValueError ('--bfile-chr not provided' )
101
105
get_file_name (args , 'fam' , chr_num , verify_exists = True )
102
106
get_file_name (args , 'bed' , chr_num , verify_exists = True )
103
107
if not args .compute_partitions :
@@ -143,30 +147,31 @@ def polyloc_partitions(self, args):
143
147
144
148
self .load_posterior_betas (args )
145
149
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 )
154
150
self .df_bins = set_snpid_index (self .df_bins )
155
151
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 )
159
160
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 )
170
175
171
176
#save the bins to disk
172
177
self .save_bins_to_disk (args )
0 commit comments