Skip to content

Commit d7ed99d

Browse files
committed
Added argument to skip parsing immutable covariates.
1 parent a762a37 commit d7ed99d

File tree

2 files changed

+19
-9
lines changed

2 files changed

+19
-9
lines changed

file_parser.py

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ def parse_envfile(envfile_filename):
3434
return covariates
3535

3636

37-
def baypass_summary_betai_parser(summary_filename, bf_treshold):
37+
def baypass_summary_betai_parser(summary_filename, bf_treshold, immutables):
3838
"""
3939
Parses a baypass summary file to extract any significant associations
4040
between a marker and a covariate.
@@ -51,11 +51,13 @@ def baypass_summary_betai_parser(summary_filename, bf_treshold):
5151
associations = []
5252
for lines in summary:
5353
splitline = lines.strip().split()
54-
marker_id = splitline[1]
5554
covariate = splitline[0]
56-
bf_value = float(splitline[bf_col])
57-
if bf_value >= float(bf_treshold):
58-
associations.append((marker_id, covariate))
55+
# Remove "immutable" covariates (Lat, Long, Alt)
56+
if covariate not in immutables:
57+
marker_id = splitline[1]
58+
bf_value = float(splitline[bf_col])
59+
if bf_value >= float(bf_treshold):
60+
associations.append((marker_id, covariate))
5961

6062
summary.close()
6163

pyRona.py

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -144,7 +144,8 @@ def results_summary(ronas, use_weights):
144144

145145
if use_weights is True:
146146
means = [str(np.average(list(x.corr_coef.values()),
147-
weights=list(x.corr_coef.values()))) for x in ronas]
147+
weights=list(x.corr_coef.values()))) for x in
148+
ronas]
148149
else:
149150
means = [str(np.average(list(x.corr_coef.values()))) for x in ronas]
150151
print("Average R²\t%s" % "\t".join(means))
@@ -156,8 +157,8 @@ def ronas_filterer(ronas, use_weights, num_covars):
156157
represented covariables.
157158
"""
158159
# Delete immutable covariates:
159-
immutables = ("1", "2", "3")
160-
ronas = {key: ronas[key] for key in ronas if key not in immutables}
160+
# immutables = ("1", "2", "3")
161+
# ronas = {key: ronas[key] for key in ronas if key not in immutables}
161162

162163
sortable_representation = {}
163164
for k, rona in ronas.items():
@@ -205,6 +206,13 @@ def argument_parser(args):
205206
"outlier and 2 removes **any** number of "
206207
"outliers that match the distance criteria.")
207208

209+
parameters.add_argument("-immutables", dest="immutables", type=list,
210+
default=["1", "2", "3"], required=False,
211+
help="List of immutable covariates. These are "
212+
"not even parsed from the betai file. By "
213+
"default the first 3 covars are skipped. "
214+
"You can enter any other values here.")
215+
208216
parameters.add_argument("-ronatype", dest="rtype", type=str,
209217
default="absdiff", required=False,
210218
choices=["diff", "absdiff", "dist"],
@@ -256,7 +264,7 @@ def main(params):
256264
future_covariates = fp.parse_envfile(arg.future_covars_file)
257265
RonaClass.POP_NAMES = fp.popnames_parser(arg.popnames_file)
258266
assocs = fp.baypass_summary_betai_parser(arg.baypass_summary_betai_file,
259-
arg.bayes_factor)
267+
arg.bayes_factor, arg.immutables)
260268
al_freqs = fp.baypass_pij_parser(arg.baypass_pij_file, assocs)
261269

262270
ronas = {}

0 commit comments

Comments
 (0)