Skip to main content

A specialized datastructure and tokenization library for counting DNA sequences for use in Bioinformatics.

Project description

DNA Hash

A specialized datastructure and tokenization library for counting DNA sequences for use in Bioinformatics. DNA Hash stores k-mer sequence counts by their up2bit encoding - an efficient two-way hash that works with variable-length sequences. As such, DNA Hash uses considerably less memory than a lookup table that stores sequences in plaintext. In addition, DNA Hash's novel autoscaling Bloom filter eliminates the need to explicitly store singletons and makes it suitable for use on streaming data.

  • Variable sequence lengths
  • Ultra-low memory footprint
  • Embarrassingly parallelizable
  • Open-source and free to use commercially

Note: Due to the probabilistic nature of the Bloom filter, DNA Hash may over count sequences at a bounded rate.

Installation

Install DNA Hash using a Python package manager, example pip:

pip install dnahash

Example Usage

from dna_hash import DNAHash
from dna_hash.tokenizers import Kmer, Canonical

from Bio import SeqIO
from matplotlib import pyplot as plt

hash_table = DNAHash(max_false_positive_rate=0.001)

tokenizer = Canonical(Kmer(6))

with open('covid-19-virus.fasta', 'r') as file:
    for record in SeqIO.parse(file, 'fasta'):
        for token in tokenizer.tokenize(str(record.seq)):
            hash_table.increment(token)

for sequence, count in hash_table.top(25):
    print(f'{sequence}: {count}')

print(f'Total sequences: {hash_table.num_sequences}')
print(f'# of unique sequences: {hash_table.num_unique_sequences}')
print(f'# of singletons: {hash_table.num_singletons}')

plt.hist(list(hash_table.counts.values()), bins=20)
plt.title('SARS-CoV-2 Genome')
plt.xlabel('Counts')
plt.ylabel('Frequency')
plt.show()
TAACAA: 70
TTAAAA: 68
ACAACA: 65
...
CATTAA: 49

Total sequences: 29876
# of unique sequences: 2013
# of singletons: 100

SARS-CoV-2 Histogram

References

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

dnahash-0.0.2.tar.gz (6.3 kB view details)

Uploaded Source

Built Distribution

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

DNAHash-0.0.2-py3-none-any.whl (6.4 kB view details)

Uploaded Python 3

File details

Details for the file dnahash-0.0.2.tar.gz.

File metadata

  • Download URL: dnahash-0.0.2.tar.gz
  • Upload date:
  • Size: 6.3 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/5.1.1 CPython/3.12.3

File hashes

Hashes for dnahash-0.0.2.tar.gz
Algorithm Hash digest
SHA256 ce878fba0656c9605d6171b15d550699f414c8a616dba54b6ecfe17b6adf1b07
MD5 42a72d17415e3f3fc3e5ada6baf4b313
BLAKE2b-256 2b1429206bdc56ea3009d153c3afbfba7478b051d9ce044af2b466b01d8d96aa

See more details on using hashes here.

File details

Details for the file DNAHash-0.0.2-py3-none-any.whl.

File metadata

  • Download URL: DNAHash-0.0.2-py3-none-any.whl
  • Upload date:
  • Size: 6.4 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/5.1.1 CPython/3.12.3

File hashes

Hashes for DNAHash-0.0.2-py3-none-any.whl
Algorithm Hash digest
SHA256 7310ccc7d392bdc8b4e4eadd298655b5c071325f00b5f5db3ffdfb1678d8b1b2
MD5 8d3d7c31307fd8925a238b42ebc13a74
BLAKE2b-256 3e359faf9cb230e062b5a73aaf8bfe00f044214fef143a5781f0a956db0d4ecc

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