omics.co.in logo omics.co.in
📋 One-Liner Cookbook & Reference VCF • BAM • BED • GFF3 Samtools • Bcftools • Bedtools • Seqkit

The Bioinformatician's Command Cookbook & Format Reference

High-yield command-line one-liners, CLI tool syntax cards, and comprehensive field-by-field specifications for core genomic formats. Designed for daily computational biology practice, pipeline engineering, and quick lookups.

Jump to: ⚡ One-Liner Cookbook 🛠️ Samtools & Bcftools 📐 Bedtools & Intervals ✂️ Seqkit Sequences 📄 VCF / BAM / BED Specifications

⚡ The Bioinformatician's One-Liner Cookbook

Awk, Sed, Grep & Bash

Count Total Reads in Gzipped FASTQ

FASTQ

Divides total line count by 4. Fast, streaming without uncompressing to disk.

zcat reads.fq.gz | awk '{s++}END{print s/4}'

Convert FASTQ to FASTA

FASTQ

Replaces '@' with '>' on line 1 and keeps line 2 (sequence), skipping quality scores.

zcat reads.fq.gz | paste - - - - | cut -f 1,2 | sed 's/^@/>/' | tr " " " " > out.fa

Keep Only Mapped High-Quality Reads

BAM

Discards unmapped reads (-F 4) and requires Mapping Quality ≥ 30 (-q 30).

samtools view -b -F 4 -q 30 in.bam > filtered.bam

Count Mapped Reads per Chromosome

BAM

Instant lookup from BAM index (.bai) without parsing read alignments.

samtools idxstats in.bam | cut -f 1,3 | head -n 25

Filter VCF for PASS & High-Frequency SNVs

VCF

Keeps only high-confidence variants passing all filters with AF > 5%.

bcftools view -f 'PASS' -i 'TYPE="snp" && INFO/AF > 0.05' in.vcf.gz -Oz -o filtered.vcf.gz

Calculate Transition / Transversion (Ti/Tv) Ratio

VCF

Expected Ti/Tv is ~2.0-2.1 for human WGS, and ~2.8-3.0 for whole exome (WES).

bcftools stats in.vcf.gz | grep "^TSTV" | cut -f 5

🛠️ Samtools & Bcftools Essential Syntax

v1.19+ Standards
Task / ActionCommand SyntaxKey Flags & Notes
SAM to Sorted BAMsamtools sort -@ 8 -o out.bam in.sam-@ 8 uses 8 CPU threads for multi-threaded compression.
Index BAM Filesamtools index -@ 4 in.bamGenerates in.bam.bai required for random coordinate queries.
Alignment Statisticssamtools flagstat in.bam > stats.txtShows total reads, primary alignments, proper pair %, and duplicates.
Per-Base Depth of Coveragesamtools depth -a -b targets.bed in.bam > depth.tsv-a outputs all positions including 0-depth; -b restricts to BED.
Normalize & Split Multiallelicsbcftools norm -m -any -f ref.fa in.vcf.gz -Oz -o norm.vcf.gzLeft-aligns indels and splits lines with multiple ALT alleles (e.g. A,T).
Query Genotypes to TSVbcftools query -f '%CHROM %POS %REF %ALT[ %GT] ' in.vcf.gzSquare brackets [...] iterate over all samples in the VCF.

📐 Bedtools Interval Arithmetic Reference

Genomic Arithmetic
bedtools intersect

Find overlaps between features in A and B (e.g. ChIP peaks in Promoters).

bedtools intersect -a peaks.bed -b promoters.bed -wa -wb > overlaps.bed
bedtools merge

Combine overlapping or contiguous intervals into unified single intervals.

sort -k1,1 -k2,2n in.bed | bedtools merge -i - > merged.bed
bedtools subtract

Remove regions in B from features in A (e.g. Exclude repetitive elements).

bedtools subtract -a exons.bed -b repeats.bed > non_repeat_exons.bed
bedtools getfasta

Extract nucleotide sequences from reference FASTA for BED coordinates.

bedtools getfasta -fi hg38.fa -bed peaks.bed -fo peaks.fa

📄 Genomic File Formats Field-by-Field Reference

Specification Standards

VCF 4.2 / 4.3 Fixed Columns & Standard Tags

Every VCF file has 8 mandatory fixed tab-separated columns, followed by an optional 9th column (FORMAT) and sample columns (10+).

Col #Field NameType / ConventionDescription & Biological Context
1CHROMStringChromosome identifier (e.g. chr17 or 17).
2POSInteger (1-based)Reference coordinate of the first base in the REF allele.
3IDStringIdentifier (e.g. dbSNP rsID rs121913529 or . if unassigned).
4REFString [A,C,G,T,N]Reference allele sequence from the reference genome build.
5ALTComma-separatedAlternate non-reference allele(s) detected in the sample(s).
6QUALFloat (Phred-scale)-10 * log10(P(error)) that ALT is wrong. QUAL 30 = 99.9% accurate.
7FILTERStringPASS if passed all quality filters; or semicolon list of failed filters.
8INFOKey-Value (Semicolon)Site-level annotations (e.g. DP=120;AF=0.45;AN=2;AC=1).
Essential Sample FORMAT Sub-Tags:
GT: Genotype (0/0 ref hom, 0/1 het, 1/1 alt hom, 0|1 phased)
AD: Allelic Depths (e.g. 32,18 = 32 ref reads, 18 alt reads)
DP: Total Filtered Depth at this sample locus (e.g. 50)
GQ: Genotype Quality Phred score (0-99, confidence in assigned GT)

SAM / BAM Mandatory Fields & CIGAR Operators

The Sequence Alignment/Map (SAM) format has 11 mandatory tab-delimited columns for every aligned segment.

CIGAR String Operators (Column 6):

M: Alignment match/mismatch
I: Insertion into reference
D: Deletion from reference
N: Skipped intron (RNA-seq)
S: Soft clipping (bases in SEQ)
H: Hard clipping (not in SEQ)
Example: 15S85M1200N50M
→ 15 bp soft-clipped adapter/primer + 85 bp exon alignment + 1,200 bp spliced intron + 50 bp downstream exon alignment.