Skip to content

Building and Serving Tutorial

This tutorial walks through the complete refgenie asset lifecycle: initialize a genome, build assets, stage them for serving, serve them locally, and push them to cloud storage. Each stage builds on the previous one, and you can follow along using a small test genome (~16 KB) so the steps run quickly.

Refgenie separates asset management into three distinct stages:

build → stage → push
StageWhat happensOutput
buildRun a recipe; produce asset files in genome_folderFiles on disk, DB record
stageMake a built asset servable in genome_stage_folderSymlink (file mode) or .tgz (archive mode), DB StagedAsset record
pushUpload staged assets to cloud storageRemoteAssetLink records, cloud files

This separation gives you control: you can build locally, stage selectively, and push only what you want to host publicly.

  • Python 3.10+
  • refgenie1 installed (pip install refgenie1-*.whl)
  • Snakemake installed (pip install snakemake) — only needed for Section 7
  • Cloud CLI (e.g., aws, az, gsutil) — only needed for Section 8

Set up refgenie with explicit paths for where to store assets and staged (servable) assets. Using a temporary directory makes this tutorial self-contained:

Terminal window
mkdir -p /tmp/rg_tutorial/{genomes,staged}
refgenie1 init \
--genome-folder /tmp/rg_tutorial/genomes \
--genome-stage-folder /tmp/rg_tutorial/staged

Verify the configuration:

Terminal window
refgenie1 config get

Expected output:

Refgenie configuration
┏━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┳━━━━━━━━━┳━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┳━━━━━━━━━┓
┃ genome_folder ┃ version ┃ genome_stage_folder ┃ servers ┃
┡━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━╇━━━━━━━━━╇━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━╇━━━━━━━━━┩
│ /tmp/rg_tutorial/genomes │ 1 │ /tmp/rg_tutorial/staged │ [] │
└────────────────────────────────────┴─────────┴────────────────────────────────────┴─────────┘

Download the rCRSd FASTA — the revised Cambridge Reference Sequence for human mitochondrial DNA, ~16 KB:

Terminal window
curl -L https://raw.githubusercontent.com/refgenie/refgenie-build-fasta/main/test_data/rCRSd.fa \
-o /tmp/rCRSd.fa

Register the genome with refgenie. This reads the FASTA, computes sequence digests, builds a RefgetStore, and records the genome in the database:

Terminal window
refgenie1 genome init \
--fasta /tmp/rCRSd.fa \
--name rCRSd \
--description "Revised Cambridge Reference Sequence (mitochondrial)" \
--species "Homo sapiens"

What happened:

  1. Each sequence in the FASTA was digested (SHA-512/24) and stored in the RefgetStore
  2. A sequence collection digest was computed from all sequences
  3. The genome was registered in the database with that digest
  4. The alias rCRSd was set, pointing to the genome digest

Verify:

Terminal window
refgenie1 genome list

Asset classes define what an asset contains (seek keys and serving modes). Recipes define how to build one. They are separate so the same recipe can produce assets of different classes, and the same class can be built by different recipes.

List asset classes and recipes available locally:

Terminal window
refgenie1 asset_class list
refgenie1 recipe list

View the requirements for a recipe with the -q flag:

Terminal window
refgenie1 recipe show fasta -q

This shows the recipe’s input asset classes, input files, input parameters, and associated Docker image.

For a recipe with asset dependencies:

Terminal window
refgenie1 recipe show bowtie2_index -q

Expected output (abbreviated):

Recipes
┏━━━━━━━━━━━━━━━┳━━━━━━━━━┳━━━━━━━━━━━━━━━━━━━━┳━━━━━━━━━━━━━━━━━━━━━━━━━━┳━━━━━━━━━━━━━┓
┃ Name ┃ Version ┃ Output asset class ┃ Input asset classes ┃ Input files ┃
┡━━━━━━━━━━━━━━━╇━━━━━━━━━╇━━━━━━━━━━━━━━━━━━━━╇━━━━━━━━━━━━━━━━━━━━━━━━━━╇━━━━━━━━━━━━━┩
│ bowtie2_index │ 0.0.1 │ bowtie2_index │ • fasta (fasta asset) │ None │
└───────────────┴─────────┴────────────────────┴──────────────────────────┴─────────────┘

The three input types:

Input typeCLI flagDescription
required_assets--assetsA pre-built refgenie asset (e.g., fasta)
required_files--filesA path to a file on disk
required_parameters--paramsA string value (e.g., number of threads)

The fasta asset exports sequences from the RefgetStore to standard FASTA files on disk:

Terminal window
refgenie1 build rCRSd/fasta

Refgenie runs the fasta recipe, which:

  1. Exports sequences from the RefgetStore
  2. Computes a FASTA index natively (no samtools needed)
  3. Writes chromosome sizes
  4. Records the asset in the database

Verify the asset is present:

Terminal window
refgenie1 list

Retrieve the path to the asset and its seek keys:

