This is a test version of Biostars. For the public version, visit https://www.biostars.org.
get the snp sequence from dbSNP programally

How to get the sequence of snp from dbSNP/ pubmed?

For example,

http://www.ncbi.nlm.nih.gov/snp/?term=rs1173745

get the sequence:

TATTGACAAGTTTAGATTTGGGGCT[C/T]ATATTTTTTCAGTTGGGACTCCTGT

(keep the [C/T]) Thank you.

snp dbsnp

1) my answer is 4 years old, eutils has moved to HTTPS

2) "stylesheet" is, of course, the name of the xslt file.

1 answer

you can get the fasta sequence with NCBI-efetch

$ curl "http://eutils.ncbi.nlm.nih.gov/entrez/eutils/efetch.fcgi?db=snp&id=1173745&rettype=fasta"
>gnl|dbSNP|rs1173745 rs=1173745|pos=26|len=51|taxid=9606|mol="genomic"|class=snp|alleles="C/T"|build=142|suspect=?|GMAF=T:145:0.029
TATTGACAAG TTTAGATTTG GGGCT
Y
ATATTTTTTC AGTTGGGACT CCTGT

If you really want to keep the [C/T] in the sequence. Use the following XSLT stylesheet:

<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:S="http://www.ncbi.nlm.nih.gov/SNP/docsum" version="1.0">
  <xsl:output method="text"/>
  <xsl:template match="/">
    <xsl:apply-templates select="/S:ExchangeSet/S:Rs"/>
  </xsl:template>
  <xsl:template match="S:Rs">
    <xsl:text>>rs</xsl:text>
    <xsl:value-of select="@rsId"/>
    <xsl:text>
</xsl:text>
    <xsl:apply-templates select="S:Sequence"/>
    <xsl:text>
</xsl:text>
  </xsl:template>
  <xsl:template match="S:Sequence">
    <xsl:value-of select="S:Seq5"/>
    <xsl:text>[</xsl:text>
    <xsl:value-of select="S:Observed"/>
    <xsl:text>]</xsl:text>
    <xsl:value-of select="S:Seq3"/>
  </xsl:template>
</xsl:stylesheet>

usage:

$ xsltproc stylesheet "http://eutils.ncbi.nlm.nih.gov/entrez/eutils/efetch.fcgi?db=snp&id=1173745,25&retmode=xml" 

>rs1173745
TATTGACAAGTTTAGATTTGGGGCT[C/T]ATATTTTTTCAGTTGGGACTCCTGT
>rs25
TCTGTGAGCTTCTGCATGCAATCCT[A/G]TGCAATTGGAATTTGATAGTCCTTT

Pierre - is it possible to get the amino acid sequence instead?

a snp is a variation of a genomic (dna) sequence. if you just want the prediction , see tools like VEP, snpEff, etc...

I'm interested in using predicted secondary structure change due to SNPs, and it would seem like an easy way to obtain the amino acid sequence with the SNP already subbed in, rather than having to get the reference protein sequence and "parse in" the mutation myself.

Log in to answer this question.