Skip to main content

GCGC is a preprocessing library for biological sequence model development.

Project description


GCGC is a tool for feature processing on Biological Sequences.

code style black


GCGC is primarily intended to be used as part of a larger workflow inside Python.

To install via pip:

$ pip install gcgc

If you'd like to use code that helps gcgc's tokenizers integrate with common third party libraries, either install those packages separately, or use gcgc's extras.

$ pip install 'gcgc[pytorch,hf]'


The GCGC documentation is at, please see it for examples.

Quick Start

The easiest way to get started is to import the kmer tokenizer, configure it, then start tokenizing.

from gcgc import KmerTokenizer

kmer_tokenizer = KmerTokenizer(alphabet="unambiguous_dna")
encoded = kmer_tokenizer.encode("ATCG")

sample output:

[1, 6, 7, 8, 5, 2]

This output includes the "bos" token, the "eos" token, and the four nucleotide tokens in between.

You can go the other way and convert the integers to strings.

from gcgc import KmerTokenizer

kmer_tokenizer = KmerTokenizer(alphabet="unambiguous_dna")
decoded = kmer_tokenizer.decode(kmer_tokenizer.encode("ATCG"))

sample output:

['>', 'A', 'T', 'C', 'G', '<']

There's also the vocab for the kmer tokenizer.

from gcgc import KmerTokenizer

kmer_tokenizer = KmerTokenizer(alphabet="unambiguous_dna")

sample output:

{'|': 0, '>': 1, '<': 2, '#': 3, '?': 4, 'G': 5, 'A': 6, 'T': 7, 'C': 8}


The Transformers library has an idea of a tokenizer that is used for various modeling tasks.

To make it easier to use the Transformers library on biological sequences, gcgc has a Transformers compatible tokenizer that can be created from the KmerTokenizer.

from gcgc import KmerTokenizer
from gcgc.third_party.hf import GCGCTransformersTokenizer

kmer_tokenizer = KmerTokenizer(
  kmer_length=2, kmer_stride=2, alphabet="unambiguous_dna"

tt = GCGCTransformersTokenizer.from_kmer_tokenizer(

batch = tt.batch_encode_plus(["ATGC", "GCGC"])

sample output:

[[1, 11, 8, 2], [1, 8, 8, 2]]

Project details

Release history Release notifications | RSS feed

Download files

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

Files for gcgc, version 0.13.0
Filename, size File type Python version Upload date Hashes
Filename, size gcgc-0.13.0-py3-none-any.whl (477.9 kB) File type Wheel Python version py3 Upload date Hashes View
Filename, size gcgc-0.13.0.tar.gz (472.9 kB) File type Source Python version None Upload date Hashes View

Supported by

Pingdom Pingdom Monitoring Google Google Object Storage and Download Analytics Sentry Sentry Error logging AWS AWS Cloud computing DataDog DataDog Monitoring Fastly Fastly CDN DigiCert DigiCert EV certificate StatusPage StatusPage Status page