# AUTOGENERATED FILE! PLEASE DON'T EDIT
"""All tools related to cif file format that describes protein structures.
Expected to use behind the "cif" module name, like this::
from k1lib.imports import *
cif.cat("abc.cif")
"""
from k1lib import cli; import k1lib
from typing import Iterator, List
from k1lib.cli.typehint import *
import k1lib._k1a as k1a
__all__ = ["tables"]
hasTable = lambda: cli.filt(cli.grep("loop_") | cli.shape(0) | (cli.op() > 0))
toBlocks = lambda: cli.cat() | cli.grep("^#", sep=True).till()
def collect(l):
inBlock = False; tmp = []
for e in l:
if e.startswith(";"):
inBlock = not inBlock
if not inBlock: yield ("".join(tmp))[1:]; continue
if not inBlock: yield e
else: tmp.append(e)
[docs]def tables():
"""Loads table info.
Example::
"abc.cif" | cif.tables()
Result is a dictionary of ``table name -> dict()``. That inner dictionary maps from
column name to a list of elements. All columns should have the same number of rows."""
def inner(url): # f is iden() or deref(), depending on perf characteristics that you want
a = url | toBlocks() | hasTable() | cli.apply(~cli.head(2) | cli.op().strip().all()) | cli.deref() # preprocessing, split to blocks
b = a | cli.apply(~cli.filt(cli.op().startswith("_")) | (cli.aS(k1a.str_split, " ") | cli.filt(cli.op() != "")).all() | cli.joinStreams())
fieldss = a | cli.apply(cli.filt(cli.op().startswith("_")) | cli.op().split(".")[1].all()) | cli.toList().all()
c = [b, fieldss] | cli.transpose() | ~cli.apply(lambda l, fields: collect(l) | cli.batched(len(fields), True) | cli.insert(fields) | cli.transpose() | cli.apply(cli.item() & ~cli.head(1)) | cli.transpose() | cli.toDict())
return [a | cli.op()[0].split(".")[0].all(), c] | cli.toDict()
return cli.aS(inner)