<p>Personally, I would download the entire file and split it using something like <code>fastaexplode</code> from the <code>exonerate</code> package. On an Ubuntu machine, you can do that with:</p>

<pre><code>wget ftp://ftp-trace.ncbi.nih.gov/1000genomes/ftp/technical/reference/phase2_reference_assembly_sequence/hs37d5.fa.gz
gunzip hs37d5.fa.gz
sudo apt install exonerate
fastaexplode hs37d5.fa
</code></pre>

<p>Alternatively, you could do this on the fly while downloading:</p>

<pre><code>wget -O - ftp://ftp-trace.ncbi.nih.gov/1000genomes/ftp/technical/reference/phase2_reference_assembly_sequence/hs37d5.fa.gz | 
  gunzip | awk '/&gt;/{name=$1; sub(/&gt;/,"",name)} {print &gt;&gt; name".fa"}'
</code></pre>

CC BY-SA 4.0
2019-03-26T14:19:22.577Z
Thank you  very much, [fi1d18@cyan01 ~]$ sudo apt install exonerate
[sudo] password for fi1d18:     So I am not able to install from root, your alternative suggestion gave me all chr fasta, but why you are saying on fly?
Zizogolu
CC BY-SA 4.0
2019-03-26T14:21:54.490Z
@FereshTeh yes, you need root access to install software. If you are not running this on your machine, then next time remember to mention that in your question. As for "on the fly", that's because that command downloads the file to standard output, decompresses it as it is coming in and then writes the output to each  .fa file, so it is creating the files on the fly.
terdon
CC BY-SA 4.0
2019-03-26T14:08:43.253Z
2019-03-26T14:08:43.253Z
terdon
<p>It is common that reference genomes will be published only as a complete genome, without separate files for each chromosome. Fortunately, a google search for "split fasta by chromosome" will give you many options for downloading a complete genome Fasta file and splitting it by chromosome. The top answer on <a href="https://www.biostars.org/p/173723/#173819" rel="nofollow noreferrer">this biostar thread</a> looks promising.</p>

<pre><code>pip install pyfaidx
pyfaidx -x sequences.fa
</code></pre>

<p>Alternatively, I typically use a homebrew Python script. If there are unlocalized/unplaced scaffolds in the file, this will create a bunch of files with ugly unexpected names. These are easy to ignore or delete.</p>

<pre class="lang-py prettyprint-override"><code># usage: ./split.py &lt; genome.fasta
from Bio import SeqIO
import sys
reader = SeqIO.parse(sys.stdin, 'fasta')
for record in reader:
    outfile = 'chr{chrid}.fasta'.format(chrid=record.id)
    with open(outfile, 'w') as outstream:
        count = SeqIO.write(record, outstream, 'fasta')
</code></pre>

<p><a href="https://bioinformatics.stackexchange.com/help/how-to-ask">With a little bit of searching</a>, you will find a wealth of helpful information on blogs, forums, and library documentation.</p>

CC BY-SA 4.0
2019-03-26T13:58:10.673Z
2019-03-26T14:04:29.027Z
2019-03-26T14:04:29.027Z
Daniel Standage
<p>Whatever I am googling I am not able to find fasta file of each chromosome for hs37d5.fa. hs37d5.fa whole fasta file however is here </p>

<p><a href="ftp://ftp-trace.ncbi.nih.gov/1000genomes/ftp/technical/reference/phase2_reference_assembly_sequence/hs37d5.fa.gz" rel="nofollow noreferrer">ftp://ftp-trace.ncbi.nih.gov/1000genomes/ftp/technical/reference/phase2_reference_assembly_sequence/hs37d5.fa.gz</a></p>

<p>Do you know where I can get fasta file for each chromosome for this genome?</p>

