{ "cells": [ { "cell_type": "markdown", "metadata": {}, "source": [ "# Computing digests locally\n", "\n", "## Introduction\n", "\n", "This tutorial shows you how to compute GA4GH content-addressable identifiers for sequences and FASTA files using the `refget` package.\n", "\n", "
\n", "

New to GA4GH digests?

\n", "

See What are GA4GH digests? for background on why content-addressable identifiers matter.

\n", "
\n", "\n", "
\n", "

Learning objectives

\n", " \n", "
" ] }, { "cell_type": "markdown", "metadata": {}, "source": [] }, { "cell_type": "markdown", "metadata": {}, "source": [ "## Computing a sequence digest\n", "\n", "Use `sha512t24u_digest()` to compute the GA4GH digest for any string:" ] }, { "cell_type": "code", "execution_count": 1, "metadata": { "execution": { "iopub.execute_input": "2026-01-23T03:30:31.110278Z", "iopub.status.busy": "2026-01-23T03:30:31.110136Z", "iopub.status.idle": "2026-01-23T03:30:31.141513Z", "shell.execute_reply": "2026-01-23T03:30:31.141128Z" } }, "outputs": [], "source": [ "from refget.digests import sha512t24u_digest\n", "from refget.store import digest_fasta\n", "from refget.utils import fasta_to_seqcol_dict" ] }, { "cell_type": "code", "execution_count": 2, "metadata": { "execution": { "iopub.execute_input": "2026-01-23T03:30:31.143507Z", "iopub.status.busy": "2026-01-23T03:30:31.143315Z", "iopub.status.idle": "2026-01-23T03:30:31.148689Z", "shell.execute_reply": "2026-01-23T03:30:31.148434Z" } }, "outputs": [ { "data": { "text/plain": [ "'YBbVX0dLKG1ieEDCiMmkrTZFt_Z5Vdaj'" ] }, "execution_count": 2, "metadata": {}, "output_type": "execute_result" } ], "source": [ "sha512t24u_digest('GGAA')" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "## Computing a collection digest from FASTA\n", "\n", "For a FASTA file containing multiple sequences, compute the top-level collection digest:" ] }, { "cell_type": "code", "execution_count": 3, "metadata": { "execution": { "iopub.execute_input": "2026-01-23T03:30:31.204413Z", "iopub.status.busy": "2026-01-23T03:30:31.204182Z", "iopub.status.idle": "2026-01-23T03:30:31.207699Z", "shell.execute_reply": "2026-01-23T03:30:31.207271Z" } }, "outputs": [ { "data": { "text/plain": [ "'XZlrcEGi6mlopZ2uD8ObHkQB1d0oDwKk'" ] }, "execution_count": 3, "metadata": {}, "output_type": "execute_result" } ], "source": [ "digest_fasta('../../../test_fasta/base.fa').digest" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "## Getting the full sequence collection (level 2)\n", "\n", "To see the complete sequence collection representation with all attributes (names, lengths, sequences, and derived attributes), use `fasta_to_seqcol_dict()`:\n", "\n", "Note: `sequences` contains `SQ.`-prefixed digests for each sequence. The `sorted_*` attributes enable order-independent comparison." ] }, { "cell_type": "code", "execution_count": 4, "metadata": { "execution": { "iopub.execute_input": "2026-01-23T03:30:31.208868Z", "iopub.status.busy": "2026-01-23T03:30:31.208760Z", "iopub.status.idle": "2026-01-23T03:30:31.211572Z", "shell.execute_reply": "2026-01-23T03:30:31.211266Z" } }, "outputs": [ { "data": { "text/plain": [ "{'lengths': [8, 4, 4],\n", " 'names': ['chrX', 'chr1', 'chr2'],\n", " 'sequences': ['SQ.iYtREV555dUFKg2_agSJW6suquUyPpMw',\n", " 'SQ.YBbVX0dLKG1ieEDCiMmkrTZFt_Z5Vdaj',\n", " 'SQ.AcLxtBuKEPk_7PGE_H4dGElwZHCujwH6'],\n", " 'sorted_name_length_pairs': ['IWFt7HQ4XoMk34U27BKO-4szSRifP6H5',\n", " 'chDD8A4S8YZKNNctCimHasAA2Dn596SZ',\n", " 'enZNOGccwFbN9yJ3YZVifFTFCVA9hIpH'],\n", " 'sorted_sequences': ['SQ.iYtREV555dUFKg2_agSJW6suquUyPpMw',\n", " 'SQ.YBbVX0dLKG1ieEDCiMmkrTZFt_Z5Vdaj',\n", " 'SQ.AcLxtBuKEPk_7PGE_H4dGElwZHCujwH6']}" ] }, "execution_count": 4, "metadata": {}, "output_type": "execute_result" } ], "source": [ "fasta_to_seqcol_dict('../../../test_fasta/base.fa')\n" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "## Iterating over sequences\n", "\n", "For lower-level access to individual sequence metadata (name, length, digests), use the `digest_fasta` function. This returns an iterator over each sequence:" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "
\n", "

Summary

\n", " \n", "
" ] } ], "metadata": { "kernelspec": { "display_name": "Python 3", "language": "python", "name": "python3" }, "language_info": { "codemirror_mode": { "name": "ipython", "version": 3 }, "file_extension": ".py", "mimetype": "text/x-python", "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython3", "version": "3.12.3" } }, "nbformat": 4, "nbformat_minor": 2 }