{"id":20969912,"url":"https://github.com/jumphone/beer","last_synced_at":"2025-05-14T11:32:46.470Z","repository":{"id":44437197,"uuid":"174378464","full_name":"jumphone/BEER","owner":"jumphone","description":"BEER: Batch EffEct Remover for single-cell data","archived":false,"fork":false,"pushed_at":"2025-01-09T06:01:33.000Z","size":63001,"stargazers_count":24,"open_issues_count":0,"forks_count":9,"subscribers_count":2,"default_branch":"master","last_synced_at":"2025-04-02T17:22:34.158Z","etag":null,"topics":["batch-effects","scatac-seq","scrna-seq","single-cell-analysis","umap"],"latest_commit_sha":null,"homepage":"","language":"R","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/jumphone.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2019-03-07T16:11:40.000Z","updated_at":"2025-01-09T06:01:36.000Z","dependencies_parsed_at":"2025-01-09T07:20:00.188Z","dependency_job_id":"d3901025-68b2-4c68-8347-d80e679d1023","html_url":"https://github.com/jumphone/BEER","commit_stats":null,"previous_names":[],"tags_count":18,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jumphone%2FBEER","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jumphone%2FBEER/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jumphone%2FBEER/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jumphone%2FBEER/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/jumphone","download_url":"https://codeload.github.com/jumphone/BEER/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":254131676,"owners_count":22019979,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["batch-effects","scatac-seq","scrna-seq","single-cell-analysis","umap"],"created_at":"2024-11-19T03:53:31.339Z","updated_at":"2025-05-14T11:32:46.448Z","avatar_url":"https://github.com/jumphone.png","language":"R","funding_links":[],"categories":[],"sub_categories":[],"readme":"\u003cimg src=\"https://github.com/jumphone/BEER/raw/master/DATA/BEER_LOGO.png\" width=\"200\"\u003e\n\n# BEER: Batch EffEct Remover for single-cell data\n\nEnvironment: R\n\nBEER's latest version: https://github.com/jumphone/BEER/releases\n\n# News:\n\n* Mar. 2021 ( V0.1.9 ): First version for Seurat 4.0.0\n\n* Feb. 2021 ( V0.1.8 ): Last version for Seurat 3.0.0\n\n* Nov. 2019 ( v0.1.7 ): In \".simple_combine(D1, D2, FILL=TRUE)\", \"FILL\" can help users to keep genes that are expressed in only one condition (fill the matrix with “0”). Default \"FILL\" is FALSE\n\n* July 2019 ( v0.1.6 ): BEER can automatically adjust \"GNUM\" when cell number is small in some batch \n\n* July 2019 ( v0.1.5 ): \"ComBat\" is used to replace \"regression\" of \"ScaleData\" (ComBat is much faster)\n\n* July 2019 ( v0.1.4 ): Users can provide genes which need to be removed.\n\n* July 2019 ( v0.1.3 ): Users can use [VISA](https://github.com/jumphone/VISA) to extract peaks of scATAC-seq.\n\n* ...\n\n# Content:\n\n* [Workflow](#workflow)\n* [Requirement (Installation)](#requirement)\n* [Vignettes (Usage)](#vignettes)\n* [Reference](#reference)\n* [License](#license)\n\n\u003c/br\u003e\n\u003c/br\u003e\n\u003c/br\u003e\n\n--------------------------------------------------------------------------------------------\n\n\n# Workflow:\n\n#### Latest version\n\n\u003cimg src=\"https://github.com/jumphone/BEER/raw/master/DATA/BP.png\" width=\"400\"\u003e\n\nPlease see [V. Batch-effect Removal Enhancement](#v-batch-effect-removal-enhancement) for details of \"Enhancement\".\n\n\u003c/br\u003e\n\u003c/br\u003e\n\n# Requirement:\n\n    #R \u003e=3.5\n    install.packages('Seurat') # ==4.0.0 \n    \n    # Install ComBat:\n    if (!requireNamespace(\"BiocManager\", quietly = TRUE))\n    install.packages(\"BiocManager\")\n    BiocManager::install(\"sva\")\n    BiocManager::install(\"limma\")\n\n    # Users can use \"BEER\" by directly importing \"BEER.R\" on the github webpage:\n    \n    source('https://raw.githubusercontent.com/jumphone/BEER/master/BEER.R')\n    \n    # Or, download and import it:\n    \n    source('BEER.R')\n    \n    \nFor batch-effect removal enhancement, please install BBKNN: https://github.com/Teichlab/bbknn\n\n\u003c/br\u003e\n\u003c/br\u003e\n\n\n# Vignettes:\n\n* [I. Combine Two Batches](#I-Combine-Two-Batches)\n* [II. Combine Multiple Batches](#II-Combine-Multiple-Batches)\n* [III. UMAP-based Clustering](#III-UMAP-based-Clustering)\n* [IV. Combine scATAC-seq \u0026 scRNA-seq](#iv-combine-scatac-seq--scrna-seq)\n* [V. Batch-effect Removal Enhancement](#v-batch-effect-removal-enhancement)\n* [VI. Transfer Labels](#vi-transfer-labels)\n* [VII. Biological Interpretation](#vii-biological-interpretation)\n* [VIII. QC before using BEER](#viii-QC-before-using-beer)\n\n\n\u003c/br\u003e\n\n# Set Python\n\n    library(reticulate)\n    use_python(\"/home/toolkit/local/bin/python3\",required=T)\n    py_config()\n\n\u003c/br\u003e\n\n# I. Combine Two Batches\n\nDownload demo data: https://github.com/jumphone/BEER/raw/master/DATA/demodata.zip \n\nPlease do basic quality control before using BEER (e.g. remove low-quality cells \u0026 genes). \n\nFor QC, please see: https://satijalab.org/seurat/v3.0/pbmc3k_tutorial.html \n\n### Step1. Load Data\n\n    library(Seurat)\n  \n    source('https://raw.githubusercontent.com/jumphone/BEER/master/BEER.R')\n    #source('BEER.R')\n    \n    #Read 10X data: pbmc.data \u003c- Read10X(data.dir = \"../data/pbmc3k/filtered_gene_bc_matrices/hg19/\")\n    \n    #Load Demo Data (subset of GSE70630: MGH53 \u0026 MGH54)\n    #Download: https://github.com/jumphone/BEER/raw/master/DATA/demodata.zip\n    \n    D1 \u003c- read.table(unz(\"demodata.zip\",\"DATA1_MAT.txt\"), sep='\\t', row.names=1, header=T)\n    D2 \u003c- read.table(unz(\"demodata.zip\",\"DATA2_MAT.txt\"), sep='\\t', row.names=1, header=T)\n\n    # \"D1\" \u0026 \"D2\" are UMI matrix (or FPKM, RPKM, TPM, PKM ...; Should not be gene-centric scaled data)\n    # Rownames of \"D1\" \u0026 \"D2\" are gene names\n    # Colnames of \"D1\" \u0026 \"D2\" are cell names \n    \n    # There shouldn't be duplicated colnames in \"D1\" \u0026 \"D2\":\n    colnames(D1)=paste0('D1_', colnames(D1))\n    colnames(D2)=paste0('D2_', colnames(D2))\n\n    DATA=.simple_combine(D1,D2)$combine\n    \n    # Users can use \"DATA=.simple_combine(D1,D2, FILL=TRUE)$combine\" to keep genes that are expressed in only one condition.\n    \n    BATCH=rep('D2',ncol(DATA))\n    BATCH[c(1:ncol(D1))]='D1'\n    \n    # Simple Quality Control (QC): check the number of sequenced genes\n    # PosN=apply(DATA,2,.getPos)\n    # USED=which(PosN\u003e500 \u0026 PosN\u003c4000) \n    # DATA=DATA[,USED]; BATCH=BATCH[USED] \n    \n\n### Step2. Detect Batch Effect\n\n    mybeer=BEER(DATA, BATCH, GNUM=30, PCNUM=50, ROUND=1, GN=2000, SEED=1, COMBAT=TRUE, RMG=NULL)   \n\n    # DATA: Expression matrix. Rownames are genes. Colnames are cell names.\n    # BATCH: A character vector. Length is equal to the \"ncol(DATA)\".\n    # GNUM: the number of groups in each batch (default: 30)\n    # PCNUM: the number of computated PCA subspaces (default: 50)\n    # ROUND: batch-effect removal strength, positive integer (default: 1)\n    # GN: the number of variable genes in each batch (default: 2000)\n    # RMG: genes need to be removed (default: NULL)\n    # COMBAT: use ComBat to adjust expression value(default: TRUE)    \n    \n    # Users can use \"ReBEER\" to adjust GNUM, PCNUM, ROUND, and RMG (it's faster than directly using BEER).\n    # mybeer \u003c- ReBEER(mybeer, GNUM=30, PCNUM=50, ROUND=1, SEED=1, RMG=NULL) \n    \n    # Check selected PCs\n    PCUSE=mybeer$select\n    COL=rep('black',length(mybeer$cor))\n    COL[PCUSE]='red'\n    plot(mybeer$cor,mybeer$lcor,pch=16,col=COL,\n        xlab='Rank Correlation',ylab='Linear Correlation',xlim=c(0,1),ylim=c(0,1))\n    \nUsers can select PCA subspaces based on the distribution of \"Rank Correlation\" and \"Linear Correlation\".\n\n    # PCUSE=.selectUSE(mybeer, CUTR=0.7, CUTL=0.7, RR=0.5, RL=0.5)\n    \n        \n\u003cimg src=\"https://github.com/jumphone/BEER/raw/master/DATA/PLOT1.png\" width=\"400\"\u003e\n    \n### Step3. Visualization \n    \n#### Keep batch effect:\n   \n    pbmc_batch=CreateSeuratObject(counts = DATA, min.cells = 0, min.features = 0, project = \"ALL\") \n    pbmc_batch@meta.data$batch=BATCH\n    pbmc_batch=FindVariableFeatures(object = pbmc_batch, selection.method = \"vst\", nfeatures = 2000)   \n    VariableFeatures(object = pbmc_batch)\n    pbmc_batch \u003c- NormalizeData(object = pbmc_batch, normalization.method = \"LogNormalize\", scale.factor = 10000)\n    pbmc_batch \u003c- ScaleData(object = pbmc_batch, features = VariableFeatures(object = pbmc_batch))\n    pbmc_batch \u003c- RunPCA(object = pbmc_batch, seed.use=123, npcs=50, features = VariableFeatures(object = pbmc_batch), ndims.print=1,nfeatures.print=1)\n    pbmc_batch \u003c- RunUMAP(pbmc_batch, dims = 1:50, seed.use = 123,n.components=2)\n    DimPlot(pbmc_batch, reduction='umap', group.by='batch', pt.size=0.1) \n    \n\u003cimg src=\"https://github.com/jumphone/BEER/raw/master/DATA/PLOT2.png\" width=\"400\"\u003e\n     \n\n#### Remove batch effect:\n\n    pbmc \u003c- mybeer$seurat\n    PCUSE \u003c- mybeer$select\n    pbmc \u003c- RunUMAP(object = pbmc, reduction='pca',dims = PCUSE, check_duplicates=FALSE)\n    \n    DimPlot(pbmc, reduction='umap', group.by='batch', pt.size=0.1) \n    \n\u003cimg src=\"https://github.com/jumphone/BEER/raw/master/DATA/PLOT3.png\" width=\"400\"\u003e\n\n      \n    \n    \n\u003c/br\u003e\n\u003c/br\u003e\n    \n# II. Combine Multiple Batches\n\nDownload demo data: https://sourceforge.net/projects/beergithub/files/\n   \n### Step1. Load Data\n    \n    source('https://raw.githubusercontent.com/jumphone/BEER/master/BEER.R')\n    \n    #Load Demo Data (Oligodendroglioma, GSE70630)\n    #Download: https://sourceforge.net/projects/beergithub/files/\n    \n    D1=readRDS('MGH36.RDS')\n    D2=readRDS('MGH53.RDS')\n    D3=readRDS('MGH54.RDS')\n    D4=readRDS('MGH60.RDS')\n    D5=readRDS('MGH93.RDS')\n    D6=readRDS('MGH97.RDS')\n    \n    BATCH=c(rep('D1',ncol(D1)),\n            rep('D2',ncol(D2)),\n            rep('D3',ncol(D3)),\n            rep('D4',ncol(D4)),\n            rep('D5',ncol(D5)),\n            rep('D6',ncol(D6)) )\n            \n    D12=.simple_combine(D1,D2)$combine\n    D34=.simple_combine(D3,D4)$combine\n    D56=.simple_combine(D5,D6)$combine\n    D1234=.simple_combine(D12,D34)$combine\n    D123456=.simple_combine(D1234,D56)$combine\n    \n    DATA=D123456   \n   \n    rm(D1);rm(D2);rm(D3);rm(D4);rm(D5);rm(D6)\n    rm(D12);rm(D34);rm(D56);rm(D1234);rm(D123456)\n    \n    # Simple Quality Control (QC): check the number of sequenced genes\n    # PosN=apply(DATA,2,.getPos)\n    # USED=which(PosN\u003e500 \u0026 PosN\u003c4000) \n    # DATA=DATA[,USED]; BATCH=BATCH[USED] \n    \n### Step2. Use BEER to Detect Batch Effect\n\n    mybeer=BEER(DATA, BATCH, GNUM=30, PCNUM=50, ROUND=1, GN=2000, SEED=1, COMBAT=TRUE )\n\n    # Check selected PCs\n    PCUSE=mybeer$select\n    COL=rep('black',length(mybeer$cor))\n    COL[PCUSE]='red'\n    plot(mybeer$cor,mybeer$lcor,pch=16,col=COL,\n        xlab='Rank Correlation',ylab='Linear Correlation',xlim=c(0,1),ylim=c(0,1))\n    \n\n\u003cimg src=\"https://github.com/jumphone/BEER/raw/master/DATA/PLOT4.png\" width=\"400\"\u003e\n\n    \n### Step3. Visualization \n        \n#### Keep batch effect:\n  \n\n    pbmc_batch=CreateSeuratObject(counts = DATA, min.cells = 0, min.features = 0, project = \"ALL\") \n    pbmc_batch@meta.data$batch=BATCH\n    pbmc_batch=FindVariableFeatures(object = pbmc_batch, selection.method = \"vst\", nfeatures = 2000)   \n    VariableFeatures(object = pbmc_batch)\n    pbmc_batch \u003c- NormalizeData(object = pbmc_batch, normalization.method = \"LogNormalize\", scale.factor = 10000)\n    pbmc_batch \u003c- ScaleData(object = pbmc_batch, features = VariableFeatures(object = pbmc_batch))\n    pbmc_batch \u003c- RunPCA(object = pbmc_batch, seed.use=123, npcs=50, features = VariableFeatures(object = pbmc_batch), ndims.print=1,nfeatures.print=1)\n    pbmc_batch \u003c- RunUMAP(pbmc_batch, dims = 1:50, seed.use = 123,n.components=2)\n    DimPlot(pbmc_batch, reduction='umap', group.by='batch', pt.size=0.1) \n \n    \n\u003cimg src=\"https://github.com/jumphone/BEER/raw/master/DATA/PLOT5.png\" width=\"400\"\u003e\n\n\n#### Remove batch effect:\n\n\n    pbmc \u003c- mybeer$seurat\n    PCUSE \u003c- mybeer$select\n    pbmc \u003c- RunUMAP(object = pbmc, reduction='pca',dims = PCUSE, check_duplicates=FALSE)\n    \n    DimPlot(pbmc, reduction='umap', group.by='batch', pt.size=0.1)   \n    \n\u003cimg src=\"https://github.com/jumphone/BEER/raw/master/DATA/PLOT6.png\" width=\"400\"\u003e\n   \n    \n\u003c/br\u003e   \n\u003c/br\u003e\n\n\n# III. UMAP-based Clustering\n   \n\n    VEC=pbmc@reductions$umap@cell.embeddings\n\n    # Here, we use K-means to do the clustering\n    N=20\n    set.seed(123)\n    K=kmeans(VEC,centers=N)\n\n    CLUST=K$cluster\n    pbmc@meta.data$clust=as.character(CLUST)\n    DimPlot(pbmc, reduction='umap', group.by='clust', pt.size=0.5,label=TRUE)\n    \n\n\u003cimg src=\"https://github.com/jumphone/BEER/raw/master/DATA/CLUST1.png\" width=\"400\"\u003e    \n\n\n    # Or, manually select some cells\n\n    ppp=DimPlot(pbmc, reduction='umap', pt.size=0.5)\n    used.cells \u003c- CellSelector(plot = ppp)\n    \n\n\u003cimg src=\"https://github.com/jumphone/BEER/raw/master/DATA/PLOT6.png\" width=\"400\"\u003e    \n\n    # Press \"ESC\"\n    \n\u003cimg src=\"https://github.com/jumphone/BEER/raw/master/DATA/CLUST3.png\" width=\"400\"\u003e    \n    \n    markers \u003c- FindMarkers(pbmc, ident.1=used.cells,only.pos=T)    \n    head(markers, n=20)\n    \n    \n\u003c/br\u003e   \n\u003c/br\u003e\n\n# IV. Combine scATAC-seq \u0026 scRNA-seq\n\nPlease install \"Signac\": https://satijalab.org/signac/\n\nDownload DEMO data: https://sourceforge.net/projects/beer-file/files/ATAC/ \u0026 https://satijalab.org/signac/articles/pbmc_vignette.html\n\n### Step1. Load Data\n\n    source('https://raw.githubusercontent.com/jumphone/BEER/master/BEER.R')\n    #source('BEER.R')\n    \n    library(Seurat)\n    library(Signac)\n    library(EnsDb.Hsapiens.v75)\n    \n    counts \u003c- Read10X_h5(filename = \"./data/atac_v1_pbmc_10k_filtered_peak_bc_matrix.h5\")\n    \n    metadata \u003c- read.csv(\n      file = \"./data/atac_v1_pbmc_10k_singlecell.csv\",\n      header = TRUE,\n      row.names = 1\n        )\n\n    chrom_assay \u003c- CreateChromatinAssay(\n        counts = counts,\n        sep = c(\":\", \"-\"),\n        genome = 'hg19',\n        fragments = './data/atac_v1_pbmc_10k_fragments.tsv.gz',\n        min.cells = 10,\n        min.features = 200\n       )\n\n    pbmc.atac \u003c- CreateSeuratObject(\n        counts = chrom_assay,\n        assay = \"peaks\",\n        meta.data = metadata\n        )\n    \n    annotations \u003c- GetGRangesFromEnsDb(ensdb = EnsDb.Hsapiens.v75)\n    seqlevelsStyle(annotations) \u003c- \"UCSC\"\n    genome(annotations) \u003c- \"hg19\"\n    Annotation(pbmc.atac) \u003c- annotations\n\n\n    gene.activities \u003c- GeneActivity(pbmc.atac)\n         \n    pbmc.rna \u003c- readRDS(\"./data/pbmc_10k_v3.rds\")\n    \n    D1=as.matrix(gene.activities)\n    D2=as.matrix(pbmc.rna@assays$RNA@counts)\n    colnames(D1)=paste0('ATAC_', colnames(D1))\n    colnames(D2)=paste0('RNA_', colnames(D2))\n    \n    D1=.check_rep(D1)\n    D2=.check_rep(D2)\n    \n    DATA=.simple_combine(D1,D2)$combine\n    BATCH=rep('RNA',ncol(DATA))\n    BATCH[c(1:ncol(D1))]='ATAC'\n    \n \n \n### Step2. Use BEER to Detect Batch Effect\n\n    mybeer \u003c- BEER(DATA, BATCH, GNUM=30, PCNUM=50, ROUND=1, GN=5000, SEED=1, COMBAT=TRUE)\n    saveRDS(mybeer, file='mybeer')\n    \n    # Users can use \"ReBEER\" to adjust parameters\n    mybeer \u003c- ReBEER(mybeer, GNUM=100, PCNUM=100, ROUND=3, SEED=1)\n    \n    PCUSE=mybeer$select\n    #PCUSE=.selectUSE(mybeer, CUTR=0.8, CUTL=0.8, RR=0.5, RL=0.5)\n    \n    COL=rep('black',length(mybeer$cor))\n    COL[PCUSE]='red'\n    plot(mybeer$cor,mybeer$lcor,pch=16,col=COL,\n        xlab='Rank Correlation',ylab='Linear Correlation',xlim=c(0,1),ylim=c(0,1))\n    \n\n\u003cimg src=\"https://github.com/jumphone/BEER/raw/master/DATA/PLOT7.png\" width=\"400\"\u003e   \n\n\n### Step3. Visualization \n    \n#### Keep batch effect:\n  \n    pbmc_batch=CreateSeuratObject(counts = DATA, min.cells = 0, min.features = 0, project = \"ALL\") \n    pbmc_batch@meta.data$batch=BATCH\n    pbmc_batch=FindVariableFeatures(object = pbmc_batch, selection.method = \"vst\", nfeatures = 2000)   \n    VariableFeatures(object = pbmc_batch)\n    pbmc_batch \u003c- NormalizeData(object = pbmc_batch, normalization.method = \"LogNormalize\", scale.factor = 10000)\n    pbmc_batch \u003c- ScaleData(object = pbmc_batch, features = VariableFeatures(object = pbmc_batch))\n    pbmc_batch \u003c- RunPCA(object = pbmc_batch, seed.use=123, npcs=50, features = VariableFeatures(object = pbmc_batch), ndims.print=1,nfeatures.print=1)\n    pbmc_batch \u003c- RunUMAP(pbmc_batch, dims = 1:50, seed.use = 123,n.components=2)\n    DimPlot(pbmc_batch, reduction='umap', group.by='batch', pt.size=0.1)   \n    \n\u003cimg src=\"https://github.com/jumphone/BEER/raw/master/DATA/PLOT8.png\" width=\"400\"\u003e\n       \n\n#### Remove batch effect:\n\n    pbmc \u003c- mybeer$seurat  \n    PCUSE=mybeer$select\n    pbmc \u003c- RunUMAP(object = pbmc, reduction='pca',dims = PCUSE, check_duplicates=FALSE)\n    \n    DimPlot(pbmc, reduction='umap', group.by='batch', pt.size=0.1)    \n    \n\u003cimg src=\"https://github.com/jumphone/BEER/raw/master/DATA/PLOT9.png\" width=\"400\"\u003e\n   \n    pbmc@meta.data$celltype=rep(NA,length(pbmc@meta.data$batch))\n    pbmc@meta.data$celltype[which(pbmc@meta.data$batch=='RNA')]=pbmc.rna@meta.data$celltype\n    \n    DimPlot(pbmc, reduction='umap', group.by='celltype', pt.size=0.1,label=T)\n    \n\u003cimg src=\"https://github.com/jumphone/BEER/raw/master/DATA/PLOT10.png\" width=\"400\"\u003e\n\n    saveRDS(mybeer, file='mybeer.final.RDS')\n    \n\n# It's not good enough !\n\n### For further enhancement, please see [V. Batch-effect Removal Enhancement](#v-batch-effect-removal-enhancement).\n\n\u003c/br\u003e\n\u003c/br\u003e\n\n# V. Batch-effect Removal Enhancement\n\nPlease install BBKNN: https://github.com/Teichlab/bbknn\n    \nThis DEMO follows [IV. Combine scATAC-seq \u0026 scRNA-seq](#iv-combine-scatac-seq--scrna-seq)\n    \n    source('https://raw.githubusercontent.com/jumphone/BEER/master/BEER.R')\n    #source('BEER.R')\n    mybeer=readRDS('mybeer.final.RDS')\n    pbmc.rna \u003c- readRDS(\"./data/pbmc_10k_v3.rds\")\n    \n    \n### Use ComBat \u0026 BBKNN without BEER:\n\n    pbmc \u003c- mybeer$seurat\n    PCUSE=c(1:ncol(pbmc@reductions$pca@cell.embeddings))\n    pbmc=BEER.combat(pbmc) #Adjust PCs using ComBat\n    umap=BEER.bbknn(pbmc, PCUSE, NB=3, NT=10)\n    pbmc@reductions$umap@cell.embeddings=umap\n    DimPlot(pbmc, reduction='umap', group.by='batch', pt.size=0.1,label=F)\n    \n    \n\u003cimg src=\"https://github.com/jumphone/BEER/raw/master/DATA/PLOT12.png\" width=\"400\"\u003e     \n\n### Use ComBat \u0026 BBKNN with BEER:\n\n    pbmc \u003c- mybeer$seurat\n    PCUSE=mybeer$select   \n    pbmc=BEER.combat(pbmc) #Adjust PCs using ComBat\n    umap=BEER.bbknn(pbmc, PCUSE, NB=3, NT=10)\n    pbmc@reductions$umap@cell.embeddings=umap\n    DimPlot(pbmc, reduction='umap', group.by='batch', pt.size=0.1,label=F)\n     \n    saveRDS(pbmc, file='seurat.enh.RDS')\n  \n\u003cimg src=\"https://github.com/jumphone/BEER/raw/master/DATA/PLOT13.png\" width=\"400\"\u003e \n  \n    pbmc@meta.data$celltype=rep(NA,length(pbmc@meta.data$batch))\n    pbmc@meta.data$celltype[which(pbmc@meta.data$batch=='RNA')]=pbmc.rna@meta.data$celltype\n    DimPlot(pbmc, reduction='umap', group.by='celltype', pt.size=0.1,label=T)\n     \n\u003cimg src=\"https://github.com/jumphone/BEER/raw/master/DATA/PLOT14.png\" width=\"400\"\u003e \n\n### Use BBKNN in Python:\n\nPlease download [beer_bbknn.py](https://raw.githubusercontent.com/jumphone/BEER/master/beer_bbknn.py).\n\n    source('https://raw.githubusercontent.com/jumphone/BEER/master/BEER.R')\n    #source('BEER.R')\n    pbmc \u003c- mybeer$seurat\n    pbmc=BEER.combat(pbmc) #Adjust PCs using ComBat\n    PCUSE = mybeer$select\n    used.pca = pbmc@reductions$pca@cell.embeddings[,PCUSE]\n    .writeTable(DATA=used.pca, PATH='used.pca.txt',SEP=',')\n    .writeTable(DATA=pbmc@meta.data$batch, PATH='batch.txt',SEP=',')\n    \nThen, use \"beer_bbknn.py\" in your command line (please modify parameters in [beer_bbknn.py](https://raw.githubusercontent.com/jumphone/BEER/master/beer_bbknn.py)):\n\n    python beer_bbknn.py\n\nFinally, load the output of beer_bbknn.py and draw UMAP:\n\n    umap=read.table('bbknn_umap.txt',sep='\\t',header=FALSE)\n    umap=as.matrix(umap)\n    rownames(umap)=rownames(pbmc@reductions$umap@cell.embeddings)\n    colnames(umap)=colnames(pbmc@reductions$umap@cell.embeddings)\n    pbmc@reductions$umap@cell.embeddings=umap\n    DimPlot(pbmc, reduction='umap', group.by='batch', pt.size=0.1,label=F)\n     \n\n\u003c/br\u003e\n\n# VI. Transfer labels\n\nThis DEMO follows [V. Batch-effect Removal Enhancement](#v-batch-effect-removal-enhancement)\n   \n    pbmc@meta.data$celltype=rep(NA,length(pbmc@meta.data$batch))\n    pbmc@meta.data$celltype[which(pbmc@meta.data$batch=='RNA')]=pbmc.rna@meta.data$celltype\n    #DimPlot(pbmc, reduction='umap', group.by='celltype', pt.size=0.1,label=T)\n    \n    #######\n    VEC=pbmc@reductions$umap@cell.embeddings\n    set.seed(123)\n    N=150\n    K=kmeans(VEC,centers=N)\n    pbmc@meta.data$kclust=K$cluster   \n    #DimPlot(pbmc, reduction='umap', group.by='kclust', pt.size=0.1,label=T)\n\n    pbmc@meta.data$transfer=rep(NA, length(pbmc@meta.data$celltype))\n    TMP=cbind(pbmc@meta.data$celltype, pbmc@meta.data$kclust)\n    \n    KC=unique(pbmc@meta.data$kclust)\n    i=1\n    while(i\u003c=length(KC)){\n        this_kc=KC[i]\n        this_index=which(pbmc@meta.data$kclust==this_kc)\n        this_tb=table(pbmc@meta.data$celltype[this_index])\n        if(length(this_tb)!=0){\n            this_ct=names(this_tb)[which(this_tb==max(this_tb))[1]]\n            pbmc@meta.data$transfer[this_index]=this_ct}\n        i=i+1}\n        \n    pbmc@meta.data$tf.ct=pbmc@meta.data$celltype\n    NA.index=which(is.na(pbmc@meta.data$celltype))\n    pbmc@meta.data$tf.ct[NA.index]=pbmc@meta.data$transfer[NA.index]\n    \n    ######\n    RNA.cells=colnames(pbmc)[which(pbmc@meta.data$batch=='RNA')]\n    ATAC.cells=colnames(pbmc)[which(pbmc@meta.data$batch=='ATAC')]\n    \n    library(ggplot2)\n    \n    plot.all \u003c- DimPlot(pbmc, reduction='umap', group.by='batch', \n        pt.size=0.1,label=F) + labs(title = \"Batches\")\n    \n    plot.ct \u003c- DimPlot(pbmc,reduction='umap', group.by='tf.ct', \n        pt.size=0.1,label=T) + labs(title = \"CellType\")\n    \n    plot.rna \u003c- DimPlot(pbmc, cells=RNA.cells,reduction='umap', \n        group.by='tf.ct', pt.size=0.1,label=T,plot.title='RNA.transfer') + labs(title = \"RNA\")\n    \n    plot.atac \u003c- DimPlot(pbmc, cells=ATAC.cells,reduction='umap', \n        group.by='tf.ct', pt.size=0.1,label=T,plot.title='ATAC.transfer') + labs(title = \"ATAC\")\n    \n    CombinePlots(list(all=plot.all, ct=plot.ct, rna=plot.rna, atac=plot.atac))\n    \n\n\u003cimg src=\"https://github.com/jumphone/BEER/raw/master/DATA/PLOT15.png\" width=\"900\"\u003e \n\nIf you want to visualize peak signals of any given cluster, please go to https://github.com/jumphone/VISA.\n\n\u003c/br\u003e\n\u003c/br\u003e\n\n# VII. Biological Interpretation\n\nPlease install \"RITANdata\" and \"RITAN\".\n\nRITAN: https://bioconductor.org/packages/devel/bioc/vignettes/RITAN/inst/doc/enrichment.html\n\nThis DEMO follows [IV. Combine scATAC-seq \u0026 scRNA-seq](#iv-combine-scatac-seq--scrna-seq)\n\n    library(RITANdata)\n    library(RITAN)\n    \n    PCUSE \u003c- mybeer$select\n    PCALL \u003c- c(1:length(mybeer$cor))\n    PCnotUSE \u003c- PCALL[which(!PCALL %in% PCUSE)]\n    \n    LD=mybeer$seurat@reductions$pca@feature.loadings\n    GNAME=rownames(LD)\n    \n    N=100\n    getPosAndNegTop \u003c- function(x){\n        O=c(order(x)[1:N],order(x)[(length(x)-(N-1)):length(x)])\n        G=GNAME[O]\n        return(G)\n        }\n    \n    GMAT=apply(LD,2,getPosAndNegTop)\n    colnames(GMAT)=paste0(colnames(GMAT),'_R_',round(mybeer$cor,1),\"_L_\",round(mybeer$lcor,1))\n    GMAT=toupper(GMAT)\n    \n    GMAT=GMAT[,PCnotUSE]\n    #GMAT=GMAT[,PCUSE]\n  \n    study_set=list()\n    TAG=colnames(GMAT)\n    i=1\n    while(i\u003c=ncol(GMAT)){\n         study_set=c(study_set,list(GMAT[,i]))\n         i=i+1\n         }  \n         \n    names(study_set)=TAG\n    #names(geneset_list)\n    resources=c('KEGG_filtered_canonical_pathways','MSigDB_Hallmarks')\n    \n    e \u003c- term_enrichment_by_subset( study_set, q_value_threshold = 1e-5, \n                                resources = resources,\n                                all_symbols = cached_coding_genes )\n    \n    plot( e, show_values = FALSE, label_size_y = 7, label_size_x = 7, cap=10 )\n    \n\u003c/br\u003e \n\n\u003cimg src=\"https://github.com/jumphone/BEER/raw/master/DATA/PLOTEB.png\" width=\"600\"\u003e \n\n\u003c/br\u003e   \n\u003c/br\u003e \n\n\n# VIII. QC before using BEER\n\nDownload demo data: https://sourceforge.net/projects/beergithub/files/\n\n### Step1. Load Data\n\n    source('https://raw.githubusercontent.com/jumphone/BEER/master/BEER.R')\n\n    #Load Demo Data (Oligodendroglioma, GSE70630)\n    #Download: https://sourceforge.net/projects/beergithub/files/\n\n    D1=readRDS('MGH36.RDS')\n    D2=readRDS('MGH53.RDS')\n    D3=readRDS('MGH54.RDS')\n    D4=readRDS('MGH60.RDS')\n    D5=readRDS('MGH93.RDS')\n    D6=readRDS('MGH97.RDS')\n\n    BATCH=c(rep('D1',ncol(D1)),\n            rep('D2',ncol(D2)),\n            rep('D3',ncol(D3)),\n            rep('D4',ncol(D4)),\n            rep('D5',ncol(D5)),\n            rep('D6',ncol(D6)) )\n        \n    D12=.simple_combine(D1,D2)$combine\n    D34=.simple_combine(D3,D4)$combine\n    D56=.simple_combine(D5,D6)$combine\n    D1234=.simple_combine(D12,D34)$combine\n    D123456=.simple_combine(D1234,D56)$combine\n\n    DATA=D123456   \n\n    rm(D1);rm(D2);rm(D3);rm(D4);rm(D5);rm(D6)\n    rm(D12);rm(D34);rm(D56);rm(D1234);rm(D123456)\n    \n\n\n### Step2. QC\n    \n    pbmc \u003c- CreateSeuratObject(counts = DATA, project = \"pbmc3k\", min.cells = 0, min.features = 0)\n    Idents(pbmc)=BATCH\n    pbmc@meta.data$batch=BATCH\n    \n    pbmc \u003c- subset(pbmc, subset = nFeature_RNA \u003e 200 \u0026 nFeature_RNA \u003c 2500 \u0026 percent.mt \u003c 5)\n    \nPlease fllow https://satijalab.org/seurat/v3.1/pbmc3k_tutorial.html to do Quality Control.\n\n    \n    BATCH=pbmc@meta.data$batch\n    \n    DATA=as.matrix(pbmc@assays$RNA@counts[,which(colnames(pbmc@assays$RNA@counts) %in% colnames(pbmc@assays$RNA@data))])\n    \n \n\n### Step3. BEER\n\nRefer to [II. Combine Multiple Batches](#II-Combine-Multiple-Batches) \n\n\u003c/br\u003e \n\n\n\n\n# Reference:\n\nFeng Zhang, Yu Wu, Weidong Tian*; A novel approach to remove the batch effect of single-cell data, Cell Discovery, 2019, https://doi.org/10.1038/s41421-019-0114-x\n\n\n### Differences between the latest version and the manuscript version\n\nLatest version: https://github.com/jumphone/BEER/releases\n\nManuscript version: https://github.com/jumphone/BEER/archive/0.0.2.zip\n\n\u003cimg src=\"https://github.com/jumphone/BEER/raw/master/DATA/DIFF.png\" width=\"600\"\u003e\n\n\u003c/br\u003e\n\u003c/br\u003e\n\n\n\n\n\u003cimg src=\"https://fzhang.bioinfo-lab.com/img/white.png\" height=\"50\"\u003e\n\n-------------------------------------------------------------------------------------------------------------------\n\n\u003cimg src=\"https://fzhang.bioinfo-lab.com/img/panda_happy_logo.png\" height='150'\u003e\n\n#### More tools \u0026 studies: https://fzhang.bioinfo-lab.com/\n\n    \n# License\n    \n    MIT License\n    \n    Copyright (c) 2019 Zhang, Feng\n\n    Permission is hereby granted, free of charge, to any person obtaining a copy\n    of this software and associated documentation files (the \"Software\"), to deal\n    in the Software without restriction, including without limitation the rights\n    to use, copy, modify, merge, publish, distribute, sublicense, and/or sell\n    copies of the Software, and to permit persons to whom the Software is\n    furnished to do so, subject to the following conditions:\n\n    The above copyright notice and this permission notice shall be included in all\n    copies or substantial portions of the Software.\n\n    THE SOFTWARE IS PROVIDED \"AS IS\", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR\n    IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,\n    FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE\n    AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER\n    LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,\n    OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE\n    SOFTWARE.\n\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fjumphone%2Fbeer","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fjumphone%2Fbeer","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fjumphone%2Fbeer/lists"}