Skip to content

Commit 21473b8

Browse files
author
Nolan Woods
committed
Wrap biopython iterator in type generator
1 parent 49c4097 commit 21473b8

1 file changed

Lines changed: 6 additions & 1 deletion

File tree

biopython_convert/__init__.py

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -107,6 +107,11 @@ def get_records(input_handle, input_type: str, jpath: str = ''):
107107
:param jpath: JMESPath selecting records to keep. The root is the list of records. The path must return a list of records.
108108
:return: iterable of resulting records
109109
"""
110+
def gentype(x):
111+
# Newer versions of biopython return iterator that is not of type Generator, wrap in generator type so jmespath can detect
112+
for a in x:
113+
yield a
114+
110115
if input_type in gff_types:
111116
# If input is GFF load with gffutils library
112117
db = gffutils.create_db(input_handle, ":memory:", merge_strategy="create_unique")
@@ -123,7 +128,7 @@ def get_records(input_handle, input_type: str, jpath: str = ''):
123128

124129
# Wrap input in JMESPath selector if provided
125130
if jpath:
126-
input_records = JMESPathGen.search(jpath, input_records)
131+
input_records = JMESPathGen.search(jpath, gentype(input_records))
127132

128133
if isinstance(input_records, dict):
129134
# Support generating a new record in JMESPath

0 commit comments

Comments
 (0)