From b2a5c0cdceb74c1fe0bb464f1fbbf03994cb8a40 Mon Sep 17 00:00:00 2001 From: dimalvovs Date: Mon, 20 May 2024 13:00:17 -0400 Subject: [PATCH] refactor --- modules/local/spacemarkers.nf | 20 +++++++------------- 1 file changed, 7 insertions(+), 13 deletions(-) diff --git a/modules/local/spacemarkers.nf b/modules/local/spacemarkers.nf index c7ba64c..b1f3550 100644 --- a/modules/local/spacemarkers.nf +++ b/modules/local/spacemarkers.nf @@ -31,24 +31,18 @@ process SPACEMARKERS { """ mkdir "${prefix}" Rscript -e 'library("SpaceMarkers"); + #load expression data, filter out genes with arbitrarly low expression dataMatrix <- load10XExpr("$data"); - keepGenes <- rownames(dataMatrix); - keepGenes <- keepGenes[which(apply(dataMatrix,1,sum) > 10)]; + keepGenes <- rownames(dataMatrix)[which(apply(dataMatrix, 1, sum)>10)]; dataMatrix <- dataMatrix[keepGenes,] - coords <- load10XCoords("$data"); - rownames(coords) <- coords$barcode; - features <- getSpatialFeatures("$cogapsResult"); - barcodes <- intersect(rownames(features), rownames(coords)) - spPatterns <- cbind(coords[barcodes,], features[barcodes,]); - + #load spatial coordinates from tissue positions + coords <- load10XCoords(data); + features <- getSpatialFeatures(cogapsresult); + spPatterns <- merge(coords, features, by.x = "barcode", by.y = "row.names"); saveRDS(spPatterns, file = "${prefix}/spPatterns.rds"); - #temp fix to remove barcodes with no spatial data - barcodes <- intersect(rownames(spPatterns), colnames(dataMatrix)) - dataMatrix <- dataMatrix[keepGenes, barcodes] - spPatterns <- spPatterns[barcodes,] - + #compute optimal parameters for spatial patterns optParams <- getSpatialParameters(spPatterns); saveRDS(optParams, file = "${prefix}/optParams.rds");