-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #37 from menchelab/v1.1.0
V1.1.0
- Loading branch information
Showing
11 changed files
with
415 additions
and
39 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
"""[intended for internal use only] | ||
Make sure an Experiment's data are numerical | ||
and do not include missing values, NaNs or infs. | ||
""" | ||
function _assert_clean_data(e::Experiment) | ||
# Column type cannot be used as for instance a Union type | ||
# could support missing values but the selected data subset | ||
# might contain only numbers | ||
|
||
# This excludes strings and missings (and more) | ||
hasnumbers = getdata(e) |> | ||
x -> isa.(x, Number) |> | ||
eachcol |> | ||
x -> all.(x) |> | ||
all | ||
@assert hasnumbers "Selected data include non-numeric values." | ||
|
||
# Exclude NaNs | ||
hasnonans = getdata(e) |> | ||
x -> isnan.(x) |> | ||
eachcol |> | ||
x -> any.(x) |> | ||
any |> ~ | ||
@assert hasnonans "Selected data include NaNs." | ||
|
||
# Exclude Inf | ||
hasnoinf = getdata(e) |> | ||
x -> isinf.(x) |> | ||
eachcol |> | ||
x -> any.(x) |> | ||
any |> ~ | ||
@assert hasnoinf "Selected data include Inf values." | ||
end | ||
|
||
"""[intended for internal use only] | ||
Convert all selected data columns to floats | ||
""" | ||
function _data_to_float!(e::Experiment) | ||
# Make sure all values are numbers | ||
@assert all( [x <: Number for x in eltype.(eachcol(getdata(e)))] ) | ||
# Convert each column to floats | ||
for colname in names(getdata(e)) | ||
e.data[!,colname] = float.(e.data[:,colname]) | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,88 @@ | ||
""" | ||
Return the features of `e` ranked by decreasing | ||
median absolute deviation. Trim to the | ||
first `top` features if a value is provided. | ||
""" | ||
function most_variable_features(e::Experiment; top::Int64 = 0) | ||
e_mad_ind = e |> | ||
getdata |> | ||
eachcol |> | ||
x -> mad.(x, normalize = true) |> | ||
sortperm |> | ||
reverse | ||
|
||
# Get symbols from indices | ||
e_mad_sym = names(getdata(e))[e_mad_ind] | ||
|
||
# Truncate if needed | ||
if (top > 0) && (length(e_mad_sym) > top) | ||
e_mad_sym = e_mad_sym[1:top] | ||
end | ||
|
||
return(e_mad_sym) | ||
end | ||
|
||
""" | ||
Return (all or if provided the `top`) features | ||
varying the most in `e` (largest absolute log | ||
fold change), when comparing entries matching | ||
filters `f1` and `f2`. Columns for which the | ||
fold change is negative come last. | ||
""" | ||
function characteristic_features(e::Experiment, | ||
f1::AbstractFilter, | ||
f2::AbstractFilter; | ||
top::Int64 = 0) | ||
f1_col = filter_entries(e,f1) | ||
f2_col = filter_entries(e,f2) | ||
|
||
lfc_ind = e.data[:, e.selected_features] |> | ||
eachcol |> | ||
y -> map(x -> mean(x[f1_col]) / mean(x[f2_col]), y) |> | ||
y -> map(x -> x <= 0 ? 0 : abs(log2(x)), y) |> | ||
sortperm |> | ||
reverse | ||
|
||
# Get symbols from indices | ||
sym = names(getdata(e))[lfc_ind] | ||
|
||
# Truncate if needed | ||
if (top > 0) && (length(sym) > top) | ||
sym = sym[1:top] | ||
end | ||
|
||
return(sym) | ||
end | ||
|
||
""" | ||
Return (all or if provided the `top`) features | ||
in `e` associated the most with `ref` (absolute | ||
Pearson correlation). | ||
""" | ||
function most_correlated(e::Experiment, | ||
ref::AbstractVector; | ||
top::Int64 = 0) | ||
@assert all( [x <: Number for x in eltype.(eachcol(getdata(e)))] ) | ||
mostcor_ind = e |> getdata |> | ||
x -> cor(ref, Array(x)) |> | ||
x -> abs.(x) |> | ||
x -> sortperm([x...]) |> | ||
reverse | ||
|
||
# Get symbols from indices | ||
mostcor = names(getdata(e))[mostcor_ind] | ||
|
||
# Truncate if needed | ||
if (top > 0) && (length(mostcor) > top) | ||
mostcor = mostcor[1:top] | ||
end | ||
|
||
return(mostcor) | ||
end | ||
|
||
function most_correlated(e::Experiment, | ||
ref::Symbol; | ||
top::Int64 = 0) | ||
ref_vector = e.data[e.selected_entries,ref] | ||
most_correlated(e,ref_vector,top = top) | ||
end |
Oops, something went wrong.
15c0e2d
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@JuliaRegistrator register()
15c0e2d
There was a problem hiding this comment.
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/45430
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: