Skip to content

Commit

Permalink
faidx function can now search for multiple sequences in one execution
Browse files Browse the repository at this point in the history
  • Loading branch information
JLSteenwyk committed Jun 17, 2024
1 parent eefd5d3 commit 4b3b41b
Show file tree
Hide file tree
Showing 5 changed files with 35 additions and 5 deletions.
7 changes: 6 additions & 1 deletion docs/usage/index.rst
Original file line number Diff line number Diff line change
Expand Up @@ -377,7 +377,12 @@ Command line interface: pk_faidx; pk_get_entry; pk_ge
Extracts sequence entry from fasta file.

This function works similarly to the faidx function
in samtools, but does not requiring an indexing function.
in samtools, but does not requiring an indexing step.

To obtain multiple entries, input multiple entries separated
by a comma (,). For example, if you want entries
named "seq_0" and "seq_1", the string "seq_0,seq_1"
should be associated with the -e argument.

.. code-block:: shell
Expand Down
7 changes: 6 additions & 1 deletion phykit/phykit.py
Original file line number Diff line number Diff line change
Expand Up @@ -738,7 +738,12 @@ def faidx(argv):
Extracts sequence entry from fasta file.
This function works similarly to the faidx function
in samtools, but does not requiring an indexing function.
in samtools, but does not requiring an indexing step.
To obtain multiple entries, input multiple entries separated
by a comma (,). For example, if you want entries
named "seq_0" and "seq_1", the string "seq_0,seq_1"
should be associated with the -e argument.
Aliases:
faidx, get_entry; ge
Expand Down
4 changes: 3 additions & 1 deletion phykit/services/alignment/faidx.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,9 @@ def __init__(self, args) -> None:

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

def process_args(self, args):
return dict(fasta=args.fasta, entry=args.entry)
2 changes: 1 addition & 1 deletion phykit/version.py
Original file line number Diff line number Diff line change
@@ -1 +1 @@
__version__ = "1.19.7"
__version__ = "1.19.8"
20 changes: 19 additions & 1 deletion tests/integration/alignment/test_faidx.py
Original file line number Diff line number Diff line change
Expand Up @@ -65,4 +65,22 @@ def test_faidx_alias1(self, mocked_print):
]
with patch.object(sys, "argv", testargs):
Phykit()
assert mocked_print.mock_calls == [call(expected_result)]
assert mocked_print.mock_calls == [call(expected_result)]

@patch("builtins.print")
def test_faidx_multiple_entries(self, mocked_print):
expected_result0 = ">1\nA-GTAT"
expected_result1 = ">2\nA-G-AT"
testargs = [
"phykit",
"faidx",
f"{here.parent.parent.parent}/sample_files/simple.fa",
'-e',
'1,2'
]
with patch.object(sys, "argv", testargs):
Phykit()
assert mocked_print.mock_calls == [
call(expected_result0),
call(expected_result1)
]

0 comments on commit 4b3b41b

Please sign in to comment.