Answers.Body: <p>Modify SNPs and gene annotations for your genome assembly of interest. This example shows how one might do this for <code>hg19</code>, for instance:</p>
  
  <ol>
  <li><p>Download SNPs and convert to BED:</p>
  
  <pre><code><span class="math-container">$ wget -qO- ftp://ftp.ncbi.nih.gov/snp/organisms/human_9606_b151_GRCh37p13/VCF/common_all_20180423.vcf.gz \
      | gunzip -c \
      | convert2bed --input=vcf --output=bed --sort-tmpdir=$</span>{PWD} - \
      &gt; hg19.snp151.bed
  </code></pre></li>
  <li><p>Filter this BED file for entries of interest:</p>
  
  <pre><code>$ grep -wFf snps-of-interest.txt hg19.snp151.bed | cut -f1-6 &gt; hg19.snp151.filtered.bed6
  </code></pre></li>
  <li><p>Download gene annotations and convert to BED:</p>
  
  <pre><code><span class="math-container">$ wget -O - ftp://ftp.ebi.ac.uk/pub/databases/gencode/Gencode_human/release_19/gencode.v19.annotation.gtf.gz \
      | gunzip -c \
      | awk '($</span>3 == "gene")' \
      | gtf2bed \
      &gt; gencode.v19.genes.bed
  </code></pre>
  
  <p><strong><em>Note</strong>: In the future, newer versions of Gencode annotations may be available for your reference assembly. Always check their site to confirm what is most recent.</em></p></li>
  <li><p>Map genes to SNPs:</p>
  
  <pre><code>$ bedmap --echo --echo-map-id hg19.snp151.filtered.bed6 gencode.v19.genes.bed &gt; snps_with_associated_gene_names.bed
  </code></pre></li>
  </ol>
  
  <p>A list of genes that overlap a SNP of interest will be in the seventh column of the output.</p>
  
  <p>If this must be done within Python, you could use something like <code>subprocess.call(...)</code>, where <code>...</code> includes commands wrapped in <code>bash -c</code>. </p>
  
  <p>I don't recommend this because of the need to escape quote marks and deal with Python's quirks in running command-line tasks, which makes a Python-based approach very difficult to set up and maintain. I'd suggest learning some basic <code>bash</code> scripting to make this easy and fast.</p>
  
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2019-08-01T09:38:24.370Z
Answers.Text: I have SNP list. Can your suggested technique be applied in Python?
Answers.UserDisplayName: studentcoder
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2019-08-01T11:46:38.143Z
Answers.Text: Maybe look into `subprocess.call()` to run command line tasks inside Python.
Answers.UserDisplayName: Alex Reynolds
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2019-07-31T21:07:35.133Z
Answers.LastActivityDate: 2019-09-03T16:58:47.307Z
Answers.LastEditDate: 2019-09-03T16:58:47.307Z
Answers.UserDisplayName: Alex Reynolds
Answers.Body: <p>Run them through the <a href="http://www.ensembl.org/info/docs/tools/vep/index.html" rel="nofollow noreferrer">Ensembl VEP</a>. You'll get the gene name and all the information about how the genes are affected by the variants.</p>
  
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2019-09-03T07:56:33.203Z
Answers.LastActivityDate: 2019-09-03T07:56:33.203Z
Answers.UserDisplayName: Emily_Ensembl
Body: <p>I found a good answer related to my question here:
  <a href="https://bioinformatics.stackexchange.com/questions/2503/how-to-get-a-list-of-genes-corresponding-to-the-list-of-snps-rs-ids">How to get a list of genes corresponding to the list of SNPs (rs ids)?</a></p>
  
  <p>But it says about small number of SNPs. I want to get gene names based on approximately 12000 to 19000 SNPs. NCBI says about 10 read per second with API key. Is there any efficient way to get gene names for thousands of SNPs? Is that database available to store locally? Any advice please?</p>
  
Comments.ContentLicense: CC BY-SA 4.0
Comments.CreationDate: 2019-07-31T12:40:09.307Z
Comments.Text: Yes, you can download the NCBI data locally, see [this page](https://www.ncbi.nlm.nih.gov/books/NBK279177/).
Comments.UserDisplayName: llrs
Tags: <gene><snp><python>
Title: How to efficiently get human gene names from NCBI based on a large list of SNPs
ThreadText: # How to efficiently get human gene names from NCBI based on a large list of SNPs
  
  (Asked by: username_0 on 2019-07-31)
  
  I found a good answer related to my question here:
  [How to get a list of genes corresponding to the list of SNPs (rs ids)?](https://bioinformatics.stackexchange.com/questions/2503/how-to-get-a-list-of-genes-corresponding-to-the-list-of-snps-rs-ids)
  
  But it says about small number of SNPs. I want to get gene names based on approximately 12000 to 19000 SNPs. NCBI says about 10 read per second with API key. Is there any efficient way to get gene names for thousands of SNPs? Is that database available to store locally? Any advice please?
  
  **Tags:** gene, snp, python
  
  > **Comments:**
  > **username_1**: Yes, you can download the NCBI data locally, see [this page](https://www.ncbi.nlm.nih.gov/books/NBK279177/).  
  
  ---
  
  ## 2 answers
  
  ### Answer by username_2 on 2019-07-31. Score: 1
  
  Modify SNPs and gene annotations for your genome assembly of interest. This example shows how one might do this for `hg19`, for instance:
  
  1. Download SNPs and convert to BED:
  
     ```
     $ wget -qO- ftp://ftp.ncbi.nih.gov/snp/organisms/human_9606_b151_GRCh37p13/VCF/common_all_20180423.vcf.gz \
         | gunzip -c \
         | convert2bed --input=vcf --output=bed --sort-tmpdir=${PWD} - \
         > hg19.snp151.bed
  
     ```
  2. Filter this BED file for entries of interest:
  
     ```
     $ grep -wFf snps-of-interest.txt hg19.snp151.bed | cut -f1-6 > hg19.snp151.filtered.bed6
  
     ```
  3. Download gene annotations and convert to BED:
  
     ```
     $ wget -O - ftp://ftp.ebi.ac.uk/pub/databases/gencode/Gencode_human/release_19/gencode.v19.annotation.gtf.gz \
         | gunzip -c \
         | awk '($3 == "gene")' \
         | gtf2bed \
         > gencode.v19.genes.bed
  
     ```
  
     ***Note***: In the future, newer versions of Gencode annotations may be available for your reference assembly. Always check their site to confirm what is most recent.
  4. Map genes to SNPs:
  
     ```
     $ bedmap --echo --echo-map-id hg19.snp151.filtered.bed6 gencode.v19.genes.bed > snps_with_associated_gene_names.bed
  
     ```
  
  A list of genes that overlap a SNP of interest will be in the seventh column of the output.
  
  If this must be done within Python, you could use something like `subprocess.call(...)`, where `...` includes commands wrapped in `bash -c`.
  
  I don't recommend this because of the need to escape quote marks and deal with Python's quirks in running command-line tasks, which makes a Python-based approach very difficult to set up and maintain. I'd suggest learning some basic `bash` scripting to make this easy and fast.
  
  > **Comments:**
  > **username_0**: I have SNP list. Can your suggested technique be applied in Python?  
  > **username_2**: Maybe look into `subprocess.call()` to run command line tasks inside Python.  
  
  ---
  
  ### Answer by username_3 on 2019-09-03. Score: 0
  
  Run them through the [Ensembl VEP](http://www.ensembl.org/info/docs/tools/vep/index.html). You'll get the gene name and all the information about how the genes are affected by the variants.
  
  
  ---
  
  