# Global options
knitr::opts_chunk$set(echo = TRUE)

# Load required libraries
ezLoadPackage('DT')
ezLoadPackage('ggplot2')
ezLoadPackage('plotly')
ezLoadPackage('Seurat')
data <- ezRead.table("metrics_summary.tsv", row.names = NULL)
param <- readRDS('param.rds')
if(param$visiumType == 'SD'){
    myPlots <- readRDS("myPlots.rds")
    scData <- readRDS("scData.rds")
}

{.tabset}

Overview

datatable(
  data,
  options = list(pageLength = 20, autoWidth = TRUE), rownames = FALSE)
mappingStats <- data[,c('Number_of_Reads','umiCounts')]
if(param$visiumType == 'SD'){
    mappingStats[['Reads_Under_Tissue']] <- data$Fraction_Reads_in_Spots_Under_Tissue * data$Number_of_Reads - mappingStats[['umiCounts']]
} else {
    mappingStats[['Reads_Under_Tissue']] <- data$Fraction_Reads_in_Squares_Under_Tissue * data$Number_of_Reads - mappingStats[['umiCounts']]
}
mappingStats[['otherReads']] <- mappingStats[['Number_of_Reads']] - mappingStats[['Reads_Under_Tissue']] - mappingStats[['umiCounts']]
rownames(mappingStats) <- data$sampleName
par(mar=c(10.1,4.1,4.1,2.1))
barplot(
    t(mappingStats[, 2:4] / 10^6),beside = FALSE,las = 2,cex.names = 1, main = "Reads per sample", ylab = "Reads in M", xlab = NULL,
    legend.text = TRUE, args.legend = list(x = "topright", inset = c(-0.1, -0.1),bty   = "n"))
data$umiCounts = NULL

Barplots per metric

# Identify numeric columns
numeric_cols <- names(data)[sapply(data, is.numeric)]

for (col in numeric_cols) {
    p <- ggplot(data, aes(x = sampleName, y = !!sym(col))) + 
    geom_bar(stat = "identity", fill = "steelblue") +
    xlab('') +
    ylab(col) +
    theme_minimal() + 
    ggtitle(col) + theme(axis.text.x = element_text(angle = 90, vjust = 0.5, hjust=0.1))

  print(p)
}

Images for Signals per Slide

if(param$visiumType=='SD'){
    for (j in 1:length(myPlots)) {
    sampleName <- names(myPlots)[j]
    print(myPlots[[sampleName]][['Overview']])
    print(myPlots[[sampleName]][['Tissue']])
    print(myPlots[[sampleName]][['Signal']])
}
} else if(param$visiumType=='HD'){
    cat('\n Not available for HD slides \n')
}

Determine Spot Size

if(param$visiumType=='SD'){
   imageName <- names(scData@images)
    coord <- GetTissueCoordinates(object = scData@images[[imageName]])
    myRatio <- (max(coord$x) - min(coord$x)) / (max(coord$y) - min(coord$y))
    for (j in 1:length(param$sizeFactors)){
        p <- SpatialFeaturePlot(scData, features = "nCount_Spatial", pt.size.factor =  param$sizeFactors[j]) 
        p <- p + theme(legend.position = "right") + theme(aspect.ratio = myRatio) + ggtitle(paste("pt.size.factor = ", param$sizeFactors[j]))
        print(p)
    }
} else if(param$visiumType=='HD'){
    cat('\n Not available for HD slides \n')
}

SessionInfo

ezSessionInfo()


uzh/ezRun documentation built on March 5, 2025, 3:41 p.m.