Skip to content

Commit

Permalink
add file typeing
Browse files Browse the repository at this point in the history
  • Loading branch information
gordonkoehn committed Sep 13, 2024
1 parent 961b872 commit 119237c
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 13 deletions.
1 change: 1 addition & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ pandas = "^2.2.2"
matplotlib = "^3.9.2"
seaborn = "^0.13.2"
pandas-stubs = "^2.2.2.240807"
click = "^8.1.7"

[tool.poetry.group.dev.dependencies]
pytest = "^7.2.1"
Expand Down
44 changes: 31 additions & 13 deletions scripts/amplicon_covs_click.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,8 @@
import matplotlib.pyplot as plt
import seaborn as sns

from pathlib import Path

from typing import Optional


Expand All @@ -62,7 +64,7 @@ def safe_regex_search(pattern: str, text: str, group: int = 1) -> Optional[str]:
return match.group(group) if match else None


def load_bedfile(bed: str) -> pd.DataFrame:
def load_bedfile(bed: Path) -> pd.DataFrame:
"""Load bedfile and parse it."""
bedfile = pd.read_table(bed, header=None)

Expand Down Expand Up @@ -234,34 +236,46 @@ def make_median_coverage_barplot(cov_df, output=None):
"-r",
"--bedfile-addr",
required=True,
type=click.Path(exists=True),
type=click.Path(exists=True, path_type=Path),
help="Bedfile of the articV3 primers.",
)
@click.option(
"-s",
"--samp-file",
default="/cluster/project/pangolin/working/samples.tsv",
type=click.Path(exists=True),
type=click.Path(exists=True, path_type=Path),
help="TSV file like samples.tsv.",
)
@click.option(
"-f",
"--samp-path",
default="/cluster/project/pangolin/working/samples",
type=click.Path(exists=True),
type=click.Path(exists=True, path_type=Path),
help="Main path to samples.",
)
@click.option(
"-o", "--outdir", default=os.getcwd(), type=click.Path(), help="Output directory."
"-o",
"--outdir",
default=os.getcwd(),
type=click.Path(exists=True, path_type=Path),
help="Output directory.",
)
@click.option("-p", "--makeplots", is_flag=True, help="Output plots.")
@click.option("-v", "--verbose", is_flag=True, help="Verbose output.")
def main(bedfile_addr, samp_file, samp_path, outdir, makeplots, verbose):
def main(
bedfile_addr: Path,
samp_file: Path,
samp_path: Path,
outdir: Path,
makeplots,
verbose,
):
"""
Compute per amplicon relative coverage for a batch of samples.
"""
if not os.path.exists(outdir):
os.makedirs(outdir)
outdir = Path(outdir) # Ensure outdir is a Path object
if not outdir.exists():
outdir.mkdir(parents=True, exist_ok=True)

if verbose:
click.echo("Loading primers bedfile.")
Expand Down Expand Up @@ -315,13 +329,17 @@ def main(bedfile_addr, samp_file, samp_path, outdir, makeplots, verbose):
click.echo("Outputting plots.")
make_cov_heatmap(all_covs, os.path.join(outdir, "cov_heatmap.pdf"))

make_median_cov_hist(all_covs, outdir + "/median_cov_hist.pdf")
make_median_coverage_barplot(all_covs, outdir + "/median_coverage_barplot.pdf")
make_median_cov_hist(all_covs, os.path.join(outdir, "median_cov_hist.pdf"))
make_median_coverage_barplot(
all_covs, os.path.join(outdir, "median_coverage_barplot.pdf")
)

make_cov_heatmap(all_covs_frac, outdir + "/cov_heatmap_norm.pdf")
make_median_cov_hist(all_covs_frac, outdir + "/median_cov_hist_norm.pdf")
make_cov_heatmap(all_covs_frac, os.path.join(outdir, "cov_heatmap_norm.pdf"))
make_median_cov_hist(
all_covs_frac, os.path.join(outdir, "median_cov_hist_norm.pdf")
)
make_median_coverage_barplot(
all_covs_frac, outdir + "/median_coverage_barplot_norm.pdf"
all_covs_frac, os.path.join(outdir, "median_coverage_barplot_norm.pdf")
)


Expand Down

0 comments on commit 119237c

Please sign in to comment.