<p>If you know the coordinates, you could just use <a href="https://www.htslib.org/doc/samtools-faidx.html" rel="nofollow noreferrer"><code>samtools faidx</code></a> to extract the corresponding subsequence from the FASTA file(s). Regions can be specified on the command line with the format: <code>RNAME[:STARTPOS[-ENDPOS]]</code>. For example, to extract the first ten bases from <code>chr1</code> in your reference FASTA file, you would use:</p>
<pre><code>samtools faidx ref.fasta chr1:1-10
</code></pre>
<p>Or if you wanted the whole chromosome, you would use:</p>
<pre><code>samtools faidx ref.fasta chr1
</code></pre>
<hr />
<hr />
<p>With regards to your specific example, you could try:</p>
<pre><code>samtools faidx NC_037078.1.fasta NC_037078.1:96630-98120
</code></pre>
<p>Results:</p>
<pre><code>&gt;NC_037078.1:96630-98120
TCTCATGGAGAGTTCGATCCTGGCTCAGGATGAACGCTGGCGGCATGCTTAACACATGCA
AGTCGGACGGGAAGTGGTGTTTCCAGTGGCGGACGGGTGAGTAACGCGTAAGAACCTGCC
CTTGGGAGGGGAACAACAGCTGGAAACGGCTGCTAATACCCCGTAGGCTGAGGAGCAAAA
GGAGGAATCCGCCCGAGGAGGGGCTTGCGTCTGATTAGCTAGTTGGTGAGGCAATAGCTT
ACCAAGGCGATGATCAGTAGCTGGTCCGAGAGGATGATCAGCCACACTGGGACTGAGACA
CGGCCCAGACTCCTACGGGAGGCAGCAGTGGGGAATTTTCCGCAATGGGCGAAAGCCTGA
CGGAGCAATGCCGCGTGGAGGTAGAAGGCCCACGGGTCGTGAACTTCTTTTCCCGGAGAA
GAAGCAATGACGGTATCTGGGGAATAAGCATCGGCTAACTCTGTGCCAGCAGCCGCGGTA
AGACAGAGGATGCAAGCGTTATCCGGAATGATTGGGCGTAAAGCGTCTGTAGGTGGCTTT
TTAAGTCCGCCGTCAAATCCCAGGGCTCAACCCTGGACAGGCGGTGGAAACTACCAAGCT
GGAGTACGGTAGGGGCAGAGGGAATTTCCGGTGGAGCGGTGAAATGCGTAGAGATCGGAA
AGAACACCAACGGCGAAAGCACTCTGCTGGGCCGACACTGACACTGAGAGACGAAAGCTA
GGGGAGCGAATGGGATTAGATACCCCAGTAGTCCTAGCCGTAAACGATGGATACTGGGCG
CTGTGCGTATCGACCCGTGCAGTGCTGTAGCTAACGCGTTAAGTATCCCGCCTGGGGAGT
ACGTTCGCAAGAATGAAACTCAAAGGAATTGACGGGGGCCCGCACAAGCGGTGGAGCATG
TGGTTTAATTCGATGCAAAGCGAAGAACCTTACCAGGGCTTGACATGCCGCGAATCCTTT
TGAAAGAGAGGGGTGCCTTCGGGAACGCGGACACAGGTGGTGCATGGCTGTCGTCAGCTC
GTGCCGTAAGGTGTTGGGTTAAGTCCCGCAACGAGCGCAACCCTCGTGTTTAGTTGCCAT
CGTTGAATTTGGAACCCTGAACAGACTGCCGGTGATAAGCCGGAGGAAGGTGAGGATGAC
GTCAAGTCATCATGCCCCTTATGCCCTGGGCGACACACGTGCTACAATGGCCGGGACAAA
GGGTCGCGATCTCGCGAGGGTGAGCTAACCCCAAAAACCCGTCCTCAGTTCGGATTGCAG
GCTGCAACTCGCCTGCATGAAGCCGGAATCGCTAGTAATCGCCGGTCAGCCATACGGCGG
TGAATTCGTTCCCGGGCCTTGTACACACCGCCCGTCACACTATGGGAGCTGGCCATGCCC
GAAGTCGTTACCTTAACCGCAAGGAGGGGGATGCCGAAGGCAGGGCTAGTGACTGGAGTG
AAGTCGTAACAAGGTAGCCGTACTGGAAGGTGCGGCTGGATCACCTCCTTT
</code></pre>
<p>Note that one or more regions may be specified on the command line and all position coordinates are 1-based. If the index file (i.e. <code>&lt;ref.fasta&gt;.fai</code>) doesn't exist, it will be created. If no regions are specified, <code>samtools faidx</code> will simply create the index file and exit. This is useful if you need to create the index prior to querying it. Only uncompressed FASTA files or FASTA files compressed with <a href="https://www.htslib.org/doc/bgzip.html" rel="nofollow noreferrer">bgzip</a> can be indexed.</p>
<pre><code>$ samtools faidx -h
Usage: samtools faidx &lt;file.fa|file.fa.gz&gt; [&lt;reg&gt; [...]]
Option: 
 -o, --output FILE        Write FASTA to file.
 -n, --length INT         Length of FASTA sequence line. [60]
 -c, --continue           Continue after trying to retrieve missing region.
 -r, --region-file FILE   File of regions.  Format is chr:from-to. One per line.
 -i, --reverse-complement Reverse complement sequences.
     --mark-strand TYPE   Add strand indicator to sequence name
                          TYPE = rc   for /rc on negative strand (default)
                                 no   for no strand indicator
                                 sign for (+) / (-)
                                 custom,&lt;pos&gt;,&lt;neg&gt; for custom indicator
     --fai-idx      FILE  name of the index file (default file.fa.fai).
     --gzi-idx      FILE  name of compressed file index (default file.fa.gz.gzi).
 -f, --fastq              File and index in FASTQ format.
 -h, --help               This message.
