@@ -45,8 +45,8 @@ ExportToCellbrowser <- function(
4545 skip.markers = FALSE ,
4646 all.meta = FALSE
4747) {
48- if (substr(object @ version , 1 , 1 )!= ' 2' ) {
49- stop(" can only process Seurat2 objects, version of rds is " , object @ version )
48+ if (substr(object @ version , 1 , 1 )!= ' 2' ) {
49+ stop(" can only process Seurat2 objects, version of rds is " , object @ version )
5050 }
5151
5252 # idents <- FetchData(object,c("ident"))$ident;
@@ -150,23 +150,32 @@ ExportToCellbrowser <- function(
150150 }
151151 file <- paste0(" markers." , ext )
152152 fname <- file.path(dir , file )
153- if (is.null(markers.file ) & ! skip.markers ) {
153+
154+ if (! is.null(markers.file ) && ! skip.markers ) {
155+ message(" Copying " , markers.file , " to " , fname )
156+ file.copy(markers.file , fname )
157+ }
158+ if (is.null(markers.file ) && skip.markers ) {
159+ file <- NULL
160+ }
161+ if (is.null(markers.file ) && ! skip.markers ) {
154162 if (length(levels(idents )) > 1 ) {
155163 message(" Running FindAllMarkers(), using ROC test, min logfc diff 0.35, and writing top " , markers.n , " , cluster markers to " , fname )
156164 markers <- FindAllMarkers(object , do.print = TRUE , print.bar = TRUE , test.use = " roc" , logfc.threshold = 0.35 )
157- require(dplyr ) # if this fails, install dplyr with install.packages("dplyr")
158- top.markers <- markers %> % group_by(cluster ) %> % top_n(markers.n , avg_logFC )
159- write.table(top.markers , fname , quote = FALSE , sep = " \t " , row.names = FALSE )
165+ markers.helper <- function (x ) {
166+ partition <- markers [x ,]
167+ ord <- order(partition $ p_val_adj < 0.05 , - partition $ avg_logFC )
168+ res <- x [ord ]
169+ res <- c(res [1 : markers.n ], rep(NA , length(x ) - markers.n ))
170+ return (res )
171+ }
172+ markers.order <- ave(rownames(markers ), markers $ cluster , FUN = markers.helper )
173+ top.markers <- markers [markers.order [! is.na(markers.order )],]
174+ write.table(top.markers , fname , quote = FALSE , sep = " \t " , col.names = NA )
160175 } else {
176+ message(" No clusters found in Seurat object, so no marker genes can be computed" )
161177 file <- NULL
162178 }
163- } else if (! skip.markers ) {
164- message(" Copying " , markers.file , " to " , fname )
165- file.copy(markers.file , fname )
166- }
167- else {
168- message(" No marker genes file defined" )
169- file <- NULL
170179 }
171180
172181 if (! is.null(file )) {
0 commit comments