# AUTOGENERATED FILE! PLEASE DON'T EDIT
import k1lib.bioinfo.cli as _cli
from k1lib.bioinfo.cli.init import BaseCli as _BaseCli
from typing import List as _List
import time as _time
from collections import deque as _deque
__all__ = ["feats", "origin"]
[docs]class feats(_BaseCli):
"""Fetches features, each on a separate stream"""
[docs] def __ror__(self, it):
it = it | _cli.grep("FEATURES", 0, 1e9).till("ORIGIN") | _cli.rows()[1:-1]
cache = []
for line in it:
if line[4:9] != " ": # new section detected
if len(cache) > 0: yield iter(cache)
cache = []
cache.append(line)
if len(cache) > 0: yield iter(cache)
[docs] @staticmethod
def filt(term:str) -> _BaseCli:
"""Filters for a specific term in all the features texts"""
return ((_cli.grep(term) | _cli.shape(0)) & _cli.identity()).all()\
| ~_cli.isValue(0, 0) | _cli.cut(1)
[docs] @staticmethod
def tag(tag:str) -> _BaseCli:
"""Gets a single tag out. Applies this on a single feature only"""
class _tag(_BaseCli):
def __ror__(self, it):
lines = it | _cli.grep(f"/{tag}").till("/") | _cli.dereference()
# check if on same line
if len(lines) > 1 and lines[-1].lstrip().startswith("/"): lines.pop()
return (lines | _cli.split(f"/{tag}=\"") | ~_cli.head(1)\
| _cli.strip() | _cli.to1Str("") | _cli.item()).rstrip("\"")
return _tag()
[docs]class origin(_BaseCli):
"""Return the origin section of the genbank file"""
[docs] def __ror__(self, it):
return it | _cli.grep("ORIGIN", 0, 1e9) | ~_cli.head(1) | _cli.strip()\
| _cli.table(" ") | _cli.cut()[1:] | _cli.stitch("")\
| _cli.remove("/") | _cli.to1Str("") | _cli.item()