Commit d3941a28 authored by HaojiaWu's avatar HaojiaWu
Browse files

bug fixes

parent 01474202
Loading
Loading
Loading
Loading
+4 −2
Original line number Diff line number Diff line
@@ -36,7 +36,8 @@ Imports:
    GenomeInfoDb,
    EnsDb.Hsapiens.v86,
    cowplot,
    rlang
    rlang,
    GEOquery
Depends:
    Seurat,
    plotly,
@@ -65,7 +66,8 @@ Depends:
    GenomeInfoDb,
    EnsDb.Hsapiens.v86,
    cowplot,
    rlang
    rlang,
    GEOquery
License: GPL-3 
Encoding: UTF-8
LazyData: true
+2 −0
Original line number Diff line number Diff line
# Generated by roxygen2: do not edit by hand

export(Install.example)
export(add_sliding_windows)
export(add_track)
export(cell_order)
export(change_strip_background)
export(complex_dotplot_multiple)
export(complex_dotplot_single)
export(complex_featureplot)
export(complex_vlnplot_single)
export(convert_geneid)
export(creat_cellphonedb_file)
+1 −1
Original line number Diff line number Diff line
@@ -18,7 +18,7 @@ modified_dotplot <- function(
  levels(seu_obj) <- rev(levels(seu_obj))
  dataplot<-DotPlot(seu_obj, features = features)
  dataplot<-dataplot$data
  dataplot$avg.exp<-scale(dataplot$avg.exp)
  dataplot$avg.exp<-dataplot$avg.exp.scaled
  colnames(dataplot)[1:2]<-c('Avg.Exp', 'Pct.Exp')
  if(is.null(col_palette)){
    col_palette = colorRampPalette(c('grey80','lemonchiffon1','indianred1','darkred'))(255)
+10 −10
Original line number Diff line number Diff line
@@ -26,25 +26,25 @@ transform_coordinates <- function(
#' This function extracts the metadata from a Seurat object and transforms the
#' UMAP/tSNE coordinates.
#'
#' @param obj SeuratObject
#' @param seu_obj SeuratObject
#' @param reductions reductions methods, e.g."umap" or "tsne".
#' @param color Colors assigned to the cell clusters
#' @param coord_scale value from c(0,1) to adjust the UMAP/tSNE coordinates.
#' @return A metadata dataframe
#' @export
get_metadata <- function(
  obj, 
  seu_obj, 
  reductions = "umap", 
  coord_scale = 0.8, 
  color
  ){
  metadata<-obj@meta.data
  metadata$Cluster<-obj@active.ident
  metadata$dim1<-as.numeric(obj[[reductions]]@cell.embeddings[,1])
  metadata$dim2<-as.numeric(obj[[reductions]]@cell.embeddings[,2])
  metadata<-seu_obj@meta.data
  metadata$Cluster<-seu_obj@active.ident
  metadata$dim1<-as.numeric(seu_obj[[reductions]]@cell.embeddings[,1])
  metadata$dim2<-as.numeric(seu_obj[[reductions]]@cell.embeddings[,2])
  metadata$x<-transform_coordinates(metadata$dim1, zoom = coord_scale)
  metadata$y<-transform_coordinates(metadata$dim2, zoom = coord_scale)
  color_df<-data.frame(Cluster=levels(obj), Colors=color)
  color_df<-data.frame(Cluster=levels(seu_obj), Colors=color)
  cellnames<-rownames(metadata)
  metadata$cells<-rownames(metadata)
  metadata<-merge(metadata, color_df, by='Cluster')
@@ -58,15 +58,15 @@ get_metadata <- function(
#' This function labels the cells based their expression levels of the selected 
#' marker genes.
#'
#' @param obj SeuratObject
#' @param seu_obj SeuratObject
#' @param features Selected marker genes
#' @return A dataframe with cells labeled by marker genes
#' @export
mk_marker_ct <- function(
  obj, 
  seu_obj, 
  features
  ){
  dat <- Seurat::FetchData(obj, vars = features)
  dat <- Seurat::FetchData(seu_obj, vars = features)
  ori_names <- rownames(dat)
  zero_ct <- dat[rowSums(dat)==0,]
  non_zero <- dat[rowSums(dat)!=0,]
+3 −6
Original line number Diff line number Diff line
@@ -4,10 +4,7 @@
#' Plot single gene across groups
#'
#' This function can be used for plotting a single gene expression across 
#' different groups in a study with complex group design. It uses the data
#' output from the DotPlot function in the Seurat package and uses ggplot2 
#' to re-create a dotplot for better visualization. In the output graph, y axis
#' is the cluster name and x axis is the group ID.
#' different groups in a study with complex group design.
#'
#' @param seu_obj A complete Seurat object
#' @param feature Gene name. Only one gene is allowed.
@@ -27,11 +24,11 @@ complex_dotplot_single <- function(
  do.scale=T,
  scale.by='radius'
){
  groupby_level<-levels(seu_obj@meta.data[,groupby])
  seu_obj@meta.data[,groupby]<-gsub("_","-",seu_obj@meta.data[,groupby])
  if (is.null(levels(seu_obj@meta.data[,groupby]))){
  if (is.null(groupby_level)){
    seu_obj@meta.data[,groupby] <-factor(seu_obj@meta.data[,groupby], levels = names(table(seu_obj@meta.data[,groupby])))
  }
  groupby_level<-levels(seu_obj@meta.data[,groupby])
  levels(seu_obj)<-rev(levels(seu_obj))
  celltypes<-levels(seu_obj)
  celltypes<-gsub("_", "-", celltypes)
Loading