name: bwa_index
version: 0.2.1
output_asset_class: bwa_index
description: |
  Genome index for Burrows-Wheeler Alignment Tool, produced with bwa index.
  Creates the FM-index files required by bwa mem, bwa aln, and other BWA
  alignment commands.
input_files: {}
input_params: {}
input_assets:
  fasta:
    asset_class: fasta
    description: fasta asset for genome
    default: fasta
docker_image: quay.io/biocontainers/bwa:0.7.19--h577a1d6_1
command_templates:
  # Read the fasta directly from the genome folder and write the index with an
  # explicit output prefix (-p) into the output folder. Do NOT colocate the
  # fasta as a symlink and let bwa "write next to the input": bwa realpath()s
  # its reference, so with a symlinked input it drops the .amb/.ann/.bwt/.pac/.sa
  # next to the symlink TARGET (polluting the fasta asset) and leaves this asset
  # empty. -p makes the output location explicit and symlink-proof.
  - bwa index -p {{values.output_folder}}/{{values.genome_digest}} {{values.genome_folder}}/{{values.assets["fasta"].seek_keys_dict["fasta"]}}
custom_seek_keys:
  # sed -E, not grep -P: the biocontainers image's grep is BusyBox (no -P),
  # and the whole pipeline runs inside that one image now.
  version: bwa 2>&1 | sed -nE 's/^Version:[[:space:]]*([0-9]+\.[0-9]+\.[0-9]+).*/\1/p' | head -1 # uses stderr; monitor https://github.com/lh3/bwa/issues/202
default_asset: "{{values.custom_seek_keys.version}}"

tags:
- alignment
- dna-seq
- short-read
outputs:
- pattern: '*.amb'
  description: BWA index - sequence ambiguity information
- pattern: '*.ann'
  description: BWA index - sequence annotation (names, lengths)
- pattern: '*.bwt'
  description: BWA index - Burrows-Wheeler transform
- pattern: '*.pac'
  description: BWA index - packed reference sequence
- pattern: '*.sa'
  description: BWA index - suffix array
test:
  commands:
  - test -f {output_dir}/{genome}.bwt
  - test -f {output_dir}/{genome}.sa
  - test -f {output_dir}/{genome}.amb
  - test -f {output_dir}/{genome}.ann
  - test -f {output_dir}/{genome}.pac
resources:
  memory: 8GB
  disk: 10GB
  time: 2h
metadata:
  author: nsheff
  created: '2026-05-20'
  license: BSD-2-Clause
