Skip to content

Commit

Permalink
Merge pull request #134 from jaleezyy/qol_patch
Browse files Browse the repository at this point in the history
Quality of life changes by including snakemake parameters into main executable
  • Loading branch information
jaleezyy authored Feb 16, 2023
2 parents 7ff6f8b + cc3b980 commit 98c9631
Show file tree
Hide file tree
Showing 4 changed files with 28 additions and 9 deletions.
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -47,14 +47,14 @@ If you use this software please [cite](https://doi.org/10.3390/v12080895):
wget https://repo.anaconda.com/miniconda/Miniconda3-latest-Linux-x86_64.sh
bash Miniconda3-latest-Linux-x86_64.sh # follow instructions
source $(conda info --base)/etc/profile.d/conda.sh
conda create -n signal -c conda-forge -c bioconda -c defaults snakemake pandas conda
conda create -n signal -c conda-forge -c bioconda -c defaults snakemake pandas conda mamba
conda activate signal

There are some issues with `conda` failing to install newer versions of snakemake
so alternatively install `mamba` and use that (snakemake has beta support for it within the workflow)

conda install -c conda-forge mamba
mamba create -c conda-forge -c bioconda -n signal snakemake pandas conda
mamba create -c conda-forge -c bioconda -n signal snakemake pandas conda mamba
conda activate signal

Additional software dependencies are managed directly by `snakemake` using conda environment files:
Expand Down
6 changes: 3 additions & 3 deletions scripts/assign_lineages.py
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ def update_nextclade_dataset(vers, skip):
try:
if software_ver != "None": # specific version requested, check if available
try:
softrequest = subprocess.check_output(f"conda search -c bioconda -f nextclade={software_ver}".split()).decode('utf-8').strip().split()[-3]
softrequest = subprocess.check_output(f"conda search -c bioconda -f nextclade", shell=True).split()[-3].strip().decode('utf-8')
# check if already installed
if softrequest == nextclade_version:
print(f"Nextclade {softrequest} already installed! Skipping update!")
Expand All @@ -86,15 +86,15 @@ def update_nextclade_dataset(vers, skip):
subprocess.run(f"conda install -q -y -c bioconda nextclade={softrequest}", shell=True, check=True)
except subprocess.CalledProcessError:
print("Cannot find version requested, will ensure latest version!")
softrequest = subprocess.check_output(f"conda search -c bioconda -f nextclade".split()).decode('utf-8').strip().split()[-3]
softrequest = subprocess.check_output(f"conda search -c bioconda -f nextclade", shell=True).split()[-3].strip().decode('utf-8')
# check if already installed
if softrequest == nextclade_version:
print(f"Nextclade {softrequest} already installed! Skipping update!")
else:
subprocess.run(f"conda install -q -y -c bioconda nextclade={softrequest}", shell=True, check=True)
else:
print(f"Installing latest version of Nextclade!")
softrequest = subprocess.check_output(f"conda search -c bioconda -f nextclade".split()).decode('utf-8').strip().split()[-3]
softrequest = subprocess.check_output(f"conda search -c bioconda -f nextclade", shell=True).split()[-3].strip().decode('utf-8')
if softrequest == nextclade_version:
print(f"Nextclade {softrequest} already installed! Skipping update!")
else:
Expand Down
2 changes: 1 addition & 1 deletion scripts/signal_postprocess.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@

assert long_git_id.startswith('$Id: ')
#short_git_id = long_git_id[5:12]
short_git_id = "v1.5.7"
short_git_id = "v1.5.8"

# Suppresses matplotlib warning (https://github.com/jaleezyy/covid-19-signal/issues/59)
# Creates a small memory leak, but it's nontrivial to fix, and won't be a practical concern!
Expand Down
25 changes: 22 additions & 3 deletions signal.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,12 @@ def create_parser():
parser.add_argument('--add-breseq', action='store_true', help="Configuration file generator parameter. Set flag to ENABLE optional breseq step (will take more time for analysis to complete)")
parser.add_argument('-neg', '--neg-prefix', default=None, help="Configuration file generator parameter. Comma-separated list of negative sontrol sample name(s) or prefix(es). For example, 'Blank' will cover Blank1, Blank2, etc. Recommended if running ncov-tools. Will be left empty, if not provided")
parser.add_argument('--dependencies', action='store_true', help="Download data dependencies (under a created 'data' directory) required for SIGNAL analysis and exit. Note: Will override other flags! (~10 GB storage required)")
parser.add_argument('-ri', '--rerun-incomplete', action='store_true', help="Snakemake parameter. Re-run any incomplete samples from a previously failed run")
parser.add_argument('--unlock', action='store_true', help="Snakemake parameter. Remove a lock on the working directory after a failed run")
parser.add_argument('-F', '--forceall', action='store_true', help='Snakemake parameter. Force the re-run of all rules regardless of prior output')
parser.add_argument('-n', '--dry-run', action='store_true', help='Snakemake parameter. Do not execute anything and only display what would be done')
parser.add_argument('--verbose', action='store_true', help="Snakemake parameter. Display snakemake debugging output")
parser.add_argument('-v', '--version', action='store_true', help="Display version number")
args, unknown = parser.parse_known_args()

provided = []
Expand Down Expand Up @@ -232,7 +238,12 @@ def write_config_file(run_name, config_file, opt_tasks):
# note: add root_dir to determine the root directory of SIGNAL
script_path = os.path.join(os.path.abspath(sys.argv[0]).rsplit("/",1)[0])
args, allowed = create_parser()

version = 'v1.5.8'
alt_options = []

if args.version:
exit(f"{version}")

if args.dependencies:
print("Downloading necessary reference and dependency files!")
download_dependences()
Expand All @@ -256,17 +267,25 @@ def write_config_file(run_name, config_file, opt_tasks):
if not any([allowed[x] for x in allowed]):
exit("No task specified! Please provide at least one of 'all', 'postprocess', or 'ncov_tools'! See 'signal.py -h' for details!")
else:
if args.verbose: alt_options.append('--verbose')
if args.unlock: alt_options.append('--unlock')
if args.forceall: alt_options.append('--forceall')
if args.dry_run: alt_options.append('--dry-run')
if args.rerun_incomplete: alt_options.append('--rerun-incomplete')
opt = " ".join(alt_options)
for task in allowed:
if allowed[task] is True:
print(f"Running SIGNAL {task}!")
try:
subprocess.run(f"snakemake --conda-frontend mamba --configfile {config_file} --cores={args.cores} --use-conda --conda-prefix=$PWD/.snakemake/conda {task} -kp", shell=True, check=True)
subprocess.run(f"snakemake --conda-frontend mamba --configfile {config_file} --cores={args.cores} --use-conda --conda-prefix=$PWD/.snakemake/conda {task} -kp {opt}", shell=True, check=True)
except subprocess.CalledProcessError: # likely missing mamba
if task == "ncov_tools":
check_submodule(os.getcwd())
if opt.split(" ")[-1] == '--rerun-incomplete': # remove redundant flag
opt = " ".join(opt.split(" ")[:-1])
try:
print("Retrying...")
subprocess.run(f"snakemake --conda-frontend conda --configfile {config_file} --cores={args.cores} --use-conda --conda-prefix=$PWD/.snakemake/conda {task} -kp --rerun-incomplete", shell=True, check=True)
subprocess.run(f"snakemake --conda-frontend conda --configfile {config_file} --cores={args.cores} --use-conda --conda-prefix=$PWD/.snakemake/conda {task} -kp --rerun-incomplete {opt}", shell=True, check=True)
except subprocess.CalledProcessError:
exit(f"Something went wrong running SIGNAL {task}! Check input and try again!")

Expand Down

0 comments on commit 98c9631

Please sign in to comment.