diff --git a/R/NimbleAPI.R b/R/NimbleAPI.R index d577823..4f92e0f 100644 --- a/R/NimbleAPI.R +++ b/R/NimbleAPI.R @@ -312,7 +312,7 @@ DownloadAndAppendNimble <- function(seuratObject, targetAssayName, outPath=tempd colFilter=makeFilter( c("library_id", "EQUALS", libraryId), c("ref_nt_id/lineage", "NOT_MISSING", ''), - c("ref_nt_id/name", "IN", paste0(unique(df$V1), collapse = ';')) + c("ref_nt_id/name", "IN", paste0(feats, collapse = ';')) ), colNameOpt="rname" )) diff --git a/R/NimbleAppend.R b/R/NimbleAppend.R index 4ef7839..347fe49 100644 --- a/R/NimbleAppend.R +++ b/R/NimbleAppend.R @@ -81,19 +81,30 @@ AppendNimbleCounts <- function(seuratObject, nimbleFile, targetAssayName, maxAmb paste0('Distinct features after pruning: ', length(unique(df$V1))) } - # Ensure consistent sorting of ambiguous features, and re-group if needed: - if (any(grepl(df$V1, pattern = ','))) { - print('Ensuring consistent feature sort within ambiguous features:') - df$V1 <- unlist(sapply(df$V1, function(y){ - return(paste0(sort(unlist(strsplit(y, split = ','))), collapse = ',')) - })) - - df <- df %>% - group_by(V1, V3) %>% - summarize(V2 = sum(V2)) - - paste0('Distinct features after re-grouping: ', length(unique(df$V1))) - } + # TODO: consider a percent filter on ambiguous classes... + + # Ensure consistent sorting of ambiguous features, and re-group if needed: + if (any(grepl(df$V1, pattern = ','))) { + print('Ensuring consistent feature sort within ambiguous features:') + df$V1 <- unlist(sapply(df$V1, function(y){ + return(paste0(sort(unlist(strsplit(y, split = ','))), collapse = ',')) + })) + + df <- df %>% + group_by(V1, V3) %>% + summarize(V2 = sum(V2)) + + paste0('Distinct features after re-grouping: ', length(unique(df$V1))) + } + + if (any(duplicated(df[c('V1','V3')]))) { + print(paste0('Duplicate cell/features found. Rows at start: ', nrow(df))) + df <- df %>% + group_by(V1, V3) %>% + summarize(V2 = sum(V2)) + + print(paste0('After re-grouping: ', nrow(df))) + } tryCatch({ # Group to ensure we have one value per combination: