-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'template_0924' into 'dev'
Template update See merge request epi2melabs/workflows/wf-cas9!56
- Loading branch information
Showing
17 changed files
with
1,110 additions
and
196 deletions.
There are no files selected for viewing
This file contains 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 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 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 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 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 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 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 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 |
---|---|---|
@@ -0,0 +1,43 @@ | ||
"""Validate a single (u)BAM file index.""" | ||
|
||
from pathlib import Path | ||
import sys | ||
|
||
import pysam | ||
|
||
from .util import get_named_logger, wf_parser # noqa: ABS101 | ||
|
||
|
||
def validate_xam_index(xam_file): | ||
"""Use fetch to validate the index. | ||
Invalid indexes will fail the call with a ValueError: | ||
ValueError: fetch called on bamfile without index | ||
""" | ||
with pysam.AlignmentFile(xam_file, check_sq=False) as alignments: | ||
try: | ||
alignments.fetch() | ||
has_valid_index = True | ||
except ValueError: | ||
has_valid_index = False | ||
return has_valid_index | ||
|
||
|
||
def main(args): | ||
"""Run the entry point.""" | ||
logger = get_named_logger("checkBamIdx") | ||
|
||
# Check if a XAM has a valid index | ||
has_valid_index = validate_xam_index(args.input_xam) | ||
# write `has_valid_index` out so that they can be set as env. | ||
sys.stdout.write( | ||
f"HAS_VALID_INDEX={int(has_valid_index)}" | ||
) | ||
logger.info(f"Checked (u)BAM index for: '{args.input_xam}'.") | ||
|
||
|
||
def argparser(): | ||
"""Argument parser for entrypoint.""" | ||
parser = wf_parser("check_xam_index") | ||
parser.add_argument("input_xam", type=Path, help="Path to target XAM") | ||
return parser |
Oops, something went wrong.