Skip to content

Commit

Permalink
feat: rare clonotype abundance
Browse files Browse the repository at this point in the history
  • Loading branch information
nahid18 committed Jun 16, 2024
1 parent face0ab commit d47b2b1
Show file tree
Hide file tree
Showing 4 changed files with 34 additions and 5 deletions.
1 change: 1 addition & 0 deletions DESCRIPTION
Original file line number Diff line number Diff line change
Expand Up @@ -29,4 +29,5 @@ Imports:
stringr,
methods,
utils,
RColorBrewer,
magrittr
2 changes: 1 addition & 1 deletion R/plot_reads_group_abundance.R
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
#' }
plot_reads_group_abundance <- function(data) {
label_order <- unique(data$reads_group)
colors <- c("#E41A1C", "#377EB8", "#4DAF4A", "#984EA3", "#FF7F00")
colors <- RColorBrewer::brewer.pal(n = length(label_order), name = "Set1")

df_counts <- data %>%
dplyr::filter(reads_group != "None") %>%
Expand Down
31 changes: 28 additions & 3 deletions R/utils-clonality.R
Original file line number Diff line number Diff line change
Expand Up @@ -50,13 +50,38 @@
}
}

abundance_top <- data %>%
.reads_group_rare <- function(count) {
if (count == 1) {
return("1")
} else if (count >= 2 && count <= 3) {
return("2-3")
} else if (count >= 4 && count <= 10) {
return("4-10")
} else if (count >= 11 && count <= 30) {
return("11-30")
} else if (count >= 31 && count <= 100) {
return("31-100")
} else if (count >= 101 && count <= 200) {
return("101-200")
} else {
return("None")
}
}

df_top <- data %>%
dplyr::arrange(sample, dplyr::desc(freq)) %>%
dplyr::group_by(sample) %>%
dplyr::slice_head(n = 100) %>%
dplyr::mutate(reads_group = purrr::map_chr(count, .reads_group_top)) %>%
dplyr::select(sample, !!rlang::sym(attr_col), reads_group)

df_rare <- data %>%
dplyr::arrange(sample, freq) %>%
dplyr::group_by(sample) %>%
dplyr::slice_head(n = 100) %>%
dplyr::mutate(reads_group = purrr::map_chr(count, .reads_group_rare)) %>%
dplyr::select(sample, !!rlang::sym(attr_col), reads_group)

return(
methods::new(
"Clonality",
Expand All @@ -78,8 +103,8 @@
dplyr::group_by(sample, !!rlang::sym(attr_col), clonotype_group) %>%
dplyr::summarize(relative_abundance = sum(freq)) %>%
dplyr::ungroup(),
abundance_top = abundance_top,
abundance_rare = data.frame()
abundance_top = df_top,
abundance_rare = df_rare
)
)
}
5 changes: 4 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -127,6 +127,9 @@ print(proj@clonality@abundance_top)
# plot reads group abbundance in top 100 clonotypes
reTCR::plot_reads_group_abundance(proj@clonality@abundance_top)

# relative abundance (in rare clonotypes)
# relative abundance (in rare 100 clonotypes)
print(proj@clonality@abundance_rare)

# plot reads group abbundance in rare 100 clonotypes
reTCR::plot_reads_group_abundance(proj@clonality@abundance_top)
```

0 comments on commit d47b2b1

Please sign in to comment.