Commit 41e072f4 authored by HaojiaWu's avatar HaojiaWu
Browse files

bug fixes

parent f4cab112
Loading
Loading
Loading
Loading
+4 −2
Original line number Diff line number Diff line
@@ -37,7 +37,8 @@ Imports:
    EnsDb.Hsapiens.v86,
    cowplot,
    rlang,
    GEOquery
    GEOquery,
    simplifyEnrichment
Depends:
    Seurat,
    plotly,
@@ -67,7 +68,8 @@ Depends:
    EnsDb.Hsapiens.v86,
    cowplot,
    rlang,
    GEOquery
    GEOquery,
    simplifyEnrichment
License: GPL-3 
Encoding: UTF-8
LazyData: true
+2 −0
Original line number Diff line number Diff line
@@ -22,6 +22,8 @@ export(mk_marker_ct)
export(modified_coverageplot)
export(modified_dimplot)
export(modified_dotplot)
export(order_gene_down)
export(order_gene_up)
export(plot_circlize)
export(plot_qpcr)
export(plot_upset)
+36 −0
Original line number Diff line number Diff line
@@ -460,3 +460,39 @@ Install.example<-function(){
  unlink("GSE139107/",recursive=TRUE)
  iri.integrated
}

#' A function to order genes upregulated from the first to the last column
#' @param df A data frames with genes in row and samples in column
#' @export
order_gene_up<-function(df){
  min.col <- function(m, ...) max.col(-m, ...)
  df$celltype<-colnames(df)[min.col(df,ties.method="first")]
  df$celltype<-factor(df$celltype, levels = names(df))
  df<-df[order(df$celltype),]
  gene.names<-list()
  for (i in names(df)){
    aa<-df[df$celltype==i,]
    aa<-aa[order(aa[,i],decreasing = T),]
    gene.names[[i]]<-rownames(aa)
  }
  gene.names<-as.character(unlist(gene.names))
  return(gene.names)
}

#' A function to order genes downregulated from the first to the last column
#' @param df A data frames with genes in row and samples in column
#' @export
order_gene_down<-function(df){
  df$celltype<-colnames(df)[max.col(df,ties.method="first")]
  df$celltype<-factor(df$celltype, levels = names(df))
  df<-df[order(df$celltype),]
  gene.names<-list()
  for (i in names(df)){
    aa<-df[df$celltype==i,]
    aa<-aa[order(aa[,i],decreasing = F),]
    gene.names[[i]]<-rownames(aa)
  }
  gene.names<-as.character(unlist(gene.names))
  return(gene.names)
}
+9 −8
Original line number Diff line number Diff line
@@ -5,26 +5,27 @@ This package allows users to visualize the single cell data on the R objects or
## Installation
plot1cell R package can be easily installed from Github using devtools. Please make sure you have installed Seurat 4.0, circlize and ComplexHeatmap packages.
```
devtools::install_github("HaojiaWu/plot1cell")
devtools::install_github("TheHumphreysLab/plot1cell")
## or devtools::install_github("HaojiaWu/plot1cell")
```

## Usage
We provide some example codes to help generate figures on user's provided Seurat object. The Seurat object input to plot1cell should be a final object with completed clustering and cell type annotation. If a seurat object is not available, we suggest to use the demo data from Satija's lab (https://satijalab.org/seurat/articles/integration_introduction.html). To demonstrate the plotting functions in plot1cell, we re-created a Seurat object from our recent paper <a href="https://www.pnas.org/doi/10.1073/pnas.2005477117">Kirita et al, PNAS 2020</a> by integrating the count matrices we uploaded to GEO (GSE139107).
We provide some example codes to help generate figures from user's provided Seurat object. The Seurat object input to plot1cell should be a final object with completed clustering and cell type annotation. If a seurat object is not available, we suggest to use the demo data from Satija's lab (https://satijalab.org/seurat/articles/integration_introduction.html). To demonstrate the plotting functions in plot1cell, we re-created a Seurat object from our recent paper <a href="https://www.pnas.org/doi/10.1073/pnas.2005477117">Kirita et al, PNAS 2020</a> by integrating the count matrices we uploaded to GEO (GSE139107).
```
iri.integrated <- Install.example() 

# Please note that this Seurat object is just for demo purpose and 
# does not exactly the same as we published on PNAS.
# is not exactly the same as we published on PNAS.
# It take about 2 hours to run in a linux server with 500GB RAM and 32 CPU cores.
# You can skip this step and use your own Seurat object instead
```

### 1. Circlize plot to visualize cell clustering and meta data
```
###check and see the meta data info on your Seurat object
###Check and see the meta data info on your Seurat object
colnames(iri.integrated@meta.data)  

###Generate data for ploting
###Prepare data for ploting
circ_data <- prepare_circlize_data(iri.integrated, scale = 0.8 )
set.seed(1234)
cluster_colors<-rand_color(length(levels(iri.integrated)))
@@ -34,8 +35,8 @@ rep_colors<-group_colors<-rand_color(length(table(iri.integrated$orig.ident)))
###plot and save figures
png(filename =  'circlize_plot.png', width = 6, height = 6,units = 'in', res = 300)
plot_circlize(circ_data,do.label = T, pt.size = 0.01, col.use = cluster_colors ,bg.color = 'white', kde2d.n = 200)
add_track(circ_data, group = "Group", colors = group_colors) ## can change the meta data on your data
add_track(circ_data, group = "orig.ident",colors = rep_colors) ## can change the meta data on your data
add_track(circ_data, group = "Group", colors = group_colors) ## can change it to one of the columns in the meta data of your seurat object
add_track(circ_data, group = "orig.ident",colors = rep_colors) ## can change it to one of the columns in the meta data of your seurat object
dev.off()
```
![alt text](https://github.com/HaojiaWu/Plot1cell/blob/master/data/circlize_plot.png) <br />
@@ -76,7 +77,7 @@ dev.off()
Note that the Replicates group here is for demo purpose. This is not the mouse ID as reported in our original paper.

#### Multiple genes/multiple groups.
The violin plot will look too messy in this scenario so it is not included in plot1cell. It would highly recommend to use the complex_dot_plot instead. <br />
The violin plot will look too messy in this scenario so it is not included in plot1cell. It is highly recommended to use the complex_dot_plot instead. <br />
For scRNA-seq studies with higher complexity, the complex_vlnplot_single function also allows split the group by another group in the meta data with the argument "split.by". Since the demo dataset doesn't have this complexity, examples are not included here. Users can refer to our recent DKD dataset with multiple treatments/two timepoints (the PCT violin graph in <a href="https://humphreyslab.com/SingleCell/">K.I.T.</a>)

### 4. Umap geneplot across groups

man/order_gene_down.Rd

0 → 100644
+14 −0
Original line number Diff line number Diff line
% Generated by roxygen2: do not edit by hand
% Please edit documentation in R/utils.R
\name{order_gene_down}
\alias{order_gene_down}
\title{A function to order genes downregulated from the first to the last column}
\usage{
order_gene_down(df)
}
\arguments{
\item{df}{A data frames with genes in row and samples in column}
}
\description{
A function to order genes downregulated from the first to the last column
}
Loading