Skip to content

Commit

Permalink
Make loading work_queue and cyvcf2 optional
Browse files Browse the repository at this point in the history
  • Loading branch information
tjstruck committed Jun 8, 2024
1 parent 549d190 commit e4df957
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 9 deletions.
16 changes: 10 additions & 6 deletions dadi_cli/GenerateFs.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import dadi, random
from cyvcf2 import VCF


def generate_fs(
Expand Down Expand Up @@ -60,11 +59,16 @@ def generate_fs(
raise ValueError("The lengths of `pop_ids` and `projections` must match.")

if polarized:
if not VCF(vcf).contains('AA'):
raise ValueError(
f'The AA (Ancestral allele) INFO field cannot be found in the header of {vcf}, ' +
'but an unfolded frequency spectrum is requested.'
)
try:
from cyvcf2 import VCF
if not VCF(vcf).contains('AA'):
raise ValueError(
f'The AA (Ancestral allele) INFO field cannot be found in the header of {vcf}, ' +
'but an unfolded frequency spectrum is requested.'
)
except ModuleNotFoundError:
print("Unable to load cyvcf2 and check if ancestral alleles are in provided VCF.\n"+
"Generated FS may be empty if ancestral allele not found.")

if subsample:
subsample_dict = {}
Expand Down
5 changes: 4 additions & 1 deletion dadi_cli/parsers/infer_dfe_parsers.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import argparse, glob, pickle, os, random, sys, time, warnings
import work_queue as wq
from multiprocessing import Process, Queue
from dadi_cli.parsers.common_arguments import *
from dadi_cli.parsers.argument_validation import *
Expand Down Expand Up @@ -212,6 +211,10 @@ def _run_infer_dfe(args: argparse.Namespace) -> None:
bestfits = None

if args.work_queue:
try:
import work_queue as wq
except ModuleNotFoundError:
raise ValueError("Work Queue could not be loaded.")

if args.debug_wq:
q = wq.WorkQueue(name=args.work_queue[0], debug_log="debug.log", port=args.port)
Expand Down
10 changes: 8 additions & 2 deletions dadi_cli/parsers/infer_dm_parsers.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import argparse, inspect, nlopt, os, random, sys, time, warnings
import work_queue as wq
from multiprocessing import Process, Queue
from sys import exit
from dadi_cli.parsers.common_arguments import *
Expand Down Expand Up @@ -191,7 +190,10 @@ def _run_infer_dm(args: argparse.Namespace) -> None:
else:
global_algorithm = nlopt.GN_MLSL_LDS
if args.work_queue:

try:
import work_queue as wq
except ModuleNotFoundError:
raise ValueError("Work Queue could not be loaded.")
if args.debug_wq:
q = wq.WorkQueue(name=args.work_queue[0], debug_log="debug.log", port=args.port)
else:
Expand Down Expand Up @@ -346,6 +348,10 @@ def _run_infer_dm(args: argparse.Namespace) -> None:
bestfits]

if args.work_queue:
try:
import work_queue as wq
except ModuleNotFoundError:
raise ValueError("Work Queue could not be loaded.")
if args.debug_wq:
q = wq.WorkQueue(name=args.work_queue[0], debug_log="debug.log", port=args.port)
else:
Expand Down

0 comments on commit e4df957

Please sign in to comment.