Skip to content
Snippets Groups Projects
Commit 0a3d229a authored by François  LAURENT's avatar François LAURENT
Browse files

additional argument to appendlabel!

parent 57774376
No related branches found
No related tags found
No related merge requests found
Pipeline #100084 passed
name = "PlanarLarvae" name = "PlanarLarvae"
uuid = "c2615984-ef14-4d40-b148-916c85b43307" uuid = "c2615984-ef14-4d40-b148-916c85b43307"
authors = ["François Laurent", "Institut Pasteur"] authors = ["François Laurent", "Institut Pasteur"]
version = "0.9.1" version = "0.9.2"
[deps] [deps]
DelimitedFiles = "8bb1440f-4735-579b-a4ab-409b98df4dab" DelimitedFiles = "8bb1440f-4735-579b-a4ab-409b98df4dab"
......
...@@ -1138,16 +1138,21 @@ coerce(ref::AbstractVector, a) = coerce(eltype(ref), a) ...@@ -1138,16 +1138,21 @@ coerce(ref::AbstractVector, a) = coerce(eltype(ref), a)
coerce(ref, a) = coerce(typeof(ref), a) coerce(ref, a) = coerce(typeof(ref), a)
""" """
appendlabel!(run, label; recordname=:labels, attrname=(:secondarylabels, :names), ignore=String[]) appendlabel!(run, label; recordname=:labels, attrname=(:secondarylabels, :names), ignore=String[], ifempty=true)
Append a label to existing labels, at every track steps. Append a label to existing labels, at every track steps.
Per default, the label to append is considered secondary, meaning it is represented appart in Per default, the label to append is considered secondary, meaning it is represented appart in
the metadata. Secondary labels are recorded as such in metadata, so that they can be the metadata. Secondary labels are recorded as such in metadata, so that they can be
distinguished from primary labels. distinguished from primary labels.
Argument `ignore` lists uncompatible labels that prevent the label to be appended. Argument `ignore` lists uncompatible labels that prevent the label to be appended.
Argument `ifempty`, if set to false, additionally allows preventing the specified label to be
appended in cases the label is explicitly undefined with an empty list of labels.
""" """
function appendlabel!(run::Run, label::Union{Symbol, String}; function appendlabel!(run::Run, label::Union{Symbol, String};
recordname=:labels, attrname=(:secondarylabels, :names), ignore=String[]) recordname=:labels, attrname=(:secondarylabels, :names), ignore=String[],
ifempty=true)
decodelabels!(run) decodelabels!(run)
topattr = attrname isa Symbol ? attrname : attrname[1] topattr = attrname isa Symbol ? attrname : attrname[1]
labels = if topattr== recordname labels = if topattr== recordname
...@@ -1178,7 +1183,9 @@ function appendlabel!(run::Run, label::Union{Symbol, String}; ...@@ -1178,7 +1183,9 @@ function appendlabel!(run::Run, label::Union{Symbol, String};
for (i, existinglabel) in enumerate(labels) for (i, existinglabel) in enumerate(labels)
if isa(existinglabel, Vector) if isa(existinglabel, Vector)
if isempty(existinglabel) if isempty(existinglabel)
labels[i] = label # not a vector if ifempty
labels[i] = label # not a vector
end
elseif isempty(existinglabel ignore) elseif isempty(existinglabel ignore)
push!(existinglabel, label) push!(existinglabel, label)
end end
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment