Answers.Body: <p>The HLA region is already a part of chromosome 6. When you split the file, it will just be included with the rest of the chromosome. Whether or not you include the remaining contigs depends on your specific objectives. Inclusion of the unplaced and unlocalized scaffolds usually helps to reduce mapping errors, for example. To split/extract <strong>only</strong> chr1-22 from the UCSC <a href="http://hgdownload.cse.ucsc.edu/goldenPath/hg38/bigZips/hg38.fa.gz" rel="nofollow noreferrer">hg38.fa.gz</a>, we can just use <a href="/questions/tagged/awk" class="post-tag" title="show questions tagged &#39;awk&#39;" aria-label="show questions tagged &#39;awk&#39;" rel="tag" aria-labelledby="awk-container">awk</a>. With the following in a file called <code>script.awk</code>:</p>
  <pre><code>BEGIN {
      for(i=1;i&lt;=22;i++) {
          arr[&quot;chr&quot; i]
      }
  }
  
  /^&gt;/ {
      f=substr($0,2)
  }
  
  f in arr {
      print &gt; f &quot;.fa&quot;
  }
  </code></pre>
  <p>Run using:</p>
  <pre><code>awk -f script.awk &lt;(zcat hg38.fa.gz)
  </code></pre>
  
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2022-12-17T13:56:05.497Z
Answers.Text: Of course, if that's what the OP wants, it would make more sense to just download the individual chromosomes from https://hgdownload.cse.ucsc.edu/goldenPath/hg38/chromosomes/.
Answers.UserDisplayName: terdon
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2022-12-17T07:02:08.757Z
Answers.LastActivityDate: 2022-12-17T07:02:08.757Z
Answers.UserDisplayName: Steve
Body: <p>HG38 human reference is the collection of reference from all 22 chromosomes,x,y chromosomes, and some others. I was targeting to split the reference file into 22 chromosomes fasta files. I am following this link <a href="https://crashcourse.housegordon.org/split-fasta-files.html" rel="nofollow noreferrer">https://crashcourse.housegordon.org/split-fasta-files.html</a> to split the fasta files.More specifically I want to split the fasta file into all possible (placed,unlocalized and unplaced) sequence and the merge placed and localized sequences.
  However, I am unsure where to put the HLA part of the reference. Should I put it in Chromosome 6? Also, should I dump the unknown chromosomes as I am specifically interested in chromosomes 1-22?</p>
  <p>Any suggestion on splitting the fasta file into 22 chromosomes would be nice.</p>
  
Comments.ContentLicense: CC BY-SA 4.0
Comments.CreationDate: 2022-12-16T17:10:33.647Z
Comments.Text: "should I dump the unknown chromosomes as I am specifically interested in chromosomes 1-22". That's up to you. We cannot tell you what your data preservation strategy should be.
Comments.UserDisplayName: Ram RS
Comments.ContentLicense: CC BY-SA 4.0
Comments.CreationDate: 2022-12-16T17:49:06.853Z
Comments.Text: Is the question about the computing/parsing side (how do I make one file per sequence from a multi-fasta file?) or is it more about the biology of what the different chromosomes in hg38 actually are? You seem to be asking about both sides but I can't quite understand.
Comments.UserDisplayName: terdon
Comments.ContentLicense: CC BY-SA 4.0
Comments.CreationDate: 2022-12-16T17:55:39.237Z
Comments.Text: It is more about biology
Comments.UserDisplayName: Shafayet Rahat
Comments.ContentLicense: CC BY-SA 4.0
Comments.CreationDate: 2022-12-16T18:11:25.023Z
Comments.Text: Then please [edit] your question and make that clear. As it stands, I read this as asking about how to split a multi-fasta file. One thing though: if the people who generated the genome couldn't put the extra sequences in a specific chromosome, what makes you think you will be able to? This feels like an [XY problem](https://meta.stackexchange.com/q/66377/203101). Why do you think you need to end up with exactly 22 chromosomes? Can you explain what the final objective is here?
Comments.UserDisplayName: terdon
Tags: <fasta><reference-genome>
Title: split fast reference fast file by 22 chromosome
ThreadText: # split fast reference fast file by 22 chromosome
  
  (Asked by: username_0 on 2022-12-16)
  
  HG38 human reference is the collection of reference from all 22 chromosomes,x,y chromosomes, and some others. I was targeting to split the reference file into 22 chromosomes fasta files. I am following this link <https://crashcourse.housegordon.org/split-fasta-files.html> to split the fasta files.More specifically I want to split the fasta file into all possible (placed,unlocalized and unplaced) sequence and the merge placed and localized sequences.
  However, I am unsure where to put the HLA part of the reference. Should I put it in Chromosome 6? Also, should I dump the unknown chromosomes as I am specifically interested in chromosomes 1-22?
  
  Any suggestion on splitting the fasta file into 22 chromosomes would be nice.
  
  **Tags:** fasta, reference-genome
  
  > **Comments:**
  > **username_1**: "should I dump the unknown chromosomes as I am specifically interested in chromosomes 1-22". That's up to you. We cannot tell you what your data preservation strategy should be.  
  > **username_2**: Is the question about the computing/parsing side (how do I make one file per sequence from a multi-fasta file?) or is it more about the biology of what the different chromosomes in hg38 actually are? You seem to be asking about both sides but I can't quite understand.  
  > **username_0**: It is more about biology  
  > **username_2**: Then please [edit] your question and make that clear. As it stands, I read this as asking about how to split a multi-fasta file. One thing though: if the people who generated the genome couldn't put the extra sequences in a specific chromosome, what makes you think you will be able to? This feels like an [XY problem](https://meta.stackexchange.com/q/66377/203101). Why do you think you need to end up with exactly 22 chromosomes? Can you explain what the final objective is here?  
  
  ---
  
  ## 1 answers
  
  ### Answer by username_3 on 2022-12-17. Score: 2 | Accepted answer
  
  The HLA region is already a part of chromosome 6. When you split the file, it will just be included with the rest of the chromosome. Whether or not you include the remaining contigs depends on your specific objectives. Inclusion of the unplaced and unlocalized scaffolds usually helps to reduce mapping errors, for example. To split/extract **only** chr1-22 from the UCSC [hg38.fa.gz](http://hgdownload.cse.ucsc.edu/goldenPath/hg38/bigZips/hg38.fa.gz), we can just use [awk](/questions/tagged/awk "show questions tagged 'awk'"). With the following in a file called `script.awk`:
  
  ```
  BEGIN {
      for(i=1;i<=22;i++) {
          arr["chr" i]
      }
  }
  
  /^>/ {
      f=substr($0,2)
  }
  
  f in arr {
      print > f ".fa"
  }
  
  ```
  
  Run using:
  
  ```
  awk -f script.awk <(zcat hg38.fa.gz)
  
  ```
  
  > **Comments:**
  > **username_2**: Of course, if that's what the OP wants, it would make more sense to just download the individual chromosomes from https://hgdownload.cse.ucsc.edu/goldenPath/hg38/chromosomes/.  
  
  ---
  
  