Skip to content

Commit

Permalink
Update inference subcommands for LowPass
Browse files Browse the repository at this point in the history
  • Loading branch information
tjstruck committed Aug 7, 2024
1 parent 56a439b commit 06e314d
Show file tree
Hide file tree
Showing 4 changed files with 28 additions and 8 deletions.
15 changes: 15 additions & 0 deletions dadi_cli/InferDFE.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@ def infer_dfe(
lower_bounds: list[float],
fixed_params: list[float],
misid: bool,
cov_args: list,
cov_inbreeding: list,
cuda: bool,
maxeval: int,
maxtime: int,
Expand Down Expand Up @@ -109,6 +111,19 @@ def infer_dfe(
if misid:
func = dadi.Numerics.make_anc_state_misid_func(func)

if cov_args != []:
try:
from dadi.LowPass.LowPass import make_low_pass_func_GATK_multisample as func_cov
except ModuleNotFoundError:
raise ImportError("ERROR:\nCurrent dadi version does not support coverage model\n")
nseq = [int(ele) for ele in cov_args[1:]]
if cov_inbreeding == []:
Fx = None
else:
Fx = cov_inbreeding

func = func_cov(func, cov_args[0], fs.pop_ids, nseq, fs.sample_sizes, Fx=Fx)

p0_len = len(p0)
lower_bounds = convert_to_None(lower_bounds, p0_len)
upper_bounds = convert_to_None(upper_bounds, p0_len)
Expand Down
14 changes: 6 additions & 8 deletions dadi_cli/InferDM.py
Original file line number Diff line number Diff line change
Expand Up @@ -88,17 +88,15 @@ def infer_demography(
if cov_args != []:
try:
from dadi.LowPass.LowPass import make_low_pass_func_GATK_multisample as func_cov
import pickle
except ModuleNotFoundError:
raise ImportError("ERROR:\nCurrent dadi version does not support coverage model\n")
cov_dd = cov_args[0]
nseq = [int(ele) for ele in cov_args[1:]]
if cov_inbreeding == []:
Fx = None
else:
Fx = cov_inbreeding

cov_dd = pickle.load(open(cov_dd, 'rb'))
func_ex = func_cov(func_ex, cov_dd, fs.pop_ids, nseq, fs.sample_sizes, Fx=Fx)
print(func_cov)
func_ex = func_cov(func_ex, cov_args[0], fs.pop_ids, nseq, fs.sample_sizes, Fx=Fx)

p0_len = len(p0)
lower_bounds = convert_to_None(lower_bounds, p0_len)
Expand Down Expand Up @@ -217,13 +215,13 @@ def infer_global_opt(
import pickle
except ModuleNotFoundError:
raise ImportError("ERROR:\nCurrent dadi version does not support coverage model\n")
cov_dd = cov_args[0]
nseq = [int(ele) for ele in cov_args[1:]]
if cov_inbreeding == []:
Fx = None
else:
Fx = cov_inbreeding

cov_dd = pickle.load(open(cov_dd, 'rb'))
func_ex = func_cov(func_ex, cov_dd, fs.pop_ids, nseq, fs.sample_sizes, Fx=Fx)
func_ex = func_cov(func_ex, cov_args[0], fs.pop_ids, nseq, fs.sample_sizes, Fx=Fx)

p0_len = len(p0)
lower_bounds = convert_to_None(lower_bounds, p0_len)
Expand Down
3 changes: 3 additions & 0 deletions dadi_cli/parsers/infer_dfe_parsers.py
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,9 @@ def _run_infer_dfe(args: argparse.Namespace) -> None:
# Due to development history, much of the code expects a args.misid variable, so create it.
args.misid = not (fs.folded or args.nomisid)

if args.cov_args != []:
args.cov_args[0] = pickle.load(open(args.cov_args[0], 'rb'))

make_dir(args.output_prefix)

# # Things need to be updated for these to work
Expand Down
4 changes: 4 additions & 0 deletions dadi_cli/parsers/infer_dm_parsers.py
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,10 @@ def _run_infer_dm(args: argparse.Namespace) -> None:

make_dir(args.output_prefix)

if args.cov_args != []:
import pickle
args.cov_args[0] = pickle.load(open(args.cov_args[0], 'rb'))

# Because basic standard neutral models do not need to optimized
# we can calculate the log-likelihood and theta
if args.model in ['snm_1d', 'snm_2d'] and args.p0 == -1 and args.lbounds == None and args.ubounds == None:
Expand Down

0 comments on commit 06e314d

Please sign in to comment.