Terminal window
refgenie1 seek rCRSd/fasta # default seek key (FASTA file)
refgenie1 seek rCRSd/fasta.fai # FASTA index
refgenie1 seek rCRSd/fasta.chrom_sizes # chromosome sizes

Build a bowtie2 index. The bowtie2_index recipe requires a fasta asset as input. Refgenie resolves this dependency automatically:

Terminal window
refgenie1 build rCRSd/bowtie2_index

To override the parent asset explicitly:

Terminal window
refgenie1 build rCRSd/bowtie2_index --assets fasta=rCRSd/fasta:default

To run the build inside a Docker container (requires Docker):

Terminal window
refgenie1 build rCRSd/bowtie2_index -d

The --stage flag builds and stages in a single command:

Terminal window
refgenie1 build rCRSd/bwa_index --stage

Staging makes a built asset servable. It creates a StagedAsset record in the database and prepares the asset in genome_stage_folder.

Refgenie supports three serving modes, set per asset class. See Serving modes for the full reference.

ModeWhat is stored in stage folderUse case
fileDirectory symlink to asset in genome_folderIndividual file access; files served at their own URLs
archiveCompressed .tgz tarballAligner indexes and large bundles; bulk download
noneNothingMetadata-only; users must build locally

The fasta asset class defaults to file mode. Staging creates a symlink in the stage folder:

Terminal window
refgenie1 stage rCRSd/fasta

Inspect the stage folder:

Terminal window
ls -la /tmp/rg_tutorial/staged/

You will see a directory symlink pointing to the built asset in genome_folder. Individual files in that directory are each accessible at their own URL when served.

The bowtie2_index asset class uses archive mode. Staging creates a .tgz tarball:

Terminal window
refgenie1 stage rCRSd/bowtie2_index

Inspect the stage folder:

Terminal window
ls /tmp/rg_tutorial/staged/

You will see a .tgz file. Clients download this tarball and extract it locally.

Terminal window
refgenie1 stage staged

Unstaging removes the symlink or tarball from the stage folder. The original asset in genome_folder is not affected:

Terminal window
refgenie1 stage unstage rCRSd/fasta

Start the refgenie server:

Terminal window
refgenie1 serve

By default, this serves on http://localhost:8000. To use a different port:

Terminal window
refgenie1 serve --port 9000
Asset modeEndpointDescription
AnyGET /v4/assetsList all staged assets
fileGET /v4/assets/{digest}/filesList individual files in a file-mode asset
fileGET /v4/assets/{digest}/files/{path}Download a specific file
archiveGET /v4/assets/{digest}/archiveDownload the .tgz tarball
Any (DRS)GET /ga4gh/drs/v1/objects/{id}DRS object metadata

File-mode assets expose each file at its own URL, so downstream tools and web applications can fetch exactly the file they need. Archive-mode assets are served as a single tarball download.

Get remote URLs to individual files without downloading them:

Terminal window
refgenie1 seekr rCRSd/fasta -s http://localhost:8000

This returns URLs that point directly to the files, suitable for streaming workflows.

On another machine that has subscribed to the server, pull assets normally:

Terminal window
refgenie1 subscribe http://yourserver.example.com
refgenie1 pull rCRSd/fasta

Pull behavior adapts to serving mode automatically:

  • archive mode: downloads the .tgz and extracts it
  • file mode: downloads files individually
  • none mode: returns an error with instructions to build locally

Section 7: Building in bulk with PEP and Snakemake

Section titled “Section 7: Building in bulk with PEP and Snakemake”

For building many genomes and asset types together, refgenie integrates with PEP and Snakemake.

The workflow:

  1. Define what to build in a PEP (sample and subsample tables)
  2. Generate a Snakefile from the PEP using refgenie
  3. Run snakemake to build all assets in parallel, with correct dependency ordering

Create a project directory:

Terminal window
mkdir -p /tmp/rg_pep

/tmp/rg_pep/config.yaml:

pep_version: 2.0.0
sample_table: sample_table.csv
subsample_table: subsample_table.csv
sample_modifiers:
derive:
attributes: [fasta_file_path]
sources:
local: /tmp/{genome_name}.fa

/tmp/rg_pep/sample_table.csv:

sample_name,genome_name,genome_description,species_name,fasta_file_path
rCRSd,rCRSd,Revised Cambridge Reference Sequence,Homo sapiens,local

/tmp/rg_pep/subsample_table.csv:

genome_name,asset_group
rCRSd,fasta
rCRSd,bowtie2_index
rCRSd,bwa_index

Each row in subsample_table.csv declares one asset to build for a genome. The asset_group value must match a recipe name known to refgenie.

Terminal window
refgenie1 generate snakefile --output-path /tmp/rg_pep/build.smk

The generated Snakefile contains:

  • A genome_init rule that initializes each genome from its FASTA file
  • Build rules for each asset, derived from the configured recipes
  • Stage rules that run after each build
  • Dependency chains ensuring that derived assets (e.g., bowtie2_index) are built after their parents (e.g., fasta)
