Skip to content

Commit

Permalink
update
Browse files Browse the repository at this point in the history
  • Loading branch information
PharmCat committed Aug 3, 2021
1 parent 407990d commit aa64e3f
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 1 deletion.
30 changes: 29 additions & 1 deletion src/types.jl
Original file line number Diff line number Diff line change
Expand Up @@ -223,7 +223,35 @@ function subset(d::DataSet, sort::Dict)
nothing
end
################################################################################

# metida_table from DataSet{AbstractIDResult}
################################################################################
function metida_table(obj::DataSet{RD}; order = nothing, results = nothing, ids = nothing) where RD <: AbstractIDResult
idset = Set(keys(first(obj).data.id))
resset = Set(keys(first(obj).result))
if length(obj) > 1
for i = 2:length(obj)
union!(idset, Set(keys(obj[i].data.id)))
union!(resset, Set(keys(obj[i].result)))
end
end
if !isnothing(results)
if isa(results, Symbol) results = [results] end
if isa(results, String) results = [Symbol(results)] end
ressetl = isnothing(order) ? collect(intersect(resset, results)) : sortbyvec!(collect(intersect(resset, results)), order)
else
ressetl = isnothing(order) ? collect(resset) : sortbyvec!(collect(resset), order)
end
if !isnothing(ids)
if isa(ids, Symbol) ids = [ids] end
if isa(ids, String) ids = [Symbol(ids)] end
ids idset || error("Some id not in dataset!")
idset = intersect(idset, ids)
end
mt1 = MetidaBase.metida_table((getid(obj, :, c) for c in idset)...; names = idset)
mt2 = MetidaBase.metida_table((obj[:, c] for c in ressetl)...; names = ressetl)
MetidaTable(merge(mt1.table, mt2.table))
end
################################################################################
# MetidaFreq.jl

struct Proportion <: AbstractData
Expand Down
3 changes: 3 additions & 0 deletions src/utils.jl
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,9 @@ function indsdict!(d::Dict{T}, cdata::Tuple) where T
d
end

function sortbyvec!(a, vec)
sort!(a, by = x -> findfirst(y -> x == y, vec))
end

isnanormissing(x::Number) = isnan(x)
isnanormissing(x::Missing) = true

2 comments on commit aa64e3f

@PharmCat
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@JuliaRegistrator
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Registration pull request created: JuliaRegistries/General/42194

After the above pull request is merged, it is recommended that a tag is created on this repository for the registered package version.

This will be done automatically if the Julia TagBot GitHub Action is installed, or can be done manually through the github interface, or via:

git tag -a v0.3.1 -m "<description of version>" aa64e3f31b3cafd3969f587f54a34e15b4cddf9e
git push origin v0.3.1

Please sign in to comment.