Skip to content

Commit

Permalink
Merge pull request #166 from pdimens/logview
Browse files Browse the repository at this point in the history
add harpy view
  • Loading branch information
pdimens authored Nov 22, 2024
2 parents 632f853 + 1475a93 commit 736e540
Show file tree
Hide file tree
Showing 5 changed files with 78 additions and 6 deletions.
6 changes: 4 additions & 2 deletions harpy/__main__.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,9 @@
from . import simulate
from . import snp
from . import sv
from .popgroups import popgroup
from .popgroup import popgroup
from .imputeparams import imputeparams
from . import view

click.rich_click.USE_MARKDOWN = True
click.rich_click.SHOW_ARGUMENTS = False
Expand All @@ -44,6 +45,7 @@ def cli():
# main program
cli.add_command(popgroup)
cli.add_command(imputeparams)
cli.add_command(view.view)
cli.add_command(preflight.preflight)
cli.add_command(demultiplex.demultiplex)
cli.add_command(qc.qc)
Expand All @@ -70,7 +72,7 @@ def cli():
},
{
"name": "Other Commands",
"commands": sorted(["deconvolve", "hpc", "imputeparams", "popgroup","preflight","resume"])
"commands": sorted(["deconvolve", "hpc", "imputeparams", "popgroup","preflight","resume", "view"])
}
],
} | simulate.commandstring | hpc.docstring
Expand Down
File renamed without changes.
72 changes: 72 additions & 0 deletions harpy/view.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
"""View the latest log or snakefile of a workflow"""

import os
import sys
import glob
import subprocess
import rich_click as click
from ._printing import print_error
from ._validations import is_gzip

@click.command(no_args_is_help = True, context_settings=dict(allow_interspersed_args=False))
@click.option('-s', '--snakefile', is_flag = True, show_default = True, default = False, help = "View the snakefile, not the log file")
@click.argument('directory', required=True, type=click.Path(exists=True, file_okay=False))
def view(directory, snakefile):
"""
View a workflow log file or snakefile
This convenience command lets you view the latest workflow log file
of a Harpy output directory. You can use `--snakefile` to view the workflow
snakefile instead. Output is printed to the screen via `less` and
accepts the typical keyboard shortcuts to navigate the output, e.g.:
| key | function |
| :---------------------- | :------------------------- |
| `up arrow`/`down arrow` | scroll up/down |
| `Page Up`/`Page Down` | scroll up/down, but faster |
| `q` | exit |
"""
# check if there is a workflow or log folder
# and whether the expected files are in there
err = 0
if snakefile:
files = [i for i in glob.iglob(f"{directory}/workflow/*.smk")]
err_dir = f"{directory}/workflow/"
err_file = "snakefiles"
if not os.path.exists(f"{directory}/workflow"):
err = 1
elif not files:
err = 2
else:
files = [i for i in glob.iglob(f"{directory}/logs/snakemake/*.log*")]
err_dir = f"{directory}/logs/snakemake/"
err_file = "log files"
if not os.path.exists(f"{directory}/logs/snakemake"):
err = 1
elif not files:
err = 2
if err == 1:
print_error(
"Directory not found",
f"The file you are trying to view is expected to be in [blue]{err_dir}[/blue], but that directory was not found. Please check that this is the correct folder."
)
sys.exit(1)
elif err == 2:
print_error(
"File not found",
f"There are no {err_file} in [blue]{err_dir}[/blue]. Please check that this is the correct folder."
)
sys.exit(1)
# sort and pull only the most recent file (based on modification time)
file = sorted(files, key = os.path.getmtime)[-1]
if not os.access(file, os.R_OK):
print_error(
"Incorrect permissions",
f"[blue]{file}[/blue] does not have read access. Please check the file permissions."
)
sys.exit(1)

cat_cmd = "zcat" if is_gzip(file) else "cat"
stream = subprocess.Popen([cat_cmd, file], stdout=subprocess.PIPE)
pygment = subprocess.Popen(["pygmentize", "-l", "yaml"], stdin = stream.stdout, stdout = subprocess.PIPE)
subprocess.run(["less", "-R"], stdin = pygment.stdout)
2 changes: 0 additions & 2 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,5 @@ exclude = ["test"]
[project.scripts]
harpy = "harpy.__main__:cli"

[tool.setuptools_scm]

[project.urls]
Homepage = "https://github.com/pdimens/harpy"
4 changes: 2 additions & 2 deletions resources/buildlocal.sh
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,8 @@ mkdir -p ${CONDA_PREFIX}/bin
g++ harpy/bin/extractReads.cpp -O3 -o ${CONDA_PREFIX}/bin/extractReads

# install harpy proper
pip install . --no-deps && \
rm -r build harpy.egg-info
pip install --no-deps --disable-pip-version-check -e . && \
rm -rf build #harpy.egg-info

# associated scripts
chmod +x harpy/bin/*
Expand Down

0 comments on commit 736e540

Please sign in to comment.