<p>There are two different kinds of <code>.bed</code> files in bioinformatics; one related to storing <a href="https://en.wikipedia.org/wiki/BED_(file_format)" rel="nofollow noreferrer">genomic coordinate data</a> and one which is part of the <a href="https://www.cog-genomics.org/plink/1.9/formats#bed" rel="nofollow noreferrer">plink binary dataset</a>, so it's important to check which kind of file you are actually converting. If you have <code>.bed</code>, <code>.bim</code> and <code>.fam</code> files, you could use <a href="https://www.cog-genomics.org/plink/2.0/" rel="nofollow noreferrer">PLINK 2.0</a> to export them as VCF:</p>
<pre><code>plink2 --bfile [prefix] --export vcf --out &lt;prefix&gt;
</code></pre>
<p>The relevant options from the docs:</p>
<pre><code>&lt;...&gt;

  --bfile  &lt;prefix&gt; ['vzs'] : Specify .bed + .bim[.zst] + .fam prefix

&lt;...&gt;

  --out &lt;prefix&gt;     : Specify prefix for output files.

&lt;...&gt;

  --export &lt;output format(s)...&gt; [{01 | 12}] ['bgz'] ['id-delim='&lt;char&gt;]
           ['id-paste='&lt;column set descriptor&gt;] ['include-alt']
           ['omit-nonmale-y'] ['spaces'] ['vcf-dosage='&lt;field&gt;] ['ref-first']
           ['bits='&lt;#&gt;] ['sample-v2']
    Create a new fileset with all filters applied.  The following output
    formats are supported:

...

    * 'vcf',     : VCF (default version 4.3).  If PAR1 and PAR2 are present,
      'vcf-4.2',   they are automatically merged with chrX, with proper
      'bcf',       handling of chromosome codes and male ploidy.
      'bcf-4.2'    When the 'bgz' modifier is present, the VCF file is
                   block-gzipped.  (This always happens with BCF output.)
                   The 'id-paste' modifier controls which .psam columns are
                   used to construct sample IDs (choices are maybefid, fid,
                   iid, maybesid, and sid; default is maybefid,iid,maybesid),
                   while the 'id-delim' modifier sets the character between the
                   ID pieces (default '_').

...
</code></pre>

CC BY-SA 4.0
2022-12-17T09:57:10.497Z
+1, but it's probably best to use plink2 for this, I think it's much quicker and can handle some different kind of variants I think.
user438383
CC BY-SA 4.0
2022-12-17T14:00:25.883Z
Oh wow. I've never worked with PLINK so this is news to me. Why in the world would they call their format "bed"? That's just...
terdon
CC BY-SA 4.0
2022-12-18T11:08:46.440Z
@user438383 Updated, thanks!
Steve
CC BY-SA 4.0
2022-12-18T11:51:39.077Z
@terdon as an experienced bioinformatician this shouldn’t surprise you :)
user438383
CC BY-SA 4.0
2022-12-17T02:13:38.100Z
2022-12-18T11:06:56.587Z
2022-12-18T11:06:56.587Z
Steve
<p>I have some .bed files (and .bim and .fam files) containing data for a number of different samples, and I need to convert them to .vcf.</p>
<p>I've found <a href="https://www.rdocumentation.org/packages/bedr/versions/1.0.7/topics/bed2vcf" rel="nofollow noreferrer"><code>bed2vcf</code> which is from the <code>bedr</code> R package</a>, and also available as a stand-alone python program of the same name, but it requires a .fasta file corresponding to the reference genome used to create the .bed file. So we need to know what genome reference build was used to get the right <code>.fasta</code>.</p>
<p><strong>Question</strong> Is there any tool or way to inspect the files I have and determine what genome reference build is required to do a correct conversion to .vcf, or is there any other method?</p>
<p>There is a <code>bed2vcf</code> related post <a href="https://stackoverflow.com/questions/63306507/convert-bed-file-to-vcf-with-bed2vcf-function">here</a>.</p>

