Skip to content

Commit

Permalink
Merge pull request #301 from noranekonobokkusu/master
Browse files Browse the repository at this point in the history
Allow custom variable in .convertClonecall
  • Loading branch information
ncborcherding authored Jan 4, 2024
2 parents ce55335 + 2b8bb29 commit e701198
Showing 1 changed file with 6 additions and 29 deletions.
35 changes: 6 additions & 29 deletions R/utils.R
Original file line number Diff line number Diff line change
Expand Up @@ -255,9 +255,9 @@ is_seurat_or_se_object <- function(obj) {
x <- .convertClonecall(x)
if(check.df) {
if(inherits(df, "list") & !any(colnames(df[[1]]) %in% x)) {
stop("Check the clonal variabe (cloneCall) being used in the function, it does not appear in the data provided.")
stop("Check the clonal variable (cloneCall) being used in the function, it does not appear in the data provided.")
} else if (inherits(df, "data.frame") & !any(colnames(df) %in% x)) {
stop("Check the clonal variabe (cloneCall) being used in the function, it does not appear in the data provided.")
stop("Check the clonal variable (cloneCall) being used in the function, it does not appear in the data provided.")
}
}
return(x)
Expand Down Expand Up @@ -288,35 +288,12 @@ is_seurat_or_se_object <- function(obj) {
if (!is.null(clonecall_dictionary[[x]])) {
return(clonecall_dictionary[[x]])
}

stop(paste(
"invalid input cloneCall, did you mean: '",
closest_word(
x,
c(names(clonecall_dictionary),
unname(hash::values(clonecall_dictionary)))
),
"'?",
sep = ""
))
else {
warning("A custom variable ", x, " will be used to call clones")
return(x)
}
}

# helper for .convertClonecall
closest_word <- function(s, strset) {
strset_lowercase <- tolower(strset)
s <- tolower(s)

closest_w <- strset_lowercase[1]
closest_dist <- utils::adist(s, closest_w)
for(i in 2:length(strset_lowercase)) {
curr_dist <- utils::adist(s, strset_lowercase[i])
if (curr_dist < closest_dist) {
closest_w <- strset[i]
closest_dist <- curr_dist
}
}
closest_w
}

# Assigning positions for TCR contig data
# Used to be .parseTCR(Con.df, unique_df, data2) in v1
Expand Down

0 comments on commit e701198

Please sign in to comment.