name: fasta_index
version: 1.1.1
output_asset_class: fasta_index
description:
  Creates a FASTA index (.fa.fai) and chromosome sizes file using samtools faidx.
  The .fai file enables random access to sequences within the FASTA. The
  chrom.sizes file lists each sequence name and its length, required by many
  tools (bedtools, UCSC utilities)
input_files: {}
input_params: {}
input_assets:
  fasta:
    asset_class: fasta
    description: fasta asset for genome
    default: fasta
docker_image: quay.io/biocontainers/samtools:1.24--h9dcdb79_1
command_templates:
  # Read the fasta from the genome folder and write the .fai explicitly into the
  # output folder via --fai-idx. Do NOT colocate the fasta as a symlink and run
  # `samtools faidx <symlink>`: samtools writes the index next to the resolved
  # target, so the .fai would land in the fasta asset dir, not here. --fai-idx
  # makes the output location explicit and symlink-proof.
  - samtools faidx {{values.genome_folder}}/{{values.assets["fasta"].seek_keys_dict["fasta"]}} --fai-idx {{values.output_folder}}/{{values.genome_digest}}.fa.fai
  - cut -f1,2 {{values.output_folder}}/{{values.genome_digest}}.fa.fai > {{values.output_folder}}/{{values.genome_digest}}.chrom.sizes
default_asset: "default"

# --- Additive non-runtime metadata (ignored by the builder) ---
tags:
- index
- reference
- foundational
outputs:
- pattern: '*.fa.fai'
  description: FASTA index file (samtools format)
- pattern: '*.chrom.sizes'
  description: Chromosome/sequence sizes (name<tab>length)
test:
  commands:
  - test -f {output_dir}/{genome}.fa.fai
  - test -f {output_dir}/{genome}.chrom.sizes
  - test "$(wc -l < {output_dir}/{genome}.fa.fai)" -gt 0
  - test "$(wc -l < {output_dir}/{genome}.chrom.sizes)" -gt 0
resources:
  memory: 2GB
  disk: 1GB
  time: 30m
metadata:
  author: nsheff
  created: '2026-05-20'
  license: BSD-2-Clause
