<p>I would suggest using <code>bedtools makewindows</code> and <code>bedtools nuc</code> to compute the GC content for genomic windows as shown in Fig 2 of the linked paper.</p>
<p>See related question <a href="https://www.biostars.org/p/9522847/" rel="nofollow noreferrer">here</a>.</p>
<p>This will slice the genome into 5Kbp (or whatever size specified to <code>makewindows</code>) pieces and compute the GC content of each piece, which can be plotted as a distribution as in the figure.</p>
<p>Something like this would work for the 5000 bp example:</p>
<pre><code># assemble a bedtools compatible genome file:
# see https://www.biostars.org/p/70795/ for hints how to do this.
bedtools makewindows -w 5000 -g my_genome.genome &gt; windows.bed # you just made this .genome file manually
bedtools nuc -bed windows.bed -fi my_genome.fasta &gt; windows_gc.bed
</code></pre>
<p>The bed output file will contain the GC content of each window in the <code>7_pct_gc</code> column (according to my understanding of the output file).</p>

CC BY-SA 4.0
2023-09-16T13:34:23.180Z
Please note that you do not have to make ".genome" file manually if you have `samtools`. You could simply generate an index file by running `samtools faidx genome.fasta`, and use the output file with extension `.fasta.fai` as input in your makewindwos command.
Supertech
CC BY-SA 4.0
2023-09-16T13:59:24.483Z
`tail -n +2 windows_gc.bed | cut -f 5 | awk '{printf("%d\n",$1*100)}' | sort | uniq -c | sed 's/^ *//'| sed 's/ /,/'>output.csv`. This should print a CSV file which you can easily plot.
Supertech
CC BY-SA 4.0
2023-09-07T21:13:05.297Z
2023-09-07T21:13:05.297Z
Maximilian Press
<p>Try this small package/library:
<a href="https://github.com/willros/GuCi/" rel="nofollow noreferrer">https://github.com/willros/GuCi/</a></p>
<p>It produces a plot of the gc content of the whole genome. It works on small genomes, like bacteria.</p>
<p>Hope you like!</p>

CC BY-SA 4.0
2024-04-18T19:29:36.900Z
At least state that you're the developer of this kinda-related tool that absolutely DOES NOT generate the kind of plot shown in the question.
Ram RS
CC BY-SA 4.0
2024-04-18T09:24:40.293Z
2024-04-18T09:24:40.293Z
William Rosenbaum
<p>I have the assembly file of a certain lizard species, I wanted to recreate Fig. 2 of the following paper, which compares the GC content distribution over 5kb windows, how would I go about doing this?</p>
<p><a href="https://bmcecolevol.biomedcentral.com/articles/10.1186/s12862-022-02086-7#Sec10" rel="nofollow noreferrer">https://bmcecolevol.biomedcentral.com/articles/10.1186/s12862-022-02086-7#Sec10</a></p>
<p><a href="https://i.sstatic.net/q4uns.png" rel="nofollow noreferrer"><img src="https://i.sstatic.net/q4uns.png" alt="enter image description here" /></a></p>

<fasta><genome>
How to analyze GC content of fasta file?
# How to analyze GC content of fasta file?

(Asked by: username_0 on 2023-09-07)

I have the assembly file of a certain lizard species, I wanted to recreate Fig. 2 of the following paper, which compares the GC content distribution over 5kb windows, how would I go about doing this?

<https://bmcecolevol.biomedcentral.com/articles/10.1186/s12862-022-02086-7#Sec10>

[![enter image description here](https://i.sstatic.net/q4uns.png)](https://i.sstatic.net/q4uns.png)

**Tags:** fasta, genome

---

## 2 answers

### Answer by username_1 on 2023-09-07. Score: 4

I would suggest using bedtools makewindows and bedtools nuc to compute the GC content for genomic windows as shown in Fig 2 of the linked paper.
See related question here.
This will slice the genome into 5Kbp (or whatever size specified to makewindows) pieces and compute the GC content of each piece, which can be plotted as a distribution as in the figure.
Something like this would work for the 5000 bp example:
# assemble a bedtools compatible genome file:
# see https://www.biostars.org/p/70795/ for hints how to do this.
bedtools makewindows -w 5000 -g my_genome.genome > windows.bed # you just made this .genome file manually
bedtools nuc -bed windows.bed -fi my_genome.fasta > windows_gc.bed

The bed output file will contain the GC content of each window in the 7_pct_gc column (according to my understanding of the output file).

> **Comments:**
> **username_2**: Please note that you do not have to make ".genome" file manually if you have `samtools`. You could simply generate an index file by running `samtools faidx genome.fasta`, and use the output file with extension `.fasta.fai` as input in your makewindwos command.  
> **username_2**: `tail -n +2 windows_gc.bed | cut -f 5 | awk '{printf("%d\n",$1*100)}' | sort | uniq -c | sed 's/^ *//'| sed 's/ /,/'>output.csv`. This should print a CSV file which you can easily plot.  

---

### Answer by username_3 on 2024-04-18. Score: -2

Try this small package/library:
<https://github.com/willros/GuCi/>

It produces a plot of the gc content of the whole genome. It works on small genomes, like bacteria.

Hope you like!

> **Comments:**
> **username_4**: At least state that you're the developer of this kinda-related tool that absolutely DOES NOT generate the kind of plot shown in the question.  

---

