Skip to content

Commit a549cd6

Browse files
committed
Merge branch 'main' of github.com:FertigLab/spatial-pipeline
2 parents 264748b + 818c2ae commit a549cd6

File tree

1 file changed

+33
-22
lines changed

1 file changed

+33
-22
lines changed

modules/local/spacemarkers.nf

Lines changed: 33 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -91,35 +91,46 @@ process SPACEMARKERS_MQC {
9191
9292
#[['']] notation needed to allow nextflow var susbtitution
9393
94+
#init all report variables
95+
n_pairs_total <- NA
96+
n_pairs_interact <- NA
97+
min_spacemarker_metric <- NA
98+
max_spacemarker_metric <- NA
99+
min_genes <- NA
100+
max_genes <- NA
101+
avg_hotspot_area <- NA
102+
94103
sm <- readRDS("$spaceMarkers")
95104
smi <- sm[which(sapply(sm, function(x) length(x[['interacting_genes']]))>0)]
96105
97106
#interacting patterns stats
98107
n_pairs_total <- length(sm)
99108
n_pairs_interact <- length(smi)
100109
101-
#spacemarker metric
102-
max_spacemarker_metric <- max(sapply(smi, function(x) {
103-
max(x[['interacting_genes']][[1]][['SpaceMarkersMetric']])
104-
}))
105-
min_spacemarker_metric <- min(sapply(smi, function(x) {
106-
min(x[['interacting_genes']][[1]][['SpaceMarkersMetric']])
107-
}))
108-
109-
#average number of genes in each pair
110-
min_genes <- min(sapply(smi, function(x) {
111-
nrow(x[['interacting_genes']][[1]])
112-
}))
113-
114-
#average number of genes in each pair
115-
max_genes <- max(sapply(smi, function(x) {
116-
nrow(x[['interacting_genes']][[1]])
117-
}))
118-
119-
#average percent overlap across interacting patterns
120-
avg_hotspot_area <- mean(sapply(smi, function(x) {
121-
sum(!is.na(x[['hotspots']]))/length(x[['hotspots']][,1])
122-
}))
110+
if(n_pairs_interact >0 ) {
111+
#spacemarker metric
112+
max_spacemarker_metric <- max(sapply(smi, function(x) {
113+
max(x[['interacting_genes']][[1]][['SpaceMarkersMetric']])
114+
}))
115+
min_spacemarker_metric <- min(sapply(smi, function(x) {
116+
min(x[['interacting_genes']][[1]][['SpaceMarkersMetric']])
117+
}))
118+
119+
#average number of genes in each pair
120+
min_genes <- min(sapply(smi, function(x) {
121+
nrow(x[['interacting_genes']][[1]])
122+
}))
123+
124+
#average number of genes in each pair
125+
max_genes <- max(sapply(smi, function(x) {
126+
nrow(x[['interacting_genes']][[1]])
127+
}))
128+
129+
#average percent overlap across interacting patterns
130+
avg_hotspot_area <- mean(sapply(smi, function(x) {
131+
sum(!is.na(x[['hotspots']]))/length(x[['hotspots']][,1])
132+
}))
133+
}
123134
124135
#report
125136
report_data <- list(

0 commit comments

Comments
 (0)