</code></pre>

CC BY-SA 4.0
2023-02-01T12:28:03.937Z
2023-02-01T23:54:05.087Z
2023-02-01T23:54:05.087Z
Steve
<p>Good morning, I study bioinformatics and I need some help with a work. I have the NCBI accession numbers for the species I want for example: NC_037078.1 and I have the specific coordinates where I need to cut them to obtain the 16s gene but I don´t know how to do it. I'm using the language shell script. Is there some way to cut the genome into one specific region?</p>

CC BY-SA 4.0
2023-02-01T11:44:51.447Z
Please [edit] your question and add some details: i) what operating system are you using? ii) is each of these genomes a single file or are they split by chromosome? iii) If a single file, are they split into chromosomes  within that file (multiple `>` headers)? iv) what regions do you want? Do you have specific coordinates? What are they? v) are the input files compressed or not?
terdon
CC BY-SA 4.0
2023-02-01T12:21:01.990Z
Please edit the question to limit it to a specific problem with enough detail to identify an adequate answer.
Community
<shell>
How do I cut a genome into one specific region?
# How do I cut a genome into one specific region?

(Asked by: username_0 on 2023-02-01)

Good morning, I study bioinformatics and I need some help with a work. I have the NCBI accession numbers for the species I want for example: NC\_037078.1 and I have the specific coordinates where I need to cut them to obtain the 16s gene but I don´t know how to do it. I'm using the language shell script. Is there some way to cut the genome into one specific region?

**Tags:** shell
> **Comments:**
> **username_1**: Please [edit] your question and add some details: i) what operating system are you using? ii) is each of these genomes a single file or are they split by chromosome? iii) If a single file, are they split into chromosomes  within that file (multiple `>` headers)? iv) what regions do you want? Do you have specific coordinates? What are they? v) are the input files compressed or not?  
> **username_2**: Please edit the question to limit it to a specific problem with enough detail to identify an adequate answer.  

---

## 1 answers

### Answer by username_3 on 2023-02-01. Score: 3

If you know the coordinates, you could just use samtools faidx to extract the corresponding subsequence from the FASTA file(s). Regions can be specified on the command line with the format: RNAME[:STARTPOS[-ENDPOS]]. For example, to extract the first ten bases from chr1 in your reference FASTA file, you would use:
samtools faidx ref.fasta chr1:1-10

Or if you wanted the whole chromosome, you would use:
samtools faidx ref.fasta chr1



With regards to your specific example, you could try:
samtools faidx NC_037078.1.fasta NC_037078.1:96630-98120

