<p>You can use <a href="https://www.well.ox.ac.uk/%7Egav/qctool_v2/" rel="nofollow noreferrer">qctool</a> for this. If you create a list of IDs in <code>list.txt</code> (one ID per line), you can filter the .bgen file(s) by running</p>
<pre><code> qctool -g yourdata.bgen -s yourdata.sample -incl-samples list.txt -og yourdata_filtered.bgen

</code></pre>

CC BY-SA 4.0
2021-12-09T20:16:00.303Z
what does .sample file contain?
serenaarez
CC BY-SA 4.0
2021-12-09T20:27:14.363Z
It's a type of file in the Oxford format that usually contains IDs, missingness, sex, and other covariates (similar to a plink's .fam file). More info here: https://www.well.ox.ac.uk/~gav/qctool/documentation/sample_file_formats.html
Giulio Centorame
CC BY-SA 4.0
2021-12-10T11:28:44.470Z
so in my .sample file do i only need the ids that need to be extracted or all the ids present in the .bgen file?
serenaarez
CC BY-SA 4.0
2021-12-10T11:35:40.717Z
the order of the ids must be the same as in the genotype file, how can i know the order in the genotype files?
serenaarez
CC BY-SA 4.0
2021-12-10T16:51:27.107Z
You should have a .sample file together with the BGEN data already. If you don't, it might be worth checking with who provided the data in the first place, since you can technically obtain one from the BGEN file but it's a laborious process.
Giulio Centorame
CC BY-SA 4.0
2021-12-10T16:52:46.740Z
It might not have the extension .sample, but it should be a plain text file with multiple columns structured as above
Giulio Centorame
CC BY-SA 4.0
2021-12-09T16:04:27.803Z
2021-12-09T16:04:27.803Z
Giulio Centorame
<p>I have 10,000 controls and 3000 cases and the .bgen file has genotype of 200,000 individuals. I would like to extract only those individuals from the .bgen file that are either cases or controls using plink for downstream analyses. How can i do that?</p>

<file-formats><plink><filtering>
How to extract a subset of individuals from a .bgen file?
# How to extract a subset of individuals from a .bgen file?

(Asked by: username_0 on 2021-12-08)

I have 10,000 controls and 3000 cases and the .bgen file has genotype of 200,000 individuals. I would like to extract only those individuals from the .bgen file that are either cases or controls using plink for downstream analyses. How can i do that?

**Tags:** file-formats, plink, filtering

---

## 1 answers

### Answer by username_1 on 2021-12-09. Score: 2

You can use qctool for this. If you create a list of IDs in list.txt (one ID per line), you can filter the .bgen file(s) by running
 qctool -g yourdata.bgen -s yourdata.sample -incl-samples list.txt -og yourdata_filtered.bgen

> **Comments:**
> **username_0**: what does .sample file contain?  
> **username_1**: It's a type of file in the Oxford format that usually contains IDs, missingness, sex, and other covariates (similar to a plink's .fam file). More info here: https://www.well.ox.ac.uk/~gav/qctool/documentation/sample_file_formats.html  
> **username_0**: so in my .sample file do i only need the ids that need to be extracted or all the ids present in the .bgen file?  
> **username_0**: the order of the ids must be the same as in the genotype file, how can i know the order in the genotype files?  
> **username_1**: You should have a .sample file together with the BGEN data already. If you don't, it might be worth checking with who provided the data in the first place, since you can technically obtain one from the BGEN file but it's a laborious process.  
> **username_1**: It might not have the extension .sample, but it should be a plain text file with multiple columns structured as above  

---

