Skip to content

Commit 9f6ef41

Browse files
Merge pull request #372 from ncborcherding/dev
v2.0.4
2 parents c5e0f3c + 2d9861f commit 9f6ef41

File tree

88 files changed

+14364
-1102
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

88 files changed

+14364
-1102
lines changed

DESCRIPTION

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
Package: scRepertoire
22
Title: A toolkit for single-cell immune receptor profiling
3-
Version: 2.0.3
3+
Version: 2.0.4
44
Authors@R: c(
55
person(given = "Nick", family = "Borcherding", role = c("aut", "cre"), email = "ncborch@gmail.com"),
66
person(given = "Qile", family = "Yang", role = c("aut"), email = "qile0317@gmail.com"),

NAMESPACE

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -103,11 +103,12 @@ importFrom(methods,slot)
103103
importFrom(plyr,join)
104104
importFrom(plyr,llply)
105105
importFrom(quantreg,rqss)
106-
importFrom(reshape2,dcast)
107106
importFrom(reshape2,melt)
108107
importFrom(rjson,fromJSON)
108+
importFrom(rlang,"!!")
109109
importFrom(rlang,"%||%")
110110
importFrom(rlang,":=")
111+
importFrom(rlang,ensym)
111112
importFrom(rlang,sym)
112113
importFrom(stats,as.dist)
113114
importFrom(stats,hclust)
@@ -121,6 +122,7 @@ importFrom(stats,sd)
121122
importFrom(stats,setNames)
122123
importFrom(stringdist,stringdist)
123124
importFrom(stringr,str_c)
125+
importFrom(stringr,str_remove_all)
124126
importFrom(stringr,str_replace_all)
125127
importFrom(stringr,str_replace_na)
126128
importFrom(stringr,str_sort)

NEWS.md

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,22 @@
1+
# scRepertoire VERSION 2.0.4
2+
3+
## UNDERLYING CHANGES
4+
* ```getCirclize()``` refactored to prevent assumptions and added **include.self** argument
5+
* Added ```.count.clones()``` internal function for ```getCirclize()``` and ```clonalNetwork()```
6+
* Added **order.by** parameter to visualizations to specifically call order of plotting using a vector or can use "alphanumeric" to plot things in order
7+
* Fix issue with ```clonalLength()``` and NA handling
8+
* ```clonalCompare()``` now retains the original clonal info if using **relabel.clones**
9+
* Add Dandelion support in to ```loadContigs()``` and testthat
10+
* Fixed issue with ```positionalProperty()``` assumption that the clones will all have 20 amino acids.
11+
* Fixed IGH/K/L mistaking gene issue in ```vizGenes()```
12+
13+
114
# scRepertoire VERSION 2.0.3
215

316
## UNDERLYING CHANGES
417

518
* Modified support for Omniscope format to allow for dual chains
6-
* Added ParseBio support int ```loadContigs()``` and testthat
19+
* Added ParseBio support in to ```loadContigs()``` and testthat
720
* Added support for productive variable to ```loadContigs()``` for BD, Omniscope, and Immcantation formats
821
* Replace numerical indexing with name indexing for ```loadContigs()```
922
* ```combineBCR()``` and ```combineTCR()``` no allow for unproductive contig inclusions with new **filterNonproductive** parameter.

R/clonalAbundance.R

Lines changed: 21 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,8 @@
2626
#' @param chain indicate if both or a specific chain should be used -
2727
#' e.g. "both", "TRA", "TRG", "IGH", "IGL"
2828
#' @param group.by The variable to use for grouping
29+
#' @param order.by A vector of specific plotting order or "alphanumeric"
30+
#' to plot groups in order
2931
#' @param scale Converts the graphs into density plots in order to show
3032
#' relative distributions.
3133
#' @param exportTable Returns the data frame used for forming the graph
@@ -42,7 +44,8 @@ clonalAbundance <- function(input.data,
4244
chain = "both",
4345
scale=FALSE,
4446
group.by = NULL,
45-
exportTable = FALSE,
47+
order.by = NULL,
48+
exportTable = FALSE,
4649
palette = "inferno") {
4750
Con.df <- NULL
4851
xlab <- "Abundance"
@@ -58,11 +61,17 @@ clonalAbundance <- function(input.data,
5861
data1 <- .parseContigs(input.data, i, names, cloneCall)
5962
label <- input.data[[i]][1,group.by]
6063
data1[,paste(group.by)] <- label
61-
Con.df<- rbind.data.frame(Con.df, data1) }
62-
Con.df <- data.frame(Con.df)
63-
col <- length(unique(Con.df[,group.by]))
64-
fill <- group.by
65-
if (scale == TRUE) {
64+
Con.df<- rbind.data.frame(Con.df, data1)
65+
}
66+
Con.df <- data.frame(Con.df)
67+
col <- length(unique(Con.df[,group.by]))
68+
fill <- group.by
69+
if(!is.null(order.by)) {
70+
Con.df <- .ordering.function(vector = order.by,
71+
group.by = group.by,
72+
data.frame = Con.df)
73+
}
74+
if (scale == TRUE) {
6675
ylab <- "Density of Clones"
6776
plot <- ggplot(Con.df, aes(x=Abundance, fill=Con.df[,group.by])) +
6877
geom_density(aes(y=after_stat(scaled)),
@@ -86,7 +95,12 @@ clonalAbundance <- function(input.data,
8695
Con.df<- rbind.data.frame(Con.df, data1)
8796
}
8897
Con.df <- data.frame(Con.df)
89-
Con.df$values <- factor(Con.df$values, levels=names(input.data))
98+
if(!is.null(order.by)) {
99+
Con.df <- .ordering.function(vector = order.by,
100+
group.by = "values",
101+
data.frame = Con.df)
102+
}
103+
90104
col <- length(unique(Con.df$values))
91105
fill <- "Samples"
92106
if (scale == TRUE) {

R/clonalCompare.R

Lines changed: 22 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -22,25 +22,27 @@
2222
#' @param cloneCall How to call the clone - VDJC gene (\strong{gene}),
2323
#' CDR3 nucleotide (\strong{nt}), CDR3 amino acid (\strong{aa}),
2424
#' VDJC gene + CDR3 nucleotide (\strong{strict}) or a custom variable
25-
#' in the data.
25+
#' in the data
2626
#' @param chain indicate if both or a specific chain should be used -
27-
#' e.g. "both", "TRA", "TRG", "IGH", "IGL".
27+
#' e.g. "both", "TRA", "TRG", "IGH", "IGL"
2828
#' @param samples The specific samples to isolate for visualization.
29-
#' @param clones The specific clonal sequences of interest.
29+
#' @param clones The specific clonal sequences of interest
3030
#' @param top.clones The top number of clonal sequences per group.
3131
#' (e.g., top.clones = 5)
3232
#' @param highlight.clones Clonal sequences to highlight, if present,
33-
#' all other clones returned will be grey.
33+
#' all other clones returned will be grey
3434
#' @param relabel.clones Simplify the legend of the graph by returning
35-
#' clones that are numerically indexed.
35+
#' clones that are numerically indexed
3636
#' @param group.by If using a single-cell object, the column header
3737
#' to group the new list. \strong{NULL} will return the active
38-
#' identity or cluster.
38+
#' identity or cluster
39+
#' @param order.by A vector of specific plotting order or "alphanumeric"
40+
#' to plot groups in order
3941
#' @param graph The type of graph produced, either \strong{"alluvial"}
40-
#' or \strong{"area"}.
41-
#' @param exportTable Returns the data frame used for forming the graph.
42+
#' or \strong{"area"}
43+
#' @param exportTable Returns the data frame used for forming the graph
4244
#' @param palette Colors to use in visualization - input any
43-
#' \link[grDevices]{hcl.pals}.
45+
#' \link[grDevices]{hcl.pals}
4446
#' @import ggplot2
4547
#' @importFrom stringr str_sort
4648
#'
@@ -56,7 +58,8 @@ clonalCompare <- function(input.data,
5658
top.clones = NULL,
5759
highlight.clones = NULL,
5860
relabel.clones = FALSE,
59-
group.by = NULL,
61+
group.by = NULL,
62+
order.by = NULL,
6063
graph = "alluvial",
6164
exportTable = FALSE,
6265
palette = "inferno"){
@@ -95,7 +98,7 @@ clonalCompare <- function(input.data,
9598
Con.df <- Con.df[Con.df$clones %in% top$clones,]
9699
}
97100
if (nrow(Con.df) < length(unique(Con.df$Sample))) {
98-
stop("Reasses the filtering strategies here, there are not
101+
stop("Please reasses the filtering strategies here, there are not
99102
enough clones to examine.")
100103
}
101104
#Clones relabeling
@@ -107,6 +110,7 @@ clonalCompare <- function(input.data,
107110
if(!is.null(highlight.clones)) {
108111
highlight.clones <- unname(new.clones[which(names(new.clones) %in% highlight.clones)])
109112
}
113+
Con.df[,"original.clones"] <- Con.df[,"clones"]
110114
Con.df[,"clones"] <- new.clones[as.vector(Con.df[,"clones"])]
111115
Con.df[,"clones"] <- factor(Con.df[,"clones"],
112116
levels = str_sort(unique(Con.df[,"clones"]), numeric = TRUE))
@@ -116,6 +120,13 @@ clonalCompare <- function(input.data,
116120
return(Con.df)
117121
}
118122

123+
if(!is.null(order.by)) {
124+
Con.df <- .ordering.function(vector = order.by,
125+
group.by = "Sample",
126+
data.frame = Con.df)
127+
}
128+
129+
119130
#Plotting Functions
120131
plot <- ggplot(Con.df, aes(x = Sample,
121132
fill = clones,

R/clonalDiversity.R

Lines changed: 17 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -49,19 +49,21 @@
4949
#' @param cloneCall How to call the clone - VDJC gene (\strong{gene}),
5050
#' CDR3 nucleotide (\strong{nt}), CDR3 amino acid (\strong{aa}),
5151
#' VDJC gene + CDR3 nucleotide (\strong{strict}) or a custom variable
52-
#' in the data.
52+
#' in the data
5353
#' @param chain indicate if both or a specific chain should be used -
54-
#' e.g. "both", "TRA", "TRG", "IGH", "IGL".
55-
#' @param group.by Variable in which to combine for the diversity calculation.
56-
#' @param x.axis Additional variable grouping that will space the sample along the x-axis.
54+
#' e.g. "both", "TRA", "TRG", "IGH", "IGL"
55+
#' @param group.by Variable in which to combine for the diversity calculation
56+
#' @param order.by A vector of specific plotting order or "alphanumeric"
57+
#' to plot groups in order
58+
#' @param x.axis Additional variable grouping that will space the sample along the x-axis
5759
#' @param metrics The indices to use in diversity calculations -
58-
#' "shannon", "inv.simpson", "norm.entropy", "gini.simpson", "chao1", "ACE".
60+
#' "shannon", "inv.simpson", "norm.entropy", "gini.simpson", "chao1", "ACE"
5961
#' @param exportTable Exports a table of the data into the global environment
60-
#' in addition to the visualization.
62+
#' in addition to the visualization
6163
#' @param palette Colors to use in visualization - input any
62-
#' \link[grDevices]{hcl.pals}.
64+
#' \link[grDevices]{hcl.pals}
6365
#' @param n.boots number of bootstraps to down sample in order to
64-
#' get mean diversity.
66+
#' get mean diversity
6567
#' @param return.boots export boot strapped values calculated -
6668
#' will automatically exportTable = TRUE.
6769
#' @param skip.boots remove down sampling and boot strapping from the calculation.
@@ -77,6 +79,7 @@ clonalDiversity <- function(input.data,
7779
cloneCall = "strict",
7880
chain = "both",
7981
group.by = NULL,
82+
order.by = NULL,
8083
x.axis = NULL,
8184
metrics = c("shannon", "inv.simpson", "norm.entropy", "gini.simpson", "chao1", "ACE"),
8285
exportTable = FALSE,
@@ -151,6 +154,12 @@ clonalDiversity <- function(input.data,
151154
rownames(mat) <- names(input.data)
152155

153156
mat_melt <- suppressMessages(melt(mat, id.vars = c(group.by, x.axis)))
157+
if(!is.null(order.by)) {
158+
mat_melt <- .ordering.function(vector = order.by,
159+
group.by = names(mat_melt)[1],
160+
mat_melt)
161+
}
162+
154163
if (x.axis == "x.axis") {
155164
plot <- ggplot(mat_melt, aes(x=1, y=as.numeric(value)))
156165
} else {

R/clonalHomeostasis.R

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,9 @@
2323
#' in the data.
2424
#' @param chain indicate if both or a specific chain should be used -
2525
#' e.g. "both", "TRA", "TRG", "IGH", "IGL".
26-
#' @param group.by The variable to use for grouping.
26+
#' @param group.by The variable to use for grouping
27+
#' @param order.by A vector of specific plotting order or "alphanumeric"
28+
#' to plot groups in order
2729
#' @param exportTable Exports a table of the data into the global
2830
#' environment in addition to the visualization.
2931
#' @param palette Colors to use in visualization - input any
@@ -40,6 +42,7 @@ clonalHomeostasis <- function(input.data,
4042
cloneCall = "strict",
4143
chain = "both",
4244
group.by = NULL,
45+
order.by = NULL,
4346
exportTable = FALSE,
4447
palette = "inferno") {
4548
cloneSize <- c(None = 0, cloneSize)
@@ -75,6 +78,14 @@ clonalHomeostasis <- function(input.data,
7578

7679
#Plotting
7780
mat_melt <- melt(mat)
81+
82+
if(!is.null(order.by)) {
83+
mat_melt <- .ordering.function(vector = order.by,
84+
group.by = "Var1",
85+
data.frame = mat_melt)
86+
}
87+
88+
7889
col <- length(unique(mat_melt$Var2))
7990
plot <- ggplot(mat_melt, aes(x=as.factor(Var1), y=value, fill=Var2)) +
8091
geom_bar(stat = "identity", position="fill",

R/clonalLength.R

Lines changed: 20 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -16,17 +16,19 @@
1616
#' clonalLength(combined, cloneCall="aa", chain = "both")
1717
#'
1818
#' @param input.data The product of \code{\link{combineTCR}},
19-
#' \code{\link{combineBCR}}, or \code{\link{combineExpression}}.
19+
#' \code{\link{combineBCR}}, or \code{\link{combineExpression}}
2020
#' @param cloneCall How to call the clone - CDR3 nucleotide (\strong{nt})
21-
#' or CDR3 amino acid (\strong{aa}).
22-
#' @param group.by The variable to use for grouping.
21+
#' or CDR3 amino acid (\strong{aa})
22+
#' @param group.by The variable to use for grouping
23+
#' @param order.by A vector of specific plotting order or "alphanumeric"
24+
#' to plot groups in order description
2325
#' @param scale Converts the graphs into density plots in order to show
2426
#' relative distributions.
2527
#' @param chain indicate if both or a specific chain should be used -
26-
#' e.g. "both", "TRA", "TRG", "IGH", "IGL".
28+
#' e.g. "both", "TRA", "TRG", "IGH", "IGL"
2729
#' @param exportTable Returns the data frame used for forming the graph.
2830
#' @param palette Colors to use in visualization - input any
29-
#' \link[grDevices]{hcl.pals}.
31+
#' \link[grDevices]{hcl.pals}
3032
#' @importFrom stringr str_split
3133
#' @importFrom ggplot2 ggplot
3234
#' @export
@@ -37,6 +39,7 @@ clonalLength <- function(input.data,
3739
cloneCall = "aa",
3840
chain = "both",
3941
group.by = NULL,
42+
order.by = NULL,
4043
scale = FALSE,
4144
exportTable = FALSE,
4245
palette = "inferno") {
@@ -80,6 +83,18 @@ clonalLength <- function(input.data,
8083
return(Con.df)
8184
}
8285

86+
if(!is.null(order.by)) {
87+
if (!is.null(group.by)) {
88+
Con.df <- .ordering.function(vector = order.by,
89+
group.by = group.by,
90+
data.frame = Con.df)
91+
} else {
92+
Con.df <- .ordering.function(vector = order.by,
93+
group.by = "values",
94+
data.frame = Con.df)
95+
}
96+
}
97+
8398
#Plotting
8499
if (!is.null(group.by)) {
85100
fill <- group.by

R/clonalNetwork.R

Lines changed: 11 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -90,14 +90,9 @@ clonalNetwork <- function(sc.data,
9090
}
9191
#Filtering clones based on the minimum value
9292
min_val <- min(min)
93-
table <- meta %>%
94-
group_by(across(all_of(c(group.by, cloneCall)))) %>%
95-
count() %>%
96-
na.omit() %>%
97-
arrange(desc(n)) %>%
98-
mutate(cumSum = cumsum(n))
99-
cut <- which.min(abs(table$cumSum - min_val))
100-
clones.to.filter <- table$group.by[seq_len(cut)]
93+
table <- .clone.counter(meta, group.by, cloneCall)
94+
cut <- which.min(abs(table$clone.sum - min_val))
95+
clones.to.filter <- table[,1][seq_len(cut)]
10196
} else if (is.numeric(filter.clones)) {
10297
#Filtering based on a numeric value
10398
table <- meta %>%
@@ -114,18 +109,16 @@ clonalNetwork <- function(sc.data,
114109

115110
if(exportClones) {
116111
#Summarizing all the clones by group.by
117-
table <- meta %>%
118-
group_by(meta[,group.by], meta[, cloneCall]) %>%
119-
dplyr::count() %>%
120-
na.omit() %>%
121-
arrange(desc(n))
112+
table <- .clone.counter(meta, group.by, cloneCall)[,seq_len(3)]
122113
#Identifying the clones across the group by
123-
clones.across.identities <- names(which(table(table[[2]]) > 1))
114+
clones.across.identities <- names(which(table(table[,2]) > 1))
115+
if(length(clones.across.identities) < 1) {
116+
stop("No shared clones across group.by variables for the current parameters selected")
117+
}
124118
#Getting the clones to output
125-
subset.table <- as.data.frame(table)
126-
subset.table <- subset.table[subset.table[,2] %in% clones.across.identities,]
127-
colnames(subset.table) <- c("id", "clone", "n")
128-
dupl.clones <- subset.table %>%
119+
table <- table[table[,2] %in% clones.across.identities,]
120+
colnames(table) <- c("id", "clone", "n")
121+
dupl.clones <- table %>%
129122
group_by(clone) %>%
130123
summarise(sum = sum(n))%>%
131124
arrange(desc(sum))

0 commit comments

Comments
 (0)