Get the genomic sequence of the specified region of the given species

In one of the project, we need to get the genomic sequence of a specified region. In this case, I use the API by ensemble

http://rest.ensembl.org/documentation/info/sequence_region

GET sequence/region/:species/:region
Returns the genomic sequence of the specified region of the given species. Supports feature masking and expand options.

ensemble api get seq by range (example)

In my case, I need to get the human (hg19), so I can simply paste the following URL on browser to get the result:

http://grch37.rest.ensembl.org/sequence/region/human/1:100000..100200:1?content-type=text/plain

 

ensemble api get seq by range (my case)

If you have a list of range, you may write Excel Macro to help. For example, create a button and associate with the following VBA code.

After filling the chromosome and range in Colume A, B and C, and then click “Submit” button. The sequence will be shown in the Column D (Response)

ensemble api get seq by range (macro)

Sub Button1_click()
Dim i As Integer
Dim Chr, StartPos, EndPos As String
Dim responseStr As String

'Skip header row
i = 2

Do While Cells(i, 1).Value <> ""
Chr = Cells(i, 1).Value
StartPos = Cells(i, 2).Value
EndPos = Cells(i, 3).Value


URL = "http://grch37.rest.ensembl.org/sequence/region/human/" & Chr & ":" & StartPos & ".." & EndPos & ":1?content-type=text/plain"
responseStr = http(URL)
Cells(i, 4).Value = responseStr

i = i + 1
Loop

MsgBox "Done!!"
End Sub

Function http(ByVal URL) As String
Dim MyRequest As Object
Set MyRequest = CreateObject("WinHttp.WinHttpRequest.5.1")
MyRequest.Open "GET", URL
' Send Request.
MyRequest.send
'And we get this response
http = MyRequest.responseText
End Function

Hope this helps!

Leave a comment