Results:
>NC_037078.1:96630-98120
TCTCATGGAGAGTTCGATCCTGGCTCAGGATGAACGCTGGCGGCATGCTTAACACATGCA
AGTCGGACGGGAAGTGGTGTTTCCAGTGGCGGACGGGTGAGTAACGCGTAAGAACCTGCC
CTTGGGAGGGGAACAACAGCTGGAAACGGCTGCTAATACCCCGTAGGCTGAGGAGCAAAA
GGAGGAATCCGCCCGAGGAGGGGCTTGCGTCTGATTAGCTAGTTGGTGAGGCAATAGCTT
ACCAAGGCGATGATCAGTAGCTGGTCCGAGAGGATGATCAGCCACACTGGGACTGAGACA
CGGCCCAGACTCCTACGGGAGGCAGCAGTGGGGAATTTTCCGCAATGGGCGAAAGCCTGA
CGGAGCAATGCCGCGTGGAGGTAGAAGGCCCACGGGTCGTGAACTTCTTTTCCCGGAGAA
GAAGCAATGACGGTATCTGGGGAATAAGCATCGGCTAACTCTGTGCCAGCAGCCGCGGTA
AGACAGAGGATGCAAGCGTTATCCGGAATGATTGGGCGTAAAGCGTCTGTAGGTGGCTTT
TTAAGTCCGCCGTCAAATCCCAGGGCTCAACCCTGGACAGGCGGTGGAAACTACCAAGCT
GGAGTACGGTAGGGGCAGAGGGAATTTCCGGTGGAGCGGTGAAATGCGTAGAGATCGGAA
AGAACACCAACGGCGAAAGCACTCTGCTGGGCCGACACTGACACTGAGAGACGAAAGCTA
GGGGAGCGAATGGGATTAGATACCCCAGTAGTCCTAGCCGTAAACGATGGATACTGGGCG
CTGTGCGTATCGACCCGTGCAGTGCTGTAGCTAACGCGTTAAGTATCCCGCCTGGGGAGT
ACGTTCGCAAGAATGAAACTCAAAGGAATTGACGGGGGCCCGCACAAGCGGTGGAGCATG
TGGTTTAATTCGATGCAAAGCGAAGAACCTTACCAGGGCTTGACATGCCGCGAATCCTTT
TGAAAGAGAGGGGTGCCTTCGGGAACGCGGACACAGGTGGTGCATGGCTGTCGTCAGCTC
GTGCCGTAAGGTGTTGGGTTAAGTCCCGCAACGAGCGCAACCCTCGTGTTTAGTTGCCAT
CGTTGAATTTGGAACCCTGAACAGACTGCCGGTGATAAGCCGGAGGAAGGTGAGGATGAC
GTCAAGTCATCATGCCCCTTATGCCCTGGGCGACACACGTGCTACAATGGCCGGGACAAA
GGGTCGCGATCTCGCGAGGGTGAGCTAACCCCAAAAACCCGTCCTCAGTTCGGATTGCAG
GCTGCAACTCGCCTGCATGAAGCCGGAATCGCTAGTAATCGCCGGTCAGCCATACGGCGG
TGAATTCGTTCCCGGGCCTTGTACACACCGCCCGTCACACTATGGGAGCTGGCCATGCCC
GAAGTCGTTACCTTAACCGCAAGGAGGGGGATGCCGAAGGCAGGGCTAGTGACTGGAGTG
AAGTCGTAACAAGGTAGCCGTACTGGAAGGTGCGGCTGGATCACCTCCTTT

Note that one or more regions may be specified on the command line and all position coordinates are 1-based. If the index file (i.e. .fai) doesn't exist, it will be created. If no regions are specified, samtools faidx will simply create the index file and exit. This is useful if you need to create the index prior to querying it. Only uncompressed FASTA files or FASTA files compressed with bgzip can be indexed.
$ samtools faidx -h
Usage: samtools faidx  [ [...]]
Option: 
 -o, --output FILE        Write FASTA to file.
 -n, --length INT         Length of FASTA sequence line. [60]
 -c, --continue           Continue after trying to retrieve missing region.
 -r, --region-file FILE   File of regions.  Format is chr:from-to. One per line.
 -i, --reverse-complement Reverse complement sequences.
     --mark-strand TYPE   Add strand indicator to sequence name
                          TYPE = rc   for /rc on negative strand (default)
                                 no   for no strand indicator
                                 sign for (+) / (-)
                                 custom,, for custom indicator
     --fai-idx      FILE  name of the index file (default file.fa.fai).
     --gzi-idx      FILE  name of compressed file index (default file.fa.gz.gzi).
 -f, --fastq              File and index in FASTQ format.
 -h, --help               This message.


---