CC BY-SA 4.0
2019-03-26T13:53:34.070Z
Is there something stopping you from downloading the entire FASTA and then splitting it? Also, there are quite a few typos in your post making it a little difficult to understand - can you fix those please? Thank you!
Ram RS
CC BY-SA 4.0
2019-03-26T14:02:40.510Z
@oka I rolled back your edit because it seemed to be introducing almost as many gramatical issues as it was fixing.
terdon
CC BY-SA 4.0
2019-03-26T14:32:54.140Z
@FereshTeh Sorry, but does your comment have anything to do with the question at hand?
Ram RS
CC BY-SA 4.0
2019-03-26T14:37:10.627Z
Sorry you right, I deleted my comment
Zizogolu
<fasta><reference-genome>
Downloading Fasta for each chromosome of a complete genome
# Downloading Fasta for each chromosome of a complete genome

(Asked by: username_0 on 2019-03-26)

Whatever I am googling I am not able to find fasta file of each chromosome for hs37d5.fa. hs37d5.fa whole fasta file however is here

<ftp://ftp-trace.ncbi.nih.gov/1000genomes/ftp/technical/reference/phase2_reference_assembly_sequence/hs37d5.fa.gz>

Do you know where I can get fasta file for each chromosome for this genome?

**Tags:** fasta, reference-genome
> **Comments:**
> **username_1**: Is there something stopping you from downloading the entire FASTA and then splitting it? Also, there are quite a few typos in your post making it a little difficult to understand - can you fix those please? Thank you!  
> **username_2**: @oka I rolled back your edit because it seemed to be introducing almost as many gramatical issues as it was fixing.  
> **username_1**: @FereshTeh Sorry, but does your comment have anything to do with the question at hand?  
> **username_0**: Sorry you right, I deleted my comment  

---

## 2 answers

### Answer by username_2 on 2019-03-26. Score: 2 | Accepted answer

Personally, I would download the entire file and split it using something like fastaexplode from the exonerate package. On an Ubuntu machine, you can do that with:
wget ftp://ftp-trace.ncbi.nih.gov/1000genomes/ftp/technical/reference/phase2_reference_assembly_sequence/hs37d5.fa.gz
gunzip hs37d5.fa.gz
sudo apt install exonerate
fastaexplode hs37d5.fa

Alternatively, you could do this on the fly while downloading:
wget -O - ftp://ftp-trace.ncbi.nih.gov/1000genomes/ftp/technical/reference/phase2_reference_assembly_sequence/hs37d5.fa.gz | 
  gunzip | awk '/>/{name=$1; sub(/>/,"",name)} {print >> name".fa"}'

> **Comments:**
> **username_0**: Thank you  very much, [fi1d18@cyan01 ~]$ sudo apt install exonerate [sudo] password for fi1d18:     So I am not able to install from root, your alternative suggestion gave me all chr fasta, but why you are saying on fly?  
> **username_2**: @FereshTeh yes, you need root access to install software. If you are not running this on your machine, then next time remember to mention that in your question. As for "on the fly", that's because that command downloads the file to standard output, decompresses it as it is coming in and then writes the output to each  .fa file, so it is creating the files on the fly.  

---

### Answer by username_3 on 2019-03-26. Score: 2

It is common that reference genomes will be published only as a complete genome, without separate files for each chromosome. Fortunately, a google search for "split fasta by chromosome" will give you many options for downloading a complete genome Fasta file and splitting it by chromosome. The top answer on this biostar thread looks promising.
pip install pyfaidx
pyfaidx -x sequences.fa

Alternatively, I typically use a homebrew Python script. If there are unlocalized/unplaced scaffolds in the file, this will create a bunch of files with ugly unexpected names. These are easy to ignore or delete.
# usage: ./split.py < genome.fasta
from Bio import SeqIO
import sys
reader = SeqIO.parse(sys.stdin, 'fasta')
for record in reader:
    outfile = 'chr{chrid}.fasta'.format(chrid=record.id)
    with open(outfile, 'w') as outstream:
        count = SeqIO.write(record, outstream, 'fasta')

With a little bit of searching, you will find a wealth of helpful information on blogs, forums, and library documentation.


---

