Answers.Body: <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>
  
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2021-12-09T20:16:00.303Z
Answers.Text: what does .sample file contain?
Answers.UserDisplayName: serenaarez
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2021-12-09T20:27:14.363Z
Answers.Text: 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
Answers.UserDisplayName: Giulio Centorame
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2021-12-10T11:28:44.470Z
Answers.Text: 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?
Answers.UserDisplayName: serenaarez
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2021-12-10T11:35:40.717Z
Answers.Text: the order of the ids must be the same as in the genotype file, how can i know the order in the genotype files?
Answers.UserDisplayName: serenaarez
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2021-12-10T16:51:27.107Z
Answers.Text: 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.
Answers.UserDisplayName: Giulio Centorame
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2021-12-10T16:52:46.740Z
Answers.Text: It might not have the extension .sample, but it should be a plain text file with multiple columns structured as above
Answers.UserDisplayName: Giulio Centorame
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2021-12-09T16:04:27.803Z
Answers.LastActivityDate: 2021-12-09T16:04:27.803Z
Answers.UserDisplayName: Giulio Centorame
Body: <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>
  
Tags: <file-formats><plink><filtering>
Title: How to extract a subset of individuals from a .bgen file?
ThreadText: # 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](https://www.well.ox.ac.uk/%7Egav/qctool_v2/) 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  
  
  ---
  
  