Skip to content

Commit 6d5acb7

Browse files
author
Nolan Woods
committed
Add extract() function
1 parent a2e3f8a commit 6d5acb7

4 files changed

Lines changed: 15912 additions & 2 deletions

File tree

README.rst

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,8 @@ directly rather than trying to copy/paste the data.
5353

5454
`split()`_ and `let()`_ functions are available in addition to the JMESPath standard functions
5555

56+
`extract(Seq, SeqFeature)` is also made available to allow access to the `SeqFeature.extract()`_ function within the query
57+
5658
Examples:
5759
Append a new record::
5860

@@ -98,4 +100,5 @@ See CONTRIBUTING.rst_ for information on contributing to this repo.
98100
.. _constructor parameters: https://biopython.org/DIST/docs/api/Bio.SeqRecord.SeqRecord-class.html#__init__
99101
.. _JMESPath playground: https://glenveegee.github.io/jmespath-edit/
100102
.. _split(): https://github.com/jmespath/jmespath.py/issues/159
101-
.. _let(): https://github.com/jmespath/jmespath.site/pull/6
103+
.. _let(): https://github.com/jmespath/jmespath.site/pull/6
104+
.. _SeqFeature.extract(): https://biopython.org/docs/latest/api/Bio.SeqFeature.html#Bio.SeqFeature.SeqFeature.extract

biopython_convert/JMESPathGen.py

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,9 @@
55
import itertools
66
import types
77

8+
from Bio.Seq import Seq
9+
from Bio.SeqFeature import SeqFeature
10+
811
from collections import deque
912

1013
# Register generator type in jmespath
@@ -14,6 +17,8 @@
1417
# Register biopython types in jmespath
1518
jmespath.functions.TYPES_MAP['Seq'] = 'string'
1619
jmespath.functions.REVERSE_TYPES_MAP['string'] += ('Seq',)
20+
jmespath.functions.REVERSE_TYPES_MAP['Seq'] = ('Seq',)
21+
jmespath.functions.REVERSE_TYPES_MAP['SeqFeature'] = ('SeqFeature',)
1722
jmespath.functions.TYPES_MAP['ExactPosition'] = 'number'
1823
jmespath.functions.REVERSE_TYPES_MAP['number'] += ('ExactPosition',)
1924

@@ -68,6 +73,10 @@ def _func_let(self, lexical_scope, expref, **kwargs):
6873
def _func_split(self, on, val):
6974
return val.split(on)
7075

76+
@jmespath.functions.signature({'types': ['Seq']}, {'types': ['SeqFeature']})
77+
def _func_extract(self, seq, feature):
78+
return feature.extract(seq)
79+
7180

7281
class _Expression(jmespath.visitor._Expression):
7382
def __init__(self, expression, interpreter, context):

0 commit comments

Comments
 (0)