Skip to content

Commit

Permalink
fun
Browse files Browse the repository at this point in the history
scBarplotFractionAboveThr

nf
gene.expression.level.plots
  • Loading branch information
vertesy committed Oct 31, 2021
1 parent c697497 commit 83b745e
Showing 1 changed file with 28 additions and 11 deletions.
39 changes: 28 additions & 11 deletions Functions/Plotting.statistics.and.QC.R
Original file line number Diff line number Diff line change
Expand Up @@ -381,20 +381,21 @@ plot.clust.size.distr <- function(obj = combined.obj, ident = GetClusteringRuns(
# ------------------------------------------------
gene.expression.level.plots <- function(gene = 'TOP2A', obj = ls.Seurat[[1]], slot = c('counts', 'data')[2] ) {
slot = 'data'
GEX.Counts <- GetAssayData(object = obj, assay = 'RNA', slot = )
range(GEX.Counts)
print(gene)
if (gene %in% rownames(obj)) {
GEX.Counts <- GetAssayData(object = obj, assay = 'RNA', slot = slot)

GEX.Counts.total <- rowSums(GEX.Counts)
genes.expression <- GEX.Counts.total[gene]
mean.expr <- iround(mean(GEX.Counts[gene,]))
suffx = if (slot == 'counts') 'raw' else 'normalised, logtransformed'
(pname = paste(gene, 'and the', suffx,'transcript count distribution'))

qhistogram(GEX.Counts.total, vline = genes.expression, logX = T, w = 6, h = 4
, subtitle = paste('It belong to the top', pc_TRUE(GEX.Counts.total > genes.expression), 'of genes (black line). Mean expr:', mean.expr)
, plotname = pname, xlab = 'Total Transcripts in Dataset', ylab = 'Number of Genes')
GEX.Counts.total <- rowSums(GEX.Counts)
genes.expression <- GEX.Counts.total[gene]
mean.expr <- iround(mean(GEX.Counts[gene,]))

suffx = if (slot == 'counts') 'raw' else 'normalised, logtransformed'
(pname = paste(gene, 'and the', suffx,'transcript count distribution'))

qhistogram(GEX.Counts.total, vline = genes.expression, logX = T, w = 6, h = 4
, subtitle = paste('It belong to the top', pc_TRUE(GEX.Counts.total > genes.expression), 'of genes (black line). Mean expr:', mean.expr)
, plotname = pname, xlab = 'Total Transcripts in Dataset', ylab = 'Number of Genes')
} else { print(" !!! Gene not found in object!")}
}

# ------------------------------------------------
Expand Down Expand Up @@ -431,6 +432,22 @@ ww.calc_helper <- function(object, genes){ # From Github/Ryan-Zhu https://github

# ------------------------------------------------

scBarplotFractionAboveThr <- function(thrX = 0.01, columns.used = c('cl.names.top.gene.res.0.3', 'percent.ribo')
, obj = combined.obj, ) { # Calculat the fraction of cells per cluster above a certain threhold
meta = obj@meta.data
(fr_ribo_low_cells <- meta %>%
dplyr::select(columns.used) %>%
dplyr::group_by_(columns.used[1]) %>%
summarize(n_cells = n(),
n_ribo_low_cells = sum(!!as.name(columns.used[2]) < thrX),
fr_ribo_low_cells = n_ribo_low_cells / n_cells) %>%
FirstCol2RowNames())
print(fr_ribo_low_cells)

(v.fr_ribo_low_cells <- 100* as.named.vector(fr_ribo_low_cells[3]))
qbarplot(v.fr_ribo_low_cells, xlab.angle = 45, xlab = 'Clusters', ylab = '% Cells')
}



# ------------------------------------------------
Expand Down

0 comments on commit 83b745e

Please sign in to comment.