Skip to content

Commit

Permalink
MAINT: change function load_card_db to load all files globally inst…
Browse files Browse the repository at this point in the history
…ead of locally (#66)
  • Loading branch information
VinzentRisch authored Jun 20, 2024
1 parent 75d4efa commit 5ace3a6
Show file tree
Hide file tree
Showing 6 changed files with 6 additions and 15 deletions.
3 changes: 1 addition & 2 deletions q2_amr/card/mags.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ def annotate_mags_card(
amr_annotations = CARDAnnotationDirectoryFormat()
frequency_list = []
with tempfile.TemporaryDirectory() as tmp:
load_card_db(tmp=tmp, card_db=card_db)
load_card_db(card_db=card_db)
for samp_bin in list(manifest.index):
bin_dir = os.path.join(str(amr_annotations), samp_bin[0], samp_bin[1])
os.makedirs(bin_dir, exist_ok=True)
Expand Down Expand Up @@ -79,7 +79,6 @@ def run_rgi_main(
alignment_tool,
"--input_type",
"contig",
"--local",
]
if include_loose:
cmd.append("--include_loose")
Expand Down
2 changes: 0 additions & 2 deletions q2_amr/card/reads.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,6 @@ def annotate_reads_card(
amr_gene_annotation = CARDGeneAnnotationDirectoryFormat()
with tempfile.TemporaryDirectory() as tmp:
load_card_db(
tmp=tmp,
card_db=card_db,
fasta=True,
include_other_models=include_other_models,
Expand Down Expand Up @@ -126,7 +125,6 @@ def run_rgi_bwt(
f"{cwd}/{samp}/output",
"-n",
str(threads),
"--local",
"--clean",
"--aligner",
aligner,
Expand Down
1 change: 0 additions & 1 deletion q2_amr/card/tests/test_mags.py
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,6 @@ def test_run_rgi_main(self):
"DIAMOND",
"--input_type",
"contig",
"--local",
"--include_loose",
"--include_nudge",
"--low_quality",
Expand Down
2 changes: 0 additions & 2 deletions q2_amr/card/tests/test_reads.py
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,6 @@ def annotate_reads_card_test_body(self, read_type):
# Expected call object for mock_run_rgi_load
exp_calls_mock_load = [
call(
tmp=tmp_dir,
card_db=ANY,
fasta=True,
include_other_models=False,
Expand Down Expand Up @@ -174,7 +173,6 @@ def test_run_rgi_bwt(self):
"path_tmp/sample1/output",
"-n",
"8",
"--local",
"--clean",
"--aligner",
"bowtie2",
Expand Down
6 changes: 2 additions & 4 deletions q2_amr/card/tests/test_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,6 @@ def test_load_card_db_fasta(self):
# Run load_card_db two times with include_other_models set to True and False
for parameters in [False, True]:
load_card_db(
tmp="path_tmp",
card_db=card_db,
kmer_db=kmer_db,
kmer=True,
Expand All @@ -95,12 +94,11 @@ def test_load_card_db_fasta(self):

expected_calls = [
call(
[
cmd=[
"rgi",
"load",
"--card_json",
os.path.join(str(card_db), "card.json"),
"--local",
f"--card_annotation{flag}",
os.path.join(
str(card_db), f"card_database_v3.2.5{parameter}.fasta"
Expand All @@ -118,7 +116,7 @@ def test_load_card_db_fasta(self):
"--kmer_size",
"61",
],
"path_tmp",
cwd=None,
verbose=True,
)
for flag, parameter in zip(flags, parameters)
Expand Down
7 changes: 3 additions & 4 deletions q2_amr/card/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@ def run_command(cmd, cwd, verbose=True):


def load_card_db(
tmp,
card_db,
kmer_db=None,
kmer: bool = False,
Expand All @@ -36,8 +35,8 @@ def load_card_db(
# Get path to card.json
path_card_json = os.path.join(str(card_db), "card.json")

# Base command that only loads card.json into the local database
cmd = ["rgi", "load", "--card_json", path_card_json, "--local"]
# Base command that only loads card.json
cmd = ["rgi", "load", "--card_json", path_card_json]

# Define suffixes for card fasta file
models = ("_all", "_all_models") if include_other_models is True else ("", "")
Expand Down Expand Up @@ -83,7 +82,7 @@ def load_card_db(

# Run command
try:
run_command(cmd, tmp, verbose=True)
run_command(cmd=cmd, cwd=None, verbose=True)
except subprocess.CalledProcessError as e:
raise Exception(
f"An error was encountered while running rgi, "
Expand Down

0 comments on commit 5ace3a6

Please sign in to comment.