Skip to content

Commit

Permalink
Get tests passing (#20)
Browse files Browse the repository at this point in the history
Now that alignments are back on Interpro, we can fix errors in the new
implementions.
  • Loading branch information
timholy committed May 30, 2024
1 parent aa6125f commit 2ff90e3
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 13 deletions.
7 changes: 4 additions & 3 deletions src/alphafold.jl
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ alphafoldfilename(uniprotXname; version=4) = "AF-$uniprotXname-F1-model_v$versio
Return the latest version of the AlphaFold file for `uniprotXname` in `dirname`.
If `join` is `true`, then the full path is returned.
"""
function alphafoldfile(uniprotXname, dirname=pwd(); join::Bool=false)
function alphafoldfile(uniprotXname::AbstractString, dirname=pwd(); join::Bool=false)
rex = regex_alphafold_pdb(uniprotXname)
lv = 0
for fn in readdir(dirname)
Expand Down Expand Up @@ -52,7 +52,7 @@ end
Return a dictionary mapping `MSACode`s to the corresponding AlphaFold structure files.
"""
function alphafoldfiles(msa::AnnotatedMultipleSequenceAlignment, dirname=pwd())
function alphafoldfiles(msa::AnnotatedMultipleSequenceAlignment, dirname=pwd(); join::Bool=false)
afs = alphafoldfiles(dirname)
accesscode2idx = Dict{AccessionCode,Int}()
for (i, af) in pairs(afs)
Expand All @@ -63,7 +63,8 @@ function alphafoldfiles(msa::AnnotatedMultipleSequenceAlignment, dirname=pwd())
for name in sequencenames(msa)
ac = AccessionCode(msa, name)
if haskey(accesscode2idx, ac)
msacode2structfile[MSACode(name)] = afs[accesscode2idx[ac]]
fn = afs[accesscode2idx[ac]]
msacode2structfile[MSACode(name)] = join ? joinpath(dirname, fn) : fn
end
end
return msacode2structfile
Expand Down
8 changes: 4 additions & 4 deletions src/chimerax.jl
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ function chimerax_script(scriptfilename, struct_filenames, ridxs::AbstractVector
end
end
if isa(extras, AbstractString)
println(io, extras)
println(io, extras)
else
for ex in extras
println(io, ex)
Expand Down Expand Up @@ -68,12 +68,12 @@ function chimerax_script(scriptfilename, uprot_list, msa::AnnotatedMultipleSeque
ridxs = [Int[] for _ in 1:length(uprot_list)]
struct_filenames = Vector{String}(undef, length(uprot_list))
rcstyles = Dict{Tuple{Int,Int},String}()
afs = alphafoldfile(msa, dir; join=true)
afs = alphafoldfiles(msa, dir; join=true)
uprot2msaidx = Dict{AccessionCode,Int}(AccessionCode(msa, name) => i for (i, name) in enumerate(sequencenames(msa)))
for (i, p) in enumerate(uprot_list)
j = uprot2msaidx[AccessionCode(p)]
struct_filenames[i] = afs[MSACode(sequencenames(msa, j))]
sm = getsequencemapping(msa, seqidx)
struct_filenames[i] = afs[MSACode(sequencenames(msa)[j])]
sm = getsequencemapping(msa, j)
for (j, c) in enumerate(colidxs)
ridx = sm[c]
if iszero(ridx)
Expand Down
12 changes: 6 additions & 6 deletions test/runtests.jl
Original file line number Diff line number Diff line change
Expand Up @@ -285,7 +285,7 @@ using Test
msacode2structfile = alphafoldfiles(msa, path)
afnbyidx(i) = getchain(joinpath(path, msacode2structfile[MSACode(sequencenames(msa)[i])]))

c1, c2 = getchain(afnbyidx(1)), getchain(afnbyidx(5))
c1, c2 = afnbyidx(1), afnbyidx(5)
conserved_residues = c1[SequenceMapping(getsequencemapping(msa, 1))[conserved_cols]]
badidx = findall(==(nothing), conserved_residues)
conserved_residues = convert(Vector{PDBResidue}, conserved_residues[Not(badidx)])
Expand All @@ -305,7 +305,7 @@ using Test
# Choose a sufficiently-divergent pair that structural alignment is nontrivial
idxref = findfirst(str -> startswith(str, "K7N701"), sequencenames(msa))
idxcmp = findfirst(str -> startswith(str, "K7N778"), sequencenames(msa))
cref, ccmp = getchain(afnbyidx(idxref)), getchain(afnbyidx(idxcmp))
cref, ccmp = afnbyidx(idxref), afnbyidx(idxcmp)
sa = StructAlign(cref, ccmp, joinpath(@__DIR__, "tmalign.txt"))
@test !ismapped(sa, 1, nothing)
@test ismapped(sa, 11, nothing)
Expand Down Expand Up @@ -335,11 +335,11 @@ using Test
@test length(setdiff(idxclose, sa.m2.a2s)) < 0.05 * length(idxclose) # almost same as TMalign

chimerafile = tempname() * ".cxc"
chimerax_script(chimerafile, ["K7N775", "K7N731"], msa, [66, 69]; dir="somedir")
chimerax_script(chimerafile, ["K7N775", "K7N731"], msa, [66, 69]; dir=path)
script = read(chimerafile, String)
@test occursin("open somedir/AF-K7N775", script)
@test occursin("open somedir/AF-K7N731", script)
@test !occursin("open somedir/AF-K7N701", script)
@test occursin("open $path/AF-K7N775", script)
@test occursin("open $path/AF-K7N731", script)
@test !occursin("open $path/AF-K7N701", script)
@test occursin("show #1 :67", script)
@test occursin("show #1 :70", script)
@test occursin("show #2 :70", script)
Expand Down

0 comments on commit 2ff90e3

Please sign in to comment.