-
Notifications
You must be signed in to change notification settings - Fork 203
fix: resolve 'Couldn't locate file' error with input BAM with extra delimiters #4682
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
andrewgull
wants to merge
15
commits into
snakemake:master
Choose a base branch
from
andrewgull:fix_cnvkit_batch
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from 13 commits
Commits
Show all changes
15 commits
Select commit
Hold shift + click to select a range
43c2535
fix: resolve 'Couldn't locate file' error with tagged BAMs
andrewgull 03a9f48
fix: add a check for length mismatch between temp_files and destinati…
andrewgull 63b1598
fix: robust way of matching temp and snakemake output files
andrewgull 3e0ec51
style: add a comma to the last element in file_map
andrewgull 160a1e5
style: format with black
andrewgull 756f490
Merge branch 'master' into fix_cnvkit_batch
andrewgull 7840ec2
fix: upate file matching approach
andrewgull b3c43e2
feat: check that output file is not None before constructing source-d…
andrewgull 7ba9956
feat: use move_files
andrewgull 96adaf3
refactor: add logging of stdout and append=True
andrewgull 61fe501
build: add snakemake-wrapper-utils to conda env description
andrewgull 067f845
build: add snakemake-wrapper-utils url to the pin file
andrewgull 462b5e1
Merge branch 'master' into fix_cnvkit_batch
andrewgull 3559e15
fix: update bio/cnvkit/batch/wrapper.py
andrewgull e45499e
Merge branch 'master' into fix_cnvkit_batch
andrewgull File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Some comments aren't visible on the classic Files Changed page.
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -4,3 +4,4 @@ channels: | |
| - nodefaults | ||
| dependencies: | ||
| - cnvkit =0.9.12 | ||
| - snakemake-wrapper-utils =0.8.0 | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -3,16 +3,14 @@ | |
| __email__ = "[email protected]" | ||
| __license__ = "MIT" | ||
|
|
||
| import logging | ||
| from os import listdir | ||
| from os.path import basename | ||
| from os.path import dirname | ||
| from os.path import join | ||
| from tempfile import TemporaryDirectory | ||
| import shutil | ||
| from snakemake.shell import shell | ||
| from snakemake_wrapper_utils.snakemake import move_files | ||
|
|
||
| log = snakemake.log_fmt_shell(stdout=False, stderr=True) | ||
|
|
||
| log = snakemake.log_fmt_shell(stdout=True, stderr=True, append=True) | ||
|
|
||
| input_bam_files = f"{snakemake.input.bam}" | ||
|
|
||
|
|
@@ -50,9 +48,7 @@ | |
| with TemporaryDirectory() as tmpdirname: | ||
| if create_reference: | ||
| output = f"--output-reference {join(tmpdirname, 'reference.cnn')}" | ||
| output_list = [snakemake.output.reference] | ||
| else: | ||
| output_list = [value for key, value in snakemake.output.items()] | ||
| output = f"-d {tmpdirname} " | ||
| shell( | ||
| "(cnvkit.py batch {input_bam_files} " | ||
|
|
@@ -65,15 +61,33 @@ | |
| "{extra}) {log}" | ||
| ) | ||
|
|
||
| for output_file in output_list: | ||
| filename = basename(output_file) | ||
| parent = dirname(output_file) | ||
|
|
||
| try: | ||
| shutil.copy2(join(tmpdirname, filename), output_file) | ||
| except FileNotFoundError as e: | ||
| temp_files = listdir(tmpdirname) | ||
| logging.error( | ||
| f"Couldn't locate file {basename} possible files are {[basename(f) for f in temp_files]}" | ||
| ) | ||
| raise e | ||
| # actual generated files | ||
| temp_files = listdir(tmpdirname) | ||
|
|
||
| # mapping of file suffixes to snakemake.output attributes | ||
| file_map = { | ||
| "antitargetcoverage.cnn": "antitarget_coverage", | ||
| "bintest.cns": "bins", | ||
| ".cnr": "regions", | ||
| "call.cns": "segments_called", | ||
| "targetcoverage.cnn": "target_coverage", | ||
| ".cns": "segments", | ||
| "reference.cnn": "reference", | ||
| } | ||
|
|
||
| mapping = {} | ||
|
|
||
| # find matches btw generated files and snakemake output | ||
| for file in temp_files: | ||
| for suffix, attr in file_map.items(): | ||
| if file.endswith(suffix): | ||
| # Skip ambiguous matches | ||
| if attr == "segments" and any( | ||
| x in file for x in ["call.cns", "bintest.cns"] | ||
| ): | ||
| continue | ||
fgvieira marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| mapping[attr] = join(tmpdirname, file) | ||
| break # stop after first match | ||
andrewgull marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
|
|
||
| for file in move_files(snakemake, mapping): | ||
| shell("{file} {log}") | ||
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.