Skip to content

Commit

Permalink
rewrote faidx function to be more efficient in dicitonary access
Browse files Browse the repository at this point in the history
  • Loading branch information
JLSteenwyk committed Sep 12, 2024
1 parent 2bb20e1 commit d349cbc
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 7 deletions.
14 changes: 9 additions & 5 deletions phykit/services/alignment/faidx.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
from typing import Dict

from Bio import SeqIO

from .base import Alignment
Expand All @@ -7,11 +9,13 @@ class Faidx(Alignment):
def __init__(self, args) -> None:
super().__init__(**self.process_args(args))

def run(self):
def run(self) -> None:
record_dict = SeqIO.index(self.fasta, "fasta")
entry = self.entry.split(',')
for e in entry:
print(f">{record_dict[e].name}\n{record_dict[e].seq}")

def process_args(self, args):
# Split entries and iterate
for e in map(str.strip, self.entry.split(',')):
record = record_dict[e]
print(f">{record.name}\n{record.seq}")

def process_args(self, args) -> Dict[str, str]:
return dict(fasta=args.fasta, entry=args.entry)
3 changes: 1 addition & 2 deletions tests/integration/alignment/test_faidx.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,14 @@
import sys
from mock import patch, call
from pathlib import Path
from textwrap import dedent

from phykit.phykit import Phykit

here = Path(__file__)


@pytest.mark.integration
class TestGCContent(object):
class TestFaidx(object):
@patch("builtins.print")
def test_faidx(self, mocked_print):
expected_result = ">1\nA-GTAT"
Expand Down

0 comments on commit d349cbc

Please sign in to comment.