-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #2 from CLIMB-COVID/development
0.2.0
- Loading branch information
Showing
7 changed files
with
96 additions
and
78 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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 |
---|---|---|
|
@@ -5,4 +5,3 @@ | |
# __all__ = maptide.__all__ | ||
|
||
from .api import query, parse_region | ||
del api |
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 |
---|---|---|
@@ -1,42 +1,55 @@ | ||
from .maptide import all_, query_, parse_region_ | ||
from typing import Optional | ||
import os | ||
from typing import Dict, Tuple, List | ||
from . import maptide # type: ignore | ||
|
||
|
||
def query( | ||
bam: str, | ||
region: Optional[str] = None, | ||
bai: Optional[str] = None, | ||
region: str | None = None, | ||
bai: str | None = None, | ||
mapping_quality: int = 0, | ||
base_quality: int = 0, | ||
indexed=True, | ||
): | ||
"""Obtain base frequencies from the provided BAM file. | ||
Required arguments: | ||
`bam`: Path to the BAM file. | ||
Optional arguments: | ||
`region` | ||
`bai` | ||
`mapping_quality` | ||
`base_quality` | ||
`indexed` | ||
Returns: | ||
A `dict` mapping tuples of the form `(int, int)` to base frequencies. | ||
""" | ||
) -> Dict[str, Dict[Tuple[int, int], List[int]]]: | ||
"""Performs a pileup over a region, obtaining per-position base frequencies for the provided BAM file. | ||
Parameters | ||
---------- | ||
bam : str | ||
Path to the BAM file. | ||
region : str, optional | ||
Region to query, in the form `CHROM:START-END` (default: all positions) | ||
bai : str, optional | ||
Path to index file (default: same path as the BAM file, but with .bai appended) | ||
mapping_quality : int, optional | ||
Minimum mapping quality for a read to be included in the pileup (default: 0) | ||
base_quality : int, optional | ||
Minimum base quality for a base within a read to be included in the pileup (default: 0) | ||
if not indexed and bai: | ||
raise Exception("Cannot set indexed=False while also providing a BAI file") | ||
Returns | ||
------- | ||
dict | ||
Mapping: reference -> (reference position, insert position) -> [base frequencies]. | ||
""" | ||
|
||
if region: | ||
if indexed: | ||
if not bai: | ||
bai = bam + ".bai" | ||
return query_(bam, bai, region, mapping_quality, base_quality) | ||
else: | ||
return query_(bam, None, region, mapping_quality, base_quality) | ||
if not bai and os.path.isfile(bam + ".bai"): | ||
bai = bam + ".bai" | ||
return maptide.query(bam, bai, region, mapping_quality, base_quality) | ||
else: | ||
return all_(bam, mapping_quality, base_quality) | ||
return maptide.all(bam, mapping_quality, base_quality) | ||
|
||
|
||
def parse_region(region: str): | ||
return parse_region_(region) | ||
def parse_region(region: str) -> Tuple[str, int, int]: | ||
"""Parses a region of the form `CHROM:START-END`, returning the tuple `(CHROM, START, END)`. | ||
Parameters | ||
---------- | ||
region : str | ||
Region to parse. | ||
Returns | ||
------- | ||
tuple | ||
Parsed region tuple. | ||
""" | ||
return maptide.parse_region(region) |
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