Skip to content

Commit 2bdc216

Browse files
committed
Patch: check and require dependencies for each sub command.
1 parent e6b5ff0 commit 2bdc216

File tree

1 file changed

+47
-5
lines changed

1 file changed

+47
-5
lines changed

rna-seek

+47-5
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ import argparse # potential python3 3rd party package, added in python/3.5
2121

2222
# Pipeline Metadata and globals
2323
__author__ = 'Skyler Kuhn'
24-
__version__ = 'v1.9.4'
24+
__version__ = 'v1.9.5'
2525
__email__ = '[email protected]'
2626
__home__ = os.path.dirname(os.path.abspath(__file__))
2727
_name = os.path.basename(sys.argv[0])
@@ -122,6 +122,34 @@ def exe_in_path(cmd, path=None):
122122
return False
123123

124124

125+
def require(cmds, suggestions, path=None):
126+
"""Enforces an executable is in $PATH
127+
@param cmds list[<str>]:
128+
List of executable names to check
129+
@param suggestions list[<str>]:
130+
Name of module to suggest loading for a given index
131+
in param cmd.
132+
@param path list[<str>]]:
133+
Optional list of PATHs to check [default: $PATH]
134+
@return None
135+
"""
136+
error = False
137+
138+
for i in range(len(cmds)):
139+
available = exe_in_path(cmds[i])
140+
if not available:
141+
c = Colors
142+
error = True
143+
err(
144+
"\n{0}{1}Fatal: {2} is not in $PATH and is required during runtime!{3}".format(c.bg_red, c.white, cmds[i], c.end),
145+
"\n └── Possible solution: please 'module load {0}' and run again!".format(suggestions[i])
146+
)
147+
148+
if error: fatal()
149+
150+
return
151+
152+
125153
def permissions(parser, filename, *args, **kwargs):
126154
"""Checks permissions using os.access() to see the user is authorized to access
127155
a file/directory. Checks for existence, readability, writability and executability via:
@@ -653,7 +681,6 @@ def dryrun(outdir, config='config.json', snakefile=os.path.join('workflow', 'Sna
653681
'--configfile={}'.format(config)
654682
], cwd = outdir,
655683
stderr=subprocess.STDOUT)
656-
657684
except subprocess.CalledProcessError as e:
658685
# Singularity is NOT in $PATH
659686
# Tell user to load both main dependencies to avoid the OSError below
@@ -841,6 +868,11 @@ def run(sub_args):
841868
@param sub_args <parser.parse_args() object>:
842869
Parsed arguments for run sub-command
843870
"""
871+
# Check for required dependencies
872+
# The pipelines has only two requirements:
873+
# snakemake and singularity
874+
require(['snakemake', 'singularity'], ['snakemake', 'singularity'])
875+
844876
# Get PATH to RNA-seek git repository for copying over pipeline resources
845877
git_repo = os.path.dirname(os.path.abspath(__file__))
846878

@@ -911,6 +943,9 @@ def unlock(sub_args):
911943
print("Unlocking the pipeline's output directory...")
912944
outdir = sub_args.output
913945

946+
# Check for required dependencies: snakemake
947+
require(['snakemake'], ['snakemake'])
948+
914949
try:
915950
unlock_output = subprocess.check_output([
916951
'snakemake', '--unlock',
@@ -1037,8 +1072,13 @@ def build(sub_args):
10371072
"""Builds the reference files for the RNA-seek pipeline from a genomic FASTA
10381073
file and a GTF file. Disclaimer: hybrid genomes not supported.
10391074
@param sub_args <parser.parse_args() object>:
1040-
Parsed arguments for unlock sub-command
1075+
Parsed arguments for build sub-command
10411076
"""
1077+
# Check for required dependencies
1078+
# The pipelines has only two requirements:
1079+
# snakemake and singularity
1080+
require(['snakemake', 'singularity'], ['snakemake', 'singularity'])
1081+
10421082
# Get PATH to RNA-seek git repository
10431083
# for copying over pipeline resources
10441084
git_repo = os.path.dirname(os.path.abspath(__file__))
@@ -1115,14 +1155,16 @@ def cache(sub_args):
11151155
Local SIFs will be created from images defined in 'config/containers/images.json'.
11161156
@TODO: add option to cache other shared S3 resources (i.e. kraken db and fqscreen indices)
11171157
@param sub_args <parser.parse_args() object>:
1118-
Parsed arguments for unlock sub-command
1158+
Parsed arguments for cache sub-command
11191159
"""
1160+
# Check for required dependencies: singularity
1161+
require(['singularity'], ['singularity'])
1162+
11201163
sif_cache = sub_args.sif_cache
11211164
# Get absolute PATH to templates in rna-seek git repo
11221165
repo_path = os.path.dirname(os.path.abspath(__file__))
11231166
images = os.path.join(repo_path, 'config','containers', 'images.json')
11241167

1125-
11261168
# Create image cache
11271169
if not exists(sif_cache):
11281170
# Pipeline output directory does not exist on filesystem

0 commit comments

Comments
 (0)