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
7679Query the [AlphaFold](https://alphafold.com/) API for the latest structure of `uniprotXname`.
7780`format` should be "cif", "pdb", or "bcif".
7881"""
79- function query_alphafold_latest (uniprotXname; format= " cif" )
82+ function query_alphafold_latest (uniprotXname:: AbstractString ; format= " cif" )
8083 resp = HTTP. get (" https://alphafold.com/api/prediction/$uniprotXname ?key=AIzaSyCeurAJz7ZGjPQUtEaerUkBZ3TaBkXrY94" , [" Accept" => " application/json" ]; status_exception = false )
8184 if resp. status == 200
8285 j = JSON3. read (String (resp. body))[1 ]
8386 return j[" $(format) Url" ]
8487 end
8588 return nothing
8689end
90+ query_alphafold_latest (uniprotXname; kwargs... ) = query_alphafold_latest (String (uniprotXname):: String ; kwargs... )
8791
8892"""
8993 try_download_alphafold(uniprotXname, path=alphafoldfilename(uniprotXname); version=4)
@@ -96,7 +100,8 @@ In general, a better approach is to use [`download_alphafolds`](@ref) for multip
96100or [`query_alphafold_latest`](@ref) combined with `Downloads.download` for a single protein.
97101"""
98102function try_download_alphafold (uniprotXname:: AbstractString , path:: AbstractString = alphafoldfilename (uniprotXname); kwargs... )
99- fn = alphafoldfilename (uniprotXname; kwargs... )
103+ ext = splitext (path)[2 ][2 : end ] # remove the leading dot
104+ fn = alphafoldfilename (uniprotXname; ext, kwargs... )
100105 isfile (path) && return path
101106 try
102107 Downloads. download (" https://alphafold.ebi.ac.uk/files/$fn " , path)
0 commit comments