Skip to content

Commit

Permalink
Support the Uniprot mapping REST API (#28)
Browse files Browse the repository at this point in the history
  • Loading branch information
timholy authored Aug 28, 2024
1 parent 4efd19d commit 40b200d
Show file tree
Hide file tree
Showing 2 changed files with 62 additions and 0 deletions.
50 changes: 50 additions & 0 deletions src/naming_conventions.jl
Original file line number Diff line number Diff line change
Expand Up @@ -99,3 +99,53 @@ function query_uniprot_accession(id)
end
return nothing
end

"""
jobID = GPCRAnalysis.map_uniprot_submit(ids, from, to="UniProtKB")
Submit a list of `ids` to the Uniprot ID mapping service, to convert from ID convention `from` to `to`.
The jobID can be used to check the status (`map_uniprot_status`) and retrieve the results (`map_uniprot_retrieve`).
# Examples
```jldoctest`
julia> jobID = GPCRAnalysis.map_uniprot_submit(["ENSMUSG00000067064", "ENSMUSG00000057464"], "Ensembl");
```
"""
function map_uniprot_submit(ids::AbstractString, from::AbstractString, to::AbstractString="UniProtKB")
resp = HTTP.post("https://rest.uniprot.org/idmapping/run", [],
Dict("from" => from, "to" => "UniProtKB", "ids" => ids))
if resp.status == 200
return JSON3.read(String(resp.body))["jobId"]
end
return nothing
end
map_uniprot_submit(ids::AbstractVector, from::AbstractString) = map_uniprot_submit(join(ids, ','), from)

"""
status = GPCRAnalysis.map_uniprot_status(jobId)
Check the status of a Uniprot ID mapping job. Returns `true` if the results are
ready. Otherwise, returns the status object.
"""
function map_uniprot_status(jobId)
resp = HTTP.get("https://rest.uniprot.org/idmapping/status/$jobId", ["Accept" => "application/json"])
if resp.status == 200
status = JSON3.read(String(HTTP.decode(resp)))
haskey(status, "results") && return true
return status
end
return nothing
end

"""
result = GPCRAnalysis.map_uniprot_retrieve(jobId)
Retrieve the results of a Uniprot ID mapping job.
"""
function map_uniprot_retrieve(jobId)
resp = HTTP.get("https://rest.uniprot.org/idmapping/stream/$jobId", ["Accept" => "application/json"])
if resp.status == 200
return JSON3.read(String(HTTP.decode(resp)))
end
return nothing
end
12 changes: 12 additions & 0 deletions test/runtests.jl
Original file line number Diff line number Diff line change
Expand Up @@ -296,6 +296,18 @@ using Test
if !isdefined(@__MODULE__, :skip_download) || !skip_download
@testset "Uniprot" begin
@test query_uniprot_accession("T2R38_MOUSE") == "Q7TQA6"

jobID = GPCRAnalysis.map_uniprot_submit(["ENSMUSG00000067064", "ENSMUSG00000057464"], "Ensembl")
tstart = time()
sleep(1)
status = false
while status != true && time() < tstart + 20
sleep(1)
status = GPCRAnalysis.map_uniprot_status(jobID)
end
results = GPCRAnalysis.map_uniprot_retrieve(jobID)[:results]
resultsdict = Dict(obj["from"] => obj["to"] for obj in results)
@test resultsdict["ENSMUSG00000067064"] == "Q8VGU4"
end

@testset "EBI and NCBI" begin
Expand Down

0 comments on commit 40b200d

Please sign in to comment.