Calculate GC content of sequences with seqkit
Report per-sequence GC% and the overall mean GC of a FASTA/FASTQ file using seqkit fx2tab plus a short awk one-liner.
Prerequisites
- seqkit installed (`seqkit version` works)
- A FASTA or FASTQ file
1Report per-sequence GC%
seqkit fx2tab converts each record to a tab-delimited row, and --gc appends the GC percentage. --name --only-id trims the output to just the sequence ID and its GC, one row per sequence.
seqkit fx2tab --name --only-id --gc genome.fastaExpected output
chr1 50.72
chr2 49.88
chr3 51.15
chrM 44.032Compute the overall GC across the file
Emit the GC column for every record and average it with awk to get one file-wide number. This is an unweighted mean of per-sequence GC; for a length-weighted genome-wide GC%, run `seqkit stats -a genome.fasta` and read the GC(%) column instead.
seqkit fx2tab --gc genome.fasta | awk '{s+=$NF; n++} END{printf "mean GC: %.2f%%\n", s/n}'Expected output
mean GC: 50.31%Troubleshooting
Output has extra columns you don't want
Add `--name --only-id` to keep just the sequence ID and GC; drop `--only-id` if you want the full header line instead of the bare ID.
You need the single genome-wide GC%, not a per-contig mean
Run `seqkit stats -a genome.fasta` and read the GC(%) column — it is length-weighted, so short and long contigs are counted in proportion to their bases.