samtools-faidx(1)

πŸ’… samtools-faidx β€” index or query regions from a fasta file

okay so real talk, bestie: this little icon is part of the samtools family (you know, the bioinformatics tools squad), and it's genuinely one of the most useful things ever. It's called samtools-faidx, and it does two whole jobs. Let's get into it 🫢


✨ NAME ✨

samtools faidx β€” indexes your fasta file, or pulls regions out of one that's already indexed πŸ’–


πŸ¦‹ SYNOPSIS πŸ¦‹

samtools faidx ref.fasta [region1 [...]]

🌸 DESCRIPTION 🌸

So basically, samtools faidx indexes a reference sequence in the FASTA format, or it extracts a subsequence from a reference sequence that's already been indexed. Two moods, one command, we love that for us ✨

If you don't give it any region at all, faidx will index the file and create <ref.fasta>.fai on your disk. That's it. That's the whole vibe.

But if you do pass regions? Then the subsequences get retrieved and printed to stdout in the FASTA format. Lowkey the best party trick πŸŽ€

The input and the output can both be files compressed in the BGZF format. And when the output is compressed, the default compression level is 4 β€” noted, no cap.

πŸ’€ Important, bestie: the sequences in the input file should all have different names. If they don't, indexing will emit a warning about duplicate sequences, and retrieval will only produce subsequences from the first sequence with the duplicated name. So like… name your sequences properly, iykyk.

FASTQ files can also be read and indexed by this command β€” iconic, flexible, we stan. Just remember: without using --fastq, any extracted subsequence will be in FASTA format.


🌈 OPTIONS 🌈

  • -o, --output FILE β€” Write the FASTA to a file instead of to stdout. And if FILE ends with .gz, .bgz or .bgzf? Boom, it gets BGZF compressed automatically πŸ’…
  • -n, --length INT β€” Length for FASTA sequence line wrapping. If it's zero, that means do not line wrap. Defaults to the line length in the input file.
  • -c, --continue β€” Continue working even if a non-existent region is requested. She persists. She does not give up 😀
  • -r, --region-file FILE β€” Read regions from a file. The format is chr:from-to, one per line. Clean, simple, organized πŸŽ€
  • -f, --fastq β€” Read FASTQ files and output extracted sequences in FASTQ format. This is the same as using samtools fqidx.
  • -i, --reverse-complement β€” Output the sequence as the reverse complement. When this option is used, β€œ/rc” will be appended to the sequence names. To turn this off or change the string appended, use the --mark-strand option. (Yes, she labels her work, main character energy πŸ‘‘)
  • --mark-strand TYPE β€” Append a strand indicator to the sequence name. TYPE can be one of these:
    • rc β€” Append '/rc' when writing the reverse complement. This is the default.
    • no β€” Do not append anything. Minimalist. Respect.
    • sign β€” Append '(+)' for the forward strand or '(-)' for the reverse complement. This matches the output of β€œbedtools getfasta -s” 🧚
    • custom,<pos>,<neg> β€” Append the string <pos> to names when writing the forward strand and <neg> when writing the reverse strand. Spaces are preserved, so it's totally possible to move the indicator into the comment part of the description line by including a leading space in the strings <pos> and <neg>. Fancy, I know πŸ’œ
  • --fai-idx FILE β€” Read/Write to the specified index file.
  • --gzi-idx FILE β€” Read/Write to the specified compressed file index (used with .gz files).
  • -h, --help β€” Print the help message and exit. The classic.
  • --output-fmt-option OPT=VAL β€” Set the output format options, e.g. level=0..9 for compression level 0 to 9 πŸ“
  • --write-index β€” Create an index for the output sequence data along with the output, in the same path as <output name>.fai and <outputname>.gzi. Heads up bestie: this option is valid only for file output. Stdout girlies, this one's not for you πŸ™ˆ
  • -@, --threads N β€” Set the number of extra threads for operations on compressed files. Go faster, slay faster πŸ”₯

πŸ‘‘ AUTHOR πŸ‘‘

Written by Heng Li, with modifications by Andrew Whitwham and Robert Davies β€” all from the Sanger Institute. Legends, honestly 🫢


⭐ SEE ALSO ⭐

Samtools website: <http://www.htslib.org/> 🌐


okay that's the whole page, you're officially a faidx expert, no cap πŸ’– this was samtools-1.24, dated 9 July 2026, and it's giving "bioinformatics but make it cute" ✨ go index something, bestie πŸŽ€πŸ¦‹

πŸ“¦ where this page comes from