Skip to content

Commit

Permalink
Rename --offline to --airplane to free up -o for --output
Browse files Browse the repository at this point in the history
  • Loading branch information
bede committed Dec 17, 2024
1 parent b07f7d8 commit d3045aa
Show file tree
Hide file tree
Showing 5 changed files with 23 additions and 27 deletions.
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ hostile clean --fastq1 short.r1.fq.gz --fastq2 short.r2.fq.gz --stdout > clean.f
```bash
$ hostile clean -h
usage: hostile clean [-h] --fastq1 FASTQ1 [--fastq2 FASTQ2] [--aligner {bowtie2,minimap2,auto}] [--index INDEX] [--invert] [--rename] [--reorder] [--out-dir OUT_DIR] [-s] [-t THREADS] [--force]
[--aligner-args ALIGNER_ARGS] [--offline] [-d]
[--aligner-args ALIGNER_ARGS] [--airplane] [-d]

Remove reads aligning to an index from fastq[.gz] input files.

Expand Down Expand Up @@ -120,7 +120,7 @@ options:
--aligner-args ALIGNER_ARGS
additional arguments for alignment
(default: )
--offline disable automatic index download
--airplane disable automatic index download
(default: False)
-d, --debug show debug messages
(default: False)
Expand Down
18 changes: 7 additions & 11 deletions src/hostile/aligner.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ class Aligner:
def __post_init__(self):
Path(self.data_dir).mkdir(exist_ok=True, parents=True)

def check_index(self, index: str, offline: bool = False) -> Path:
def check_index(self, index: str, airplane: bool = False) -> Path:
"""Test aligner and check/download a ref/index if necessary, returning genome or index path"""
try:
util.run(f"{self.bin_path} --version", cwd=self.data_dir)
Expand All @@ -49,7 +49,7 @@ def check_index(self, index: str, offline: bool = False) -> Path:
elif (self.data_dir / f"{index}.1.bt2").is_file():
index_path = self.data_dir / index
logging.info(f"Found cached standard index {index}")
elif not offline and util.fetch_manifest(util.INDEX_REPOSITORY_URL).get(
elif not airplane and util.fetch_manifest(util.INDEX_REPOSITORY_URL).get(
index
):
file_name = f"{index}.tar"
Expand All @@ -70,10 +70,8 @@ def check_index(self, index: str, offline: bool = False) -> Path:
logging.info(f"Downloaded standard index {index_path}")
else:
message = f"{index} is neither a valid custom Bowtie2 index path nor a valid standard index name. Mode: short read (Bowtie2)"
if offline:
message += (
". Disable offline mode to enable discovery of standard indexes"
)
if airplane:
message += ". Disable airplane mode to enable discovery of standard indexes"
raise FileNotFoundError(message)

elif self.name == "Minimap2":
Expand All @@ -88,7 +86,7 @@ def check_index(self, index: str, offline: bool = False) -> Path:
logging.info(
f"Found cached standard index {index} (MMI file will be generated)"
)
elif not offline and util.fetch_manifest(util.INDEX_REPOSITORY_URL).get(
elif not airplane and util.fetch_manifest(util.INDEX_REPOSITORY_URL).get(
index
):
file_name = f"{index}.fa.gz"
Expand All @@ -108,10 +106,8 @@ def check_index(self, index: str, offline: bool = False) -> Path:
logging.info(f"Downloaded standard index {index_path}")
else:
message = f"{index} is neither a valid custom FASTA path, nor a valid standard index name. Mode: long read (Minimap2)"
if offline:
message += (
". Disable offline mode to enable discovery of standard indexes"
)
if airplane:
message += ". Disable airplane mode to enable discovery of standard indexes"
raise FileNotFoundError(message)

return index_path
Expand Down
12 changes: 6 additions & 6 deletions src/hostile/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,18 +34,18 @@ def clean(
aligner_args: str = "",
threads: int = util.CPU_COUNT,
force: bool = False,
offline: bool = False,
airplane: bool = False,
debug: bool = False,
) -> None:
"""
Remove reads aligning to an index from fastq[.gz] input files.
Remove reads aligning to an index from fastq[.gz] input files or stdin.
:arg fastq1: path to forward fastq[.gz] file
:arg fastq2: optional path to reverse fastq[.gz] file (short reads only)
:arg aligner: alignment algorithm. Defaults to minimap2 (long read) given fastq1 only or bowtie2 (short read)
given fastq1 and fastq2. Override with bowtie2 for single/unpaired short reads
:arg index: name of standard index or path to custom genome (Minimap2) or Bowtie2 index
:arg invert: keep only reads aligning to the target genome (and their mates if applicable)
:arg invert: keep only reads aligning to the index (and their mates if applicable)
:arg rename: replace read names with incrementing integers
:arg reorder: ensure deterministic output order
:arg casava: use Casava 1.8+ read header format
Expand All @@ -54,7 +54,7 @@ def clean(
:arg aligner_args: additional arguments for alignment
:arg threads: number of alignment threads. A sensible default is chosen automatically
:arg force: overwrite existing output files
:arg offline: disable automatic index download
:arg airplane: disable automatic index download
:arg debug: show debug messages
"""

Expand Down Expand Up @@ -84,7 +84,7 @@ def clean(
aligner_args=aligner_args,
threads=threads,
force=force,
offline=offline,
airplane=airplane,
)
else:
stats = lib.clean_fastqs(
Expand All @@ -100,7 +100,7 @@ def clean(
aligner_args=aligner_args,
threads=threads,
force=force,
offline=offline,
airplane=airplane,
)
print(json.dumps(stats, indent=4), file=sys.stderr if stdout else sys.stdout)

Expand Down
8 changes: 4 additions & 4 deletions src/hostile/lib.py
Original file line number Diff line number Diff line change
Expand Up @@ -168,7 +168,7 @@ def clean_fastqs(
aligner_args: str = "",
threads: int = util.CPU_COUNT,
force: bool = False,
offline: bool = False,
airplane: bool = False,
):
aligner_threads, compression_threads = util.allocate_threads(threads, stdout=stdout)
logging.debug(
Expand All @@ -189,7 +189,7 @@ def clean_fastqs(
logging.info(f"{fastqs=}")
raise FileNotFoundError("One or more fastq files do not exist")
Path(out_dir).mkdir(exist_ok=True, parents=True)
index_path = aligner.value.check_index(index, offline=offline)
index_path = aligner.value.check_index(index, airplane=airplane)
backend_cmds = [
aligner.value.gen_clean_cmd(
fastq=fastq,
Expand Down Expand Up @@ -246,7 +246,7 @@ def clean_paired_fastqs(
aligner_args: str = "",
threads: int = util.CPU_COUNT,
force: bool = False,
offline: bool = False,
airplane: bool = False,
):
aligner_threads, compression_threads = util.allocate_threads(threads, stdout=stdout)
logging.debug(
Expand All @@ -264,7 +264,7 @@ def clean_paired_fastqs(
if not all(path.is_file() for fastq_pair in fastqs for path in fastq_pair):
raise FileNotFoundError("One or more fastq files do not exist")
Path(out_dir).mkdir(exist_ok=True, parents=True)
index_path = aligner.value.check_index(index, offline=offline)
index_path = aligner.value.check_index(index, airplane=airplane)
backend_cmds = [
aligner.value.gen_paired_clean_cmd(
fastq1=fastq_pair[0],
Expand Down
8 changes: 4 additions & 4 deletions tests/test_all.py
Original file line number Diff line number Diff line change
Expand Up @@ -710,25 +710,25 @@ def test_mismatched_number_of_reads_bowtie2(tmp_path):
)


def test_offline_invalid_mm2_standard_index_name(tmp_path):
def test_airplane_invalid_mm2_standard_index_name(tmp_path):
with pytest.raises(FileNotFoundError):
lib.clean_fastqs(
fastqs=[data_dir / "sars-cov-2_1_1.fastq"],
index="invalid_index_name",
aligner=lib.ALIGNER.minimap2,
out_dir=tmp_path,
offline=True,
airplane=True,
)


def test_offline_invalid_bt2_standard_index_name(tmp_path):
def test_airplane_invalid_bt2_standard_index_name(tmp_path):
with pytest.raises(FileNotFoundError):
lib.clean_fastqs(
fastqs=[data_dir / "sars-cov-2_1_1.fastq"],
index="invalid_index_name",
aligner=lib.ALIGNER.bowtie2,
out_dir=tmp_path,
offline=True,
airplane=True,
)


Expand Down

0 comments on commit d3045aa

Please sign in to comment.