-
Notifications
You must be signed in to change notification settings - Fork 10
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add function to join community profiles (#58)
* add function to join community profiles * add news, bump minor version * add tests
- Loading branch information
Showing
6 changed files
with
89 additions
and
2 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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -4,7 +4,7 @@ keywords = ["microbiology", "microbiome", "biology"] | |
license = "MIT" | ||
desc = "Functions and types for working with microbial community data" | ||
authors = ["@kescobo <[email protected]>"] | ||
version = "0.7.1" | ||
version = "0.7.2" | ||
|
||
[deps] | ||
AxisIndices = "f52c9ee2-1b1c-4fd8-8546-6350938c7f11" | ||
|
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 |
---|---|---|
|
@@ -6,6 +6,7 @@ samples | |
features | ||
samplenames | ||
featurenames | ||
commjoin | ||
relativeabundance | ||
relativeabundance! | ||
present | ||
|
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,73 @@ | ||
""" | ||
commjoin(c1::CommunityProfile, comms::CommunityProfile...) | ||
Join multiple `CommunityProfile`s, creating a new `CommunityProfile`. | ||
For now, sample names cannot overlap in any of the input profiles. | ||
```jldoctest | ||
julia> mss = [MicrobiomeSample("sample\$i") for i in 1:15]; | ||
julia> txs = [Taxon("taxon\$i") for i in 1:20]; | ||
julia> cm1 = CommunityProfile(spzeros(10,5), txs[1:10], mss[1:5]) | ||
CommunityProfile{Float64, Taxon, MicrobiomeSample} with 10 things in 5 places | ||
Thing names: | ||
taxon1, taxon2, taxon3...taxon9, taxon10 | ||
Place names: | ||
sample1, sample2, sample3, sample4, sample5 | ||
julia> cm2 = CommunityProfile(spzeros(10,5), txs[6:15], mss[6:10]) | ||
CommunityProfile{Float64, Taxon, MicrobiomeSample} with 10 things in 5 places | ||
Thing names: | ||
taxon6, taxon7, taxon8...taxon14, taxon15 | ||
Place names: | ||
sample6, sample7, sample8, sample9, sample10 | ||
julia> cm3 = CommunityProfile(spzeros(10,5), txs[11:20], mss[11:15]) | ||
CommunityProfile{Float64, Taxon, MicrobiomeSample} with 10 things in 5 places | ||
Thing names: | ||
taxon11, taxon12, taxon13...taxon19, taxon20 | ||
Place names: | ||
sample11, sample12, sample13, sample14, sample15 | ||
julia> commjoin(cm1, cm2, cm3) | ||
CommunityProfile{Float64, Taxon, MicrobiomeSample} with 20 things in 15 places | ||
Thing names: | ||
taxon1, taxon2, taxon3...taxon19, taxon20 | ||
Place names: | ||
sample1, sample2, sample3...sample14, sample15 | ||
``` | ||
""" | ||
function commjoin(c1::CommunityProfile, comms::CommunityProfile...) | ||
length(intersect(samplenames(c1), samplenames.(comms)...)) == 0 || error("Duplicate sample names detected: $(intersect(samplenames(c1), samplenames.(comms)...))") | ||
|
||
all_samples = vcat(samples(c1), samples.(comms)...) | ||
sample_dict = dictionary(zip(name.(all_samples), eachindex(all_samples))) | ||
all_features = unique(vcat(features(c1), features.(comms)...)) | ||
feature_dict = dictionary(zip(name.(all_features), eachindex(all_features))) | ||
|
||
mat = spzeros(length(all_features), length(all_samples)) | ||
for comm in (c1, comms...) | ||
for sample in samplenames(comm) | ||
for feature in featurenames(comm) | ||
mat[feature_dict[feature], sample_dict[sample]] = comm[feature, sample] | ||
end | ||
end | ||
end | ||
|
||
return CommunityProfile(mat, all_features, all_samples) | ||
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