Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Suggestions: Include a Chao-Jaccard abundance index function for repOverlap #85

Open
abrown435 opened this issue Jul 20, 2020 · 1 comment · May be fixed by #88
Open

Suggestions: Include a Chao-Jaccard abundance index function for repOverlap #85

abrown435 opened this issue Jul 20, 2020 · 1 comment · May be fixed by #88
Labels
status:In progress ⏳ Work in progress tag:Methods Analysis and visualisation methods type:Enhancement New feature or request

Comments

@abrown435
Copy link

abrown435 commented Jul 20, 2020

https://github.com/immunomind/immunarch/blob/9dce2ea78f4fb15557e17664910f14c47caa8e63/R/overlap.R#L222Anne

The formula for the Jaccard index (though it might technically be a coefficient) used is a comparison of sequence occurrence, regardless of how often it appears in the set (comparison of unique sequence use) to compare similarity.

However, the Chao Jaccard Index is an abundance based index which takes into account the number of times a particular combination occurs.

We frequently use both of these metrics to calculate repertoire overlap.

I think the Chao Jaccard Index can be included in the overlap.R file by adding the following R code:

Change line 98 of overlap.R to:

                   .method = c("public", "overlap", "jaccard", "chao_jaccard_abundance_index", "tversky", "cosine", "morisita", "inc+public", "inc+morisita"),

Add the following functions in at line 222 of overlap.R:

chao_jaccard_abundance_index <- function(.x, .y) {
UseMethod("chao_jaccard_abundance_index")
}

chao_jaccard_abundance_index.default <- function(.x, .y) {
.x <- collect(.x, n = Inf)
.y <- collect(.y, n = Inf)
intersection <- nrow(dplyr::intersect(.x, .y))
proportion_of_x_in_y_counting_all_seqs <- intersection / nrow(.y)
proportion_of_y_in_x_counting_all_seqs <- intersection / nrow(.x)
(proportion_of_x_in_y_counting_all_seqs * proportion_of_y_in_x_counting_all_seqs) / (proportion_of_x_in_y_counting_all_seqs + proportion_of_y_in_x_counting_all_seqs - (proportion_of_x_in_y_counting_all_seqs * proportion_of_y_in_x_counting_all_seqs))
}

chao_jaccard_abundance_index.character <- function(.x, .y) {
intersection <- nrow(dplyr::intersect(.x, .y))
proportion_of_x_in_y_counting_all_seqs <- intersection / nrow(.y)
proportion_of_y_in_x_counting_all_seqs <- intersection / nrow(.x)
(proportion_of_x_in_y_counting_all_seqs * proportion_of_y_in_x_counting_all_seqs) / (proportion_of_x_in_y_counting_all_seqs + proportion_of_y_in_x_counting_all_seqs - (proportion_of_x_in_y_counting_all_seqs * proportion_of_y_in_x_counting_all_seqs))
}

Clarifying Points

I'm happy to add a pull request to add this, but I'm not sure if this chao_jaccard_abundance_index function is correct. The math is right, but it requires taking the sum of all the sequences in X, Y not the clones. I'm not sure exactly what the function is taking in, but I think it is on the clonal level, which would not be right.

@vadimnazarov
Copy link
Contributor

We got in contact in Alex and we will move the discussion to the Pull Request section for the convenience.

@vadimnazarov vadimnazarov added status:Help wanted status:In progress ⏳ Work in progress tag:Methods Analysis and visualisation methods type:Enhancement New feature or request labels Jul 21, 2020
@vadimnazarov vadimnazarov linked a pull request Jul 21, 2020 that will close this issue
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
status:In progress ⏳ Work in progress tag:Methods Analysis and visualisation methods type:Enhancement New feature or request
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants