Skip to content

Commit

Permalink
Add read_sam in sam_handler module
Browse files Browse the repository at this point in the history
  • Loading branch information
akikuno committed Mar 25, 2024
1 parent d00bea8 commit b37b375
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 2 deletions.
4 changes: 2 additions & 2 deletions src/DAJIN2/core/preprocess/midsv_caller.py
Original file line number Diff line number Diff line change
Expand Up @@ -215,8 +215,8 @@ def generate_midsv(ARGS, is_control: bool = False, is_insertion: bool = False) -
path_splice = Path(ARGS.tempdir, name, "sam", f"splice_{allele}.sam")
path_output_midsv = Path(ARGS.tempdir, name, "midsv", f"{allele}.json")

sam_ont = sam_handler.remove_overlapped_reads(list(midsv.read_sam(path_ont)))
sam_splice = sam_handler.remove_overlapped_reads(list(midsv.read_sam(path_splice)))
sam_ont = sam_handler.remove_overlapped_reads(list(sam_handler.read_sam(path_ont)))
sam_splice = sam_handler.remove_overlapped_reads(list(sam_handler.read_sam(path_splice)))
qname_of_map_ont = extract_qname_of_map_ont(sam_ont, sam_splice)
sam_of_map_ont = filter_sam_by_preset(sam_ont, qname_of_map_ont, preset="map-ont")
sam_of_splice = filter_sam_by_preset(sam_splice, qname_of_map_ont, preset="splice")
Expand Down
14 changes: 14 additions & 0 deletions src/DAJIN2/utils/sam_handler.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
from __future__ import annotations

import re

from pathlib import Path
from typing import Generator
from itertools import groupby
from DAJIN2.utils.dna_handler import revcomp

Expand All @@ -22,6 +25,17 @@ def is_mapped(s: list[str]) -> bool:
return not s[0].startswith("@") and s[9] != "*"


###########################################################
# Read sam
###########################################################


def read_sam(path_of_sam: str | Path) -> Generator[list]:
with open(path_of_sam) as f:
for line in f:
yield line.strip().split("\t")


###########################################################
# remove_overlapped_reads
###########################################################
Expand Down

0 comments on commit b37b375

Please sign in to comment.