diff --git a/.gitignore b/.gitignore
index 09396370d55024e1bbffaac11cf0789212434eb9..fa9ab1fcec34d2887fd38c4119bc31bfd3f714dc 100755
--- a/.gitignore
+++ b/.gitignore
@@ -1,7 +1,7 @@
 analysis/*
+!.gitkeep
 .vscode/
 WR/
-stress/*
 *.err
 *.out
 *.Rhistory
@@ -10,4 +10,4 @@ stress/*
 *~
 temp_png.png
 Rplots.pdf
-!.gitkeep
+stress/*
diff --git a/README.md b/README.md
index cfb0bb098f004ff6bb307f4e6d24454ab489540e..2612d2f655d5496786f6e09ae651ced4f13421ce 100755
--- a/README.md
+++ b/README.md
@@ -11,8 +11,8 @@ Determining cellular heterogeneity in the human prostate with single-cell RNA se
         * <a href="https://orcid.org/0000-0002-0746-927X" target="orcid.widget" rel="noopener noreferrer" style="vertical-align:top;"><img src="https://orcid.org/sites/default/files/images/orcid_16x16.png" style="width:1em;margin-right:.5em;" alt="ORCID iD icon">orcid.org/0000-0002-0746-927X</a>
         * PI Email: [douglas.strand@utsouthwestern.edu](mailto:douglas.strand@utsouthwestern.edu)
 * **ANALYZED DATA FOR QUERYING AT: [StrandLab.net](http://strandlab.net/analysis.php)**
-* **Raw data at: [GEO (scRNA-Seq)](https://www.ncbi.nlm.nih.gov/geo/query/acc.cgi?acc=GSE117403) & [GEO (popRNA-Seq)](https://www.ncbi.nlm.nih.gov/geo/query/acc.cgi?acc=GSE117271) & [GenitoUrinary Development Molecular Anatomy Project (GUDMAP)]("https://doi.org/10.25548/W-R8CM")**
-* **Publication at: PENDING**
+* **Raw data at: [GEO](https://www.ncbi.nlm.nih.gov/geo/query/acc.cgi?acc=GSE120716) & [GenitoUrinary Development Molecular Anatomy Project (GUDMAP)]("https://doi.org/10.25548/W-R8CM")**
+* **Publication at: [BioRxiv](https://www.biorxiv.org/content/early/2018/10/15/439935)**
 
 Data Analysis
 -------------
@@ -50,6 +50,10 @@ Data Analysis
         * run bash script [sc\_TissueMapper\-D17\_FACS.sh](https://git.biohpc.swmed.edu/StrandLab/sc-TissueMapper_Pr/blob/master/bash.scripts/sc_TissueMapper-D17_FACS.sh)
     * 3 Run on 2nd patient FACS samples
         * run bash script [sc\_TissueMapper\-D27\_FACS.sh](https://git.biohpc.swmed.edu/StrandLab/sc-TissueMapper_Pr/blob/master/bash.scripts/sc_TissueMapper-D27_FACS.sh)
+    * 4 Run on several downsamples from 1 sample from 1st patient
+        * run bash script [sc\_TissueMapper\-DS\_D17.sh](https://git.biohpc.swmed.edu/StrandLab/sc-TissueMapper_Pr/blob/master/bash.scripts/sc_TissueMapper-DS_D17.sh)
+    * 5 Aggregate and compare several downsamples from #4
+        * run bash script [sc\_TissueMapper\_RUN.DS\_D17.aggr.R](https://git.biohpc.swmed.edu/StrandLab/sc-TissueMapper_Pr/blob/master/r.scripts/sc_TissueMapper_RUN.DS_D17.aggr.R)
 * **Pipeline:**
     * Link cellranger count/aggr output to analysis
     * Create demultiplex file to add custom sample groups
@@ -118,4 +122,4 @@ Data Analysis
         * "c2.all.v6.1.symbols.gmt" MSigDB C2 Curated Gene Sets [**MSigDB C2**](http://software.broadinstitute.org/gsea/msigdb/genesets.jsp?collection=C2)
         * "c2.cp.kegg.v6.1.symbols" MSigDB C2 KEGG Gene Subsets [**KEGG**](http://software.broadinstitute.org/gsea/msigdb/genesets.jsp?collection=CP:KEGG)
         * "c5.all.v6.1.symbols.gmt" MSigDB C5 Gene Ontology Gene Sets [**MSigDB C5**](http://software.broadinstitute.org/gsea/msigdb/genesets.jsp?collection=C5)
-        * "c5.bp.v6.1.symbols.gmt" MSigDB C5 Gene Ontology Biological Processes Gene Subsets [**GO BP**](http://software.broadinstitute.org/gsea/msigdb/genesets.jsp?collection=BP)
\ No newline at end of file
+        * "c5.bp.v6.1.symbols.gmt" MSigDB C5 Gene Ontology Biological Processes Gene Subsets [**GO BP**](http://software.broadinstitute.org/gsea/msigdb/genesets.jsp?collection=BP)
diff --git a/bash.scripts/sc_TissueMapper-D17_FACS.sh b/bash.scripts/sc_TissueMapper-D17_FACS.sh
index a1b9e80f4b3ce0e426aa055443adfa3bf91f95cd..169f73d4397bafd30f8efab043255126f04ca0d4 100644
--- a/bash.scripts/sc_TissueMapper-D17_FACS.sh
+++ b/bash.scripts/sc_TissueMapper-D17_FACS.sh
@@ -1,5 +1,5 @@
 #!/bin/bash
-#SBATCH --job-name R_FullAnalysis
+#SBATCH --job-name R_FullAnalysis.D17FACS
 #SBATCH -p 256GB,256GBv1,384GB
 #SBATCH -N 1
 #SBATCH -t 7-0:0:0
@@ -8,6 +8,8 @@
 #SBATCH --mail-type ALL
 #SBATCH --mail-user gervaise.henry@utsouthwestern.edu
 
-module load R/3.4.1-gccmkl
+module load R/3.4.1-gccmkl_20181025
+
+sh ./sc_LinkData.sh D17_FACS
 
 Rscript ../r.scripts/sc-TissueMapper_RUN.D17_FACS.R
diff --git a/bash.scripts/sc_TissueMapper-D27_FACS.sh b/bash.scripts/sc_TissueMapper-D27_FACS.sh
index 492d870914d32d72cbfe82f9a201fee8df210ae4..326afcab5959ce5aa0b5bcf33360484659bb55cc 100644
--- a/bash.scripts/sc_TissueMapper-D27_FACS.sh
+++ b/bash.scripts/sc_TissueMapper-D27_FACS.sh
@@ -1,5 +1,5 @@
 #!/bin/bash
-#SBATCH --job-name R_FullAnalysis
+#SBATCH --job-name R_FullAnalysis.D27FACS
 #SBATCH -p 256GB,256GBv1,384GB
 #SBATCH -N 1
 #SBATCH -t 7-0:0:0
@@ -8,6 +8,8 @@
 #SBATCH --mail-type ALL
 #SBATCH --mail-user gervaise.henry@utsouthwestern.edu
 
-module load R/3.4.1-gccmkl
+module load R/3.4.1-gccmkl_20181025
+
+sh ./sc_LinkData.sh D27_FACS
 
 Rscript ../r.scripts/sc-TissueMapper_RUN.D27_FACS.R
diff --git a/bash.scripts/sc_TissueMapper-DS_D17.sh b/bash.scripts/sc_TissueMapper-DS_D17.sh
new file mode 100644
index 0000000000000000000000000000000000000000..b7ae6943ae8144209d7b4e98ab8d84957d917142
--- /dev/null
+++ b/bash.scripts/sc_TissueMapper-DS_D17.sh
@@ -0,0 +1,13 @@
+#!/bin/bash
+#SBATCH --job-name R_FullAnalysis.DS
+#SBATCH -p 256GB,256GBv1,384GB
+#SBATCH -N 1
+#SBATCH -t 7-0:0:0
+#SBATCH -o job_%j.out
+#SBATCH -e job_%j.out
+#SBATCH --mail-type ALL
+#SBATCH --mail-user gervaise.henry@utsouthwestern.edu
+
+module load R/3.4.1-gccmkl_20181025
+
+Rscript ../r.scripts/sc-TissueMapper_RUN.DS_D17.R
diff --git a/bash.scripts/sc_TissueMapper-Pd.sh b/bash.scripts/sc_TissueMapper-Pd.sh
index c75360c8ed4efff44f2eb37a5bee3eb9f152e5b5..4c4ef806410f3e4bcf5c2f3ea1f5e3138cfcb31c 100644
--- a/bash.scripts/sc_TissueMapper-Pd.sh
+++ b/bash.scripts/sc_TissueMapper-Pd.sh
@@ -1,5 +1,5 @@
 #!/bin/bash
-#SBATCH --job-name R_FullAnalysis
+#SBATCH --job-name R_FullAnalysis.Pd
 #SBATCH -p 256GB,256GBv1,384GB
 #SBATCH -N 1
 #SBATCH -t 7-0:0:0
@@ -8,6 +8,8 @@
 #SBATCH --mail-type ALL
 #SBATCH --mail-user gervaise.henry@utsouthwestern.edu
 
-module load R/3.4.1-gccmkl
+module load R/3.4.1-gccmkl_20181025
 
-Rscript ../r.scripts/sc-TissueMapper_RUN.Pd.R
\ No newline at end of file
+sh ./sc_LinkData.sh Pd
+
+Rscript ../r.scripts/sc-TissueMapper_RUN.Pd.R
diff --git a/r.scripts/sc-TissueMapper.R b/r.scripts/sc-TissueMapper.R
index 53b6d5874a9435b026be315a74d9c02dea0805bc..71d98579bb582df4326eda8683d27572aa1f90ac 100644
--- a/r.scripts/sc-TissueMapper.R
+++ b/r.scripts/sc-TissueMapper.R
@@ -346,6 +346,8 @@ scStress <- function(sc10x,stg="go",res.use=1,pc.use=10,cut=0.95){
   sc10x.Stress <- t(sc10x.Stress)
   sc10x.Stress <- sc10x.Stress[,apply(sc10x.Stress,2,var)!=0]
   sc10x.Stress.pca <- prcomp(sc10x.Stress,center=TRUE,scale.=TRUE)
+  sc10x.Stress.pca.pc1var <- round((sc10x.Stress.pca$sdev[1]^2)/sum(sc10x.Stress.pca$sdev^2)*100,0)
+  sc10x.Stress.pca.pc2var <- round((sc10x.Stress.pca$sdev[2]^2)/sum(sc10x.Stress.pca$sdev^2)*100,0)
   sc10x.Stress.pca <- sc10x.Stress.pca$x[,1:2]
   colnames(x=sc10x.Stress.pca) <- paste0("Stress",1:2)
   if (skewness(sc10x.Stress.pca[,1])<0){
@@ -363,6 +365,8 @@ scStress <- function(sc10x,stg="go",res.use=1,pc.use=10,cut=0.95){
   plot <- plot+geom_density2d(color="black",bins=25,alpha=0.5)
   plot <- plot+theme(axis.text.x=element_text(size=20),axis.text.y=element_text(size=20),axis.title.x=element_text(size=20),axis.title.y=element_text(size=20),legend.text=element_text(size=20))
   plot <- plot+guides(colour=guide_legend(override.aes=list(size=10)))
+  plot <- plot+xlab(paste0("Stress PC1 (",sc10x.Stress.pca.pc1var,"%)"))
+  plot <- plot+ylab(paste0("Stress PC2 (",sc10x.Stress.pca.pc2var,"%)"))
   plot(plot)
   dev.off()
   
@@ -397,6 +401,8 @@ scStress <- function(sc10x,stg="go",res.use=1,pc.use=10,cut=0.95){
   plot <- plot+theme(axis.text.x=element_text(size=20),axis.text.y=element_text(size=20),axis.title.x=element_text(size=20),axis.title.y=element_text(size=20),legend.text=element_text(size=20))
   plot <- plot+guides(colour=guide_legend(override.aes=list(size=10)))
   plot <- plot+geom_vline(xintercept=cut.x,color="red",lwd=2.5)
+  plot <- plot+xlab(paste0("Stress PC1 (",sc10x.Stress.pca.pc1var,"%)"))
+  plot <- plot+ylab(paste0("Stress PC2 (",sc10x.Stress.pca.pc2var,"%)"))
   plot(plot)
   dev.off()
   
@@ -845,6 +851,8 @@ scNE <- function(sc10x,neg="EurUro",cut=0.95){
   sc10x.NE <- t(sc10x.NE)
   sc10x.NE <- sc10x.NE[,apply(sc10x.NE,2,var)!=0]
   sc10x.NE.pca <- prcomp(sc10x.NE,center=TRUE,scale.=TRUE)
+  sc10x.NE.pca.pc1var <- round((sc10x.NE.pca$sdev[1]^2)/sum(sc10x.NE.pca$sdev^2)*100,0)
+  sc10x.NE.pca.pc2var <- round((sc10x.NE.pca$sdev[2]^2)/sum(sc10x.NE.pca$sdev^2)*100,0)
   sc10x.NE.pca <- sc10x.NE.pca$x[,1:2]
   colnames(x=sc10x.NE.pca) <- paste0("NE",1:2)
   if (skewness(sc10x.NE.pca[,1])<0){
@@ -861,6 +869,8 @@ scNE <- function(sc10x,neg="EurUro",cut=0.95){
   plot <- DimPlot(object=sc10x,reduction.use="NE",pt.size=2.5,do.return=TRUE,vector.friendly=FALSE)
   plot <- plot+theme(axis.text.x=element_text(size=20),axis.text.y=element_text(size=20),axis.title.x=element_text(size=20),axis.title.y=element_text(size=20),legend.text=element_text(size=20))
   plot <- plot+guides(colour=guide_legend(override.aes=list(size=10)))
+  plot <- plot+xlab(paste0("NE PC1 (",sc10x.NE.pca.pc1var,"%)"))
+  plot <- plot+ylab(paste0("NE PC2 (",sc10x.NE.pca.pc2var,"%)"))
   plot(plot)
   dev.off()
   
@@ -894,6 +904,8 @@ scNE <- function(sc10x,neg="EurUro",cut=0.95){
   plot <- plot+theme(axis.text.x=element_text(size=20),axis.text.y=element_text(size=20),axis.title.x=element_text(size=20),axis.title.y=element_text(size=20),legend.text=element_text(size=20))
   plot <- plot+guides(colour=guide_legend(override.aes=list(size=10)))
   plot <- plot+geom_vline(xintercept=cut.x,color="red",lwd=2.5)
+  plot <- plot+xlab(paste0("NE PC1 (",sc10x.NE.pca.pc1var,"%)"))
+  plot <- plot+ylab(paste0("NE PC2 (",sc10x.NE.pca.pc2var,"%)"))
   plot(plot)
   dev.off()
   
diff --git a/r.scripts/sc-TissueMapper_RUN.DS_D17.R b/r.scripts/sc-TissueMapper_RUN.DS_D17.R
new file mode 100644
index 0000000000000000000000000000000000000000..fb7d2bc6274a724da4e21a307ed20d0ae6b27370
--- /dev/null
+++ b/r.scripts/sc-TissueMapper_RUN.DS_D17.R
@@ -0,0 +1,398 @@
+gc()
+library(methods)
+library(optparse)
+library(Seurat)
+library(readr)
+library(fBasics)
+library(pastecs)
+library(qusage)
+library(RColorBrewer)
+library(monocle)
+library(dplyr)
+library(viridis)
+library(reshape2)
+library(NMI)
+
+options(bitmapType="cairo")
+
+source("../r.scripts/sc-TissueMapper.R")
+
+#Create folder structure
+setwd("../")
+if (!dir.exists("./analysis")){
+  dir.create("./analysis")
+}
+if (!dir.exists("./analysis/qc")){
+  dir.create("./analysis/qc")
+}
+if (!dir.exists("./analysis/qc/cc")){
+  dir.create("./analysis/qc/cc")
+}
+if (!dir.exists("./analysis/tSNE")){
+  dir.create("./analysis/tSNE")
+}
+if (!dir.exists("./analysis/tSNE/pre.stress")){
+  dir.create("./analysis/tSNE/pre.stress")
+}
+if (!dir.exists("./analysis/pca")){
+  dir.create("./analysis/pca")
+}
+if (!dir.exists("./analysis/pca/stress")){
+  dir.create("./analysis/pca/stress")
+}
+if (!dir.exists("./analysis/violin")){
+  dir.create("./analysis/violin")
+}
+if (!dir.exists("./analysis/violin/stress")){
+  dir.create("./analysis/violin/stress")
+}
+if (!dir.exists("./analysis/table")){
+  dir.create("./analysis/table")
+}
+if (!dir.exists("./analysis/tSNE/post.stress")){
+  dir.create("./analysis/tSNE/post.stress")
+}
+if (!dir.exists("./analysis/cor")){
+  dir.create("./analysis/cor")
+}
+if (!dir.exists("./analysis/tSNE/lin")){
+  dir.create("./analysis/tSNE/lin")
+}
+if (!dir.exists("./analysis/tSNE/epi")){
+  dir.create("./analysis/tSNE/epi")
+}
+if (!dir.exists("./analysis/tSNE/st")){
+  dir.create("./analysis/tSNE/st")
+}
+if (!dir.exists("./analysis/tSNE/merge")){
+  dir.create("./analysis/tSNE/merge")
+}
+if (!dir.exists("./analysis/pca/ne")){
+  dir.create("./analysis/pca/ne")
+}
+if (!dir.exists("./analysis/tSNE/ne")){
+  dir.create("./analysis/tSNE/ne")
+}
+if (!dir.exists("./analysis/violin/ne")){
+  dir.create("./analysis/violin/ne")
+}
+if (!dir.exists("./analysis/tSNE/FINAL")){
+  dir.create("./analysis/tSNE/FINAL")
+}
+if (!dir.exists("./analysis/deg")){
+  dir.create("./analysis/deg")
+}
+if (!dir.exists("./analysis/cca")){
+  dir.create("./analysis/cca")
+}
+if (!dir.exists("./analysis/diy")){
+  dir.create("./analysis/diy")
+}
+if (!dir.exists("./analysis/pseudotime")){
+  dir.create("./analysis/pseudotime")
+}
+
+#Retrieve command-line options
+option_list=list(
+  make_option("--p",action="store",default="DPrF",type='character',help="Project Name"),
+  make_option("--g",action="store",default="ALL",type='character',help="Group To analyze"),
+  make_option("--lg",action="store",default=0,type='integer',help="Threshold for cells with minimum genes"),
+  make_option("--hg",action="store",default=3000,type='integer',help="Threshold for cells with maximum genes"),
+  make_option("--lm",action="store",default=0,type='numeric',help="Threshold for cells with minimum %mito genes"),
+  make_option("--hm",action="store",default=0.1,type='numeric',help="Threshold for cells with maximum %mito genes"),
+  make_option("--lx",action="store",default=0.2,type='numeric',help="x low threshold for hvg selection"),
+  make_option("--hx",action="store",default=5,type='numeric',help="x high threshold for hvg selection"),
+  make_option("--ly",action="store",default=1,type='numeric',help="y low threshold for hvg selection"),
+  make_option("--cc",action="store",default=FALSE,type='logical',help="Scale cell cycle?"),
+  make_option("--cca",action="store",default=50,type='integer',help="Number of CCAs to cacluate"),
+  make_option("--acca",action="store",default=30,type='integer',help="Number of CCAs to align"),
+  make_option("--pc",action="store",default=50,type='integer',help="Number of PCs to cacluate"),
+  make_option("--res.prestress",action="store",default=1,type='numeric',help="Resolution to cluster, pre-stress"),
+  make_option("--st",action="store",default=TRUE,type='logical',help="Remove stressed cells?"),
+  make_option("--stg",action="store",default="dws",type='character',help="Geneset to use for stress ID"),
+  make_option("--cut.stress",action="store",default=0.9,type='numeric',help="Cutoff for stress score"),
+  make_option("--res.poststress",action="store",default=1,type='numeric',help="Resolution to cluster, post-stress"),
+  make_option("--cut.ne",action="store",default=0.999,type='numeric',help="Cutoff for NE score")
+)
+opt=parse_args(OptionParser(option_list=option_list))
+rm(option_list)
+if (opt$lg==0){opt$lg=-Inf}
+if (opt$lm==0){opt$lm=-Inf}
+
+sc10x.data <- Read10X(data.dir="./analysis/DATA/10x/filtered_gene_bc_matrices/GRCh38/")
+sc10x <- new("seurat",raw.data=sc10x.data)
+cell.codes <- as.data.frame(sc10x@raw.data@Dimnames[[2]])
+colnames(cell.codes) <- "barcodes"
+rownames(cell.codes) <- cell.codes$barcodes
+cell.codes$samples <- "All"
+sc10x <- CreateSeuratObject(raw.data=sc10x.data,meta.data=cell.codes["samples"],min.cells=3,min.genes=-Inf,project="DS.D17")
+rm(cell.codes)
+rm(sc10x.data)
+
+if (opt$cc==TRUE){
+  results <- scCellCycle(sc10x)
+  sc10x <- results[[1]]
+  genes.s <- results[[2]]
+  genes.g2m <- results[[3]]
+  rm(results)
+} else {
+  genes.s=""
+  genes.g2m=""
+}
+
+results <- scQC(sc10x,lg=opt$lg,hg=opt$hg,lm=opt$lm,hm=opt$hm)
+sc10x <- results[[1]]
+counts.cell.raw <- results[[2]]
+counts.gene.raw <- results[[3]]
+counts.cell.filtered <- results[[4]]
+counts.gene.filtered <- results[[5]]
+rm(results)
+
+gc()
+if (opt$cc==TRUE){
+  sc10x <- ScaleData(object=sc10x,vars.to.regress=c("nUMI","percent.mito","S.Score","G2M.Score"),display.progress=FALSE,do.par=TRUE,num.cores=45)
+} else {
+  sc10x <- ScaleData(object=sc10x,vars.to.regress=c("nUMI","percent.mito"),display.progress=FALSE,do.par=TRUE,num.cores=45)
+}
+gc()
+
+results <- scPC(sc10x,lx=opt$lx,hx=opt$hx,ly=opt$ly,cc=opt$cc,pc=50,hpc=0.85,file="pre.stress",cca=FALSE)
+sc10x <- results[[1]]
+genes.hvg.prestress <- results[[2]]
+pc.use.prestress <- results[[3]]
+rm(results)
+
+sc10x <- scCluster(sc10x,pc.use=pc.use.prestress,res.use=opt$res.prestress,folder="pre.stress",red="pca")
+
+if (opt$st==TRUE){
+  results <- scStress(sc10x,stg=opt$stg,res.use=opt$res.prestress,cut=opt$cut.stress)
+  sc10x <- results[[1]]
+  counts.cell.filtered.stress <- results[[2]]
+  sc10x.Stress <- results[[3]]
+  rm(results)
+  
+  results <- scPC(sc10x,lx=opt$lx,hx=opt$hx,ly=opt$ly,cc=opt$cc,pc=50,hpc=0.85,file="post.stress",cca=FALSE)
+  sc10x <- results[[1]]
+  genes.hvg.poststress <- results[[2]]
+  pc.use.poststress <- results[[3]]
+  rm(results)
+  
+  sc10x <- scCluster(sc10x,pc.use=pc.use.poststress,res.use=opt$res.poststress,folder="post.stress",red="pca")
+}
+
+gene.set1 <- read_delim("./genesets/genes.deg.Epi.csv",",",escape_double=FALSE,trim_ws=TRUE,col_names=TRUE)
+gene.set1 <- gene.set1[1]
+gene.set1 <- as.list(gene.set1)
+names(gene.set1) <- "Epi"
+gene.set <- c(gene.set1)
+gene.set1 <- read_delim("./genesets/genes.deg.St.csv",",",escape_double=FALSE,trim_ws=TRUE,col_names=TRUE)
+gene.set1 <- gene.set1[1]
+gene.set1 <- as.list(gene.set1)
+names(gene.set1) <- "St"
+gene.set <- c(gene.set,gene.set1)
+rm(gene.set1)
+gc()
+min.all <- min(table(sc10x@meta.data[,paste0("res",opt$res.poststress)]))
+results <- scQuSAGE(sc10x,gs=gene.set,res.use=opt$res.poststress,ds=min.all,nm="Lin",folder="lin")
+sc10x <- results[[1]]
+results.cor.Lin <- results[[2]]
+results.clust.Lin.id <- results[[3]]
+rm(results)
+rm(gene.set)
+
+sc10x <- SetAllIdent(object=sc10x,id="Lin")
+sc10x.Epi <- scSubset(sc10x,i="Lin",g="Epi")
+if (any(levels(sc10x@ident)=="Unknown")){
+  sc10x.St <- scSubset(sc10x,i="Lin",g=c("St","Unknown"))
+} else {
+  sc10x.St <- scSubset(sc10x,i="Lin",g="St")
+}
+sc10x.Epi <- SetAllIdent(object=sc10x.Epi,id=paste0("res",opt$res.poststress))
+sc10x.Epi <- BuildClusterTree(sc10x.Epi,do.reorder=TRUE,reorder.numeric=TRUE,do.plot=FALSE)
+sc10x.Epi <- StashIdent(object=sc10x.Epi,save.name=paste0("res",opt$res.poststress))
+sc10x.St <- SetAllIdent(object=sc10x.St,id=paste0("res",opt$res.poststress))
+sc10x.St <- BuildClusterTree(sc10x.St,do.reorder=TRUE,reorder.numeric=TRUE,do.plot=FALSE)
+sc10x.St <- StashIdent(object=sc10x.St,save.name=paste0("res",opt$res.poststress))
+
+sc10x.Epi <- RunTSNE(object=sc10x.Epi,reduction.use="pca",dims.use=1:pc.use.poststress,do.fast=TRUE)
+postscript(paste0("./analysis/tSNE/epi/tSNE_Sample.eps"))
+plot <- TSNEPlot(object=sc10x.Epi,group.by="samples",pt.size=2.5,do.return=TRUE,vector.friendly=FALSE)
+plot <- plot+theme(axis.text.x=element_text(size=20),axis.text.y=element_text(size=20),axis.title.x=element_text(size=20),axis.title.y=element_text(size=20),legend.text=element_text(size=20))
+plot <- plot+guides(colour=guide_legend(override.aes=list(size=10)))
+plot(plot)
+dev.off()
+postscript(paste0("./analysis/tSNE/epi/tSNE_res",opt$res.poststress,".eps"))
+plot <- TSNEPlot(object=sc10x.Epi,pt.size=5,do.label=TRUE,label.size=10,do.return=TRUE,vector.friendly=FALSE)
+plot <- plot+theme(axis.text.x=element_text(size=20),axis.text.y=element_text(size=20),axis.title.x=element_text(size=20),axis.title.y=element_text(size=20),legend.text=element_text(size=20))
+plot <- plot+guides(colour=guide_legend(override.aes=list(size=10)))
+plot(plot)
+dev.off()
+rm(plot)
+
+sc10x.St <- RunTSNE(object=sc10x.St,reduction.use="pca",dims.use=1:pc.use.poststress,do.fast=TRUE)
+postscript(paste0("./analysis/tSNE/st/tSNE_Sample.eps"))
+plot <- TSNEPlot(object=sc10x.St,group.by="samples",pt.size=2.5,do.return=TRUE,vector.friendly=FALSE)
+plot <- plot+theme(axis.text.x=element_text(size=20),axis.text.y=element_text(size=20),axis.title.x=element_text(size=20),axis.title.y=element_text(size=20),legend.text=element_text(size=20))
+plot <- plot+guides(colour=guide_legend(override.aes=list(size=10)))
+plot(plot)
+dev.off()
+postscript(paste0("./analysis/tSNE/st/tSNE_res",opt$res.poststress,".eps"))
+plot <- TSNEPlot(object=sc10x.St,pt.size=5,do.label=TRUE,label.size=10,do.return=TRUE,vector.friendly=FALSE)
+plot <- plot+theme(axis.text.x=element_text(size=20),axis.text.y=element_text(size=20),axis.title.x=element_text(size=20),axis.title.y=element_text(size=20),legend.text=element_text(size=20))
+plot <- plot+guides(colour=guide_legend(override.aes=list(size=10)))
+plot(plot)
+dev.off()
+rm(plot)
+
+gene.set1 <- read_delim("./genesets/genes.deg.BE.csv",",",escape_double=FALSE,trim_ws=TRUE,col_names=TRUE)
+gene.set1 <- gene.set1[1]
+gene.set1 <- as.list(gene.set1)
+names(gene.set1) <- "BE"
+gene.set <- c(gene.set1)
+gene.set1 <- read_delim("./genesets/genes.deg.LE.csv",",",escape_double=FALSE,trim_ws=TRUE,col_names=TRUE)
+gene.set1 <- gene.set1[1]
+gene.set1 <- as.list(gene.set1)
+names(gene.set1) <- "LE"
+gene.set <- c(gene.set,gene.set1)
+gene.set1 <- read_delim("./genesets/genes.deg.OE1.csv",",",escape_double=FALSE,trim_ws=TRUE,col_names=TRUE)
+gene.set1 <- gene.set1[1]
+gene.set1 <- as.list(gene.set1)
+names(gene.set1) <- "OE_SCGB"
+gene.set <- c(gene.set,gene.set1)
+gene.set1 <- read_delim("./genesets/genes.deg.OE2.csv",",",escape_double=FALSE,trim_ws=TRUE,col_names=TRUE)
+gene.set1 <- gene.set1[1]
+gene.set1 <- as.list(gene.set1)
+names(gene.set1) <- "OE_KRT13"
+gene.set <- c(gene.set,gene.set1)
+rm(gene.set1)
+gc()
+min.epi <- min(table(sc10x.Epi@meta.data[,paste0("res",opt$res.poststress)]))
+results <- scQuSAGE(sc10x.Epi,gs=gene.set,res.use=opt$res.poststress,ds=min.epi,nm="Epi.dws.sc",folder="epi")
+sc10x.Epi <- results[[1]]
+results.cor.Epi.dws <- results[[2]]
+results.clust.Epi.dws.id <- results[[3]]
+rm(results)
+rm(gene.set)
+
+gene.set1 <- read_delim("./genesets/genes.deg.Endo.csv",",",escape_double=FALSE,trim_ws=TRUE,col_names=TRUE)
+gene.set1 <- gene.set1[1]
+gene.set1 <- as.list(gene.set1)
+names(gene.set1) <- "Endo"
+gene.set <- c(gene.set1)
+gene.set1 <- read_delim("./genesets/genes.deg.SM.csv",",",escape_double=FALSE,trim_ws=TRUE,col_names=TRUE)
+gene.set1 <- gene.set1[1]
+gene.set1 <- as.list(gene.set1)
+names(gene.set1) <- "SM"
+gene.set <- c(gene.set,gene.set1)
+gene.set1 <- read_delim("./genesets/genes.deg.Fib.csv",",",escape_double=FALSE,trim_ws=TRUE,col_names=TRUE)
+gene.set1 <- gene.set1[1]
+gene.set1 <- as.list(gene.set1)
+names(gene.set1) <- "Fib"
+gene.set <- c(gene.set,gene.set1)
+gene.set1 <- read_delim("./genesets/genes.deg.Leu.csv",",",escape_double=FALSE,trim_ws=TRUE,col_names=TRUE)
+gene.set1 <- gene.set1[1]
+gene.set1 <- as.list(gene.set1)
+names(gene.set1) <- "Leu"
+gene.set <- c(gene.set,gene.set1)
+rm(gene.set1)
+gc()
+min.st <- min(table(sc10x.St@meta.data[,paste0("res",opt$res.poststress)]))
+results <- scQuSAGE(sc10x.St,gs=gene.set,res.use=opt$res.poststress,ds=min.st,nm="St.dws.sc",folder="st")
+sc10x.St <- results[[1]]
+results.cor.St.go <- results[[2]]
+results.clust.St.go.id <- results[[3]]
+rm(results)
+rm(gene.set)
+
+sc10x.Epi.NE <- scNE(sc10x.Epi,neg="dws",cut=opt$cut.ne)
+
+sc10x <- scMerge(sc10x,sc10x.Epi,sc10x.St,i.1="Epi.dws.sc",i.2="St.dws.sc",nm="Merge_Epi.dws.sc_St.dws.sc")
+cells.ne <- names(sc10x.Epi.NE@ident[sc10x.Epi.NE@ident=="NE"])
+sc10x <- SetAllIdent(object=sc10x,id="Merge_Epi.dws.sc_St.dws.sc")
+sc10x <- SetIdent(object=sc10x,cells.use=cells.ne,ident.use="NE")
+sc10x <- StashIdent(object=sc10x,save.name="Merge_Epi.dws.sc_St.dws.sc_NE")
+rm(cells.ne)
+
+sc10x <- SetAllIdent(object=sc10x,id="Merge_Epi.dws.sc_St.dws.sc")
+sc10x <- SetAllIdent(object=sc10x,id="Merge_Epi.dws.sc_St.dws.sc")
+sc10x@ident <- factor(sc10x@ident,levels=c("BE","LE","OE_SCGB","OE_KRT13","Fib","SM","Endo","Leu"))
+postscript("./analysis/tSNE/FINAL/tSNE_FINAL.eps")
+plot <- TSNEPlot(object=sc10x,pt.size=2.5,do.return=TRUE,vector.friendly=FALSE)
+plot <- plot+theme(axis.text.x=element_text(size=20),axis.text.y=element_text(size=20),axis.title.x=element_text(size=20),axis.title.y=element_text(size=20),legend.text=element_text(size=20))
+plot <- plot+guides(colour=guide_legend(override.aes=list(size=10)))
+plot(plot)
+dev.off()
+
+scTables(sc10x,i.1="samples",i.2="Merge_Epi.dws.sc_St.dws.sc_NE")
+
+sctSNECustCol(sc10x,i="Lin",bl="Epi",rd="St",file="D17")
+sctSNECustCol(sc10x,i="Merge_Epi.dws.sc_St.dws.sc",bl=c("BE","LE","OE_SCGB","OE_KRT13"),rd=c("Fib","SM","Endo","Leu"),file="D17")
+sctSNECustCol(sc10x.Epi,i="Epi.dws.sc",bl=c("BE","LE","OE_SCGB","OE_KRT13"),rd="",file="D17")
+sctSNECustCol(sc10x.St,i="St.dws.sc",bl="",rd=c("Fib","SM","Endo","Leu"),file="D17")
+
+sctSNEbwCol(sc10x,i=paste0("res",opt$res.poststress),file="ALL",files="D17")
+sctSNEbwCol(sc10x.Epi,i=paste0("res",opt$res.poststress),file="Epi",files="D17")
+sctSNEbwCol(sc10x.St,i=paste0("res",opt$res.poststress),file="St",files="D17")
+sctSNEbwCol(sc10x,i="Merge_Epi.dws.sc_St.dws.sc",file="ALL",files="D17")
+sctSNEbwCol(sc10x.Epi,i="Epi.dws.sc",file="Epi",files="D17")
+sctSNEbwCol(sc10x.St,i="St.dws.sc",file="St",files="D17")
+
+for (g in c("Epi","St","Unknown")){
+  sctSNEHighlight(sc10x,i="Lin",g=g,file="D17")
+}
+for (g in c("BE","LE","OE_SCGB","OE_KRT13")){
+  sctSNEHighlight(sc10x,i="Merge_Epi.dws.sc_St.dws.sc",g=g,file="D17")
+  sctSNEHighlight(sc10x.Epi,i="Epi.dws.c",g=g,file="D17")
+}
+for (g in c("Fib","SM","Endo","Leu")){
+  sctSNEHighlight(sc10x,i="Merge_Epi.dws.sc_St.dws.sc",g=g,file="D17")
+  sctSNEHighlight(sc10x.St,i="St.dws.sc",g=g,file="D17")
+}
+rm(i)
+rm(g)
+
+try(genes.deg.Stress <- scDEG(sc10x.Stress,i="Stress",g.1="Stress",g.2="ALL",pct=0.5,t=5))
+
+try(genes.deg.Epi <- scDEG(sc10x,i="Lin",g.1="Epi",g.2="St",t=2))
+try(genes.deg.St <- scDEG(sc10x,i="Lin",g.1="St",g.2="Epi",t=2))
+
+try(genes.deg.BE <- scDEG(sc10x,i="Merge_Epi.dws.sc_St.dws.sc_NE",g.1="BE",g.2=c("LE","OE_SCGB","OE_KRT13"),pct=0.25,t=2))
+try(genes.deg.LE <- scDEG(sc10x,i="Merge_Epi.dws.sc_St.dws.sc_NE",g.1="LE",g.2=c("BE","OE_SCGB","OE_KRT13"),pct=0.25,t=2))
+try(genes.deg.OE1 <- scDEG(sc10x,i="Merge_Epi.dws.sc_St.dws.sc_NE",g.1="OE_SCGB",g.2=c("BE","LE","OE_KRT13"),pct=0.25,t=2))
+try(genes.deg.OE2 <- scDEG(sc10x,i="Merge_Epi.dws.sc_St.dws.sc_NE",g.1="OE_KRT13",g.2=c("BE","LE","OE_SCGB"),pct=0.25,t=2))
+
+try(genes.deg.NE <- scDEG(sc10x,i="Merge_Epi.dws.sc_St.dws.sc_NE",g.1="NE",g.2=c("BE","LE","OE_SCGB","OE_KRT13"),pct=0.01,t=1))
+
+try(genes.deg.Fib <- scDEG(sc10x.St,i="Merge_Epi.dws.sc_St.dws.sc",g.1="Fib",g.2=c("SM","Endo","Leu"),pct=0.25,t=2))
+try(genes.deg.SM <- scDEG(sc10x.St,i="Merge_Epi.dws.sc_St.dws.sc",g.1="SM",g.2=c("Fib","Endo","Leu"),pct=0.25,t=2))
+try(genes.deg.Endo <- scDEG(sc10x.St,i="Merge_Epi.dws.sc_St.dws.sc",g.1="Endo",g.2=c("Fib","SM","Leu"),pct=0.25,t=2))
+try(genes.deg.Leu <- scDEG(sc10x.St,i="St.dws.sc",g.1="Leu",g.2=c("Fib","SM","Endo"),pct=0.25,t=2))
+
+try(genes.deg.BE.unique <- setdiff(rownames(genes.deg.BE),Reduce(union,list(rownames(genes.deg.LE),rownames(genes.deg.OE1),rownames(genes.deg.OE2),rownames(genes.deg.NE),rownames(genes.deg.Fib),rownames(genes.deg.SM),rownames(genes.deg.Endo),rownames(genes.deg.Leu)))))
+try(genes.deg.LE.unique <- setdiff(rownames(genes.deg.LE),Reduce(union,list(rownames(genes.deg.BE),rownames(genes.deg.OE1),rownames(genes.deg.OE2),rownames(genes.deg.NE),rownames(genes.deg.Fib),rownames(genes.deg.SM),rownames(genes.deg.Endo),rownames(genes.deg.Leu)))))
+try(genes.deg.OE1.unique <- setdiff(rownames(genes.deg.OE1),Reduce(union,list(rownames(genes.deg.BE),rownames(genes.deg.LE),rownames(genes.deg.OE2),rownames(genes.deg.NE),rownames(genes.deg.Fib),rownames(genes.deg.SM),rownames(genes.deg.Endo),rownames(genes.deg.Leu)))))
+try(genes.deg.OE2.unique <- setdiff(rownames(genes.deg.OE2),Reduce(union,list(rownames(genes.deg.BE),rownames(genes.deg.LE),rownames(genes.deg.OE1),rownames(genes.deg.NE),rownames(genes.deg.Fib),rownames(genes.deg.SM),rownames(genes.deg.Endo),rownames(genes.deg.Leu)))))
+try(genes.deg.NE.unique <- setdiff(rownames(genes.deg.NE),Reduce(union,list(rownames(genes.deg.BE),rownames(genes.deg.LE),rownames(genes.deg.OE1),rownames(genes.deg.OE2),rownames(genes.deg.Fib),rownames(genes.deg.SM),rownames(genes.deg.Endo),rownames(genes.deg.Leu)))))
+try(genes.deg.Fib.unique <- setdiff(rownames(genes.deg.Fib),Reduce(union,list(rownames(genes.deg.BE),rownames(genes.deg.LE),rownames(genes.deg.OE1),rownames(genes.deg.OE2),rownames(genes.deg.NE),rownames(genes.deg.SM),rownames(genes.deg.Endo),rownames(genes.deg.Leu)))))
+try(genes.deg.SM.unique <- setdiff(rownames(genes.deg.SM),Reduce(union,list(rownames(genes.deg.BE),rownames(genes.deg.LE),rownames(genes.deg.OE1),rownames(genes.deg.OE2),rownames(genes.deg.NE),rownames(genes.deg.Fib),rownames(genes.deg.Endo),rownames(genes.deg.Leu)))))
+try(genes.deg.Endo.unique <- setdiff(rownames(genes.deg.Endo),Reduce(union,list(rownames(genes.deg.BE),rownames(genes.deg.LE),rownames(genes.deg.OE1),rownames(genes.deg.OE2),rownames(genes.deg.NE),rownames(genes.deg.Fib),rownames(genes.deg.SM),rownames(genes.deg.Leu)))))
+try(genes.deg.Leu.unique <- setdiff(rownames(genes.deg.Leu),Reduce(union,list(rownames(genes.deg.BE),rownames(genes.deg.LE),rownames(genes.deg.OE1),rownames(genes.deg.OE2),rownames(genes.deg.NE),rownames(genes.deg.Fib),rownames(genes.deg.SM),rownames(genes.deg.Endo)))))
+
+try(genes.deg.5 <- c(genes.deg.BE.unique[1:5],genes.deg.LE.unique[1:5],genes.deg.OE1.unique[1:5],genes.deg.OE2.unique[1:5],genes.deg.NE.unique[1:5],genes.deg.Fib.unique[1:5],genes.deg.SM.unique[1:5],genes.deg.Endo.unique[1:5],genes.deg.Leu.unique[1:5]))
+try(genes.deg.5 <- rev(genes.deg.5))
+try(genes.deg.10 <- c(genes.deg.BE.unique[1:10],genes.deg.LE.unique[1:10],genes.deg.OE1.unique[1:10],genes.deg.OE2.unique[1:10],genes.deg.NE.unique[1:10],genes.deg.Fib.unique[1:10],genes.deg.SM.unique[1:10],genes.deg.Endo.unique[1:10],genes.deg.Leu.unique[1:10]))
+try(genes.deg.10 <- rev(genes.deg.10))
+
+for (i in ls(pattern="^genes.deg")){
+  try(write.table(get(i),file=paste0("./analysis/deg/",i,".csv"),row.names=TRUE,col.names=NA,append=FALSE,sep=","))
+}
+
+save(list=ls(pattern="sc10x.Stress"),file="./analysis/sc10x.Stress.Rda")
+rm(list=ls(pattern="sc10x.Stress"))
+save(list=ls(pattern="sc10x.Epi"),file="./analysis/sc10x.Epi.Rda")
+rm(list=ls(pattern="^sc10x.Epi"))
+save(list=ls(pattern="sc10x.St"),file="./analysis/sc10x.St.Rda")
+rm(list=ls(pattern="sc10x.St"))
+save(list=ls(pattern="^sc10x"),file="./analysis/sc10x.Rda")
+rm(list=ls(pattern="^sc10x"))
+save.image(file="./analysis/Data.RData")
diff --git a/r.scripts/sc-TissueMapper_RUN.DS_D17.aggr.R b/r.scripts/sc-TissueMapper_RUN.DS_D17.aggr.R
new file mode 100755
index 0000000000000000000000000000000000000000..91ae977c98f84b5dfcb9943b4293cccbb35f5625
--- /dev/null
+++ b/r.scripts/sc-TissueMapper_RUN.DS_D17.aggr.R
@@ -0,0 +1,106 @@
+gc()
+library(methods)
+library(optparse)
+library(Seurat)
+library(readr)
+library(fBasics)
+library(pastecs)
+library(qusage)
+library(RColorBrewer)
+library(monocle)
+library(dplyr)
+library(viridis)
+library(reshape2)
+library(NMI)
+
+options(bitmapType="cairo")
+
+source("../r.scripts/sc-TissueMapper.R")
+
+setwd("../")
+
+load("./analysis/sc10x.Rda")
+sc10x.All <-sc10x
+rm(sc10x)
+
+downsample <- c("All","350","300","250","200","150","100","075","050","037","025","012","007","005","002")
+for (i in downsample[-1]){
+  load(paste0("../../",i,"/sc-TissueMapper_Pr/analysis/sc10x.Rda"))
+  assign(paste0("sc10x.",i),sc10x)
+  rm(sc10x)
+}
+
+all.cells <- NULL
+for (i in downsample){
+  all.cells <- c(all.cells,get(paste0("sc10x.",i))@data@Dimnames[[2]])
+}
+all.cells <- unique(all.cells)
+
+shared.cells <- all.cells
+shared.cells.no002<- all.cells
+for (i in downsample){
+  shared.cells <- intersect(shared.cells,get(paste0("sc10x.",i))@data@Dimnames[[2]])
+  if (i != "002"){shared.cells <- intersect(shared.cells.no002,get(paste0("sc10x.",i))@data@Dimnames[[2]])}
+}
+
+for (i in downsample){
+  assign(paste0("sc10x.",i),SetAllIdent(get(paste0("sc10x.",i)),id="Merge_Epi.dws.sc_St.dws.sc"))
+  assign(paste0("cluster.",i),data.frame(Barcodes=names(get(paste0("sc10x.",i))@ident),Cluster=get(paste0("sc10x.",i))@ident))
+  assign(paste0("cluster.",i,".filter"),get(paste0("cluster.",i))[get(paste0("cluster.",i))$Barcodes %in% sc10x.All@data@Dimnames[[2]],])
+}
+
+nmi <- data.frame(Sample=character(),value=double())
+for (i in downsample[-1]){
+  nmi <- rbind(nmi,data.frame(Sample=i,value=NMI(cluster.All.filter,get(paste0("cluster.",i,".filter")))))
+}
+nmi$Sample <- as.numeric(levels(nmi$Sample))
+
+png(paste0("./analysis/NMI.png"),width=1000,height=500,type="cairo")
+plot.nmi <- ggplot(nmi,aes(x=Sample,y=value))+geom_point()+geom_smooth(method='loess',formula=y~log(x))+labs(x="Sample (Million Reads)",y="NMI")
+model.nmi <- loess(value~log(Sample),data=nmi)
+fit.nmi.y <- 0.9
+fit.nmi.x <- approx(x=predict(model.nmi),y=nmi$Sample,xout=fit.nmi.y)$y
+plot.nmi <- plot.nmi+geom_vline(xintercept=fit.nmi.x)+geom_hline(yintercept=fit.nmi.y)
+plot(plot.nmi)
+dev.off()
+
+for (i in downsample[-1]){
+  assign(paste0("rpc.",i),read_csv(paste0("../../../../count/",i,"M_D17PrTzF_Via/outs/metrics_summary.csv"))[,2])
+}
+
+rpc <- data.frame(Sample=character(),value=double())
+for (i in downsample[-1]){
+  rpc <- rbind(rpc,data.frame(Sample=i,value=get(paste0("rpc.",i))))
+}
+colnames(rpc)[2] <- "value"
+rpc$Sample <- as.numeric(levels(rpc$Sample))
+
+png(paste0("./analysis/RPC.png"),width=1000,height=500,type="cairo")
+plot.rpc <- ggplot(rpc,aes(x=Sample,y=value))+geom_point()+geom_smooth(method='lm',formula=y~x)+labs(x="Sample (Million Reads)",y="Mean Reads Per Cell")
+model.rpc <- lm(value~Sample,data=rpc)
+fit.rpc.y <- approx(x=rpc$Sample,y=predict(model.rpc),xout=fit.nmi.x)$y
+plot.rpc <- plot.rpc+geom_vline(xintercept=fit.nmi.x)+geom_hline(yintercept=fit.rpc.y)
+plot(plot.rpc)
+dev.off()
+
+comb <- cbind(nmi,rpc[,2])
+colnames(comb) <- c("Sample","NMI","RPC")
+
+nmi.rpc <- merge(nmi,rpc,by="Sample")
+nmi.rpc <- nmi.rpc[,-1]
+colnames(nmi.rpc) <- c("NMI","RPC")
+nmi.rpc$NMI <- round(as.numeric(nmi.rpc$NMI),2)
+
+postscript("./analysis/RPC+NMI.eps")
+plot.comb <- ggplot(nmi.rpc,aes(x=RPC,y=NMI))+geom_point(colour="blue",size=4)
+plot.comb <- plot.comb+geom_smooth(method='loess',formula=y~log(x),size=2)
+model <- loess(NMI~RPC,data=nmi.rpc)
+fit.y <- 0.9
+fit.x <- approx(y=nmi.rpc$RPC,x=predict(model),xout=fit.y)$y
+plot.comb <- plot.comb+geom_vline(xintercept=fit.x,linetype=2,size=1.5)+geom_hline(yintercept=fit.y,linetype=2,size=1.5)
+plot.comb <- plot.comb+labs(x="Mean Reads Per Cell",y="NMI")
+plot.comb <- plot.comb+scale_x_continuous(expand=c(0,0),limits=c(0,80000),breaks=c(seq(0,100000,25000),round(fit.x,0)))+scale_y_continuous(expand=c(0,0),limits=c(0,1),breaks=c(seq(0,1,0.2),fit.y))
+plot(plot.comb)
+dev.off()
+
+save.image(file="./analysis/NMI.RData")
diff --git a/r.scripts/sc-TissueMapper_RUN.Pd.R b/r.scripts/sc-TissueMapper_RUN.Pd.R
index 2b76a12cf783845896c1e4cf532c3380aea995b6..c68ab80d58731409d860799ec19763e8c85ffd13 100644
--- a/r.scripts/sc-TissueMapper_RUN.Pd.R
+++ b/r.scripts/sc-TissueMapper_RUN.Pd.R
@@ -11,6 +11,8 @@ library(monocle)
 library(dplyr)
 library(viridis)
 
+options(bitmapType="cairo")
+
 source("../r.scripts/sc-TissueMapper.R")
 
 #Create folder structure
@@ -312,7 +314,7 @@ names(gene.set1) <- "Leu"
 gene.set <- c(gene.set,gene.set1)
 rm(gene.set1)
 gc()
-min.st <- min(table(sc10x.Epi@meta.data[,paste0("res",opt$res.poststress)]))
+min.st <- min(table(sc10x.St@meta.data[,paste0("res",opt$res.poststress)]))
 results <- scQuSAGE(sc10x.St,gs=gene.set,res.use=0.2,ds=min.st,nm="St.go",folder="st")
 sc10x.St <- results[[1]]
 results.cor.St.go <- results[[2]]
@@ -407,11 +409,11 @@ scTables(sc10x,i.1="Merge_Epi.dws_St.go_NE",i.2="Merge_Epi.dws_St.go")
 
 genes.deg.Stress <- scDEG(sc10x.Stress,i="Stress",g.1="Stress",g.2="ALL",pct=0.5,t=5)
 
-genes.deg.Epi <- scDEG(sc10x,i="Lin",g.1="Epi",g.2="St",t=2)
-genes.deg.St <- scDEG(sc10x,i="Lin",g.1="St",g.2="Epi",t=2)
+genes.deg.Epi <- scDEG(sc10x,i="Lin",g.1="Epi",g.2="St",pct=0.75,t=2)
+genes.deg.St <- scDEG(sc10x,i="Lin",g.1="St",g.2="Epi",pct=0.75,t=2)
 
 genes.deg.BE <- scDEG(sc10x.Epi.NE,i="Epi.dws.sub",g.1="BE",g.2=c("LE","OE1","OE2"),pct=0.25,t=2)
-genes.deg.LE <- scDEG(sc10x.Epi.NE,i="Epi.dws.sub",g.1="LE",g.2=c("BE","LE","OE1"),pct=0.25,t=2)
+genes.deg.LE <- scDEG(sc10x.Epi.NE,i="Epi.dws.sub",g.1="LE",g.2=c("BE","OE1","OE2"),pct=0.25,t=2)
 genes.deg.OE1 <- scDEG(sc10x.Epi.NE,i="Epi.dws.sub",g.1="OE1",g.2=c("BE","LE","OE2"),pct=0.25,t=2)
 genes.deg.OE2 <- scDEG(sc10x.Epi.NE,i="Epi.dws.sub",g.1="OE2",g.2=c("BE","LE","OE1"),pct=0.25,t=2)