-
Notifications
You must be signed in to change notification settings - Fork 17
/
Copy pathClusters.jl
49 lines (35 loc) · 1.37 KB
/
Clusters.jl
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
# Clusters
# ========
abstract type AbstractCluster end
"""
Use `NoClustering()` to avoid the use of clustering where a `Clusters` type is needed.
"""
struct NoClustering <: AbstractCluster end
"""
Data structure to represent sequence clusters. The sequence data itself is not included.
"""
@auto_hash_equals struct Clusters <: AbstractCluster
clustersize::Vector{Int}
clusters::Vector{Int}
weights::StatsBase.Weights{Float64,Float64,Array{Float64,1}}
end
nelements(cl::Clusters) = length(cl.clusters)
@inline Base.convert(::Type{Clusters}, cl::Clusters) = cl # no-op
# weights
# -------
"""
The `WeightTypes` type is the same as `Union{Weights,NoClustering,Clusters}`. This type is
used to represent weights. Most of the functions taking the `weights` kerword argument in
the `Information` module accept instances of `WeightTypes`.
"""
const WeightTypes = Union{Weights,NoClustering,Clusters}
"""
`getweight(c[, i::Int])`
This function returns the weight of the sequence number `i`. getweight should be defined for
any type used for `frequencies!`/`frequencies` in order to use his weigths. If `i` isn't
used, this function returns a vector with the weight of each sequence.
"""
@inline getweight(weight::NoClustering, seq::Int) = 1.0
getweight(cl::Clusters) = cl.weights
getweight(cl::Clusters, seq::Int) = cl.weights[seq]
@inline getweight(cl::Weights, i::Int) = cl[i]