Skip to main content

Population data

Needless to say, population information is crucial for population genetics, so there are several handy tools for dealing with that information. If you need to see the population for every sample, then use sampleinfo(popdata) to retrieve the dataframe containing sample information.

View unique population names

populations(data::PopData; counts::Bool = false)

If counts = false, returns a Vector of the unique populations present in the PopData. If counts = true, returns a table of sample counts per population.

Return a vector of the unique populations.

julia> populations(sharks)
7-element Array{String,1}:
"CapeCanaveral"
"Georgia"
"SouthCarolina"
"FloridaKeys"
"MideastGulf"
"NortheastGulf"
"SoutheastGulf"

Rename populations

populations!(data::PopData, rename::Dict)
populations!(data::PopData, rename::Vector{String})
populations!(data::PopData, samples::Vector{String}, populations::Vector{String})

There are a handful of methods to alter PopData population names depending on what you find most convenient. Each of these methods start with populations!() and vary in their inputs. It's for that reason this function has an uncharacteristically long docstring. However, all the methods for populations! are unified in that they edit PopData in place.

populations!(data::PopData, rename::Dict)
tip

Recommended for renaming existing populations

Rename existing population ID's of PopData using a Dict of population_name => replacement.

# create a dictionary of name conversions
julia> new_popnames =
Dict(
"CapeCanaveral" => "Atlantic",
"Georgia" => "Atlantic",
"SouthCarolina" => "Atlantic",
"FloridaKeys" => "Gulf",
"MideastGulf" => "Gulf",
"NortheastGulf" => "Gulf",
"SoutheastGulf" => "Gulf"
);

julia> populations!(sharks, new_popnames)
julia> populations(sharks, counts = true)
2×2 DataFrame
Row │ population count
│ String Int64
─────┼───────────────────
1 │ Atlantic 79
2 │ Gulf 133