Terminal window
snakemake --snakefile /tmp/rg_pep/build.smk --jobs 4

Snakemake parallelizes across independent assets while respecting dependencies. The --jobs flag controls parallel job count.

For cluster execution with SLURM:

Terminal window
snakemake \
--snakefile /tmp/rg_pep/build.smk \
--jobs unlimited \
--default-resources slurm_account=myaccount slurm_partition=standard mem_mb=32000 \
--cores 8 \
--workflow-profile /path/to/snakemake_profile_dir

where the profile directory contains a config.yaml with executor: slurm.

Terminal window
refgenie1 list
refgenie1 stage staged

Managing software dependencies for recipes

Section titled “Managing software dependencies for recipes”

Recipes require bioinformatics tools (e.g., bowtie2-build). Options:

  • Docker (refgenie1 build -d): uses the Docker image specified in the recipe
  • Bulker: see the Bulker refgenie tutorial
  • Snakemake containers: snakemake --software-deployment-method apptainer
  • Native install: install tools in your PATH

Pushing uploads staged assets to cloud storage (S3, Azure, GCS) so they can be served publicly. Push intent is tracked in the database as RemoteAssetLink records, giving you a clear record of what has been pushed and what is pending.

Terminal window
refgenie1 remote add \
--type s3 \
--prefix s3://my-bucket/refgenie \
--description "Production S3 bucket" \
--push-command "aws s3 cp {local_path} s3://my-bucket/{relative_path}"

The --push-command template uses these placeholders:

PlaceholderValue
{local_path}Absolute path to the staged file or directory
{relative_path}Path relative to genome_stage_folder
{prefix}The remote’s prefix string
{genome_stage_folder}The genome_stage_folder path

List configured remotes:

Terminal window
refgenie1 remote list

Push all staged assets that have not yet been pushed:

Terminal window
refgenie1 push

Preview what would be pushed without uploading:

Terminal window
refgenie1 push --dry-run

Push to a specific remote only:

Terminal window
refgenie1 push --remote production

Push assets for a specific genome only:

Terminal window
refgenie1 push --genome rCRSd
Terminal window
refgenie1 remote status

This shows pushed/unpushed counts per remote along with the digests of unpushed assets.

For bulk uploads you can use your cloud CLI directly and then mark assets as pushed:

Terminal window
# Sync the entire stage folder to S3, following symlinks
aws s3 sync /tmp/rg_tutorial/staged/ s3://my-bucket/refgenie/ --follow-symlinks
# Then push using folder_sync strategy to record everything as pushed
refgenie1 push --strategy folder_sync

The folder_sync strategy marks all staged assets as pushed without re-uploading files, which is useful after a manual sync.

Here is the full lifecycle in a single command sequence:

Terminal window
# 1. Initialize
refgenie1 init \
--genome-folder /path/to/genomes \
--genome-stage-folder /path/to/staged
# 2. Initialize a genome
refgenie1 genome init \
--fasta rCRSd.fa \
--name rCRSd \
--description "Revised Cambridge Reference Sequence"
# 3. Build + stage individual assets
refgenie1 build rCRSd/fasta --stage
refgenie1 build rCRSd/bowtie2_index --stage
# 4. Or build + stage everything in bulk
refgenie1 generate snakefile --output-path build.smk
snakemake --snakefile build.smk --jobs 4
# 5. Serve locally
refgenie1 serve
# 6. Push to cloud
refgenie1 remote add \
--type s3 \
--prefix s3://bucket/refgenie \
--description "Production" \
--push-command "aws s3 cp {local_path} s3://bucket/{relative_path}"
refgenie1 push
CommandDescription
refgenie1 initInitialize refgenie configuration and database
refgenie1 genome init --fasta FILE --name NAMERegister a genome from a FASTA file
refgenie1 genome listList all registered genomes
refgenie1 asset_class listList available asset classes
refgenie1 recipe listList available recipes
refgenie1 recipe show NAME -qShow recipe requirements
refgenie1 build GENOME/ASSETBuild an asset
refgenie1 build GENOME/ASSET --stageBuild and stage in one step
refgenie1 listList all local assets
refgenie1 seek GENOME/ASSETGet local file path
refgenie1 stage GENOME/ASSETStage a built asset
refgenie1 stage unstage GENOME/ASSETUnstage an asset
refgenie1 stage stagedList all staged assets
refgenie1 serveStart the local refgenie server
refgenie1 seekr GENOME/ASSET -s URLGet remote file URL
refgenie1 generate snakefile -o FILEGenerate a Snakemake build workflow
refgenie1 remote addConfigure a cloud push remote
refgenie1 remote listList configured remotes
refgenie1 remote statusShow push status per remote
refgenie1 pushPush staged assets to cloud remotes
refgenie1 push --dry-runPreview push without uploading