Skip to content

Commit

Permalink
Merge pull request #48 from sterrettJD/work_dir
Browse files Browse the repository at this point in the history
Add alternative working directory functionality
  • Loading branch information
sterrettJD authored Dec 5, 2023
2 parents 38b9cfa + 9946cfc commit 7a6dc06
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 10 deletions.
3 changes: 3 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,9 @@ If running HoMi on a cluster with SLURM, please setup a [Snakemake SLURM profile
### Conda environment building
If conda environments have already been built, and you'd like snakemake to not build them, pass the argument `--conda_prebuilt`. This is particularly useful if running HoMi on a system with ARM architecture, like a Mac with M1/M2 chip.

### Working directory
The working directory for HoMi can be set using the `--workdir` flag. This will set the "home base" for any relative filepaths within HoMi or your config, but it will not affect the filepath of the config or profile provided to HoMi.

### Running with example dataset
```
# Create the mock community (too big for github)
Expand Down
44 changes: 34 additions & 10 deletions src/HoMi.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,21 +6,31 @@

def get_args():
parser = argparse.ArgumentParser()
parser.add_argument("config", help="path config file for pipeline (yaml)")
parser.add_argument("config",
help="path to YAML-formatted config file for pipeline")
parser.add_argument("-p", "--profile",
help="path to a snakemake profile, such as a profile to submit jobs to SLURM",
help="Path to a snakemake profile, such as a profile to submit jobs to SLURM",
default=None)
parser.add_argument("-c", "--cores",
help="Number of cores for snakemake to use",
type=int,
default=None)
parser.add_argument("-c", "--cores", help="Number of cores for snakemake to use",
type=int, default=None)
parser.add_argument("--conda_prebuilt",
action="store_true",
help="All conda environments have been prebuilt, snakemake should not build them")
parser.add_argument("--unlock", action="store_true",
help="Pass this if all conda environments have been prebuilt, \
and snakemake should not build them")
parser.add_argument("--unlock",
action="store_true",
help="Pass this to unlock a snakemake directory before running the pipeline.\
This is useful if the pipeline failed and you need to rerun it.")
parser.add_argument("--workdir",
help="Directory in which the work should be performed. \
Any relative filepaths used in HoMi will start here.",
default=None)
parser.add_argument("--snakemake_extra",
help="Extra parameters to pass snakemake",
default=None)

return parser.parse_args()


Expand Down Expand Up @@ -77,12 +87,29 @@ def construct_snakemake_command(snakepath, args):
command.append("--cores")
command.append(str(args.cores))

if args.workdir is not None:
command.append("--directory")
command.append(args.workdir)

if args.snakemake_extra is not None:
command.extend(args.snakemake_extra.split())

return command


def unlock_snakemake_directory(snakepath, args):
command = ["snakemake",
"-s", snakepath,
"--configfile", args.config,
"--unlock"]

if args.workdir is not None:
command.append("--directory")
command.append(args.workdir)

return subprocess.run(command)


def main():
args = get_args()

Expand All @@ -92,10 +119,7 @@ def main():
snakepath = make_prebuilt_conda_snakefile(snakepath)

if args.unlock == True:
subprocess.run(["snakemake",
"-s", snakepath,
"--configfile", args.config,
"--unlock"])
completed_unlock = unlock_snakemake_directory(snakepath, args)

command = construct_snakemake_command(snakepath, args)
completed_process = subprocess.run(command)
Expand Down

0 comments on commit 7a6dc06

Please sign in to comment.