Skip to content

Commit 5c2fca6

Browse files
authored
Support id list in download_alphafolds (#35)
This does less checking than the MSA-focused variant, but integrates better with pipelines that incorporate other bioinformatic tools.
1 parent e122957 commit 5c2fca6

File tree

2 files changed

+20
-1
lines changed

2 files changed

+20
-1
lines changed

src/alphafold.jl

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,7 @@ end
7676
Query the [AlphaFold](https://alphafold.com/) API for the latest structure of `uniprotXname`.
7777
"""
7878
function query_alphafold_latest(uniprotXname)
79-
resp = HTTP.get("https://alphafold.com/api/prediction/$uniprotXname")
79+
resp = HTTP.get("https://alphafold.com/api/prediction/$uniprotXname"; status_exception = false)
8080
if resp.status == 200
8181
j = JSON3.read(String(resp.body))[1]
8282
return j["pdbUrl"]
@@ -111,9 +111,13 @@ end
111111

112112
"""
113113
download_alphafolds(msa::AbstractMultipleSequenceAlignment; dirname=pwd())
114+
download_alphafolds(ids; dirname=pwd())
114115
115116
Download all available [AlphaFold](https://alphafold.com/) structures for the sequences in `msa`.
116117
Missing entries are silently skipped.
118+
119+
If a `AbstractMultipleSequenceAlignment` is provided, the downloaded PDB file is checked to ensure that
120+
the residues in the MSA sequence match those in the PDB file. If they do not match, the PDB file is removed.
117121
"""
118122
function download_alphafolds(msa::AbstractMultipleSequenceAlignment; dirname=pwd(), maxversion=nothing, kwargs...)
119123
maxversion === nothing || @warn "`download_alphafolds`: `maxversion` kwarg has no effect and is deprecated" maxlog=1
@@ -133,6 +137,18 @@ function download_alphafolds(msa::AbstractMultipleSequenceAlignment; dirname=pwd
133137
end
134138
end
135139

140+
function download_alphafolds(ids; dirname=pwd(), kwargs...)
141+
@showprogress 1 "Downloading AlphaFold files..." for uname in ids
142+
url = query_alphafold_latest(uname)
143+
url === nothing && continue
144+
fn = split(url, '/')[end]
145+
path = joinpath(dirname, fn)
146+
if !isfile(path)
147+
Downloads.download(url, path)
148+
end
149+
end
150+
end
151+
136152
const pLDDTcolors = [ # see https://github.com/sokrypton/ColabFold?tab=readme-ov-file#faq
137153
RGB{N0f8}(0.051, 0.341, 0.827),
138154
RGB{N0f8}(0.416, 0.796, 0.945),

test/runtests.jl

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -372,6 +372,9 @@ using Test
372372
conserved_cols = findall(msaentropies .< 0.5)
373373

374374
download_alphafolds(msa; dirname=path)
375+
nfiles = length(readdir(path))
376+
download_alphafolds(["K7N701", "G3UY47"]; dirname=path)
377+
@test length(readdir(path)) == nfiles + 1
375378
msacode2structfile = alphafoldfiles(msa, path)
376379
afnbyidx(i) = getchain(joinpath(path, msacode2structfile[MSACode(sequencenames(msa)[i])]))
377380

0 commit comments

Comments
 (0)