# Computing digests locally

## Introduction

This tutorial shows you how to compute GA4GH content-addressable identifiers for sequences and FASTA files using the `refget` package.

<div class="admonition tip">
  <p class="admonition-title">New to GA4GH digests?</p>
  <p>See <a href="/refget/digests-explained/">What are GA4GH digests?</a> for background on why content-addressable identifiers matter.</p>
</div>

<div class="admonition success">
  <p class="admonition-title">Learning objectives</p>
  <ul>
    <li>Compute a refget sequence digest for a sequence</li>
    <li>Compute a refget sequence collection digest from a FASTA file</li>
    <li>Understand level 1 and level 2 representations</li>
  </ul>
</div>



## Computing a sequence digest

Use `sha512t24u_digest()` to compute the GA4GH digest for any string:


```python
from refget.digests import sha512t24u_digest
from refget.store import digest_fasta
from refget.utils import fasta_to_seqcol_dict
```


```python
sha512t24u_digest('GGAA')
```




    'YBbVX0dLKG1ieEDCiMmkrTZFt_Z5Vdaj'



## Computing a collection digest from FASTA

For a FASTA file containing multiple sequences, compute the top-level collection digest:


```python
digest_fasta('../../../test_fasta/base.fa').digest
```




    'XZlrcEGi6mlopZ2uD8ObHkQB1d0oDwKk'



## Getting the full sequence collection (level 2)

To see the complete sequence collection representation with all attributes (names, lengths, sequences, and derived attributes), use `fasta_to_seqcol_dict()`:

Note: `sequences` contains `SQ.`-prefixed digests for each sequence. The `sorted_*` attributes enable order-independent comparison.


```python
fasta_to_seqcol_dict('../../../test_fasta/base.fa')

```




    {'lengths': [8, 4, 4],
     'names': ['chrX', 'chr1', 'chr2'],
     'sequences': ['SQ.iYtREV555dUFKg2_agSJW6suquUyPpMw',
      'SQ.YBbVX0dLKG1ieEDCiMmkrTZFt_Z5Vdaj',
      'SQ.AcLxtBuKEPk_7PGE_H4dGElwZHCujwH6'],
     'sorted_name_length_pairs': ['IWFt7HQ4XoMk34U27BKO-4szSRifP6H5',
      'chDD8A4S8YZKNNctCimHasAA2Dn596SZ',
      'enZNOGccwFbN9yJ3YZVifFTFCVA9hIpH'],
     'sorted_sequences': ['SQ.iYtREV555dUFKg2_agSJW6suquUyPpMw',
      'SQ.YBbVX0dLKG1ieEDCiMmkrTZFt_Z5Vdaj',
      'SQ.AcLxtBuKEPk_7PGE_H4dGElwZHCujwH6']}



## Iterating over sequences

For lower-level access to individual sequence metadata (name, length, digests), use the `digest_fasta` function. This returns an iterator over each sequence:

<div class="admonition success">
  <p class="admonition-title">Summary</p>
  <ul>
    <li><code>sha512t24u_digest()</code> computes GA4GH digests for sequences</li>
    <li><code>digest_fasta()</code> computes collection digests from FASTA files</li>
    <li><code>fasta_to_seqcol_dict()</code> returns full level 2 sequence collection data</li>
  </ul>
</div>
