Answers.Body: <p>If you want to do GWAS or mendelian randomisation, you can do it with <a href="https://www.cog-genomics.org/plink/2.0/" rel="nofollow noreferrer">Plink</a> (v2) which should be faster than R.  </p>
  
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2019-03-27T15:15:33.530Z
Answers.LastActivityDate: 2019-03-27T15:15:33.530Z
Answers.UserDisplayName: Oka
Body: <p>I have a vcf file with individual level genetic data, that I read using the R package <code>vcfR</code> </p>
  
  <pre><code>gen &lt;- read.vcfR('test.vcf')
  
  Scanning file to determine attributes.
  File attributes:
    meta lines: 9
    header_line: 10
    variant count: 152
    column count: 3798
  Meta line 9 read in.
  All meta lines processed.
  gt matrix initialized.
  Character matrix gt created.
    Character matrix gt rows: 152
    Character matrix gt cols: 3798
    skip: 0
    nrows: 153
    row_num: 0
  Processed variant: 153
  All variants processed
  </code></pre>
  
  <p>How do I convert this file to a data frame that I can use for a GWAS or Mendelian Randomization study?</p>
  
  <p>I was told that this should be a data frame where each column is a genetic variant and it take values 0, 1, or 2, depending on the number of "mutations".</p>
  
  <p>I never worked with genetic data before and do not know much about genetics.</p>
  
Comments.ContentLicense: CC BY-SA 4.0
Comments.CreationDate: 2019-03-26T16:35:13.820Z
Comments.Text: Welcome to Bioinformatics.StackExchange! GWAS is a broad area, and there are numerous tools you could use. The format of your data will depend on which tool you are using, and hopefully this will be clearly documented in the tool's manual. If on the other hand you're trying to implement your own tool, you'll have to be much more specific about what you want (or are required) to accomplish.
Comments.UserDisplayName: Daniel Standage
Comments.ContentLicense: CC BY-SA 4.0
Comments.CreationDate: 2019-03-26T16:57:09.153Z
Comments.Text: Welcome to the site! Could you please explain what have you tried? For instance, what happens if you use `as(gen, "data.frame")`?
Comments.UserDisplayName: llrs
Comments.ContentLicense: CC BY-SA 4.0
Comments.CreationDate: 2019-03-27T07:59:21.133Z
Comments.Text: I found that I can use `extract.gt`, then transform the matrix. Entries in this matrix are "0/0", "0/1", "1/0", and "1/1". I now have to recode these to 0, 1, 1, 2.
Comments.UserDisplayName: spore234
Tags: <r><vcf><gwas><data-management>
Title: how do I convert a vcf file for a GWAS study (using R package vcfR)
ThreadText: # how do I convert a vcf file for a GWAS study (using R package vcfR)
  
  (Asked by: username_0 on 2019-03-26)
  
  I have a vcf file with individual level genetic data, that I read using the R package `vcfR`
  
  ```
  gen <- read.vcfR('test.vcf')
  
  Scanning file to determine attributes.
  File attributes:
    meta lines: 9
    header_line: 10
    variant count: 152
    column count: 3798
  Meta line 9 read in.
  All meta lines processed.
  gt matrix initialized.
  Character matrix gt created.
    Character matrix gt rows: 152
    Character matrix gt cols: 3798
    skip: 0
    nrows: 153
    row_num: 0
  Processed variant: 153
  All variants processed
  
  ```
  
  How do I convert this file to a data frame that I can use for a GWAS or Mendelian Randomization study?
  
  I was told that this should be a data frame where each column is a genetic variant and it take values 0, 1, or 2, depending on the number of "mutations".
  
  I never worked with genetic data before and do not know much about genetics.
  
  **Tags:** r, vcf, gwas, data-management
  
  > **Comments:**
  > **username_1**: Welcome to Bioinformatics.StackExchange! GWAS is a broad area, and there are numerous tools you could use. The format of your data will depend on which tool you are using, and hopefully this will be clearly documented in the tool's manual. If on the other hand you're trying to implement your own tool, you'll have to be much more specific about what you want (or are required) to accomplish.  
  > **username_2**: Welcome to the site! Could you please explain what have you tried? For instance, what happens if you use `as(gen, "data.frame")`?  
  > **username_0**: I found that I can use `extract.gt`, then transform the matrix. Entries in this matrix are "0/0", "0/1", "1/0", and "1/1". I now have to recode these to 0, 1, 1, 2.  
  
  ---
  
  ## 1 answers
  
  ### Answer by username_3 on 2019-03-27. Score: 3
  
  If you want to do GWAS or mendelian randomisation, you can do it with [Plink](https://www.cog-genomics.org/plink/2.0/) (v2) which should be faster than R.
  
  
  ---
  
  