sercol provides Collection, a sequence that filters and groups while keeping
its collection type and source metadata, and saves to JSON through
serializable. It is the base class
for varcode's VariantCollection and
EffectCollection and mhctools'
BindingPredictionCollection, so their filtering and grouping behave the same.
python -m pip install sercolsercol needs Python 3.11 or later; it installs serializable and pandas 3.
from sercol import Collection
values = Collection([5, 2, 3, 2])
selected = values.filter(lambda value: value >= 3)
groups = values.groupby(lambda value: value % 2)
print(list(selected))
print({key: list(group) for key, group in groups.items()})[5, 3]
{1: [5, 3], 0: [2, 2]}
filter() returns a new collection and groupby() a dictionary of
collections, each of the original class with the same distinct, sort_key
and sources. The original collection is unchanged.
The documentation covers, in reading order:
- Getting started: filter, group, save and reload.
- Select, order and track values: duplicates, sorting, threshold lookups, multiple groups, source metadata and subclassing.
- API reference.
python -m pip install -e . pytest pytest-cov ruff
./lint.sh # ruff check
./test.sh # pytest with coverage
python -m pip install -r requirements-docs.txt
./docs.sh # mkdocs build --strict, then a rendered-link check
python scripts/check_docs_examples.py # run docs examples, compare outputApache 2.0; see LICENSE.