<p>If the goal is to extract the consensus sequence for given regions, this is how it works in 2019.</p>

<p><code>bgzip</code> and index your <code>vcf</code> file.</p>

<pre><code><span class="math-container">$ bgzip -c input.vcf &gt; input.vcf.gz
$</span> tabix input.vcf.gz
</code></pre>

<p>Create a <code>regions.txt</code> which contains one region per line in the format <code>chr:from-to</code>. If you have already a <code>bed</code> file, you can use this little <code>awk</code>script to create it:</p>

<pre><code><span class="math-container">$ awk '{print $1":"$2+1"-"$</span>3}' input.bed &gt; regions.txt
</code></pre>

<p>Now run this combination of <code>samtools</code> and <code>bcftools</code>:</p>

<pre><code>$ samtools faidx -r regions.txt genome.fa|bcftools consensus input.vcf.gz -o consensus.fa
</code></pre>

CC BY-SA 4.0
2019-01-15T19:17:46.453Z
2019-01-15T19:17:46.453Z
finswimmer
<p>I think that you need a LiftOver Chain file to transform your coordinates. You can obtain such a file using <code>bcftools consensus</code> with the <code>-c</code> parameter:</p>

<pre><code>-c, --chain &lt;file&gt;         write a chain file for liftover
</code></pre>

<p>Then you can use it to transform coordinates in various genomic formats using <a href="http://crossmap.sourceforge.net/" rel="nofollow noreferrer">CrossMap</a>.</p>

CC BY-SA 3.0
2017-05-30T16:09:40.197Z
Nice, +1. It would be great if you could expand this to include an example command the OP could run, the steps needed etc. The Stack Exchange sites have very strict guidelines about what is an answer (that's why I've been bugging you so) and ideally, we want that an answer provide all the needed information to solve the question asked. In other words, please don't post pointers (not even very helpful ones like this) as answers. Either just post a comment, or flesh the pointer into a full answer.
terdon
CC BY-SA 3.0
2017-05-30T19:43:53.007Z
Maybe is just me, but his answer seems fine, even to SE standard, but it's just me.
nuin
CC BY-SA 3.0
2017-05-30T22:34:42.523Z
@nuin agreed, which is why I upvoted. I just think it would be even better with more detail, that's all.
terdon
CC BY-SA 3.0
2017-05-31T02:42:48.147Z
No hard feelings.
nuin
CC BY-SA 3.0
2017-05-30T15:23:33.850Z
2017-05-31T01:03:59.797Z
2017-05-31T01:03:59.797Z
Karel Břinda
<p>I'm interested in obtaining coding sequences of my favourite gene in all individuals from the 1000Genomes (and similar projects). I use GATK to get the right subset of variants, vcf-consensus to map these variants onto the reference genome and finally samtools to extract the individual exons. This works fine if the variants are SNPs but if there are any indels, this changes the coordinates of exons and I end up getting the wrong region. Is there any generic way of remapping genomic coordinates to account for the changes created by indels?</p>

<variation><structural-variation>
Remapping genomic coordinates to account for indels
# Remapping genomic coordinates to account for indels

(Asked by: username_0 on 2017-05-30)

I'm interested in obtaining coding sequences of my favourite gene in all individuals from the 1000Genomes (and similar projects). I use GATK to get the right subset of variants, vcf-consensus to map these variants onto the reference genome and finally samtools to extract the individual exons. This works fine if the variants are SNPs but if there are any indels, this changes the coordinates of exons and I end up getting the wrong region. Is there any generic way of remapping genomic coordinates to account for the changes created by indels?

**Tags:** variation, structural-variation

---

## 2 answers

### Answer by username_2 on 2017-05-30. Score: 8 | Accepted answer

I think that you need a LiftOver Chain file to transform your coordinates. You can obtain such a file using bcftools consensus with the -c parameter:
-c, --chain          write a chain file for liftover

Then you can use it to transform coordinates in various genomic formats using CrossMap.

> **Comments:**
> **username_3**: Nice, +1. It would be great if you could expand this to include an example command the OP could run, the steps needed etc. The Stack Exchange sites have very strict guidelines about what is an answer (that's why I've been bugging you so) and ideally, we want that an answer provide all the needed information to solve the question asked. In other words, please don't post pointers (not even very helpful ones like this) as answers. Either just post a comment, or flesh the pointer into a full answer.  
> **username_4**: Maybe is just me, but his answer seems fine, even to SE standard, but it's just me.  
> **username_3**: @nuin agreed, which is why I upvoted. I just think it would be even better with more detail, that's all.  
> **username_4**: No hard feelings.  

---

### Answer by username_1 on 2019-01-15. Score: 2

If the goal is to extract the consensus sequence for given regions, this is how it works in 2019.
bgzip and index your vcf file.
$ bgzip -c input.vcf > input.vcf.gz
$ tabix input.vcf.gz

Create a regions.txt which contains one region per line in the format chr:from-to. If you have already a bed file, you can use this little awkscript to create it:
$ awk '{print $1":"$2+1"-"$3}' input.bed > regions.txt

Now run this combination of samtools and bcftools:
$ samtools faidx -r regions.txt genome.fa|bcftools consensus input.vcf.gz -o consensus.fa


---

