Skip to content

Commit

Permalink
Document and complete one_topology
Browse files Browse the repository at this point in the history
  • Loading branch information
Liozou committed Jan 30, 2024
1 parent 6c86635 commit c289333
Showing 1 changed file with 20 additions and 4 deletions.
24 changes: 20 additions & 4 deletions src/types.jl
Original file line number Diff line number Diff line change
Expand Up @@ -1431,12 +1431,28 @@ function Base.parse(::Type{InterpenetratedTopologyResult}, x::AbstractString)
return InterpenetratedTopologyResult([(topo1, nfold1, Int[])])
end

function one_topology(x::InterpenetratedTopologyResult, c::_Clustering)
"""
one_topology(itr::InterpenetratedTopologyResult, clustering::Union{Nothing,_Clustering}=nothing)
Return the only topology corresponding to the given clustering. If no clustering is given,
return the only topology of the result.
If several topologies are found, return `nothing`.
If the clustering is not found in one of the interpenetrated topologies, return `missing`.
"""
function one_topology(itr::InterpenetratedTopologyResult, clustering::Union{Nothing,_Clustering}=nothing)
result = nothing
for topo in x
newresult = get(topo[1], c, missing)
for topo in itr
top = topo[1]
newresult::Union{Missing,TopologicalGenome} = if clustering isa Nothing
length(top) == 1 || return nothing
only(values(top))
else
get(top, clustering, missing)
end
if result !== nothing
result == newresult || return nothing
isequal(result, newresult) || return nothing
else
result = newresult
end
Expand Down

0 comments on commit c289333

Please sign in to comment.