CC BY-SA 4.0
2022-12-16T21:18:51.400Z
Please clarify your specific problem or provide additional details to highlight exactly what you need. As it's currently written, it's hard to tell exactly what you're asking.
Community
CC BY-SA 4.0
2022-12-17T09:53:21.137Z
So it seems like you've (very reasonably) got confused between the two different types of bed file - one of them is used to store [genomic coordinate data](https://en.wikipedia.org/wiki/BED_(file_format)) and then one is used as part of the plink data set. You want the latter, but I function you used is for the former. Annoying I know...
user438383
<ngs><fasta><vcf><bed>
Need to convert .bed to .vcf. Can the reference build (and necessary .fasta) be determined for a .bed file?
# Need to convert .bed to .vcf. Can the reference build (and necessary .fasta) be determined for a .bed file?

(Asked by: username_0 on 2022-12-16)

I have some .bed files (and .bim and .fam files) containing data for a number of different samples, and I need to convert them to .vcf.

I've found [`bed2vcf` which is from the `bedr` R package](https://www.rdocumentation.org/packages/bedr/versions/1.0.7/topics/bed2vcf), and also available as a stand-alone python program of the same name, but it requires a .fasta file corresponding to the reference genome used to create the .bed file. So we need to know what genome reference build was used to get the right `.fasta`.

**Question** Is there any tool or way to inspect the files I have and determine what genome reference build is required to do a correct conversion to .vcf, or is there any other method?

There is a `bed2vcf` related post [here](https://stackoverflow.com/questions/63306507/convert-bed-file-to-vcf-with-bed2vcf-function).

**Tags:** ngs, fasta, vcf, bed
> **Comments:**
> **username_1**: Please clarify your specific problem or provide additional details to highlight exactly what you need. As it's currently written, it's hard to tell exactly what you're asking.  
> **username_2**: So it seems like you've (very reasonably) got confused between the two different types of bed file - one of them is used to store [genomic coordinate data](https://en.wikipedia.org/wiki/BED_(file_format)) and then one is used as part of the plink data set. You want the latter, but I function you used is for the former. Annoying I know...  

---

## 1 answers

### Answer by username_3 on 2022-12-17. Score: 2 | Accepted answer

There are two different kinds of .bed files in bioinformatics; one related to storing genomic coordinate data and one which is part of the plink binary dataset, so it's important to check which kind of file you are actually converting. If you have .bed, .bim and .fam files, you could use PLINK 2.0 to export them as VCF:
plink2 --bfile [prefix] --export vcf --out 

The relevant options from the docs:
<...>

  --bfile   ['vzs'] : Specify .bed + .bim[.zst] + .fam prefix

<...>

  --out      : Specify prefix for output files.

<...>

  --export  [{01 | 12}] ['bgz'] ['id-delim=']
           ['id-paste='] ['include-alt']
           ['omit-nonmale-y'] ['spaces'] ['vcf-dosage='] ['ref-first']
           ['bits='<#>] ['sample-v2']
    Create a new fileset with all filters applied.  The following output
    formats are supported:

...

    * 'vcf',     : VCF (default version 4.3).  If PAR1 and PAR2 are present,
      'vcf-4.2',   they are automatically merged with chrX, with proper
      'bcf',       handling of chromosome codes and male ploidy.
      'bcf-4.2'    When the 'bgz' modifier is present, the VCF file is
                   block-gzipped.  (This always happens with BCF output.)
                   The 'id-paste' modifier controls which .psam columns are
                   used to construct sample IDs (choices are maybefid, fid,
                   iid, maybesid, and sid; default is maybefid,iid,maybesid),
                   while the 'id-delim' modifier sets the character between the
                   ID pieces (default '_').

...

> **Comments:**
> **username_2**: +1, but it's probably best to use plink2 for this, I think it's much quicker and can handle some different kind of variants I think.  
> **username_4**: Oh wow. I've never worked with PLINK so this is news to me. Why in the world would they call their format "bed"? That's just...  
> **username_3**: @user438383 Updated, thanks!  
> **username_2**: @terdon as an experienced bioinformatician this shouldn’t surprise you :)  

---

