Skip to content

Commit 670b39f

Browse files
committed
Annotated bases flag on api.query
1 parent 38c1f06 commit 670b39f

File tree

4 files changed

+22
-20
lines changed

4 files changed

+22
-20
lines changed

Cargo.lock

+1-1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[package]
22
name = "maptide"
3-
version = "0.2.1"
3+
version = "0.3.0"
44
edition = "2021"
55

66
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html

python/maptide/api.py

+17-4
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,19 @@
11
import os
2-
from typing import Dict, Tuple, List, Optional
2+
from typing import Dict, Tuple, Optional, Any
33
from . import maptide #  type: ignore
44

55

6+
BASES = ["A", "C", "G", "T", "DS", "N"]
7+
8+
69
def query(
710
bam: str,
811
region: Optional[str] = None,
912
bai: Optional[str] = None,
1013
mapping_quality: int = 0,
1114
base_quality: int = 0,
12-
) -> Dict[str, Dict[Tuple[int, int], List[int]]]:
15+
annotated: bool = False,
16+
) -> Dict[str, Dict[Tuple[int, int], Any]]:
1317
"""Performs a pileup over a region, obtaining per-position base frequencies for the provided BAM file.
1418
1519
Parameters
@@ -24,6 +28,8 @@ def query(
2428
Minimum mapping quality for a read to be included in the pileup (default: 0)
2529
base_quality : int, optional
2630
Minimum base quality for a base within a read to be included in the pileup (default: 0)
31+
annotated : bool, optional
32+
Return frequencies annotated with their bases, as a `dict[str, int]`. Default is to return frequencies only, as a `list[int]` (default: False)
2733
2834
Returns
2935
-------
@@ -34,9 +40,16 @@ def query(
3440
if region:
3541
if not bai and os.path.isfile(bam + ".bai"):
3642
bai = bam + ".bai"
37-
return maptide.query(bam, bai, region, mapping_quality, base_quality)
43+
data = maptide.query(bam, bai, region, mapping_quality, base_quality)
3844
else:
39-
return maptide.all(bam, mapping_quality, base_quality)
45+
data = maptide.all(bam, mapping_quality, base_quality)
46+
47+
if annotated:
48+
for _, positions in data.items():
49+
for position, frequencies in positions.items():
50+
positions[position] = dict(zip(BASES, frequencies))
51+
52+
return data
4053

4154

4255
def parse_region(region: str) -> Tuple[str, int, int]:

python/maptide/cli.py

+3-14
Original file line numberDiff line numberDiff line change
@@ -108,23 +108,12 @@ def run():
108108
"pos",
109109
"ins",
110110
"cov",
111-
"a",
112-
"c",
113-
"g",
114-
"t",
115-
"ds",
116-
"n",
117-
]
111+
] + [base.lower() for base in api.BASES]
118112

119113
if args.stats:
120114
columns.extend(
121-
[
122-
"pc_a",
123-
"pc_c",
124-
"pc_g",
125-
"pc_t",
126-
"pc_ds",
127-
"pc_n",
115+
[f"pc_{base.lower()}" for base in api.BASES]
116+
+ [
128117
"entropy",
129118
"secondary_entropy",
130119
]

0 commit comments

Comments
 (0)