Skip to content

Commit 4b3b41b

Browse files
committed
faidx function can now search for multiple sequences in one execution
1 parent eefd5d3 commit 4b3b41b

File tree

5 files changed

+35
-5
lines changed

5 files changed

+35
-5
lines changed

docs/usage/index.rst

+6-1
Original file line numberDiff line numberDiff line change
@@ -377,7 +377,12 @@ Command line interface: pk_faidx; pk_get_entry; pk_ge
377377
Extracts sequence entry from fasta file.
378378

379379
This function works similarly to the faidx function
380-
in samtools, but does not requiring an indexing function.
380+
in samtools, but does not requiring an indexing step.
381+
382+
To obtain multiple entries, input multiple entries separated
383+
by a comma (,). For example, if you want entries
384+
named "seq_0" and "seq_1", the string "seq_0,seq_1"
385+
should be associated with the -e argument.
381386

382387
.. code-block:: shell
383388

phykit/phykit.py

+6-1
Original file line numberDiff line numberDiff line change
@@ -738,7 +738,12 @@ def faidx(argv):
738738
Extracts sequence entry from fasta file.
739739
740740
This function works similarly to the faidx function
741-
in samtools, but does not requiring an indexing function.
741+
in samtools, but does not requiring an indexing step.
742+
743+
To obtain multiple entries, input multiple entries separated
744+
by a comma (,). For example, if you want entries
745+
named "seq_0" and "seq_1", the string "seq_0,seq_1"
746+
should be associated with the -e argument.
742747
743748
Aliases:
744749
faidx, get_entry; ge

phykit/services/alignment/faidx.py

+3-1
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,9 @@ def __init__(self, args) -> None:
99

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

1416
def process_args(self, args):
1517
return dict(fasta=args.fasta, entry=args.entry)

phykit/version.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
__version__ = "1.19.7"
1+
__version__ = "1.19.8"

tests/integration/alignment/test_faidx.py

+19-1
Original file line numberDiff line numberDiff line change
@@ -65,4 +65,22 @@ def test_faidx_alias1(self, mocked_print):
6565
]
6666
with patch.object(sys, "argv", testargs):
6767
Phykit()
68-
assert mocked_print.mock_calls == [call(expected_result)]
68+
assert mocked_print.mock_calls == [call(expected_result)]
69+
70+
@patch("builtins.print")
71+
def test_faidx_multiple_entries(self, mocked_print):
72+
expected_result0 = ">1\nA-GTAT"
73+
expected_result1 = ">2\nA-G-AT"
74+
testargs = [
75+
"phykit",
76+
"faidx",
77+
f"{here.parent.parent.parent}/sample_files/simple.fa",
78+
'-e',
79+
'1,2'
80+
]
81+
with patch.object(sys, "argv", testargs):
82+
Phykit()
83+
assert mocked_print.mock_calls == [
84+
call(expected_result0),
85+
call(expected_result1)
86+
]

0 commit comments

Comments
 (0)