Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 13 additions & 10 deletions src/naming_conventions.jl
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,9 @@ julia> uniprotX("Q8VGW6_MOUSE/31-308")
```
"""
function uniprotX(name::AbstractString)::AbstractString
if startswith(name, "tr|") || startswith(name, "sp|")
name = name[4:end]
end
m = match(rex_uniprotX_Swiss, name)
m !== nothing && return m.captures[1]
m = match(rex_uniprot_accession, name)
Expand Down Expand Up @@ -101,7 +104,7 @@ function query_uniprot_accession(id)
end

"""
jobID = GPCRAnalysis.map_uniprot_submit(ids, from, to="UniProtKB")
jobID = GPCRAnalysis.map_uniprot_submit(ids, from="UniProtKB_AC-ID", 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`).
Expand All @@ -111,24 +114,24 @@ The jobID can be used to check the status (`map_uniprot_status`) and retrieve th
julia> jobID = GPCRAnalysis.map_uniprot_submit(["ENSMUSG00000067064", "ENSMUSG00000057464"], "Ensembl");
```
"""
function map_uniprot_submit(ids::AbstractString, from::AbstractString, to::AbstractString="UniProtKB")
function map_uniprot_submit(ids::AbstractString, from::AbstractString="UniProtKB_AC-ID", to::AbstractString="UniProtKB")
resp = HTTP.post("https://rest.uniprot.org/idmapping/run", [],
Dict("from" => from, "to" => "UniProtKB", "ids" => ids))
Dict("from" => from, "to" => to, "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)
map_uniprot_submit(ids::AbstractVector, args...) = map_uniprot_submit(join(ids, ','), args...)

"""
status = GPCRAnalysis.map_uniprot_status(jobId)
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"])
function map_uniprot_status(jobID)
resp = HTTP.get("https://rest.uniprot.org/idmapping/status/$jobID", ["Accept" => "application/json"]; decompress = true)
if resp.status == 200
status = JSON3.read(String(HTTP.decode(resp)))
haskey(status, "results") && return true
Expand All @@ -138,12 +141,12 @@ function map_uniprot_status(jobId)
end

"""
result = GPCRAnalysis.map_uniprot_retrieve(jobId)
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"])
function map_uniprot_retrieve(jobID)
resp = HTTP.get("https://rest.uniprot.org/idmapping/stream/$jobID", ["Accept" => "application/json"]; decompress = true)
if resp.status == 200
return JSON3.read(String(HTTP.decode(resp)))
end
Expand Down
16 changes: 16 additions & 0 deletions test/runtests.jl
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,8 @@ using Test
@test_throws ErrorException uniprotX("Q8VGW67_MOUSE/31-308")
@test_throws ErrorException uniprotX("q8vgw6_MOUSE/31-308")
@test_throws ErrorException uniprotX("QV8GW6_MOUSE/31-308")
# FASTA
@test @inferred(uniprotX("tr|M3WEA8|M3WEA8_FELCA Olfactory receptor family 51 subfamily S member 1 OS=Felis catus OX=9685 GN=OR51S1 PE=4 SV=2")) == "M3WEA8"

# Versioned
@test uniprotX("Q8VGW6.37") == "Q8VGW6"
Expand Down Expand Up @@ -299,6 +301,18 @@ using Test
@testset "Uniprot" begin
@test query_uniprot_accession("T2R38_MOUSE") == "Q7TQA6"

jobID = GPCRAnalysis.map_uniprot_submit(["T2R38_MOUSE"])
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["T2R38_MOUSE"] == "Q7TQA6"

jobID = GPCRAnalysis.map_uniprot_submit(["ENSMUSG00000067064", "ENSMUSG00000057464"], "Ensembl")
tstart = time()
sleep(1)
Expand All @@ -310,6 +324,8 @@ using Test
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
Loading