11# Generates 2 captures, one for the uniprotXname and the other for the version
2- const rex_alphafold_pdbs = r" AF-([OPQ][0-9][A-Z0-9]{3}[0-9]|[A-NR-Z][0-9](?:[A-Z][A-Z0-9]{2}[0-9]){1,2})-F1-model_v(\d +).pdb"
2+ const rex_alphafold_pdbs = r" AF-([OPQ][0-9][A-Z0-9]{3}[0-9]|[A-NR-Z][0-9](?:[A-Z][A-Z0-9]{2}[0-9]){1,2})-F1-model_v(\d +).(?: pdb|cif|bcif) "
33# Make a regex for a specific uniprotXname (single capture for the version)
4- regex_alphafold_pdb (uniprotXname) = Regex (" AF-$uniprotXname -F1-model_v(\\ d+).pdb" )
4+ regex_alphafold_pdb (uniprotXname) = Regex (" AF-$uniprotXname -F1-model_v(\\ d+).(?: pdb|cif|bcif) " )
55
6- alphafoldfilename (uniprotXname; version= 4 ) = " AF-$uniprotXname -F1-model_v$version .pdb "
6+ alphafoldfilename (uniprotXname; ext = " pdb " , version= 4 ) = " AF-$uniprotXname -F1-model_v$version .$ext "
77
88"""
99 fns = alphafoldfile(uniprotXname, dirname=pwd(); join=false)
@@ -13,16 +13,17 @@ If `join` is `true`, then the full path is returned.
1313"""
1414function alphafoldfile (uniprotXname:: AbstractString , dirname= pwd (); join:: Bool = false )
1515 rex = regex_alphafold_pdb (uniprotXname)
16- lv = 0
16+ fnv, lv = " " , 0
1717 for fn in readdir (dirname)
1818 m = match (rex, fn)
1919 m === nothing && continue
2020 v = parse (Int, only (m. captures))
21- lv = max (lv, v)
21+ if v > lv
22+ fnv, lv = fn, v
23+ end
2224 end
2325 lv == 0 && return nothing
24- fn = alphafoldfilename (uniprotXname; version= lv)
25- return join ? joinpath (dirname, fn) : fn
26+ return join ? joinpath (dirname, fnv) : fnv
2627end
2728
2829"""
@@ -33,6 +34,7 @@ If `join` is `true`, then the full paths are returned.
3334"""
3435function alphafoldfiles (dirname= pwd (); join:: Bool = false )
3536 latest = Dict {String,Int} ()
37+ latestfn = Dict {String,String} ()
3638 for fn in readdir (dirname)
3739 m = match (rex_alphafold_pdbs, fn)
3840 m === nothing && continue
@@ -41,9 +43,10 @@ function alphafoldfiles(dirname=pwd(); join::Bool=false)
4143 lv = get (latest, access_code, 0 )
4244 if v > lv
4345 latest[access_code] = v
46+ latestfn[access_code] = fn
4447 end
4548 end
46- fns = sort! ([ alphafoldfilename (access_code; version = v) for (access_code, v) in latest] )
49+ fns = sort! (collect ( values (latestfn)) )
4750 return join ? [joinpath (dirname, fn) for fn in fns] : fns
4851end
4952
@@ -71,18 +74,20 @@ function alphafoldfiles(msa::AnnotatedMultipleSequenceAlignment, dirname=pwd();
7174end
7275
7376"""
74- url = query_alphafold_latest(uniprotXname)
77+ url = query_alphafold_latest(uniprotXname; format="cif" )
7578
7679Query the [AlphaFold](https://alphafold.com/) API for the latest structure of `uniprotXname`.
80+ `format` should be "cif", "pdb", or "bcif".
7781"""
78- function query_alphafold_latest (uniprotXname)
79- resp = HTTP. get (" https://alphafold.com/api/prediction/$uniprotXname " ; status_exception = false )
82+ function query_alphafold_latest (uniprotXname:: AbstractString ; format = " cif " )
83+ resp = HTTP. get (" https://alphafold.com/api/prediction/$uniprotXname ?key=AIzaSyCeurAJz7ZGjPQUtEaerUkBZ3TaBkXrY94 " , [ " Accept " => " application/json " ] ; status_exception = false )
8084 if resp. status == 200
8185 j = JSON3. read (String (resp. body))[1 ]
82- return j[" pdbUrl " ]
86+ return j[" $(format) Url " ]
8387 end
8488 return nothing
8589end
90+ query_alphafold_latest (uniprotXname; kwargs... ) = query_alphafold_latest (String (uniprotXname):: String ; kwargs... )
8691
8792"""
8893 try_download_alphafold(uniprotXname, path=alphafoldfilename(uniprotXname); version=4)
@@ -95,7 +100,8 @@ In general, a better approach is to use [`download_alphafolds`](@ref) for multip
95100or [`query_alphafold_latest`](@ref) combined with `Downloads.download` for a single protein.
96101"""
97102function try_download_alphafold (uniprotXname:: AbstractString , path:: AbstractString = alphafoldfilename (uniprotXname); kwargs... )
98- fn = alphafoldfilename (uniprotXname; kwargs... )
103+ ext = splitext (path)[2 ][2 : end ] # remove the leading dot
104+ fn = alphafoldfilename (uniprotXname; ext, kwargs... )
99105 isfile (path) && return path
100106 try
101107 Downloads. download (" https://alphafold.ebi.ac.uk/files/$fn " , path)
0 commit comments