Skip to content
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

0.9.5 #7

Merged
merged 11 commits into from
Nov 17, 2023
8 changes: 5 additions & 3 deletions src/seismicrna/mask/batch.py
Original file line number Diff line number Diff line change
@@ -27,17 +27,19 @@ class MaskMutsBatch(MaskReadBatch, RefseqMutsBatch, PartialMutsBatch, ABC):
def apply_mask(batch: RefseqMutsBatch,
reads: Iterable[int] | None = None,
positions: Iterable[int] | None = None):
# Determine masked read numbers.
masked_reads = np.setdiff1d(batch.read_nums, reads)
# Clean and validate the selection.
if positions is not None:
positions = sanitize_pos(positions, batch.max_pos)
# Select mutations at each position.
muts = dict()
for pos in positions if positions is not None else batch.pos_nums:
muts[pos] = dict()
# Select reads with each type of mutation at this position.
# Remove masked reads with each type of mutation at this position.
for mut, pos_mut_reads in batch.muts.get(pos, dict()).items():
muts[pos][mut] = (np.intersect1d(pos_mut_reads,
reads,
muts[pos][mut] = (np.setdiff1d(pos_mut_reads,
masked_reads,
assume_unique=True)
if reads is not None
else pos_mut_reads)