@@ -247,6 +247,23 @@ alias_to_symbol_seurat = function(seurat_obj, organism) {
247247 rownames(RNA @ scale.data ) = newnames
248248 }
249249 }
250+
251+ if (length(RNA @ var.features ) > 0 ){
252+ newnames = convert_alias_to_symbols(RNA @ var.features , organism = organism , verbose = FALSE )
253+ doubles = newnames %> % table() %> % . [. > 1 ] %> % names()
254+ genes_remove = (names(newnames [newnames %in% doubles ]) != (newnames [newnames %in% doubles ])) %> % . [. == TRUE ] %> % names()
255+ newnames [genes_remove ] = genes_remove # set the doubles back to their old names
256+ RNA @ var.features = newnames
257+ }
258+
259+ if (nrow(RNA @ meta.features ) > 0 ){
260+ newnames = convert_alias_to_symbols(rownames(RNA @ meta.features ), organism = organism , verbose = FALSE )
261+ doubles = newnames %> % table() %> % . [. > 1 ] %> % names()
262+ genes_remove = (names(newnames [newnames %in% doubles ]) != (newnames [newnames %in% doubles ])) %> % . [. == TRUE ] %> % names()
263+ newnames [genes_remove ] = genes_remove # set the doubles back to their old names
264+ rownames(RNA @ meta.features ) = newnames
265+ }
266+
250267 } else {" Unequal gene sets: nrow(seurat_obj@assays$RNA) != nrow(newnames)" }
251268
252269 if (! is.null(RNA @ counts )){
@@ -280,6 +297,28 @@ alias_to_symbol_seurat = function(seurat_obj, organism) {
280297 }
281298 }
282299
300+ if (length(RNA @ var.features ) > 0 ){
301+ dim_before = length(RNA @ var.features )
302+ RNA @ var.features = RNA @ var.features %> % . [! is.na(. )]
303+ dim_after = length(RNA @ var.features )
304+ if (dim_before != dim_after ){
305+ print(" length of var.features changed" )
306+ print(paste0(" before: " ,dim_before ))
307+ print(paste0(" after: " ,dim_before ))
308+ }
309+ }
310+
311+ if (nrow(RNA @ meta.features ) > 0 ){
312+ dim_before = dim(RNA @ meta.features )
313+ RNA @ meta.features = RNA @ meta.features %> % . [! is.na(rownames(. )), ]
314+ dim_after = dim(RNA @ meta.features )
315+ if (sum(dim_before != dim_after ) > 0 ){
316+ print(" length of meta.features changed" )
317+ print(paste0(" before: " ,dim_before ))
318+ print(paste0(" after: " ,dim_before ))
319+ }
320+ }
321+
283322 seurat_obj @ assays $ RNA = RNA
284323
285324 if (! is.null( seurat_obj @ assays $ SCT )){
@@ -313,6 +352,23 @@ alias_to_symbol_seurat = function(seurat_obj, organism) {
313352 rownames(SCT @ scale.data ) = newnames
314353 }
315354 }
355+
356+ if (length(SCT @ var.features ) > 0 ){
357+ newnames = convert_alias_to_symbols(SCT @ var.features , organism = organism , verbose = FALSE )
358+ doubles = newnames %> % table() %> % . [. > 1 ] %> % names()
359+ genes_remove = (names(newnames [newnames %in% doubles ]) != (newnames [newnames %in% doubles ])) %> % . [. == TRUE ] %> % names()
360+ newnames [genes_remove ] = genes_remove # set the doubles back to their old names
361+ SCT @ var.features = newnames
362+ }
363+
364+ if (nrow(SCT @ meta.features ) > 0 ){
365+ newnames = convert_alias_to_symbols(rownames(SCT @ meta.features ), organism = organism , verbose = FALSE )
366+ doubles = newnames %> % table() %> % . [. > 1 ] %> % names()
367+ genes_remove = (names(newnames [newnames %in% doubles ]) != (newnames [newnames %in% doubles ])) %> % . [. == TRUE ] %> % names()
368+ newnames [genes_remove ] = genes_remove # set the doubles back to their old names
369+ rownames(SCT @ meta.features ) = newnames
370+ }
371+
316372 } else {" Unequal gene sets: nrow(seurat_obj@assays$SCT) != nrow(newnames)" }
317373
318374 if (! is.null(SCT @ counts )){
@@ -345,6 +401,30 @@ alias_to_symbol_seurat = function(seurat_obj, organism) {
345401 print(paste0(" after: " ,dim_before ))
346402 }
347403 }
404+
405+ if (length(SCT @ var.features ) > 0 ){
406+ dim_before = length(SCT @ var.features )
407+ SCT @ var.features = SCT @ var.features %> % . [! is.na(. )]
408+ dim_after = length(SCT @ var.features )
409+ if (dim_before != dim_after ){
410+ print(" length of var.features changed" )
411+ print(paste0(" before: " ,dim_before ))
412+ print(paste0(" after: " ,dim_before ))
413+ }
414+ }
415+
416+
417+ if (nrow(SCT @ meta.features ) > 0 ){
418+ dim_before = dim(SCT @ meta.features )
419+ SCT @ meta.features = SCT @ meta.features %> % . [! is.na(rownames(. )), ]
420+ dim_after = dim(SCT @ meta.features )
421+ if (sum(dim_before != dim_after ) > 0 ){
422+ print(" length of meta.features changed" )
423+ print(paste0(" before: " ,dim_before ))
424+ print(paste0(" after: " ,dim_before ))
425+ }
426+ }
427+
348428 seurat_obj @ assays $ SCT = SCT
349429 }
350430
@@ -383,6 +463,23 @@ alias_to_symbol_seurat = function(seurat_obj, organism) {
383463 rownames(integrated @ scale.data ) = newnames
384464 }
385465 }
466+
467+ if (length(integrated @ var.features ) > 0 ){
468+ newnames = convert_alias_to_symbols(integrated @ var.features , organism = organism , verbose = FALSE )
469+ doubles = newnames %> % table() %> % . [. > 1 ] %> % names()
470+ genes_remove = (names(newnames [newnames %in% doubles ]) != (newnames [newnames %in% doubles ])) %> % . [. == TRUE ] %> % names()
471+ newnames [genes_remove ] = genes_remove # set the doubles back to their old names
472+ integrated @ var.features = newnames
473+ }
474+
475+ if (nrow(integrated @ meta.features ) > 0 ){
476+ newnames = convert_alias_to_symbols(rownames(integrated @ meta.features ), organism = organism , verbose = FALSE )
477+ doubles = newnames %> % table() %> % . [. > 1 ] %> % names()
478+ genes_remove = (names(newnames [newnames %in% doubles ]) != (newnames [newnames %in% doubles ])) %> % . [. == TRUE ] %> % names()
479+ newnames [genes_remove ] = genes_remove # set the doubles back to their old names
480+ rownames(integrated @ meta.features ) = newnames
481+ }
482+
386483 } else {" Unequal gene sets: nrow(seurat_obj@assays$integrated) != nrow(newnames)" }
387484
388485 if (! is.null(integrated @ counts )){
@@ -415,6 +512,29 @@ alias_to_symbol_seurat = function(seurat_obj, organism) {
415512 print(paste0(" after: " ,dim_before ))
416513 }
417514 }
515+
516+ if (length(integrated @ var.features ) > 0 ){
517+ dim_before = length(integrated @ var.features )
518+ integrated @ var.features = integrated @ var.features %> % . [! is.na(. )]
519+ dim_after = length(integrated @ var.features )
520+ if (dim_before != dim_after ){
521+ print(" length of var.features changed" )
522+ print(paste0(" before: " ,dim_before ))
523+ print(paste0(" after: " ,dim_before ))
524+ }
525+ }
526+
527+ if (nrow(integrated @ meta.features ) > 0 ){
528+ dim_before = dim(integrated @ meta.features )
529+ integrated @ meta.features = integrated @ meta.features %> % . [! is.na(rownames(. )), ]
530+ dim_after = dim(integrated @ meta.features )
531+ if (sum(dim_before != dim_after ) > 0 ){
532+ print(" length of meta.features changed" )
533+ print(paste0(" before: " ,dim_before ))
534+ print(paste0(" after: " ,dim_before ))
535+ }
536+ }
537+
418538 seurat_obj @ assays $ integrated = integrated
419539 }
420540
0 commit comments