Skip to content

Commit

Permalink
Bug fix: paths in build
Browse files Browse the repository at this point in the history
  • Loading branch information
bricoletc committed Dec 18, 2019
1 parent cf5cc20 commit b95321b
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 25 deletions.
42 changes: 17 additions & 25 deletions gramtools/paths.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,11 +33,9 @@ def gram_path(file_name):
def generate_build_paths(args):
paths = _generate_project_paths(args.gram_dir)

## Run checks before making gram dir ##
if args.reference is not None:
_check_exists(args.reference)
if os.path.lexists(paths["original_reference"]):
os.unlink(paths["original_reference"])
os.symlink(os.path.abspath(args.reference), paths["original_reference"])

if args.vcf is not None:
vcf_files = [
Expand All @@ -58,6 +56,11 @@ def generate_build_paths(args):
os.mkdir(paths["gram_dir"])
log.debug("Creating gram directory:\n%s", paths["gram_dir"])

# Must run after gram_dir is guaranteed to exist
if args.reference is not None:
if os.path.lexists(paths["original_reference"]):
os.unlink(paths["original_reference"])
os.symlink(os.path.abspath(args.reference), paths["original_reference"])
return paths


Expand Down Expand Up @@ -130,18 +133,11 @@ def generate_quasimap_paths(args):

if not os.path.exists(all_paths["run_dir"]):
os.mkdir(all_paths["run_dir"])
else:
log.warning(
"Directory {} already exists. Existing files and directories with conflicting names"
"(eg: 'reads', 'quasimap_outputs', 'build_dir') will be overriden.".format(
all_paths["run_dir"]
)
)

if not os.path.exists(all_paths["quasimap_dir"]):
os.mkdir(all_paths["quasimap_dir"])

# Make a reference to the gram_dir made in build. This will avoid downstream commands
# Make a reference to the gram_dir made in build. This avoids downstream commands
# to require a --gram_dir argument.
if os.path.lexists(all_paths["build_dir"]):
os.unlink(all_paths["build_dir"])
Expand Down Expand Up @@ -209,19 +205,15 @@ def generate_discover_paths(args):
os.mkdir(all_paths["discover_dir"])

#  Check `infer` files are present
if not os.path.exists(all_paths["inferred_fasta"]):
log.error(
"Cannot find fasta formatted inferred personalised reference, at {}".format(
all_paths["inferred_fasta"]
)
)
_check_exists(
all_paths["inferred_fasta"],
file_description="Fasta formatted inferred personalised reference",
)

if not os.path.exists(all_paths["inferred_vcf"]):
log.error(
"Cannot find vcf formatted inferred personalised reference, at {}".format(
all_paths["inferred_fasta"]
)
)
_check_exists(
all_paths["inferred_vcf"],
file_description="Vcf formatted inferred personalised reference",
)

#  Build read file paths by scanning the reads_directory, and following symlinks.
if args.reads is None:
Expand All @@ -237,8 +229,8 @@ def generate_discover_paths(args):
return all_paths


def _check_exists(fname):
def _check_exists(fname, file_description="File"):
if not os.path.isfile(fname):
error_message = f"File required but not found: {fname}"
error_message = f"{file_description} required but not found: {fname}"
log.error(error_message)
exit(1)
3 changes: 3 additions & 0 deletions gramtools/tests/integration_tests/test_one_bqid_cycle.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
"""
b/q/i/d : build/quasimap/infer/discover
"""

0 comments on commit b95321b

Please sign in to comment.