Skip to content

Commit 1c5ddfa

Browse files
committed
Add support for subdir configuration
1 parent 61375cc commit 1c5ddfa

5 files changed

Lines changed: 43 additions & 13 deletions

File tree

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,3 +3,4 @@
33
__pycache__
44
sandbox/
55
dist/
6+
.vscode/

ezfastq/api.py

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -12,12 +12,19 @@
1212
from pathlib import Path
1313

1414

15-
def copy(sample_names, seq_path, pair_mode=PairMode.Unspecified, prefix="", workdir=Path(".")):
15+
def copy(
16+
sample_names,
17+
seq_path,
18+
pair_mode=PairMode.Unspecified,
19+
prefix="",
20+
workdir=Path("."),
21+
subdir="seq",
22+
):
1623
copier = FastqCopier.from_dir(sample_names, seq_path, prefix=prefix, pair_mode=pair_mode)
17-
copier.copy_files(workdir / "seq")
24+
copier.copy_files(workdir / subdir)
1825
copier.print_copy_log()
19-
nlogs = len(list((workdir / "seq").glob("copy-log-*.toml")))
20-
with open(workdir / "seq" / f"copy-log-{nlogs + 1}.toml", "w") as fh:
26+
nlogs = len(list((workdir / subdir).glob("copy-log-*.toml")))
27+
with open(workdir / subdir / f"copy-log-{nlogs + 1}.toml", "w") as fh:
2128
print(copier, file=fh)
2229
added_samples = set(fastq.sample for fastq in copier.copied_files)
2330
added_samples = sorted(added_samples)

ezfastq/cli.py

Lines changed: 16 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
from argparse import ArgumentParser
1313
from importlib.metadata import version
1414
from pathlib import Path
15+
from rich_argparse import RichHelpFormatter
1516

1617

1718
def main(arglist=None):
@@ -22,11 +23,12 @@ def main(arglist=None):
2223
pair_mode=args.pair_mode,
2324
prefix=args.prefix,
2425
workdir=args.workdir,
26+
subdir=args.subdir,
2527
)
2628

2729

2830
def parse_args(arglist=None):
29-
if arglist:
31+
if arglist: # pragma: no cover
3032
arglist = map(str, arglist)
3133
args = get_parser().parse_args(arglist)
3234
samples_file = Path(args.samples[0])
@@ -38,7 +40,10 @@ def parse_args(arglist=None):
3840

3941

4042
def get_parser():
41-
parser = ArgumentParser(description="Copy FASTQ files and update sample names")
43+
parser = ArgumentParser(
44+
description="Copy FASTQ files and use sample names to make filenames consistent",
45+
formatter_class=RichHelpFormatter,
46+
)
4247
parser.add_argument(
4348
"seq_path",
4449
help="path to directory containing sequences in FASTQ format; subdirectories will be searched recursively",
@@ -57,10 +62,17 @@ def get_parser():
5762
parser.add_argument(
5863
"-w",
5964
"--workdir",
60-
metavar="WD",
65+
metavar="PATH",
6166
type=Path,
6267
default=Path("."),
63-
help="directory to which input files will be copied and renamed",
68+
help="project directory to which input files will be copied and renamed; current directory is used by default",
69+
)
70+
parser.add_argument(
71+
"-s",
72+
"--subdir",
73+
metavar="PATH",
74+
default="seq",
75+
help="subdirectory path under --workdir to which sequence files will be written; PATH=`seq` by default, but can contain nesting (e.g. `seq/study`)",
6476
)
6577
parser.add_argument(
6678
"-p",

ezfastq/tests/test_cli.py

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,15 @@ def test_copy(tmp_path):
3030
assert "SkippedFiles" not in log_data
3131

3232

33+
def test_copy_subdir(tmp_path):
34+
seq_path = files("ezfastq") / "tests" / "data" / "flat"
35+
arglist = [seq_path, "test1", "test2", "--workdir", tmp_path, "--subdir", "seq/PROJa/RUNb"]
36+
cli.main(arglist)
37+
rundir = tmp_path / "seq" / "PROJa" / "RUNb"
38+
assert rundir.is_dir()
39+
assert len(list(rundir.glob("*_R?.fastq.gz"))) == 4
40+
41+
3342
def test_copy_sample_names_file(tmp_path):
3443
sample_names_file = tmp_path / "sample-names.txt"
3544
sample_names_file.write_text("test1\ntest3\ntest2\n")

pyproject.toml

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6,17 +6,14 @@ readme = "README.md"
66
requires-python = ">=3.10"
77
dependencies = [
88
"rich",
9+
"rich_argparse",
910
]
1011
authors = [
1112
{name = "Daniel Standage", email = "daniel.standage@st.dhs.gov"},
1213
{name = "Ryan Berger", email = "ryan.berger@st.dhs.gov"},
1314
]
1415

15-
[build-system]
16-
requires = ["setuptools", "setuptools-scm"]
17-
build-backend = "setuptools.build_meta"
18-
19-
[dependency-groups]
16+
[project.optional-dependencies]
2017
dev = [
2118
"black==25.1",
2219
"pytest",
@@ -26,5 +23,9 @@ dev = [
2623
[project.scripts]
2724
ezfastq = "ezfastq.cli:main"
2825

26+
[build-system]
27+
requires = ["setuptools", "setuptools-scm"]
28+
build-backend = "setuptools.build_meta"
29+
2930
[tool.setuptools]
3031
packages = ["ezfastq"]

0 commit comments

Comments
 (0)