Skip to content

Commit

Permalink
+ Standardize to use dataclass instead of NamedTuple.
Browse files Browse the repository at this point in the history
  • Loading branch information
akikuno committed Mar 25, 2024
1 parent 4c6fa03 commit b7c34fb
Show file tree
Hide file tree
Showing 4 changed files with 10 additions and 31 deletions.
5 changes: 3 additions & 2 deletions src/DAJIN2/core/consensus/consensus.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
from __future__ import annotations

from pathlib import Path
from typing import NamedTuple
from dataclasses import dataclass
from itertools import groupby
from collections import defaultdict

Expand Down Expand Up @@ -90,7 +90,8 @@ def call_percentage(cssplits: list[list[str]], mutation_loci: list[set[str]]) ->
###########################################################


class ConsensusKey(NamedTuple):
@dataclass(frozen=True)
class ConsensusKey:
allele: str
label: int
percent: float
Expand Down
8 changes: 1 addition & 7 deletions src/DAJIN2/core/consensus/name_handler.py
Original file line number Diff line number Diff line change
@@ -1,13 +1,7 @@
from __future__ import annotations

import re
from typing import NamedTuple


class ConsensusKey(NamedTuple):
allele: str
label: int
percent: float
from DAJIN2.core.consensus.consensus import ConsensusKey


def _detect_sv(cons_percentages: dict[ConsensusKey, list], threshold: int = 50) -> list[bool]:
Expand Down
15 changes: 1 addition & 14 deletions src/DAJIN2/core/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,27 +4,14 @@
import logging

from pathlib import Path
from typing import NamedTuple

from DAJIN2.utils import io, fastx_handler
from DAJIN2.core import classification, clustering, consensus, preprocess, report
from DAJIN2.core.preprocess.input_formatter import FormattedInputs

logger = logging.getLogger(__name__)


class FormattedInputs(NamedTuple):
path_sample: str
path_control: str
path_allele: str
sample_name: str
control_name: str
fasta_alleles: dict[str, str]
tempdir: Path
genome_coordinates: dict[str, str]
threads: int
uuid: str


###########################################################
# main
###########################################################
Expand Down
13 changes: 5 additions & 8 deletions src/DAJIN2/core/preprocess/input_formatter.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
import uuid

from pathlib import Path
from typing import NamedTuple
from dataclasses import dataclass
from collections import defaultdict

from DAJIN2.utils import io, config, fastx_handler
Expand Down Expand Up @@ -64,18 +64,15 @@ def get_genome_coordinates(genome_urls: dict, fasta_alleles: dict, is_cache_geno
if is_cache_genome:
genome_coordinates = next(io.read_jsonl(Path(tempdir, "cache", "genome_coordinates.jsonl")))
else:
genome_coordinates = preprocess.fetch_coordinates(
genome_coordinates, genome_urls, fasta_alleles["control"]
)
genome_coordinates["chrom_size"] = preprocess.fetch_chromosome_size(
genome_coordinates, genome_urls
)
genome_coordinates = preprocess.fetch_coordinates(genome_coordinates, genome_urls, fasta_alleles["control"])
genome_coordinates["chrom_size"] = preprocess.fetch_chromosome_size(genome_coordinates, genome_urls)
io.write_jsonl([genome_coordinates], Path(tempdir, "cache", "genome_coordinates.jsonl"))

return genome_coordinates


class FormattedInputs(NamedTuple):
@dataclass(frozen=True)
class FormattedInputs:
path_sample: str
path_control: str
path_allele: str
Expand Down

0 comments on commit b7c34fb

Please sign in to comment.