Bioinformatics File Formats Explained: FASTA, FASTQ, SAM/BAM, VCF, GTF and BED
Chapter 5 of 5: Troubleshooting, practice and next steps
Which format do I need?
| You want to… | Format | Tool to start with |
|---|---|---|
| Store a reference genome or a set of genes/proteins | FASTA (+ .fai) | samtools faidx, seqkit |
| Keep raw reads from the sequencer | FASTQ.gz (R1 + R2) | seqkit, FastQC |
| Store aligned reads for analysis | Sorted, indexed BAM | samtools |
| Archive aligned reads at minimum size | CRAM (+ the exact FASTA) | samtools |
| Share variant calls | bgzipped VCF + .tbi | bcftools |
| Work with millions of samples’ genotypes fast | BCF + .csi | bcftools |
| Count reads per gene | GTF | featureCounts, HTSeq, STAR |
| Define target regions, peaks, primers, blacklists | BED | bedtools |
| Show coverage or ChIP-seq signal in a browser | bigWig | deepTools, IGV, UCSC |
Other formats you will meet
| Format | What it is | Where you see it |
|---|---|---|
GenBank / EMBL (.gb, .embl) | Sequence plus rich annotation in one text record | NCBI and ENA downloads, plasmid maps, bacterial genomes |
bigBed (.bb) | Indexed binary BED | UCSC track hubs, ENCODE peaks |
PAF (.paf) | Simple tab-separated alignment summary | minimap2 output for long reads and genome-to-genome alignment |
SRA (.sra) | NCBI’s archive container for reads | Convert with fasterq-dump to get FASTQ |
Newick (.nwk) | A tree written with brackets | Phylogenetics (IQ-TREE, RAxML) |
| PDB / mmCIF | 3D coordinates of proteins and molecules | RCSB PDB, AlphaFold DB, docking and molecular dynamics |
| MTX + TSV, HDF5, h5ad | Sparse count matrices | Single-cell RNA-seq (Cell Ranger, Scanpy, Seurat) |
Troubleshooting
These messages are copied from the tools (samtools/bcftools/htslib 1.25, bedtools 2.31).
| Problem | Likely cause | What to do |
|---|---|---|
[tabix] the compression of 'x.vcf.gz' is not BGZF | File was compressed with gzip | zcat x.vcf.gz | bgzip > y.vcf.gz, then index |
[E::fai_build_core] Format error, unexpected "A" at line 4 | FASTA lines of uneven length | Rewrap: seqkit seq -w 60 in.fa > out.fa |
WARNING. chromosome (chr1) was not found in the FASTA file. Skipping. | chr1 vs 1 naming mismatch | Compare names (below) and rename with sed or bcftools annotate --rename-chrs |
| Region query prints nothing and exits with no error | Region name not in the file (bcftools view -r chr1 on a 1-named VCF is silent) | Always check names first; samtools at least warns “unknown reference” |
[E::hts_idx_push] Unsorted positions on sequence #2 | Indexing a BAM that is not coordinate-sorted | samtools sort -o sorted.bam in.bam, then index |
EOF marker is absent. The input is probably truncated | Interrupted copy, download or full disk | Re-copy; run samtools quickcheck -v on all BAMs |
[W::cram_get_ref] Failed to populate reference | CRAM cannot find its reference FASTA | Pass -T ref.fa or set REF_PATH |
It looks as though you have less than 3 columns…Are you sure your files are tab-delimited? | BED written with spaces | sed -E 's/ +/\t/g' or rebuild with awk -v OFS='\t' |
Strange ^M at line ends in cat -A; names “not found” | File edited in Windows (CRLF line ends) | sed -i 's/\r$//' file or dos2unix file |
| Everything is shifted by one base | 1-based coordinates written into BED (or the reverse) | BED start = 1-based start − 1; check with bedtools getfasta vs samtools faidx |
A quick consistency check for any project
Before a long analysis, confirm that the reference, the alignments and the variants use the same sequence names. This loop prints the names from each file side by side:
cut -f 1 toy.fa.fai > names_fasta.txt
samtools view -H toy.bam | grep "^@SQ" | cut -f 2 | sed 's/^SN://' > names_bam.txt
bcftools view -h toy.vcf.gz | grep "^##contig" | sed -E 's/.*ID=([^,>]+).*/\1/' > names_vcf.txt
paste names_fasta.txt names_bam.txt names_vcf.txt
samtools quickcheck -v toy.bam && echo "BAM OK"Three identical columns mean the files agree. On a human project you would see chr1 chr1 chr1… and any 1 vs chr1 row stands out at once.
Practice exercise
Use the files in ~/bhl-formats. Try first, then open the solution.
- Decode FLAG 147 and FLAG 2064. For each, say: paired or not, which strand, R1 or R2, primary or not.
- Read x3 in
toy.samhas CIGAR9M4I13Mand POS 6. How long is its sequence, and what is its last reference position? - Write the SNP at
ref2:17as a one-line BED file, then usebedtools getfastato print the reference base. Which base do you get? - Without opening the file, which column of a VCF would you
cutto get the genotype column of the first sample, and why doesbcftools querydo this better?
Complete study material
- DATAPractice data: toy files plus a simulated mini-genome project (FASTA, FASTQ, BAM, CRAM, VCF, GFF3, GTF, BED)
- DATAScripts: format checks, coordinate converters, consistency check and conversion one-liners
- IPYNBGoogle Colab notebook: every command in this tutorial in your browser
- PDFSlides: all diagrams, column tables and a format cheat sheet (PDF)
- PDFSolution with reference answers and assignment guidance (PDF)
- Every file above, yours to keep
- Notebooks open in Google Colab (free)
- Certificate with QR verification after your project report is approved
Bioinformatics file formats: frequently asked questions
Is a .fa file the same as .fasta, .fna and .faa?
Yes, all are FASTA. By convention .fna holds nucleotides and .faa amino acids, but tools look at the content, not the extension.
Should I keep SAM files?
No. Convert to sorted, indexed BAM (or CRAM) right away and delete the SAM. Better still, pipe the aligner straight into samtools sort so the SAM is never written.
Can I gunzip a .vcf.gz or a BAM?
A bgzipped VCF can be read with zcat or gunzip, but keep it compressed so it stays indexable. A BAM is binary even after decompression, so always read it with samtools view.
Why does my BAM have no index, or an old one?
samtools index must be rerun every time the BAM changes. Many tools warn that the index is older than the data file; some silently use the old one.
GTF or GFF3 for RNA-seq?
Use whatever your counting tool expects (usually GTF for STAR and featureCounts), from the same source and release as your genome FASTA.
When should I use CRAM instead of BAM?
For long-term storage and sharing of large projects, when you can keep the exact reference FASTA with it. For day-to-day work, BAM is still the most widely supported.
How do I write this in my Methods?
Name every format with its tool and version, and the reference. For example: “Reads (FASTQ) were aligned to GRCh38 (Ensembl release 115 primary assembly). Alignments were sorted and indexed with samtools 1.25 and stored as BAM. Variants were called and filtered with bcftools 1.25, normalised with bcftools norm (left-aligned, multi-allelic sites split), and released as bgzip-compressed, tabix-indexed VCFv4.2. Gene annotation: Ensembl release 115 GTF. All intervals in BED files are 0-based, half-open.”
Glossary
- BGZF: block gzip; gzip made of independent blocks of up to 64 KiB, so files can be indexed. Made by
bgzip. - CIGAR: the string in SAM column 6 that describes how a read aligns (M, I, D, N, S, H, P, =, X).
- FLAG: SAM column 2; a sum of bits that answer yes/no questions about a read.
- Half-open interval:
[start, end); start included, end excluded. Used by BED. - Index: a side file (
.fai,.bai,.csi,.crai,.tbi) that lets a tool jump to a region without reading the whole file. - MAPQ: mapping quality; Phred-scaled confidence that the read is placed at the right position.
- Meta-information line: a VCF header line starting with
##that defines contigs, INFO, FORMAT and FILTER fields. - Normalisation: writing variants in one standard form (left-aligned, minimal, one ALT per line) so they can be compared.
- Phase (GFF3): for a CDS piece, the number of bases (0–2) to skip to reach the first full codon.
- Primary alignment: the one representative line per read, with neither the secondary (0x100) nor the supplementary (0x800) bit set.
- Soft-masking: lowercase letters in a reference FASTA marking repeats.
- Read group:
@RG; tags reads with sample, library and lane, needed by variant callers and duplicate marking.
References
- SAM/BAM Format Specification Working Group. Sequence Alignment/Map Format Specification (SAMv1), 12 Aug 2025. samtools.github.io/hts-specs/SAMv1.pdf
- SAM/BAM Format Specification Working Group. Sequence Alignment/Map Optional Fields Specification (SAMtags). samtools.github.io/hts-specs/SAMtags.pdf
- The Variant Call Format Specification, VCFv4.5 and BCFv2.2, 25 Feb 2026. samtools.github.io/hts-specs/VCFv4.5.pdf
- CRAM format specification (version 3.x). samtools.github.io/hts-specs/CRAMv3.pdf
- Niu J, Denisko D, Hoffman MM. The Browser Extensible Data (BED) format, v1, 5 Jan 2022. samtools.github.io/hts-specs/BEDv1.pdf
- Stein L. Generic Feature Format Version 3 (GFF3), v1.26, 18 Aug 2020. github.com/The-Sequence-Ontology/Specifications
- Ensembl. GFF/GTF file format. ensembl.org/info/website/upload/gff.html
- htslib. faidx(5): an index enabling random access to FASTA and FASTQ files. htslib.org/doc/faidx.html
- Li H, Handsaker B, Wysoker A, et al. The Sequence Alignment/Map format and SAMtools. Bioinformatics. 2009;25(16):2078–2079. doi:10.1093/bioinformatics/btp352
- Danecek P, Auton A, Abecasis G, et al. The variant call format and VCFtools. Bioinformatics. 2011;27(15):2156–2158. doi:10.1093/bioinformatics/btr330
- Danecek P, Bonfield JK, Liddle J, et al. Twelve years of SAMtools and BCFtools. GigaScience. 2021;10(2):giab008. doi:10.1093/gigascience/giab008
- Bonfield JK, Marshall J, Danecek P, et al. HTSlib: C library for reading/writing high-throughput sequencing data. GigaScience. 2021;10(2):giab007. doi:10.1093/gigascience/giab007
- Cock PJA, Fields CJ, Goto N, Heuer ML, Rice PM. The Sanger FASTQ file format for sequences with quality scores, and the Solexa/Illumina FASTQ variants. Nucleic Acids Research. 2010;38(6):1767–1771. doi:10.1093/nar/gkp1137
- Pearson WR, Lipman DJ. Improved tools for biological sequence comparison. PNAS. 1988;85(8):2444–2448. doi:10.1073/pnas.85.8.2444
- Hsi-Yang Fritz M, Leinonen R, Cochrane G, Birney E. Efficient storage of high throughput DNA sequencing data using reference-based compression. Genome Research. 2011;21(5):734–740. doi:10.1101/gr.114819.110
- Li H. Tabix: fast retrieval of sequence features from generic TAB-delimited files. Bioinformatics. 2011;27(5):718–719. doi:10.1093/bioinformatics/btq671
- Quinlan AR, Hall IM. BEDTools: a flexible suite of utilities for comparing genomic features. Bioinformatics. 2010;26(6):841–842. doi:10.1093/bioinformatics/btq033
- Kent WJ, Zweig AS, Barber G, Hinrichs AS, Karolchik D. BigWig and BigBed: enabling browsing of large distributed datasets. Bioinformatics. 2010;26(17):2204–2207. doi:10.1093/bioinformatics/btq351
- Tan A, Abecasis GR, Kang HM. Unified representation of genetic variants. Bioinformatics. 2015;31(13):2202–2204. doi:10.1093/bioinformatics/btv112
- Shen W, Le S, Li Y, Hu F. SeqKit: a cross-platform and ultrafast toolkit for FASTA/Q file manipulation. PLoS ONE. 2016;11(10):e0163962. doi:10.1371/journal.pone.0163962
- Eilbeck K, Lewis SE, Mungall CJ, et al. The Sequence Ontology: a tool for the unification of genome annotations. Genome Biology. 2005;6(5):R44. doi:10.1186/gb-2005-6-5-r44
- Pertea G, Pertea M. GFF Utilities: GffRead and GffCompare. F1000Research. 2020;9:304. doi:10.12688/f1000research.23297.2
- Frankish A, Carbonell-Sala S, Diekhans M, et al. GENCODE: reference annotation for the human and mouse genomes in 2023. Nucleic Acids Research. 2023;51(D1):D942–D949. doi:10.1093/nar/gkac1071
What to learn next
- Check your FASTQ files before alignment: Quality Control of NGS Reads with FastQC and MultiQC.
- Browse all free tutorials on the Bioinformatics Tutorials page. Coming next in this path: aligning reads with BWA-MEM, then variant calling.
- Go further with guided projects in our courses: Introduction to NGS and Sequencing QC, Whole Exome Sequencing (WES) Data Analysis and RNA-Seq Data Analysis.