-
Notifications
You must be signed in to change notification settings - Fork 9
/
Interface.jl
211 lines (164 loc) · 5.87 KB
/
Interface.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
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
# SPDX-License-Identifier: BSD-2-Clause
using Diversity.API
using EcoBase: AbstractAssemblage, AbstractThings, AbstractPlaces
using EcoBase: thingkind, thingkindplural, placekind, placekindplural
"""
gettypes(m::AbstractAssemblage)
Returns the AbstractTypes component of the metacommunity.
"""
function gettypes(m::AbstractAssemblage)
return _gettypes(m)
end
"""
getpartition(m::AbstractAssemblage)
Returns the AbstractPartition component of the metacommunity.
"""
function getpartition(m::AbstractAssemblage)
return _getpartition(m)
end
"""
counttypes(m::AbstractAssemblage[, raw::Bool = false])
counttypes(t::AbstractTypes[, raw::Bool = false])
Returns number of types in an `AbstractTypes` object or the
`AbstractAssemblage` containing it. `raw` determines whether to
count the number of raw or processed types, which varies, for instance,
when the types are determined by a phylogeny.
"""
function counttypes end
function counttypes(m::AbstractAssemblage, raw::Bool = false)
return _counttypes(_gettypes(m), raw)
end
function counttypes(t::AbstractThings, raw::Bool = false)
return _counttypes(t, raw)
end
"""
countsubcommunities(m::AbstractAssemblage)
countsubcommunities(p::AbstractPartition)
Returns number of subcommunities in an `AbstractPartition` object or the
`AbstractAssemblage` containing it.
"""
function countsubcommunities end
function countsubcommunities(m::AbstractAssemblage)
return _countsubcommunities(_getpartition(m))
end
function countsubcommunities(p::AbstractPartition)
return _countsubcommunities(p)
end
"""
gettypenames(m::AbstractAssemblage[, raw::Bool = false])
gettypenames(t::AbstractTypes[, raw::Bool = false])
Returns the names of the types of the `AbstractTypes` object or the
`AbstractAssemblage` containing it. `raw` determines whether to
count the number of raw or processed types, which varies, for instance,
when the types are determined by a phylogeny.
"""
function gettypenames end
function gettypenames(m::AbstractAssemblage, raw::Bool = false)
return _gettypenames(_gettypes(m), raw)
end
function gettypenames(t::AbstractTypes, raw::Bool = false)
return _gettypenames(t, raw)
end
"""
getdiversityname(m::AbstractAssemblage)
getdiversityname(t::AbstractTypes)
Returns the name of the diversity type used.
"""
function getdiversityname end
getdiversityname(t::AbstractThings) = _getdiversityname(t)
getdiversityname(m::AbstractAssemblage) = _getdiversityname(_gettypes(m))
"""
addedoutputcols(m::AbstractAssemblage)
addedoutputcols(t::AbstractTypes)
Returns the name of any additional columns needed to disambiguate the
diversity type used.
"""
function addedoutputcols end
addedoutputcols(t::AbstractThings) = _addedoutputcols(t)
addedoutputcols(m::AbstractAssemblage) = addedoutputcols(_gettypes(m))
"""
getaddedoutput(::AbstractTypes)
Returns the contents of any additional columns to be added to outputs.
"""
function getaddedoutput end
getaddedoutput(t::AbstractThings) = _getaddedoutput(t)
getaddedoutput(m::AbstractAssemblage) = _getaddedoutput(_gettypes(m))
"""
getsubcommunitynames(m::AbstractAssemblage)
getsubcommunitynames(p::AbstractPartition)
Returns the names of the subcommunities in an `AbstractPartition` object or the
`AbstractAssemblage` containing it.
"""
function getsubcommunitynames end
function getsubcommunitynames(m::AbstractAssemblage)
return _getsubcommunitynames(_getpartition(m))
end
function getsubcommunitynames(p::AbstractPartition)
return _getsubcommunitynames(p)
end
"""
getabundance(m::AbstractAssemblage, raw::Bool)
Returns the abundances array of the metacommunity.
"""
function getabundance(m::AbstractAssemblage, raw::Bool = false)
return _getabundance(m, raw)
end
"""
getmetaabundance(m::AbstractAssemblage)
Returns the metacommunity abundances of the metacommunity.
"""
function getmetaabundance(m::AbstractAssemblage, raw::Bool = false)
return _getmetaabundance(m, raw)
end
"""
getweight(m::AbstractAssemblage)
Returns the subcommunity weights of the metacommunity.
"""
function getweight(m::AbstractAssemblage)
return _getweight(m)
end
"""
getordinariness!(m::AbstractAssemblage)
Returns (and possibly calculates) the ordinariness array of the subcommunities.
"""
function getordinariness!(m::AbstractAssemblage)
return _getordinariness!(m)
end
"""
getmetaordinariness!(m::AbstractAssemblage)
Returns (and possibly calculates) the ordinariness of the
metacommunity as a whole.
"""
function getmetaordinariness!(m::AbstractAssemblage)
return _getmetaordinariness!(m)
end
"""
hassimilarity(t::AbstractAssemblage)
hassimilarity(t::AbstractThings)
Is there similarity of some non-trivial type in the object?
"""
function hassimilarity end
hassimilarity(t::AbstractThings) = _hassimilarity(t)
hassimilarity(asm::AbstractAssemblage) = hassimilarity(gettypes(asm))
"""
calcsimilarity(t::AbstractTypes, scale::Real)
Retrieves (and possibly calculates) a similarity matrix from t.
"""
function calcsimilarity(t::AbstractTypes, scale::Real)
return _calcsimilarity(t, scale)
end
function createsummaryline(vec::AbstractVector{<:AbstractString})
linefunc(vec) = mapreduce(x -> x * ", ", *, vec[1:(end - 1)]) * vec[end]
length(vec) == 1 && return vec[1]
length(vec) < 6 && return linefunc(vec)
return linefunc(vec[1:3]) * "..." * linefunc(vec[(end - 1):end])
end
import Base.show
function show(io::IO, mc::AbstractMetacommunity)
sp = createsummaryline(gettypenames(mc))
si = createsummaryline(getsubcommunitynames(mc))
tk = counttypes(mc) > 1 ? thingkind(mc) : thingkindplural(mc)
pk = countsubcommunities(mc) > 1 ? placekind(mc) : placekindplural(mc)
return println(io,
"$(typeof(mc)) with $(counttypes(mc)) $tk in $(countsubcommunities(mc)) $pk measuring $(getdiversityname(gettypes(mc))) diversity.\n\n$(titlecase(tk)) names:\n$(sp)\n\n$(titlecase(pk)) names:\n$(si)")
end