Skip to content

Commit

Permalink
MAINT: Rename package to q2-rgi (#110)
Browse files Browse the repository at this point in the history
  • Loading branch information
VinzentRisch authored Nov 28, 2024
1 parent 6d140d9 commit d56e00a
Show file tree
Hide file tree
Showing 148 changed files with 155 additions and 144 deletions.
6 changes: 3 additions & 3 deletions .coveragerc
Original file line number Diff line number Diff line change
@@ -1,16 +1,16 @@
[run]
source=q2_amr
source=q2_rgi
branch = True
omit =
*/tests*
*/__init__.py
q2_amr/_version.py
q2_rgi/_version.py
versioneer.py

[report]
fail_under = 90
omit =
*/tests*
*/__init__.py
q2_amr/_version.py
q2_rgi/_version.py
versioneer.py
2 changes: 1 addition & 1 deletion .gitattributes
Original file line number Diff line number Diff line change
@@ -1 +1 @@
q2_amr/_version.py export-subst
q2_rgi/_version.py export-subst
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -131,6 +131,6 @@ dmypy.json

# PyCharm configuration
.idea/
/q2_amr/charts_testing.py
/q2_rgi/charts_testing.py
/index.html
/bwt_test_file.py
2 changes: 1 addition & 1 deletion MANIFEST.in
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
include versioneer.py
include q2_amr/_version.py
include q2_rgi/_version.py
36 changes: 18 additions & 18 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,27 +1,27 @@
# q2-amr
![CI](https://github.com/bokulich-lab/q2-amr/actions/workflows/ci-dev.yaml/badge.svg)
[![codecov](https://codecov.io/gh/bokulich-lab/q2-amr/branch/main/graph/badge.svg?token=THMBOFUZR0)](https://codecov.io/gh/bokulich-lab/q2-amr)
# q2-rgi
![CI](https://github.com/bokulich-lab/q2-rgi/actions/workflows/ci-dev.yaml/badge.svg)
[![codecov](https://codecov.io/gh/bokulich-lab/q2-rgi/branch/main/graph/badge.svg?token=THMBOFUZR0)](https://codecov.io/gh/bokulich-lab/q2-rgi)
[![Code style: black](https://img.shields.io/badge/code%20style-black-000000.svg)](https://github.com/psf/black)

QIIME 2 plugin for antimicrobial resistance gene annotation of MAGs and metagenomic reads.

## Installation
To install _q2-amr_, follow the steps described below.
To install _q2-rgi_, follow the steps described below.

<details>
<summary><b>macOS (intel) / Linux</b></summary>

```shell
mamba create -yn q2-amr \
mamba create -yn q2-rgi \
-c https://packages.qiime2.org/qiime2/2024.2/shotgun/released/ \
-c qiime2 -c conda-forge -c bioconda -c defaults \
qiime2 q2cli q2templates q2-types q2-feature-table q2-demux rgi tqdm

conda activate q2-amr
conda activate q2-rgi

pip install --no-deps --force-reinstall \
git+https://github.com/misialq/rgi.git@py38-fix \
git+https://github.com/bokulich-lab/q2-amr.git
git+https://github.com/bokulich-lab/q2-rgi.git
```

Refresh cache and check that everything worked:
Expand All @@ -35,17 +35,17 @@ qiime info
<summary><b>macOS (apple silicon)</b></summary>

```shell
CONDA_SUBDIR=osx-64 mamba create -yn q2-amr \
CONDA_SUBDIR=osx-64 mamba create -yn q2-rgi \
-c https://packages.qiime2.org/qiime2/2024.2/shotgun/released/ \
-c qiime2 -c conda-forge -c bioconda -c defaults \
qiime2 q2cli q2templates q2-types q2-feature-table q2-demux rgi tqdm

conda activate q2-amr
conda activate q2-rgi
conda config --env --set subdir osx-64

pip install --no-deps --force-reinstall \
git+https://github.com/misialq/rgi.git@py38-fix \
git+https://github.com/bokulich-lab/q2-amr.git
git+https://github.com/bokulich-lab/q2-rgi.git
```

Refresh cache and check that everything worked:
Expand All @@ -58,18 +58,18 @@ qiime info
## Functionality
This QIIME 2 plugin contains actions used to annotate short single/paired-end
sequencing reads and MAGs with antimicrobial resistance genes. Currently, the [CARD](https://card.mcmaster.ca) database is supported (for details on
the implementation and usage, please refer to the [RGI](https://github.com/arpcard/rgi) documentation). Below you will
the implementation and usage, please refer to the [rgi](https://github.com/arpcard/rgi) documentation). Below you will
find an overview of actions available in the plugin.

| Action | Description | Underlying tool | Used function |
|-----------------------|--------------------------------------------------------------------------------------|---------------------------------------|--------------------------------------|
| fetch-card-db | Download and preprocess CARD and WildCARD data. | [RGI](https://github.com/arpcard/rgi) | card_annotation, wildcard_annotation |
| annotate-mags-card | Annotate MAGs with antimicrobial resistance gene information from CARD. | [RGI](https://github.com/arpcard/rgi) | main, load |
| annotate-reads-card | Annotate metagenomic reads with antimicrobial resistance gene information from CARD. | [RGI](https://github.com/arpcard/rgi) | bwt, load |
| heatmap | Create a heatmap from annotate-mags-card output files. | [RGI](https://github.com/arpcard/rgi) | heatmap |
| kmer-query-mags-card | Pathogen-of-origin prediction for ARGs in MAGs. | [RGI](https://github.com/arpcard/rgi) | kmer-query, load |
| kmer-query-reads-card | Pathogen-of-origin prediction for ARGs in reads. | [RGI](https://github.com/arpcard/rgi) | kmer-query, load |
| kmer-build-card | Build a kmer database with a custom kmer length. | [RGI](https://github.com/arpcard/rgi) | kmer-build |
| fetch-card-db | Download and preprocess CARD and WildCARD data. | [rgi](https://github.com/arpcard/rgi) | card_annotation, wildcard_annotation |
| annotate-mags-card | Annotate MAGs with antimicrobial resistance gene information from CARD. | [rgi](https://github.com/arpcard/rgi) | main, load |
| annotate-reads-card | Annotate metagenomic reads with antimicrobial resistance gene information from CARD. | [rgi](https://github.com/arpcard/rgi) | bwt, load |
| heatmap | Create a heatmap from annotate-mags-card output files. | [rgi](https://github.com/arpcard/rgi) | heatmap |
| kmer-query-mags-card | Pathogen-of-origin prediction for ARGs in MAGs. | [rgi](https://github.com/arpcard/rgi) | kmer-query, load |
| kmer-query-reads-card | Pathogen-of-origin prediction for ARGs in reads. | [rgi](https://github.com/arpcard/rgi) | kmer-query, load |
| kmer-build-card | Build a kmer database with a custom kmer length. | [rgi](https://github.com/arpcard/rgi) | kmer-build |

## Dev environment
This repository follows the _black_ code style. To make the development slightly easier
Expand Down
8 changes: 4 additions & 4 deletions ci/recipe/meta.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
{% set version = data.get('version') or 'placehold' %}

package:
name: q2-amr
name: q2-rgi
version: {{ version }}

source:
Expand Down Expand Up @@ -32,12 +32,12 @@ test:
- coverage
- pytest-cov
imports:
- q2_amr
- q2_rgi
- qiime2.plugins.amr
commands:
- pytest --cov q2_amr --cov-report xml:coverage.xml --pyargs q2_amr
- pytest --cov q2_rgi --cov-report xml:coverage.xml --pyargs q2_rgi

about:
home: https://github.com/bokulich-lab/q2-amr
home: https://github.com/bokulich-lab/q2-rgi
license: BSD-3-Clause
license_family: BSD
4 changes: 4 additions & 0 deletions q2_amr/__init__.py → q2_rgi/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,10 @@
#
# The full license is in the file LICENSE, distributed with this software.
# ----------------------------------------------------------------------------
import importlib

from . import _version

__version__ = _version.get_versions()["version"]

importlib.import_module("q2_rgi.types")
4 changes: 2 additions & 2 deletions q2_amr/_version.py → q2_rgi/_version.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,8 +45,8 @@ def get_config():
cfg.VCS = "git"
cfg.style = "pep440"
cfg.tag_prefix = ""
cfg.parentdir_prefix = "q2-amr-"
cfg.versionfile_source = "q2_amr/_version.py"
cfg.parentdir_prefix = "q2-rgi-"
cfg.versionfile_source = "q2_rgi/_version.py"
cfg.verbose = False
return cfg

Expand Down
File renamed without changes.
File renamed without changes.
4 changes: 2 additions & 2 deletions q2_amr/card/database.py → q2_rgi/card/database.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@
import requests
from tqdm import tqdm

from q2_amr.card.utils import colorify, run_command
from q2_amr.types._format import (
from q2_rgi.card.utils import colorify, run_command
from q2_rgi.types._format import (
CARDDatabaseDirectoryFormat,
CARDKmerDatabaseDirectoryFormat,
)
Expand Down
6 changes: 3 additions & 3 deletions q2_amr/card/heatmap.py → q2_rgi/card/heatmap.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@
import pkg_resources
import q2templates

from q2_amr.card.utils import run_command
from q2_amr.types import CARDAnnotationDirectoryFormat
from q2_rgi.card.utils import run_command
from q2_rgi.types import CARDAnnotationDirectoryFormat


def heatmap(
Expand All @@ -20,7 +20,7 @@ def heatmap(
display: str = "plain",
frequency: bool = False,
):
TEMPLATES = pkg_resources.resource_filename("q2_amr", "assets")
TEMPLATES = pkg_resources.resource_filename("q2_rgi", "assets")
annotation_dir = str(amr_annotation)
with tempfile.TemporaryDirectory() as tmp:
# Create directories for the JSON annotation files and the heatmap output files
Expand Down
4 changes: 2 additions & 2 deletions q2_amr/card/kmer.py → q2_rgi/card/kmer.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@
import warnings
from pathlib import Path

from q2_amr.card.utils import load_card_db, run_command
from q2_amr.types import (
from q2_rgi.card.utils import load_card_db, run_command
from q2_rgi.types import (
CARDAlleleAnnotationDirectoryFormat,
CARDAnnotationDirectoryFormat,
CARDDatabaseDirectoryFormat,
Expand Down
4 changes: 2 additions & 2 deletions q2_amr/card/mags.py → q2_rgi/card/mags.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@
import pandas as pd
from q2_types.per_sample_sequences import MultiMAGSequencesDirFmt

from q2_amr.card.utils import create_count_table, load_card_db, read_in_txt, run_command
from q2_amr.types import CARDAnnotationDirectoryFormat, CARDDatabaseDirectoryFormat
from q2_rgi.card.utils import create_count_table, load_card_db, read_in_txt, run_command
from q2_rgi.types import CARDAnnotationDirectoryFormat, CARDDatabaseDirectoryFormat


def annotate_mags_card(
Expand Down
4 changes: 2 additions & 2 deletions q2_amr/card/partition.py → q2_rgi/card/partition.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@
import numpy as np
from qiime2.util import duplicate

from q2_amr.card.utils import copy_files
from q2_amr.types import (
from q2_rgi.card.utils import copy_files
from q2_rgi.types import (
CARDAlleleAnnotationDirectoryFormat,
CARDAnnotationDirectoryFormat,
CARDGeneAnnotationDirectoryFormat,
Expand Down
4 changes: 2 additions & 2 deletions q2_amr/card/reads.py → q2_rgi/card/reads.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,8 @@
)
from q2_types.sample_data import SampleData

from q2_amr.card.utils import create_count_table, load_card_db, read_in_txt, run_command
from q2_amr.types import (
from q2_rgi.card.utils import create_count_table, load_card_db, read_in_txt, run_command
from q2_rgi.types import (
CARDAlleleAnnotationDirectoryFormat,
CARDDatabaseDirectoryFormat,
CARDGeneAnnotationDirectoryFormat,
Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,12 @@
import requests
from qiime2.plugin.testing import TestPluginBase

from q2_amr.card.database import download_with_progress_bar, fetch_card_db, preprocess
from q2_amr.types import CARDDatabaseDirectoryFormat, CARDKmerDatabaseDirectoryFormat
from q2_rgi.card.database import download_with_progress_bar, fetch_card_db, preprocess
from q2_rgi.types import CARDDatabaseDirectoryFormat, CARDKmerDatabaseDirectoryFormat


class TestAnnotateMagsCard(TestPluginBase):
package = "q2_amr.card.tests"
package = "q2_rgi.card.tests"

def mock_preprocess(self, dir, operation):
if operation == "card":
Expand All @@ -36,8 +36,8 @@ def test_fetch_card_db(self):
wildcard_tar = self.get_data_path("wildcard_data.tar.bz2")

# Patch requests.get,
with patch("q2_amr.card.database.download_with_progress_bar"), patch(
"q2_amr.card.database.preprocess", side_effect=self.mock_preprocess
with patch("q2_rgi.card.database.download_with_progress_bar"), patch(
"q2_rgi.card.database.preprocess", side_effect=self.mock_preprocess
), patch(
"tarfile.open",
side_effect=[tarfile.open(card_tar), tarfile.open(wildcard_tar)],
Expand Down Expand Up @@ -74,7 +74,7 @@ def test_fetch_card_db(self):
def test_connection_error(self):
# Simulate a ConnectionError during requests.get
with patch(
"q2_amr.card.database.download_with_progress_bar",
"q2_rgi.card.database.download_with_progress_bar",
side_effect=requests.ConnectionError,
), self.assertRaisesRegex(
requests.ConnectionError,
Expand All @@ -85,14 +85,14 @@ def test_connection_error(self):
def test_tarfile_read_error(self):
# Simulate a tarfile.ReadError during tarfile.open
with patch("tarfile.open", side_effect=tarfile.ReadError), patch(
"q2_amr.card.database.download_with_progress_bar"
"q2_rgi.card.database.download_with_progress_bar"
), self.assertRaisesRegex(tarfile.ReadError, "Tarfile is invalid."):
fetch_card_db()

def test_subprocess_error(self):
# Simulate a subprocess.CalledProcessError during run_command
with patch(
"q2_amr.card.database.run_command",
"q2_rgi.card.database.run_command",
side_effect=subprocess.CalledProcessError(1, "cmd"),
), self.assertRaisesRegex(
Exception,
Expand All @@ -104,7 +104,7 @@ def test_subprocess_error(self):
def test_preprocess_card(self):
# Ensure preprocess calls run_command with the correct arguments for "card"
# operation
with patch("q2_amr.card.database.run_command") as mock_run_command:
with patch("q2_rgi.card.database.run_command") as mock_run_command:
preprocess("path_tmp", "card")
mock_run_command.assert_called_once_with(
["rgi", "card_annotation", "-i", "card/card.json"],
Expand All @@ -115,7 +115,7 @@ def test_preprocess_card(self):
def test_preprocess_wildcard(self):
# Ensure preprocess calls run_command with the correct arguments for "wildcard"
# operation
with patch("q2_amr.card.database.run_command") as mock_run_command:
with patch("q2_rgi.card.database.run_command") as mock_run_command:
preprocess("path_tmp", "wildcard")
mock_run_command.assert_called_once_with(
[
Expand All @@ -138,7 +138,7 @@ def test_download_with_progressbar(self):
tar_path = "/path/to/downloaded/file.tar"

with patch("requests.get") as mock_get, patch(
"q2_amr.card.database.tqdm"
"q2_rgi.card.database.tqdm"
) as mock_tqdm, patch("builtins.open") as mock_open:
# Mock response object
response_mock = MagicMock()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,17 +4,17 @@

from qiime2.plugin.testing import TestPluginBase

from q2_amr.card.heatmap import (
from q2_rgi.card.heatmap import (
InvalidParameterCombinationError,
change_names,
heatmap,
run_rgi_heatmap,
)
from q2_amr.types import CARDAnnotationDirectoryFormat
from q2_rgi.types import CARDAnnotationDirectoryFormat


class TestHeatmap(TestPluginBase):
package = "q2_amr.card.tests"
package = "q2_rgi.card.tests"

def test_heatmap(self):
amr_annotation = CARDAnnotationDirectoryFormat()
Expand All @@ -28,7 +28,7 @@ def mock_run_rgi_heatmap(tmp, json_files_dir, clus, cat, display, frequency):
file.write(file_type)

with patch(
"q2_amr.card.heatmap.run_rgi_heatmap", side_effect=mock_run_rgi_heatmap
"q2_rgi.card.heatmap.run_rgi_heatmap", side_effect=mock_run_rgi_heatmap
), tempfile.TemporaryDirectory() as tmp:
os.makedirs(os.path.join(tmp, "results"))
heatmap(tmp, amr_annotation)
Expand All @@ -45,7 +45,7 @@ def mock_run_rgi_heatmap(tmp, json_files_dir, clus, cat, display, frequency):
self.assertTrue(os.path.exists(os.path.join(tmp, "q2templateassets")))

def test_run_rgi_heatmap(self):
with patch("q2_amr.card.heatmap.run_command") as mock_run_command:
with patch("q2_rgi.card.heatmap.run_command") as mock_run_command:
run_rgi_heatmap(
"path_tmp", "json_files_dir_path", "samples", "drug_class", "fill", True
)
Expand All @@ -71,9 +71,9 @@ def test_run_rgi_heatmap(self):

def test_change_names(self):
with patch(
"q2_amr.card.heatmap.os.listdir",
"q2_rgi.card.heatmap.os.listdir",
return_value=["heatmap-7.eps", "heatmap-7.png", "heatmap-7.csv"],
), patch("q2_amr.card.heatmap.os.rename") as mock_rename:
), patch("q2_rgi.card.heatmap.os.rename") as mock_rename:
results_dir = "/path/to/results"
change_names(results_dir)
expected_calls = [
Expand All @@ -85,8 +85,8 @@ def test_change_names(self):
self.assertEqual(expected_calls, actual_calls)

def test_change_names_empty(self):
with patch("q2_amr.card.heatmap.os.listdir", return_value=[]), patch(
"q2_amr.card.heatmap.os.rename"
with patch("q2_rgi.card.heatmap.os.listdir", return_value=[]), patch(
"q2_rgi.card.heatmap.os.rename"
) as mock_rename:
results_dir = "/path/to/results"
change_names(results_dir)
Expand Down
Loading

0 comments on commit d56e00a

Please sign in to comment.