Skip to main content

Yet Another Sequence Analytics Toolkit - A modern Python library for sequence analysis with polars and plotnine

Project description

yasqat

Yet Another Sequence Analytics Toolkit

PyPI Python License: MIT

A modern Python library for categorical sequence analysis, built on polars and plotnine. Designed for social-science and life-course research — labour-market trajectories, health pathways, educational histories, and similar domains.

Inspired by TraMineR (R) and TanaT (Python).

Features

  • Polars-native data structuresAlphabet, StateSequence, IntervalSequence, SequencePool for fast sequence manipulation
  • Distance metrics — Optimal Matching, Hamming, LCS, LCP, RLCP, DTW, SoftDTW, Chi², Euclidean, DHD, TWED, and OM variants (OMloc, OMspell, OMstran, NMS, NMSMST, SVRspell), with convenience length/similarity wrappers for LCS, LCP, and RLCP
  • Substitution costs — constant, transition-rate, indels, indelslog, future (chi-squared), features (Gower distance)
  • Clustering — PAM (k-medoids) with .predict(), CLARA, hierarchical (scipy linkage); parallel pairwise distance computation via n_jobs
  • Cluster quality — silhouette (ASW), Point Biserial, Hubert's Gamma, R², PAM range analysis, distance to center, representative extraction
  • Discrepancy analysis — pseudo-ANOVA with permutation tests, multi-factor discrepancy, dissimilarity trees
  • Descriptive statistics — entropy, transition rates, complexity, turbulence, spell counts, visited states, modal states (with time granularity), sequence frequencies, log-probabilities, subsequence counts (with state filtering and log-transform)
  • Normative indicators — volatility, precarity, insecurity, degradation, badness, integration (per-state), proportion positive
  • Subsequence mining — frequent subsequence discovery with support thresholds and minimum length, returned as polars DataFrames
  • Visualization — index, distribution, frequency, spell duration, timeline, modal state, mean time, parallel coordinate, sunburst, and tree plots (all return composable ggplot objects)
  • Filtering — length, time, state, and pattern-based sequence filtering
  • Data I/O — CSV, Parquet, and DataFrame loading (Hive/Spark/Arrow interop) with automatic type inference
  • Synthetic data — Markov-chain and financial trajectory generators

Installation

pip install yasqat

Quick start

from yasqat.io import load_csv

# Load sequences from CSV (also: load_dataframe, load_parquet)
pool = load_csv("trajectories.csv", id_col="id", time_col="time", state_col="state")

# Compute pairwise distances and cluster
dm = pool.compute_distances(method="om", indel=1.0, n_jobs=4)

from yasqat.clustering import pam_clustering
result = pam_clustering(dm, n_clusters=4)

# Descriptive statistics
from yasqat.statistics import longitudinal_entropy, turbulence
longitudinal_entropy(pool.state_sequence)
turbulence(pool.state_sequence)

# Visualize (all return composable ggplot objects)
from yasqat.visualization import index_plot, sunburst_plot
index_plot(pool)
sunburst_plot(pool)

Development

# Clone and install with dev dependencies
git clone https://github.com/rexarski/yasqat.git
cd yasqat
uv venv && source .venv/bin/activate  # or activate.fish
uv pip install -e ".[dev]"

# Run tests
uv run pytest

# Lint and format
uv run ruff check src/ tests/
uv run ruff format src/ tests/

# Type check
uv run mypy src/yasqat/

License

MIT License — see LICENSE for details.

Acknowledgments

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

yasqat-0.3.2.tar.gz (114.7 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

yasqat-0.3.2-py3-none-any.whl (102.1 kB view details)

Uploaded Python 3

File details

Details for the file yasqat-0.3.2.tar.gz.

File metadata

  • Download URL: yasqat-0.3.2.tar.gz
  • Upload date:
  • Size: 114.7 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: uv/0.11.7 {"installer":{"name":"uv","version":"0.11.7","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"24.04","id":"noble","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}

File hashes

Hashes for yasqat-0.3.2.tar.gz
Algorithm Hash digest
SHA256 84fc23da10b7f6cce620d8436b0b74180149770e36e28d9d267555c1266f01d8
MD5 d53c5214e545f0fb1827dce0c90d9116
BLAKE2b-256 ebef1c2a352078a1aa90bf66032c1d0ca5070e66c4cee7f3591e2da1902be1f7

See more details on using hashes here.

File details

Details for the file yasqat-0.3.2-py3-none-any.whl.

File metadata

  • Download URL: yasqat-0.3.2-py3-none-any.whl
  • Upload date:
  • Size: 102.1 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: uv/0.11.7 {"installer":{"name":"uv","version":"0.11.7","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"24.04","id":"noble","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}

File hashes

Hashes for yasqat-0.3.2-py3-none-any.whl
Algorithm Hash digest
SHA256 a0bb499a81142c8c58d7c450571b484b7ac5d875cd2e9a21ced6fec374fe00d7
MD5 594c68ac338f54c6baa74b807b273728
BLAKE2b-256 3d5eb6ff945e7b66b3e7faa7da8d21ab5b7311533e4e40da581a04e08a2e65f1

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page