Skip to content

Commit

Permalink
Fix mypy warning + check counting and mapping types
Browse files Browse the repository at this point in the history
  • Loading branch information
fplazaonate committed Apr 2, 2024
1 parent 9405cdc commit 16c34ae
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 7 deletions.
5 changes: 5 additions & 0 deletions meteor/counter.py
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,9 @@ class Counter(Session):
json_data: dict = field(default_factory=dict)

def __post_init__(self) -> None:
if self.counting_type not in Counter.COUNTING_TYPES:
raise ValueError(f'{self.counting_type} is not a valid counting type')

if self.meteor.tmp_path:
self.meteor.tmp_path.mkdir(exist_ok=True)
self.meteor.tmp_dir = Path(mkdtemp(dir=self.meteor.tmp_path))
Expand Down Expand Up @@ -133,6 +136,8 @@ def filter_alignments(
# contains a list of alignment of each read
reads: dict[str, list[AlignedSegment]] = {}
for element in cramdesc:
assert element.query_name is not None and element.reference_name is not None

# identity = (element.query_length - element.get_tag("NM")) / element.query_length
# identity = 1.0 - (element.get_tag("NM") / element.query_alignment_length)
ali = sum(self.get_aligned_nucleotides(element))
Expand Down
7 changes: 6 additions & 1 deletion meteor/mapper.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ class Mapper(Session):
"""Run the bowtie"""

DEFAULT_NUM_THREADS : ClassVar[int] = 1
MAPPING_TYPES: ClassVar[list[str]] = ['end_to_end', 'local']
MAPPING_TYPES: ClassVar[list[str]] = ['end-to-end', 'local']
DEFAULT_MAPPING_TYPE: ClassVar[str] = 'end-to-end'
DEFAULT_TRIM: ClassVar[int] = 80
NO_TRIM: ClassVar[int] = 0
Expand All @@ -48,6 +48,10 @@ class Mapper(Session):
counting_type: str
identity_threshold: float

def __post_init__(self) -> None:
if self.mapping_type not in Mapper.MAPPING_TYPES:
raise ValueError(f'{self.mapping_type} is not a valid mapping type')

def set_mapping_config(
self,
cram_file: Path,
Expand Down Expand Up @@ -147,6 +151,7 @@ def execute(self) -> None:
stderr=PIPE,
)
# cramfile_unsorted = Path(mkstemp(dir=self.meteor.tmp_dir)[1])
assert mapping_exec.stdout is not None and mapping_exec.stderr is not None
with pysam.AlignmentFile(
mapping_exec.stdout,
"r",
Expand Down
4 changes: 2 additions & 2 deletions meteor/merging.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
import logging
import sys
import numpy as np
from biom.table import Table
from biom.table import Table # type: ignore
from typing import ClassVar


Expand Down Expand Up @@ -348,7 +348,7 @@ def execute(self) -> None:
/ ref_json["annotation"]["taxonomy"]["filename"],
sep="\t",
header=0,
usecols=self.ranks.keys(),
usecols=list(self.ranks.keys()),
)

annotation = annotation[
Expand Down
8 changes: 4 additions & 4 deletions meteor/meteor.py
Original file line number Diff line number Diff line change
Expand Up @@ -782,8 +782,8 @@ def main() -> None: # pragma: no cover
args.min_msp_abundance,
args.min_msp_occurrence,
args.remove_sample_with_no_msp,
None,
None,
False,
"a",
#args.output_mpa,
#args.taxonomic_level,
args.output_biom,
Expand All @@ -806,10 +806,10 @@ def main() -> None: # pragma: no cover
fastq_importer.execute()
meteor.fastq_dir = Path(tmpdirname) / "test"
meteor.ref_dir = meteor.ref_dir / "mock"
counter = Counter(meteor, "best", "end-to-end", 80, 0.97, 100, False, True)
counter = Counter(meteor, "total", "end-to-end", 80, 0.97, 100, False, True)
counter.execute()
meteor.fastq_dir = Path(tmpdirname) / "test2"
counter = Counter(meteor, "best", "end-to-end", 80, 0.97, 100, False, True)
counter = Counter(meteor, "total", "end-to-end", 80, 0.97, 100, False, True)
counter.execute()
# Remove the mapping directory and its contents
shutil.rmtree(Path(tmpdirname) / "test")
Expand Down

0 comments on commit 16c34ae

Please sign in to comment.