################################################ Required Packages ################################################ { ### Upload packages needed for data analysis library("ggplot2") #plotting library("plyr") #tool for playing with data.frames library("dplyr") #tool for playing with data.frames library("data.table") #tool for playing with data library("Seurat") #backbone of most single cell analysis library("MASS") library('tibble') ### personal theme for ggploting. I like these aesthetics better theme_cma <- function () { theme_bw(base_size=12, base_family="Avenir") theme( panel.background = element_blank(), axis.line = element_line(colour = "black"), legend.background = element_rect(fill="transparent", colour=NA), legend.key = element_rect(fill="transparent", colour=NA), panel.grid.major = element_blank(), axis.text=element_text(size=12), axis.title=element_text(size=14,face="bold") ) } } ################################################ Uploading data ################################################ ############### Female Upload ############### { ###### E14.5 ###### { Female.1.data <- Read10X(data.dir = "~/Documents/Projects/Sf1 in the external genitalia/10X/Time Series/Novaseq1 with tomato/E14 female 6") # import data Female.2.data <- Read10X(data.dir = "~/Documents/Projects/Sf1 in the external genitalia/10X/Time Series/Novaseq1 with tomato/E14 female 7")# import data Female.1 <- CreateSeuratObject(counts = Female.1.data, project = "Female1", min.cells = 3, min.features = 200) #create seuart obj Female.2 <- CreateSeuratObject(counts = Female.2.data, project = "Female2", min.cells = 3, min.features = 200) #create seuart obj FemaleE14.combined <- merge(Female.1, y = Female.2, add.cell.ids = c("Female1", "Female2"), project = "Female.combine") #merge data FemaleE14.combined = subset(FemaleE14.combined, cells = sample(Cells(FemaleE14.combined), 13000)) #normalize female data to the male data FemaleE14.combined[["percent.mt"]] <- PercentageFeatureSet(FemaleE14.combined, pattern = "^mt-") ## access % of mitochondrial genes in each cell FemaleE14.combined$Eday <- 'E14.5' # Identify developmental stage for the data for the data # Visualize mtRNA and gene, and RNA counts. Make rough cutoffs from here. FemaleE14.combined <- subset(FemaleE14.combined, subset = nFeature_RNA > 1000 & nFeature_RNA < 7500 & percent.mt < 25) ## filters for cell quality } ###### E16.5 ###### { Female.3.data <- Read10X(data.dir = "~/Documents/Projects/Sf1 in the external genitalia/10X/Time Series/Novaseq1 with tomato/E16 female 3")# import data Female.4.data <- Read10X(data.dir = "~/Documents/Projects/Sf1 in the external genitalia/10X/Time Series/Novaseq1 with tomato/E16 female 4")# import data Female.3 <- CreateSeuratObject(counts = Female.3.data, project = "Female3", min.cells = 3, min.features = 200) Female.4 <- CreateSeuratObject(counts = Female.4.data, project = "Female4", min.cells = 3, min.features = 200) FemaleE16.combined <- merge(Female.3, y = Female.4, add.cell.ids = c("Female3", "Female4"), project = "Female.combine") FemaleE16.combined[["percent.mt"]] <- PercentageFeatureSet(FemaleE16.combined, pattern = "^mt-") ## maybe try this will Hbb genes and filter those out. FemaleE16.combined$Eday <- 'E16.5' FemaleE16.combined <- subset(FemaleE16.combined, subset = nFeature_RNA > 1000 & nFeature_RNA < 7500 & percent.mt < 25) ## low trans } ###### E18.5 ###### { Female.5.data <- Read10X(data.dir = "~/Documents/Projects/Sf1 in the external genitalia/10X/Time Series/Novaseq1 with tomato/E18 female 5") Female.6.data <- Read10X(data.dir = "~/Documents/Projects/Sf1 in the external genitalia/10X/Time Series/Novaseq1 with tomato/E18 female 6") Female.5 <- CreateSeuratObject(counts = Female.5.data, project = "Female5", min.cells = 3, min.features = 200) #adddddd Female.6 <- CreateSeuratObject(counts = Female.6.data, project = "Female6", min.cells = 3, min.features = 200) FemaleE18.combined <- merge(Female.5, y = Female.6, add.cell.ids = c("Female5", "Female6"), project = "Female.combine") FemaleE18.combined[["percent.mt"]] <- PercentageFeatureSet(FemaleE18.combined, pattern = "^mt-") ## maybe try this will Hbb genes and filter those out. FemaleE18.combined$Eday <- 'E18.5' FemaleE18.combined <- subset(FemaleE18.combined, subset = nFeature_RNA > 1000 & nFeature_RNA < 7500 & percent.mt < 25) ## } ###### Combine Female Normalize, scale, UMAP and subcluster###### { FemaleE1416.combined <- merge(FemaleE14.combined, y = FemaleE16.combined, add.cell.ids = c("Female14", "Female16"), project = "Female.combine") Female.combined <- merge(FemaleE1416.combined, y = FemaleE18.combined, add.cell.ids = c("Female1416", "Female18"), project = "Female.combine") Female.combined <- NormalizeData(Female.combined, normalization.method = "LogNormalize", scale.factor = 10000) Female.combined <- FindVariableFeatures(Female.combined, selection.method = "vst", nfeatures = 2000) top10 <- head(VariableFeatures(Female.combined), 10) all.genes <- rownames(Female.combined) Female.combined <- ScaleData(Female.combined, features = all.genes) Female.combined <- RunPCA(Female.combined, features = VariableFeatures(object = Female.combined)) # Female.combined <-FindNeighbors(Female.combined, dims = 1:18) Female.combined <- FindClusters(Female.combined, resolution = .07) Female.combined <- RunUMAP(Female.combined, dims = 1:18) FeaturePlot(Female.combined, features = c('Foxl2'), pt.size=.5, split.by = 'Eday', col= c('grey', 'black', 'red'), cells=Cells(Female.combined)[order(Female.combined@assays$RNA@counts["Foxl2",])]) ElbowPlot(Female.combined, ndims = 50) Female.combined[["old.ident"]] <- Idents(object = Female.combined) # Rename classes. Female.combined <- RenameIdents(object = Female.combined, '0' = "Glanular Mesenchyme", '1' = "Preputial Mesenchyme", '2' = "Proliferative Mesenchyme", '3' = "Corpus Cavernosum", '4' = "Endothelium", '5' = "Preputial Gland", '6' = "Epithelium", '7' = "Smooth Muscle", "8" = "Melantocytes" ) ## Corpus Cavernosum ## Female.tot.cc <-subset(x = Female.combined, idents = c('Corpus Cavernosum'), invert=FALSE) Female.tot.cc <- NormalizeData(Female.tot.cc, normalization.method = "LogNormalize", scale.factor = 10000) Female.tot.cc <- FindVariableFeatures(Female.tot.cc, selection.method = "vst", nfeatures = 2000) top10 <- head(VariableFeatures(Female.tot.cc), 10) all.genes <- rownames(Female.tot.cc) Female.tot.cc <- ScaleData(Female.tot.cc, features = all.genes) Female.tot.cc <- RunPCA(Female.tot.cc, features = VariableFeatures(object = Female.tot.cc)) Female.tot.cc <- FindNeighbors(Female.tot.cc, dims = 1:15) Female.tot.cc <- FindClusters(Female.tot.cc, resolution = .12) Female.tot.cc <- RunUMAP(Female.tot.cc, dims = 1:15) ## Glans ## Female.tot.gm <-subset(x = Female.combined, idents = c('Glanular Mesenchyme'), invert=FALSE) Female.tot.gm <- NormalizeData(Female.tot.gm, normalization.method = "LogNormalize", scale.factor = 10000) Female.tot.gm <- FindVariableFeatures(Female.tot.gm, selection.method = "vst", nfeatures = 2000) top10 <- head(VariableFeatures(Female.tot.gm), 10) all.genes <- rownames(Female.tot.gm) Female.tot.gm <- ScaleData(Female.tot.gm, features = all.genes) Female.tot.gm <- RunPCA(Female.tot.gm, features = VariableFeatures(object = Female.tot.gm)) Female.tot.gm <- FindNeighbors(Female.tot.gm, dims = 1:15) Female.tot.gm <- FindClusters(Female.tot.gm, resolution = .12) Female.tot.gm <- RunUMAP(Female.tot.gm, dims = 1:15) ElbowPlot(Female.tot.pp, ndims=50) ## Preputial Swellings## Female.tot.pp <-subset(x = Female.combined, idents = c('Preputial Mesenchyme'), invert=FALSE) Female.tot.pp <- NormalizeData(Female.tot.pp, normalization.method = "LogNormalize", scale.factor = 10000) Female.tot.pp <- FindVariableFeatures(Female.tot.pp, selection.method = "vst", nfeatures = 2000) top10 <- head(VariableFeatures(Female.tot.pp), 10) all.genes <- rownames(Female.tot.pp) Female.tot.pp <- ScaleData(Female.tot.pp, features = all.genes) Female.tot.pp <- RunPCA(Female.tot.pp, features = VariableFeatures(object = Female.tot.pp)) Female.tot.pp <- FindNeighbors(Female.tot.pp, dims = 1:15) Female.tot.pp <- FindClusters(Female.tot.pp, resolution = .12) Female.tot.pp <- RunUMAP(Female.tot.pp, dims = 1:15) } } ############### Male Upload ############### { ###### E14.5 ###### { Male.1.data <- Read10X(data.dir = "~/Documents/Projects/Sf1 in the external genitalia/10X/Time Series/Novaseq1 with tomato/E14 male 4") Male.2.data <- Read10X(data.dir = "~/Documents/Projects/Sf1 in the external genitalia/10X/Time Series/Novaseq1 with tomato/E14 male 5") Male.1 <- CreateSeuratObject(counts = Male.1.data, project = "Male1", min.cells = 3, min.features = 200) Male.2 <- CreateSeuratObject(counts = Male.2.data, project = "Male2", min.cells = 3, min.features = 200) MaleE14.combined <- merge(Male.1, y = Male.2, add.cell.ids = c("Male1", "Male2"), project = "Male.combine") MaleE14.combined[["percent.mt"]] <- PercentageFeatureSet(MaleE14.combined, pattern = "^mt-") MaleE14.combined$Eday <- 'E14.5' MaleE14.combined <- subset(MaleE14.combined, subset = nFeature_RNA > 1000 & nFeature_RNA < 7500 & percent.mt < 25) } ###### E16.5 ###### { Male.3.data <- Read10X(data.dir = "~/Documents/Projects/Sf1 in the external genitalia/10X/Time Series/Novaseq1 with tomato/E16 male 1") Male.4.data <- Read10X(data.dir = "~/Documents/Projects/Sf1 in the external genitalia/10X/Time Series/Novaseq1 with tomato/E16 male 2") Male.3 <- CreateSeuratObject(counts = Male.3.data, project = "Male3", min.cells = 3, min.features = 200) Male.4 <- CreateSeuratObject(counts = Male.4.data, project = "Male4", min.cells = 3, min.features = 200) MaleE16.combined <- merge(Male.3, y = Male.4, add.cell.ids = c("Male3", "Male4"), project = "Male.combine") MaleE16.combined[["percent.mt"]] <- PercentageFeatureSet(MaleE16.combined, pattern = "^mt-") MaleE16.combined$Eday <- 'E16.5' MaleE16.combined <- subset(MaleE16.combined, subset = nFeature_RNA > 1000 & nFeature_RNA < 7500 & percent.mt < 25) } ###### E18.5 ###### { Male.5.data <- Read10X(data.dir = "~/Documents/Projects/Sf1 in the external genitalia/10X/Time Series/Novaseq1 with tomato/E18 male 1") Male.6.data <- Read10X(data.dir = "~/Documents/Projects/Sf1 in the external genitalia/10X/Time Series/Novaseq1 with tomato/E18 male 2") Male.5 <- CreateSeuratObject(counts = Male.5.data, project = "Male5", min.cells = 3, min.features = 200) Male.6 <- CreateSeuratObject(counts = Male.6.data, project = "Male6", min.cells = 3, min.features = 200) MaleE18.combined <- merge(Male.5, y = Male.6, add.cell.ids = c("Male.5", "Male.6"), project = "Male.combine") MaleE18.combined[["percent.mt"]] <- PercentageFeatureSet(MaleE18.combined, pattern = "^mt-") MaleE18.combined$Eday <- 'E18.5' MaleE18.combined <- subset(MaleE18.combined, subset = nFeature_RNA > 1000 & nFeature_RNA < 7500 & percent.mt < 25) ## low tra } ###### Combine Male Normalize, scale, UMAP, and sub cluster ###### { MaleE1416.combined <- merge(MaleE14.combined, y = MaleE16.combined, add.cell.ids = c("Male14", "Male16"), project = "Male.combine") Male.combined <- merge(MaleE1416.combined, y = MaleE18.combined, add.cell.ids = c("Male1416", "Male18"), project = "Male.combine") Male.combined <- NormalizeData(Male.combined, normalization.method = "LogNormalize", scale.factor = 10000) Male.combined <- FindVariableFeatures(Male.combined, selection.method = "vst", nfeatures = 2000) top10 <- head(VariableFeatures(Male.combined), 10) all.genes <- rownames(Male.combined) Male.combined <- ScaleData(Male.combined, features = all.genes) Male.combined <- RunPCA(Male.combined, features = VariableFeatures(object = Male.combined)) # Male.combined <-FindNeighbors(Male.combined, dims = 1:17) Male.combined <- FindClusters(Male.combined, resolution = 0.07) Male.combined <- RunUMAP(Male.combined, dims = 1:17) Male.combined[["old.ident"]] <- Idents(object = Male.combined) # Rename classes. Male.combined <- RenameIdents(object = Male.combined, '0' = "Glanular Mesenchyme", '1' = "Preputial Mesenchyme", '2' = "Proliferative Mesenchyme", '3' = "Corpus Cavernosum", '4' = "Endothelium", '5' = "Macrophage", '6' = "Epithelium" ) ## Corpus Cavernosum ## male.tot.cc <-subset(x = Male.combined, idents = c('Corpus Cavernosum'), invert=FALSE) male.tot.cc <- NormalizeData(male.tot.cc, normalization.method = "LogNormalize", scale.factor = 10000) male.tot.cc <- FindVariableFeatures(male.tot.cc, selection.method = "vst", nfeatures = 2000) top10 <- head(VariableFeatures(male.tot.cc), 10) all.genes <- rownames(male.tot.cc) male.tot.cc <- ScaleData(male.tot.cc, features = all.genes) male.tot.cc <- RunPCA(male.tot.cc, features = VariableFeatures(object = male.tot.cc)) male.tot.cc <- FindNeighbors(male.tot.cc, dims = 1:15) male.tot.cc <- FindClusters(male.tot.cc, resolution = 0.12) male.tot.cc <- RunUMAP(male.tot.cc, dims = 1:15) ## Glans ## male.tot.gm <-subset(x = Male.combined, idents = c('Glanular Mesenchyme'), invert=FALSE) male.tot.gm <- NormalizeData(male.tot.gm, normalization.method = "LogNormalize", scale.factor = 10000) male.tot.gm <- FindVariableFeatures(male.tot.gm, selection.method = "vst", nfeatures = 2000) top10 <- head(VariableFeatures(male.tot.gm), 10) all.genes <- rownames(male.tot.pp) male.tot.gm <- ScaleData(male.tot.gm, features = all.genes) male.tot.gm <- RunPCA(male.tot.gm, features = VariableFeatures(object = male.tot.gm)) male.tot.gm <- FindNeighbors(male.tot.gm, dims = 1:15) male.tot.gm <- FindClusters(male.tot.gm, resolution = 0.12) male.tot.gm <- RunUMAP(male.tot.gm, dims = 1:15) ## Preputial Swellings ## male.tot.pp <-subset(x = Male.combined, idents = c('Preputial Mesenchyme'), invert=FALSE) male.tot.pp <- NormalizeData(male.tot.pp, normalization.method = "LogNormalize", scale.factor = 10000) male.tot.pp <- FindVariableFeatures(male.tot.pp, selection.method = "vst", nfeatures = 2000) top10 <- head(VariableFeatures(male.tot.pp), 10) all.genes <- rownames(male.tot.pp) male.tot.pp <- ScaleData(male.tot.pp, features = all.genes) male.tot.pp <- RunPCA(male.tot.pp, features = VariableFeatures(object = male.tot.pp)) male.tot.pp <- FindNeighbors(male.tot.pp, dims = 1:15) male.tot.pp <- FindClusters(male.tot.pp, resolution = 0.12) male.tot.pp <- RunUMAP(male.tot.pp, dims = 1:15) } } ############### Combine sexes for Sex Dimorph Analysis ############### { ###### All cells included ###### { sexdimorph.combined <- merge(Male.combined, y = Female.combined, add.cell.ids = c("Male", "Female"), project = "Sex.dimorph") sexdimorph.combined <- NormalizeData(sexdimorph.combined, normalization.method = "LogNormalize", scale.factor = 10000) sexdimorph.combined <- FindVariableFeatures(sexdimorph.combined, selection.method = "vst", nfeatures = 2000) # Identify the 10 most highly variable genes top10 <- head(VariableFeatures(sexdimorph.combined), 10) # Scale data to equalize sequencing quality all.genes <- rownames(sexdimorph.combined) sexdimorph.combined <- ScaleData(sexdimorph.combined, features = all.genes) # Find dimensionality sexdimorph.combined <- RunPCA(sexdimorph.combined, features = VariableFeatures(object = sexdimorph.combined)) # # Clustering sexdimorph.combined <-FindNeighbors(sexdimorph.combined, dims = 1:15) sexdimorph.combined <- FindClusters(sexdimorph.combined, resolution = 0.07) head(Idents(MaleE18.combined), 5) sexdimorph.combined <- RunUMAP(sexdimorph.combined, dims = 1:15) sexdimorph.combined$Sex <- substr(sexdimorph.combined$orig.ident, 1,1) sexdimorph.combined$Sex.day <- interaction(sexdimorph.combined$Sex, sexdimorph.combined$Eday) sexdimorph.combined[["old.ident"]] <- Idents(object = sexdimorph.combined) # Rename classes. sexdimorph.combined <- RenameIdents(object = sexdimorph.combined, '0' = "Glanular Mesenchyme", '1' = "Preputial Mesenchyme", '2' = "Proliferative Mesenchyme", '3' = "Corpus Cavernosum" } ###### Prepuce cells only ###### { sexdimorph.pp <-subset(x = sexdimorph.combined, idents = c('Preputial Mesenchyme'), invert=FALSE) sexdimorph.pp <- NormalizeData(sexdimorph.pp, normalization.method = "LogNormalize", scale.factor = 10000) sexdimorph.pp <- FindVariableFeatures(sexdimorph.pp, selection.method = "vst", nfeatures = 2000) top10 <- head(VariableFeatures(sexdimorph.pp), 10) all.genes <- rownames(sexdimorph.pp) sexdimorph.pp <- ScaleData(sexdimorph.pp, features = all.genes) ## Run PCA sexdimorph.pp <- RunPCA(sexdimorph.pp, features = VariableFeatures(object = sexdimorph.pp)) # Recluster sexdimorph.pp <- FindNeighbors(sexdimorph.pp, dims = 1:15) sexdimorph.pp <- FindClusters(sexdimorph.pp, resolution = 0.09) head(Idents(sexdimorph.pp), 5) ElbowPlot(sexdimorph.pp, n=100) sexdimorph.pp <- RunUMAP(sexdimorph.pp, dims = 1:15) } ###### Corpus Cavernosum cells only ###### { sexdimorph.cc <-subset(x = sexdimorph.combined, idents = c('Corpus Cavernosum'), invert=FALSE) sexdimorph.cc <- NormalizeData(sexdimorph.cc, normalization.method = "LogNormalize", scale.factor = 10000) sexdimorph.cc <- FindVariableFeatures(sexdimorph.cc, selection.method = "vst", nfeatures = 2000) # Identify the 10 most highly variable genes top10 <- head(VariableFeatures(sexdimorph.cc), 10) all.genes <- rownames(sexdimorph.cc) sexdimorph.cc <- ScaleData(sexdimorph.cc, features = all.genes) ## Run PCA sexdimorph.cc <- RunPCA(sexdimorph.cc, features = VariableFeatures(object = sexdimorph.cc)) # Recluster ElbowPlot(sexdimorph.cc, ndim = 50) sexdimorph.cc <- FindNeighbors(sexdimorph.cc, dims = 1:20) sexdimorph.cc <- FindClusters(sexdimorph.cc, resolution = 0.5) head(Idents(sexdimorph.cc), 5) sexdimorph.cc <- RunUMAP(sexdimorph.cc, dims = 1:20) } ###### Glans cells only ###### { sexdimorph.gm <-subset(x = sexdimorph.combined, idents = c('Glanular Mesenchyme'), invert=FALSE) DimPlot(sexdimorph.gm, reduction = "umap", pt.size =.5) sexdimorph.gm <- NormalizeData(sexdimorph.gm, normalization.method = "LogNormalize", scale.factor = 10000) sexdimorph.gm <- FindVariableFeatures(sexdimorph.gm, selection.method = "vst", nfeatures = 2000) # Identify the 10 most highly variable genes top10 <- head(VariableFeatures(sexdimorph.gm), 10) all.genes <- rownames(sexdimorph.gm) sexdimorph.gm <- ScaleData(sexdimorph.gm, features = all.genes) ## Run PCA sexdimorph.gm <- RunPCA(sexdimorph.gm, features = VariableFeatures(object = sexdimorph.gm)) # Recluster ElbowPlot(sexdimorph.gm, ndim = 50) sexdimorph.gm <- FindNeighbors(sexdimorph.gm, dims = 1:15) sexdimorph.gm <- FindClusters(sexdimorph.gm, resolution = .12) head(Idents(sexdimorph.gm), 5) sexdimorph.gm <- RunUMAP(sexdimorph.gm, dims = 1:15) } } ############### Time analysis ############### { ### Glans { ### Male Glans { ### Separate data into separte object to work with ### sexdimorph.Mventral <-subset(x = male.tot.gm, idents = c('3', '2'), invert=FALSE) sexdimorph.Mbilat <-subset(x = male.tot.gm, idents = c('4','1'), invert=FALSE) sexdimorph.Mdorsal <-subset(x = male.tot.gm, idents = c('0'), invert=FALSE) ### Identifying Time DEGS from the Dorsal subcluster dorsal.14.18mark.M <- ((FindMarkers(sexdimorph.Mdorsal, ident.1 = "E18.5", ident.2 = "E14.5", group.by='Eday', min.pct = .1))) ## DEGs dorsal.14.18mark.M <- dorsal.14.18mark.M[order(dorsal.14.18mark.M$avg_logFC),] ## order by FC dorsal.14.18mark.M <- dorsal.14.18mark.M[abs(dorsal.14.18mark.M$p_val_adj) < .05, ] ## filter out non-significant genes dorsal.14.18mark.M<-dorsal.14.18mark.M[!grepl("^Hbb-", rownames(dorsal.14.18mark.M)),] ## remove blood genes dorsal.14.18mark.M<-dorsal.14.18mark.M[!grepl("^Hba-", rownames(dorsal.14.18mark.M)), ]## remove blood genes dorsal.14.18mark.M<-dorsal.14.18mark.M[!grepl("^RP23", rownames(dorsal.14.18mark.M)),] ## remove ribosomal genes dorsal.14.18mark.M<-dorsal.14.18mark.M[!grepl("^RP24", rownames(dorsal.14.18mark.M)),] ## remove ribosomal genes dorsal.14.18mark.M<-dorsal.14.18mark.M[!grepl("^Xist", rownames(dorsal.14.18mark.M)),] ## remove X-linked genes dorsal.14.18mark.M<-dorsal.14.18mark.M[!grepl("^Tsix", rownames(dorsal.14.18mark.M)),] ## remove X-linked gene dorsal.14.18mark.M<-dorsal.14.18mark.M[!grepl("^Ddx3y", rownames(dorsal.14.18mark.M)),] ## remove Y-linked gene dorsal.14.18mark.M<-dorsal.14.18mark.M[!grepl("^Eif2s3y", rownames(dorsal.14.18mark.M)),] ## remove Y-linked gene dorsal.14.18mark.M<-dorsal.14.18mark.M[!grepl("^Uty", rownames(dorsal.14.18mark.M)),] ## remove Y-linked gene dorsal.14.18mark.M<-dorsal.14.18mark.M[!grepl("^mt-", rownames(dorsal.14.18mark.M)),] ## remove mitochondrial gene dorsal.14.18mark.M<-dorsal.14.18mark.M[!grepl("^a", rownames(dorsal.14.18mark.M)),] ## unsure what this gene is dorsal.14.18mark.M<-dorsal.14.18mark.M[!grepl("^Kdm5d", rownames(dorsal.14.18mark.M)),] ## remove Y-linked gene ### Identifying Time DEGS from the proximal subcluster bilat.14.18mark.M <- ((FindMarkers(sexdimorph.Mbilat, ident.1 = "E18.5", ident.2 = "E14.5", group.by='Eday', min.pct = .1))) bilat.14.18mark.M <- bilat.14.18mark.M[order(bilat.14.18mark.M$avg_logFC),] bilat.14.18mark.M <- bilat.14.18mark.M[abs(bilat.14.18mark.M$p_val_adj) < .05, ] bilat.14.18mark.M<-bilat.14.18mark.M[!grepl("^Hbb-", rownames(bilat.14.18mark.M)),] bilat.14.18mark.M<-bilat.14.18mark.M[!grepl("^Hba-", rownames(bilat.14.18mark.M)),] bilat.14.18mark.M<-bilat.14.18mark.M[!grepl("^RP23", rownames(bilat.14.18mark.M)),] bilat.14.18mark.M<-bilat.14.18mark.M[!grepl("^RP24", rownames(bilat.14.18mark.M)),] bilat.14.18mark.M<-bilat.14.18mark.M[!grepl("^Xist", rownames(bilat.14.18mark.M)),] bilat.14.18mark.M<-bilat.14.18mark.M[!grepl("^Tsix", rownames(bilat.14.18mark.M)),] bilat.14.18mark.M<-bilat.14.18mark.M[!grepl("^Ddx3y", rownames(bilat.14.18mark.M)),] bilat.14.18mark.M<-bilat.14.18mark.M[!grepl("^Eif2s3y", rownames(bilat.14.18mark.M)),] bilat.14.18mark.M<-bilat.14.18mark.M[!grepl("^Uty", rownames(bilat.14.18mark.M)),] bilat.14.18mark.M<-bilat.14.18mark.M[!grepl("^mt-", rownames(bilat.14.18mark.M)),] bilat.14.18mark.M<-bilat.14.18mark.M[!grepl("^a", rownames(bilat.14.18mark.M)),] bilat.14.18mark.M<-bilat.14.18mark.M[!grepl("^Kdm5d", rownames(bilat.14.18mark.M)),] ### Identifying Time DEGS from the Ventral subcluster ventral.14.18mark.M <- ((FindMarkers(sexdimorph.Mventral, ident.1 = "E18.5", ident.2 = "E14.5", group.by='Eday', min.pct = .1))) ventral.14.18mark.M <- ventral.14.18mark.M[order(ventral.14.18mark.M$avg_logFC),] ventral.14.18mark.M <- ventral.14.18mark.M[abs(ventral.14.18mark.M$p_val_adj) < .05, ] # the most arbitrary!! ventral.14.18mark.M<-ventral.14.18mark.M[!grepl("^Hbb-", rownames(ventral.14.18mark.M)),] ventral.14.18mark.M<-ventral.14.18mark.M[!grepl("^Hba-", rownames(ventral.14.18mark.M)),] ventral.14.18mark.M<-ventral.14.18mark.M[!grepl("^RP23", rownames(ventral.14.18mark.M)),] ventral.14.18mark.M<-ventral.14.18mark.M[!grepl("^RP24", rownames(ventral.14.18mark.M)),] ventral.14.18mark.M<-ventral.14.18mark.M[!grepl("^Xist", rownames(ventral.14.18mark.M)),] ventral.14.18mark.M<-ventral.14.18mark.M[!grepl("^Tsix", rownames(ventral.14.18mark.M)),] ventral.14.18mark.M<-ventral.14.18mark.M[!grepl("^Ddx3y", rownames(ventral.14.18mark.M)),] ventral.14.18mark.M<-ventral.14.18mark.M[!grepl("^Eif2s3y", rownames(ventral.14.18mark.M)),] ventral.14.18mark.M<-ventral.14.18mark.M[!grepl("^Uty", rownames(ventral.14.18mark.M)),] ventral.14.18mark.M<-ventral.14.18mark.M[!grepl("^mt-", rownames(ventral.14.18mark.M)),] ventral.14.18mark.M<-ventral.14.18mark.M[!grepl("^a", rownames(ventral.14.18mark.M)),] ventral.14.18mark.M<-ventral.14.18mark.M[!grepl("^Kdm5d", rownames(ventral.14.18mark.M)),] ### convert row names to a column so we can work with the genes easier ventral.14.18mark.M <-ventral.14.18mark.M %>% rownames_to_column(var='rn') dorsal.14.18mark.M <-dorsal.14.18mark.M %>% rownames_to_column(var='rn') bilat.14.18mark.M <-bilat.14.18mark.M %>% rownames_to_column(var='rn') ## Separate Tissue specific genes within the glans gm.intersect.M <-ventral.14.18mark.M %>% semi_join(dorsal.14.18mark.M, by = c('rn', 'Direction')) %>% semi_join(bilat.14.18mark.M, by = c('rn', 'Direction')) nrow(gm.intersect.M[gm.intersect.M$Direction == "Down",]) nrow(gm.intersect.M[gm.intersect.M$Direction == "Up",]) ventral.specific.M <-ventral.14.18mark.M %>% anti_join(dorsal.14.18mark.M, by = c('rn', 'Direction')) %>% anti_join(bilat.14.18mark.M, by = c('rn', 'Direction')) nrow(ventral.specific.M[ventral.specific.M$Direction == "Down",]) nrow(ventral.specific.M[ventral.specific.M$Direction == "Up",]) dorsal.specific.M <- dorsal.14.18mark.M %>% anti_join(ventral.14.18mark.M, by = c('rn', 'Direction'))%>% anti_join(bilat.14.18mark.M, by = c('rn', 'Direction')) nrow(dorsal.specific.M[dorsal.specific.M$Direction == "Down",]) nrow(dorsal.specific.M[dorsal.specific.M$Direction == "Up",]) bilat.specific.M <- bilat.14.18mark.M %>% anti_join(ventral.14.18mark.M, by = c('rn', 'Direction'))%>% anti_join(dorsal.14.18mark.M, by = c('rn', 'Direction')) nrow(bilat.specific.M[bilat.specific.M$Direction == "Down",]) nrow(bilat.specific.M[bilat.specific.M$Direction == "Up",]) } ### Female Glans { ### Separate data into separte object to work with ### sexdimorph.Fdorsal <-subset(x = Female.tot.gm, idents = c('0', "4"), invert=FALSE) sexdimorph.Fventral <-subset(x = Female.tot.gm, idents = c('3'), invert=FALSE) sexdimorph.Fbilat <-subset(x = Female.tot.gm, idents = c('2', '1'), invert=FALSE) ### Identifying Time DEGS from the Dorsal subcluster dorsal.14.18mark.F <- ((FindMarkers(sexdimorph.Fdorsal, ident.1 = "E18.5", ident.2 = "E14.5", group.by='Eday', min.pct = .1))) dorsal.14.18mark.F <- dorsal.14.18mark.F[order(dorsal.14.18mark.F$avg_logFC),] dorsal.14.18mark.F <- dorsal.14.18mark.F[abs(dorsal.14.18mark.F$p_val_adj) < .05, ] dorsal.14.18mark.F<-dorsal.14.18mark.F[!grepl("^Hbb-", rownames(dorsal.14.18mark.F)),] dorsal.14.18mark.F<-dorsal.14.18mark.F[!grepl("^Hba-", rownames(dorsal.14.18mark.F)),] dorsal.14.18mark.F<-dorsal.14.18mark.F[!grepl("^RP23", rownames(dorsal.14.18mark.F)),] dorsal.14.18mark.F<-dorsal.14.18mark.F[!grepl("^RP24", rownames(dorsal.14.18mark.F)),] dorsal.14.18mark.F<-dorsal.14.18mark.F[!grepl("^Xist", rownames(dorsal.14.18mark.F)),] dorsal.14.18mark.F<-dorsal.14.18mark.F[!grepl("^Tsix", rownames(dorsal.14.18mark.F)),] dorsal.14.18mark.F<-dorsal.14.18mark.F[!grepl("^Ddx3y", rownames(dorsal.14.18mark.F)),] dorsal.14.18mark.F<-dorsal.14.18mark.F[!grepl("^Eif2s3y", rownames(dorsal.14.18mark.F)),] dorsal.14.18mark.F<-dorsal.14.18mark.F[!grepl("^Uty", rownames(dorsal.14.18mark.F)),] dorsal.14.18mark.F<-dorsal.14.18mark.F[!grepl("^mt-", rownames(dorsal.14.18mark.F)),] dorsal.14.18mark.F<-dorsal.14.18mark.F[!grepl("^a", rownames(dorsal.14.18mark.F)),] dorsal.14.18mark.F<-dorsal.14.18mark.F[!grepl("^Kdm5d", rownames(dorsal.14.18mark.F)),] ### Identifying Time DEGS from the venral subcluster ventral.14.18mark.F <- ((FindMarkers(sexdimorph.Fventral, ident.1 = "E18.5", ident.2 = "E14.5", group.by='Eday', min.pct = .1))) ventral.14.18mark.F <- ventral.14.18mark.F[order(ventral.14.18mark.F$avg_logFC),] ventral.14.18mark.F <- ventral.14.18mark.F[abs(ventral.14.18mark.F$p_val_adj) < .05, ] ventral.14.18mark.F<-ventral.14.18mark.F[!grepl("^Hbb-", rownames(ventral.14.18mark.F)),] ventral.14.18mark.F<-ventral.14.18mark.F[!grepl("^Hba-", rownames(ventral.14.18mark.F)),] ventral.14.18mark.F<-ventral.14.18mark.F[!grepl("^RP23", rownames(ventral.14.18mark.F)),] ventral.14.18mark.F<-ventral.14.18mark.F[!grepl("^RP24", rownames(ventral.14.18mark.F)),] ventral.14.18mark.F<-ventral.14.18mark.F[!grepl("^Xist", rownames(ventral.14.18mark.F)),] ventral.14.18mark.F<-ventral.14.18mark.F[!grepl("^Tsix", rownames(ventral.14.18mark.F)),] ventral.14.18mark.F<-ventral.14.18mark.F[!grepl("^Ddx3y", rownames(ventral.14.18mark.F)),] ventral.14.18mark.F<-ventral.14.18mark.F[!grepl("^Eif2s3y", rownames(ventral.14.18mark.F)),] ventral.14.18mark.F<-ventral.14.18mark.F[!grepl("^Uty", rownames(ventral.14.18mark.F)),] ventral.14.18mark.F<-ventral.14.18mark.F[!grepl("^mt-", rownames(ventral.14.18mark.F)),] ventral.14.18mark.F<-ventral.14.18mark.F[!grepl("^a", rownames(ventral.14.18mark.F)),] ventral.14.18mark.F<-ventral.14.18mark.F[!grepl("^Kdm5d", rownames(ventral.14.18mark.F)),] ### Identifying Time DEGS from the proximal subcluster bilat.14.18mark.F <- ((FindMarkers(sexdimorph.Fbilat, ident.1 = "E18.5", ident.2 = "E14.5", group.by='Eday', min.pct = .1))) bilat.14.18mark.F <- bilat.14.18mark.F[order(bilat.14.18mark.F$avg_logFC),] bilat.14.18mark.F <- bilat.14.18mark.F[abs(bilat.14.18mark.F$p_val_adj) < .05, ] bilat.14.18mark.F<-bilat.14.18mark.F[!grepl("^Hbb-", rownames(bilat.14.18mark.F)),] bilat.14.18mark.F<-bilat.14.18mark.F[!grepl("^Hba-", rownames(bilat.14.18mark.F)),] bilat.14.18mark.F<-bilat.14.18mark.F[!grepl("^RP23", rownames(bilat.14.18mark.F)),] bilat.14.18mark.F<-bilat.14.18mark.F[!grepl("^RP24", rownames(bilat.14.18mark.F)),] bilat.14.18mark.F<-bilat.14.18mark.F[!grepl("^Xist", rownames(bilat.14.18mark.F)),] bilat.14.18mark.F<-bilat.14.18mark.F[!grepl("^Tsix", rownames(bilat.14.18mark.F)),] bilat.14.18mark.F<-bilat.14.18mark.F[!grepl("^Ddx3y", rownames(bilat.14.18mark.F)),] bilat.14.18mark.F<-bilat.14.18mark.F[!grepl("^Eif2s3y", rownames(bilat.14.18mark.F)),] bilat.14.18mark.F<-bilat.14.18mark.F[!grepl("^Uty", rownames(bilat.14.18mark.F)),] bilat.14.18mark.F<-bilat.14.18mark.F[!grepl("^mt-", rownames(bilat.14.18mark.F)),] bilat.14.18mark.F<-bilat.14.18mark.F[!grepl("^a", rownames(bilat.14.18mark.F)),] bilat.14.18mark.F<-bilat.14.18mark.F[!grepl("^Kdm5d", rownames(bilat.14.18mark.F)),] ### convert row names to a column so we can work with the genes easier ventral.14.18mark.F <-ventral.14.18mark.F %>% rownames_to_column(var='rn') dorsal.14.18mark.F <-dorsal.14.18mark.F %>% rownames_to_column(var='rn') bilat.14.18mark.F <-bilat.14.18mark.F %>% rownames_to_column(var='rn') ### Find tissue specific genes within the female glans gm.intersect.F <-ventral.14.18mark.F %>% semi_join(dorsal.14.18mark.F, by = c('rn', 'Direction')) %>% semi_join(bilat.14.18mark.F, by = c('rn', 'Direction')) nrow(gm.intersect.F[gm.intersect.F$Direction == "Down",]) nrow(gm.intersect.F[gm.intersect.F$Direction == "Up",]) ventral.specific.F <-ventral.14.18mark.F %>% anti_join(dorsal.14.18mark.F, by = c('rn', 'Direction')) %>% anti_join(bilat.14.18mark.F, by = c('rn', 'Direction')) nrow(ventral.specific.F[ventral.specific.F$Direction == "Down",]) nrow(ventral.specific.F[ventral.specific.F$Direction == "Up",]) dorsal.specific.F <- dorsal.14.18mark.F %>% anti_join(ventral.14.18mark.F, by = c('rn', 'Direction')) %>% anti_join(bilat.14.18mark.F, by = c('rn', 'Direction')) nrow(dorsal.specific.F[dorsal.specific.F$Direction == "Down",]) nrow(dorsal.specific.F[dorsal.specific.F$Direction == "Up",]) bilat.specific.F <- bilat.14.18mark.F %>% anti_join(ventral.14.18mark.F, by = c('rn', 'Direction')) %>% anti_join(dorsal.14.18mark.F, by = c('rn', 'Direction')) nrow(bilat.specific.F[bilat.specific.F$Direction == "Down",]) nrow(bilat.specific.F[bilat.specific.F$Direction == "Up",]) } ### Filter for sex specific genes { ### Make a column that clossify the direction of gene expression change from E14.5 to E18.5 ventral.14.18mark.M$Direction <- ifelse(ventral.14.18mark.M$avg_logFC>0, "Up", "Down") ventral.14.18mark.F$Direction <- ifelse(ventral.14.18mark.F$avg_logFC>0, "Up", "Down") dorsal.14.18mark.F$Direction <- ifelse(dorsal.14.18mark.F$avg_logFC>0, "Up", "Down") dorsal.14.18mark.M$Direction <- ifelse(dorsal.14.18mark.M$avg_logFC>0, "Up", "Down") bilat.14.18mark.F$Direction <- ifelse(bilat.14.18mark.F$avg_logFC>0, "Up", "Down") bilat.14.18mark.M$Direction <- ifelse(bilat.14.18mark.M$avg_logFC>0, "Up", "Down") ### make a column name for each subpopulation so it is easier to parce apart dorsal.specific.F$Tissue <- "Dorsal" dorsal.specific.M$Tissue <- "Dorsal" ventral.specific.F$Tissue <- "Ventral" ventral.specific.M$Tissue <- "Ventral" bilat.specific.F$Tissue <- "Bilateral" bilat.specific.M$Tissue <- "Bilateral" gm.intersect.F$Tissue <- "Shared" gm.intersect.M$Tissue <- "Shared" ### find the sex specific genes for each subpopulation dorsal.specific.F.sexcomp <-dorsal.specific.F %>% ## from the dorsal specific genes anti_join(dorsal.14.18mark.M, by = c('rn', 'Direction')) %>% ## remove all genes that were also found to be significant in the dorsal male populations add_column(Group = "Female Dorsal")%>% ## add a column for sex and subpopulations add_column(Sex = "Female") ## add a column for sex dorsal.specific.M.sexcomp <-dorsal.specific.M %>% anti_join(dorsal.14.18mark.F, by = c('rn', 'Direction'))%>% add_column(Group = "Male Dorsal")%>% add_column(Sex = "Male") dorsal.shared.MF.sexcomp <-dorsal.specific.M %>% semi_join(dorsal.specific.F, by = c('rn', 'Direction'))%>% add_column(Group = "Shared Dorsal")%>% add_column(Sex = "Shared") ventral.specific.F.sexcomp <-ventral.specific.F %>% anti_join(ventral.14.18mark.M, by = c('rn', 'Direction'))%>% add_column(Group = "Female Ventral")%>% add_column(Sex = "Female") ventral.specific.M.sexcomp <-ventral.specific.M %>% anti_join(ventral.14.18mark.F, by = c('rn', 'Direction'))%>% add_column(Group = "Male Ventral")%>% add_column(Sex = "Male") ventral.shared.MF.sexcomp <-ventral.specific.M %>% semi_join(ventral.specific.F, by = c('rn', 'Direction'))%>% add_column(Group = "Shared Ventral")%>% add_column(Sex = "Shared") bilat.specific.F.sexcomp <-bilat.specific.F %>% anti_join(bilat.14.18mark.M, by = c('rn', 'Direction'))%>% add_column(Group = "Female bilat")%>% add_column(Sex = "Female") bilat.specific.M.sexcomp <-bilat.specific.M %>% anti_join(bilat.14.18mark.F, by = c('rn', 'Direction'))%>% add_column(Group = "Male bilat")%>% add_column(Sex = "Male") bilat.shared.MF.sexcomp <-bilat.specific.M %>% semi_join(bilat.specific.F, by = c('rn', 'Direction'))%>% add_column(Group = "Shared bilat")%>% add_column(Sex = "Shared") gm.intersect.F.sexcomp <-gm.intersect.F %>% anti_join(ventral.specific.M, by = c('rn', 'Direction'))%>% add_column(Group = "Female gm")%>% add_column(Sex = "Female") gm.intersect.M.sexcomp <-gm.intersect.M %>% anti_join(gm.intersect.F, by = c('rn', 'Direction'))%>% add_column(Group = "Male gm")%>% add_column(Sex = "Male") gm.intersect.shared.MF.sexcomp <-gm.intersect.M %>% semi_join(gm.intersect.F, by = c('rn', 'Direction'))%>% add_column(Group = "Shared gm")%>% add_column(Sex = "Shared") ### Combine all data into a single data frame gm.total.time.df <- data.table( rbind( dorsal.specific.F.sexcomp <- dorsal.specific.F.sexcomp %>% anti_join(gm.intersect.M.sexcomp, by = c('rn', 'Direction')), dorsal.specific.M.sexcomp <- dorsal.specific.M.sexcomp %>% anti_join(gm.intersect.F.sexcomp, by = c('rn', 'Direction')), ventral.specific.F.sexcomp <- ventral.specific.F.sexcomp %>% anti_join(gm.intersect.M.sexcomp, by = c('rn', 'Direction')), ventral.specific.M.sexcomp <- ventral.specific.M.sexcomp %>% anti_join(gm.intersect.F.sexcomp, by = c('rn', 'Direction')), bilat.specific.F.sexcomp <- bilat.specific.F.sexcomp %>% anti_join(gm.intersect.M.sexcomp, by = c('rn', 'Direction')), bilat.specific.M.sexcomp <- bilat.specific.M.sexcomp %>% anti_join(gm.intersect.F.sexcomp, by = c('rn', 'Direction')), gm.intersect.shared.MF.sexcomp, gm.intersect.M.sexcomp, gm.intersect.F.sexcomp ) ) } } ### Prepuce { ### Male Prepuce { ### separatte subpopulations into different objects to run analysis sexdimorph.Mgeneral <-subset(x = male.tot.pp, idents = c('0' ,'2', '3'), invert=FALSE) sexdimorph.Mventral.pp <-subset(x = male.tot.pp, idents = c('0', '1' , '4'), invert=FALSE) ### Find time DEGS general.14.18mark.M <- ((FindMarkers(sexdimorph.Mgeneral, ident.1 = "E18.5", ident.2 = "E14.5", group.by='Eday', min.pct = .1))) general.14.18mark.M <- general.14.18mark.M[order(general.14.18mark.M$avg_logFC),] general.14.18mark.M <- general.14.18mark.M[abs(general.14.18mark.M$p_val_adj) < .05, ] general.14.18mark.M<-general.14.18mark.M[!grepl("^Hbb-", rownames(general.14.18mark.M)),] general.14.18mark.M<-general.14.18mark.M[!grepl("^Hba-", rownames(general.14.18mark.M)),] general.14.18mark.M<-general.14.18mark.M[!grepl("^RP23", rownames(general.14.18mark.M)),] general.14.18mark.M<-general.14.18mark.M[!grepl("^RP24", rownames(general.14.18mark.M)),] general.14.18mark.M<-general.14.18mark.M[!grepl("^Xist", rownames(general.14.18mark.M)),] general.14.18mark.M<-general.14.18mark.M[!grepl("^Tsix", rownames(general.14.18mark.M)),] general.14.18mark.M<-general.14.18mark.M[!grepl("^Ddx3y", rownames(general.14.18mark.M)),] general.14.18mark.M<-general.14.18mark.M[!grepl("^Eif2s3y", rownames(general.14.18mark.M)),] general.14.18mark.M<-general.14.18mark.M[!grepl("^Uty", rownames(general.14.18mark.M)),] general.14.18mark.M<-general.14.18mark.M[!grepl("^mt-", rownames(general.14.18mark.M)),] general.14.18mark.M<-general.14.18mark.M[!grepl("^a", rownames(general.14.18mark.M)),] general.14.18mark.M<-general.14.18mark.M[!grepl("^Kdm5d", rownames(general.14.18mark.M)),] ventral.pp.14.18mark.M <- ((FindMarkers(sexdimorph.Mventral.pp, ident.1 = "E18.5", ident.2 = "E14.5", group.by='Eday', min.pct = .1))) ventral.pp.14.18mark.M <- ventral.pp.14.18mark.M[order(ventral.pp.14.18mark.M$avg_logFC),] ventral.pp.14.18mark.M <- ventral.pp.14.18mark.M[abs(ventral.pp.14.18mark.M$p_val_adj) < .05, ] ventral.pp.14.18mark.M<-ventral.pp.14.18mark.M[!grepl("^Hbb-", rownames(ventral.pp.14.18mark.M)),] ventral.pp.14.18mark.M<-ventral.pp.14.18mark.M[!grepl("^Hba-", rownames(ventral.pp.14.18mark.M)),] ventral.pp.14.18mark.M<-ventral.pp.14.18mark.M[!grepl("^RP23", rownames(ventral.pp.14.18mark.M)),] ventral.pp.14.18mark.M<-ventral.pp.14.18mark.M[!grepl("^RP24", rownames(ventral.pp.14.18mark.M)),] ventral.pp.14.18mark.M<-ventral.pp.14.18mark.M[!grepl("^Xist", rownames(ventral.pp.14.18mark.M)),] ventral.pp.14.18mark.M<-ventral.pp.14.18mark.M[!grepl("^Tsix", rownames(ventral.pp.14.18mark.M)),] ventral.pp.14.18mark.M<-ventral.pp.14.18mark.M[!grepl("^Ddx3y", rownames(ventral.pp.14.18mark.M)),] ventral.pp.14.18mark.M<-ventral.pp.14.18mark.M[!grepl("^Eif2s3y", rownames(ventral.pp.14.18mark.M)),] ventral.pp.14.18mark.M<-ventral.pp.14.18mark.M[!grepl("^Uty", rownames(ventral.pp.14.18mark.M)),] ventral.pp.14.18mark.M<-ventral.pp.14.18mark.M[!grepl("^mt-", rownames(ventral.pp.14.18mark.M)),] ventral.pp.14.18mark.M<-ventral.pp.14.18mark.M[!grepl("^a", rownames(ventral.pp.14.18mark.M)),] ventral.pp.14.18mark.M<-ventral.pp.14.18mark.M[!grepl("^Kdm5d", rownames(ventral.pp.14.18mark.M)),] general.14.18mark.F$Direction <- ifelse(general.14.18mark.F$avg_logFC>0, "Up", "Down") general.14.18mark.M$Direction <- ifelse(general.14.18mark.M$avg_logFC>0, "Up", "Down") ventralpp.14.18mark.F$Direction <- ifelse(ventralpp.14.18mark.F$avg_logFC>0, "Up", "Down") ventral.pp.14.18mark.M$Direction <- ifelse(ventral.pp.14.18mark.M$avg_logFC>0, "Up", "Down") ventral.pp.14.18mark.M <-ventral.pp.14.18mark.M %>% rownames_to_column(var='rn') general.14.18mark.M <-general.14.18mark.M %>% rownames_to_column(var='rn') pp.intersect.M <-ventral.pp.14.18mark.M %>% semi_join(general.14.18mark.M, by = c('rn', 'Direction')) nrow(pp.intersect.M[pp.intersect.M$Direction == "Down",]) nrow(pp.intersect.M[pp.intersect.M$Direction == "Up",]) ventral.pp.specific.M <-ventral.pp.14.18mark.M %>% anti_join(general.14.18mark.M, by = c('rn', 'Direction')) nrow(ventral.pp.specific.M[ventral.pp.specific.M$Direction == "Down",]) nrow(ventral.pp.specific.M[ventral.pp.specific.M$Direction == "Up",]) general.specific.M <- general.14.18mark.M %>% anti_join(ventral.pp.14.18mark.M, by = c('rn', 'Direction')) nrow(general.specific.M[general.specific.M$Direction == "Down",]) nrow(general.specific.M[general.specific.M$Direction == "Up",]) } ### Female Prepuce { sexdimorph.Fgeneral <-subset(x = Female.tot.pp, idents = c('2', '1', '4', '0'), invert=FALSE) #12 is epithelium #10.16.19 add 10 to be removed look like RBS sexdimorph.Fventralpp <-subset(x = Female.tot.pp, idents = c('2','3'), invert=FALSE) #12 is epithelium #10.16.19 add 10 to be removed look like RBS ventralpp.14.18mark.F <- ((FindMarkers(sexdimorph.Fventralpp, ident.1 = "E18.5", ident.2 = "E14.5", group.by='Eday', min.pct = .1))) ventralpp.14.18mark.F <- ventralpp.14.18mark.F[order(ventralpp.14.18mark.F$avg_logFC),] ventralpp.14.18mark.F <- ventralpp.14.18mark.F[abs(ventralpp.14.18mark.F$p_val_adj) < .05, ] # the most arbitrary!! ventralpp.14.18mark.F<-ventralpp.14.18mark.F[!grepl("^Hbb-", rownames(ventralpp.14.18mark.F)),] ventralpp.14.18mark.F<-ventralpp.14.18mark.F[!grepl("^Hba-", rownames(ventralpp.14.18mark.F)),] ventralpp.14.18mark.F<-ventralpp.14.18mark.F[!grepl("^RP23", rownames(ventralpp.14.18mark.F)),] ventralpp.14.18mark.F<-ventralpp.14.18mark.F[!grepl("^RP24", rownames(ventralpp.14.18mark.F)),] ventralpp.14.18mark.F<-ventralpp.14.18mark.F[!grepl("^Xist", rownames(ventralpp.14.18mark.F)),] ventralpp.14.18mark.F<-ventralpp.14.18mark.F[!grepl("^Tsix", rownames(ventralpp.14.18mark.F)),] ventralpp.14.18mark.F<-ventralpp.14.18mark.F[!grepl("^Ddx3y", rownames(ventralpp.14.18mark.F)),] ventralpp.14.18mark.F<-ventralpp.14.18mark.F[!grepl("^Eif2s3y", rownames(ventralpp.14.18mark.F)),] ventralpp.14.18mark.F<-ventralpp.14.18mark.F[!grepl("^Uty", rownames(ventralpp.14.18mark.F)),] ventralpp.14.18mark.F<-ventralpp.14.18mark.F[!grepl("^mt-", rownames(ventralpp.14.18mark.F)),] ventralpp.14.18mark.F<-ventralpp.14.18mark.F[!grepl("^a", rownames(ventralpp.14.18mark.F)),] ventralpp.14.18mark.F<-ventralpp.14.18mark.F[!grepl("^Kdm5d", rownames(ventralpp.14.18mark.F)),] ventralpp.14.18mark.F<-ventralpp.14.18mark.F[rownames(ventralpp.14.18mark.F) != "Gt(ROSA)26Sor",] ventralpp.14.18mark.F<-ventralpp.14.18mark.F[rownames(ventralpp.14.18mark.F) != "2410015M20Rik",] general.14.18mark.F <- ((FindMarkers(sexdimorph.Fgeneral, ident.1 = "E18.5", ident.2 = "E14.5", group.by='Eday', min.pct = .1))) general.14.18mark.F <- general.14.18mark.F[order(general.14.18mark.F$avg_logFC),] general.14.18mark.F <- general.14.18mark.F[abs(general.14.18mark.F$p_val_adj) < .05, ] # the most arbitrary!! general.14.18mark.F<-general.14.18mark.F[!grepl("^Hbb-", rownames(general.14.18mark.F)),] general.14.18mark.F<-general.14.18mark.F[!grepl("^Hba-", rownames(general.14.18mark.F)),] general.14.18mark.F<-general.14.18mark.F[!grepl("^RP23", rownames(general.14.18mark.F)),] general.14.18mark.F<-general.14.18mark.F[!grepl("^RP24", rownames(general.14.18mark.F)),] general.14.18mark.F<-general.14.18mark.F[!grepl("^Xist", rownames(general.14.18mark.F)),] general.14.18mark.F<-general.14.18mark.F[!grepl("^Tsix", rownames(general.14.18mark.F)),] general.14.18mark.F<-general.14.18mark.F[!grepl("^Ddx3y", rownames(general.14.18mark.F)),] general.14.18mark.F<-general.14.18mark.F[!grepl("^Eif2s3y", rownames(general.14.18mark.F)),] general.14.18mark.F<-general.14.18mark.F[!grepl("^Uty", rownames(general.14.18mark.F)),] general.14.18mark.F<-general.14.18mark.F[!grepl("^mt-", rownames(general.14.18mark.F)),] general.14.18mark.F<-general.14.18mark.F[!grepl("^a", rownames(general.14.18mark.F)),] general.14.18mark.F<-general.14.18mark.F[!grepl("^Kdm5d", rownames(general.14.18mark.F)),] general.14.18mark.F<-general.14.18mark.F[rownames(general.14.18mark.F) != "Gt(ROSA)26Sor",] general.14.18mark.M$Direction <- ifelse(general.14.18mark.M$avg_logFC>0, "Up", "Down") general.14.18mark.F$Direction <- ifelse(general.14.18mark.F$avg_logFC>0, "Up", "Down") ventralpp.14.18mark.F$Direction <- ifelse(ventralpp.14.18mark.F$avg_logFC>0, "Up", "Down") ventral.pp.14.18mark.M$Direction <- ifelse(ventral.pp.14.18mark.M$avg_logFC>0, "Up", "Down") general.14.18mark.F <-general.14.18mark.F %>% rownames_to_column(var='rn') ventralpp.14.18mark.F <-ventralpp.14.18mark.F %>% rownames_to_column(var='rn') pp.intersect.F <-general.14.18mark.F %>% semi_join(ventralpp.14.18mark.F, by = c('rn', 'Direction')) nrow(pp.intersect.F[pp.intersect.F$Direction == "Down",]) nrow(pp.intersect.F[pp.intersect.F$Direction == "Up",]) general.specific.F <-general.14.18mark.F %>% anti_join(ventralpp.14.18mark.F, by = c('rn', 'Direction')) nrow(general.specific.F[general.specific.F$Direction == "Down",]) nrow(general.specific.F[general.specific.F$Direction == "Up",]) ventralpp.specific.F <- ventralpp.14.18mark.F %>% anti_join(general.14.18mark.F, by = c('rn', 'Direction')) nrow(ventralpp.specific.F[ventralpp.specific.F$Direction == "Down",]) nrow(ventralpp.specific.F[ventralpp.specific.F$Direction == "Up",]) } ### Filter for sex specific genes { ventralpp.specific.F$Tissue <- "ventral.pp" general.specific.M$Tissue <- "general" general.specific.F$Tissue <- "general" ventral.pp.specific.M$Tissue <- "ventral.pp" pp.intersect.F$Tissue <- "Shared" #pp.intersect.M$Tissue <- "Shared" ttt <- pp.total.time.df[duplicated(pp.total.time.df$rn)] general.specific.F.sexcomp <-general.specific.F %>% anti_join(general.14.18mark.M, by = c('rn', 'Direction')) %>% add_column(Group = "Female general")%>% add_column(Sex = "Female") general.specific.M.sexcomp <-general.specific.M %>% anti_join(general.14.18mark.F, by = c('rn', 'Direction'))%>% add_column(Group = "Male general")%>% add_column(Sex = "Male") general.shared.MF.sexcomp <-general.specific.M %>% semi_join(general.specific.F, by = c('rn', 'Direction'))%>% add_column(Group = "Shared general")%>% add_column(Sex = "Shared") ventral.pp.specific.F.sexcomp <-ventralpp.specific.F %>% anti_join(ventral.pp.14.18mark.M, by = c('rn', 'Direction'))%>% add_column(Group = "Female ventral.pp")%>% add_column(Sex = "Female") ventral.pp.specific.M.sexcomp <-ventral.pp.specific.M %>% anti_join(ventralpp.14.18mark.F, by = c('rn', 'Direction'))%>% add_column(Group = "Male ventral.pp")%>% add_column(Sex = "Male") ventral.pp.shared.MF.sexcomp <-ventral.pp.specific.M %>% semi_join(ventralpp.specific.F, by = c('rn', 'Direction'))%>% add_column(Group = "Shared ventral.pp")%>% add_column(Sex = "Shared") pp.total.time.df <- data.table( rbind( ventralpp.specific.F.sexcomp <- ventralpp.specific.F.sexcomp %>% anti_join(pp.intersect.M.sexcomp, by = c('rn', 'Direction')), ventralpp.specific.M.sexcomp <- ventralpp.specific.M.sexcomp %>% anti_join(pp.intersect.F.sexcomp, by = c('rn', 'Direction')), general.specific.F.sexcomp <- general.specific.F.sexcomp %>% anti_join(pp.intersect.M.sexcomp, by = c('rn', 'Direction')), general.specific.M.sexcomp <- general.specific.M.sexcomp %>% anti_join(pp.intersect.F.sexcomp, by = c('rn', 'Direction')), pp.intersect.shared.MF.sexcomp, pp.intersect.M.sexcomp, pp.intersect.F.sexcomp } } } ############### Combined Transcriptional Kinetics ############### { ## SUB CLUSTER KINETICS ## sexdimorph.pp <- RenameIdents(object = sexdimorph.pp, ## change names of subpopulations to general and subdermal '0' = "0", '1' = "0", '2' = "2", '3' = "2" ) mat <- as.matrix(GetAssayData(sexdimorph.pp, assay = 'RNA', slot = 'data')) ## pull data out into something I am more comfortable working with. dat.1 <- data.frame(t(mat)) #Make into data frame with gene names as columns and cell names as rows. cluster <- sexdimorph.pp@meta.data$seurat_clusters ## Add clusters as a colum active <- sexdimorph.pp@active.ident ## Add identities as a column clust <- data.frame(cbind(cluster, active, rownames(dat.1))) # put into data.frame dat.2 <- cbind(dat.1, cluster, active) ## cobmine into data frame ## add rep and sex as different columns dat.3 <- data.table(cbind(dat.2, sexdimorph.pp@meta.data$orig.ident, sexdimorph.pp$Sex, sexdimorph.pp$Eday, sexdimorph.pp$Sex.day)) dat.3 <- data.table(dat.3) names(dat.3)[names(dat.3) == 'sexdimorph.pp$Eday'] <- 'Eday' ## add meta data names(dat.3)[names(dat.3) == 'sexdimorph.pp$Sex.day'] <- 'Sex.day' ## add meta data names(dat.3)[names(dat.3) == 'sexdimorph.pp$Sex'] <- 'Sex' ## add meta data names(dat.3)[names(dat.3) == 'sexdimorph.pp@meta.data$orig.ident'] <- 'orig.ident' ## add meta data ## prepuce data has single progentor the then divides into seperate populations. This is to organize the data so it recognizes that dat.3$ttt <- dat.3$active:dat.3$Eday# specifiy a population by Eday column dat.3 <- dat.3[dat.3$ttt != '2:E14.5'] # remove subdermal on E14.5 becasue they dont exist at this time dat.3$lat <- (ifelse(dat.3$ttt == '0:E14.5', "2", ## ifelse(dat.3$ttt == '2:E16.5',"2", ifelse(dat.3$ttt == '2:E18.5',"2", ifelse(dat.3$ttt == '2:E18.5', "2", "0"))))) # labeled listed cluster at sub dermal, including the E14.5 progenitors. Then everything else is labeled as general ## averaage data by orignial identity (2 replicates) and population and time and sex Sex.di.gene.noclust.1 <- aggregate(dat.3[, 1:21468], list(dat.3$active, dat.3$Sex, dat.3$Eday,dat.3$Sex.day,dat.3$orig.ident, dat.3$lat), mean) ## average data by population and time and sex sex.di.gene.noclust <- aggregate(dat.3[, 1:21468], list(dat.3$active, dat.3$Sex, dat.3$Eday,dat.3$Sex.day, dat.3$lat), mean) ## label the subpopulations and remove the duplicates sex.di.gene.noclust11 <-sex.di.gene.noclust sex.di.gene.noclust$Group.5 <- c("0", "0", "0" ,"0" ,"Lateral" ,"Lateral", "Lateral", "Lateral", "Lateral", "Lateral") sex.di.gene.noclust11$Group.5 <- c("General", "General", "General" ,"General" ,"General" ,"General", "2", "2", "2", "2") sex.di.gene.noclustrb <- rbind(sex.di.gene.noclust, sex.di.gene.noclust11) sex.di.gene.noclustrb<- sex.di.gene.noclustrb[sex.di.gene.noclustrb$Group.5 != '0',] sex.di.gene.noclustrb<- sex.di.gene.noclustrb[sex.di.gene.noclustrb$Group.5 != '2',] ## label the subpopulations and remove the duplicates sex.di.gene.noclust111 <-Sex.di.gene.noclust.1 Sex.di.gene.noclust.1$Group.6 <- c("0", "0","0", "0", "0" ,"0", "0" ,"0" ,"Lateral", "Lateral", "Lateral" ,"Lateral", "Lateral", "Lateral", "Lateral","Lateral","Lateral","Lateral","Lateral","Lateral") sex.di.gene.noclust111$Group.6 <- c("General", "General", "General" ,"General" ,"General" ,"General","2", "2", "General" ,"General" ,"2" ,"2", "2", "2", "General", "General","2" ,"2", "2", "2") sex.di.gene.noclustrb1 <- rbind(Sex.di.gene.noclust.1, sex.di.gene.noclust111) sex.di.gene.noclustrb1<- sex.di.gene.noclustrb1[sex.di.gene.noclustrb1$Group.6 != '0',] sex.di.gene.noclustrb1<- sex.di.gene.noclustrb1[sex.di.gene.noclustrb1$Group.6 != '2',] ## SUB CLUSTER KINETICS ## sexdimorph.gm <- RenameIdents(object = sexdimorph.gm, '0' = "0", '1' = "1", '2' = "1", '3' = "3", '4' = "3") mat.gm <- as.matrix(GetAssayData(sexdimorph.gm, assay = 'RNA', slot = 'data')) ## pull data out into something I am more comfortable working with. dat.1.gm <- data.frame(t(mat.gm)) #Make into data frame with gene names as columns and cell names as rows. ## Add clusters as a colum cluster <- sexdimorph.gm@meta.data$seurat_clusters active <- sexdimorph.gm@active.ident clust <- data.frame(cbind(cluster, active, rownames(dat.1.gm))) dat.2.gm <- cbind(dat.1.gm, cluster, active) ## add rep and sex as different columns dat.3.gm <- data.table(cbind(dat.2.gm, sexdimorph.gm@meta.data$orig.ident, sexdimorph.gm$Sex, sexdimorph.gm$Eday, sexdimorph.gm$Sex.day)) dat.3.gm <- data.table(dat.3.gm) names(dat.3.gm)[names(dat.3.gm) == 'sexdimorph.gm$Eday'] <- 'Eday' names(dat.3.gm)[names(dat.3.gm) == 'sexdimorph.gm$Sex.day'] <- 'Sex.day' names(dat.3.gm)[names(dat.3.gm) == 'sexdimorph.gm$Sex'] <- 'Sex' names(dat.3.gm)[names(dat.3.gm) == 'sexdimorph.gm@meta.data$orig.ident'] <- 'orig.ident' ## aveage the data Sex.di.gene.noclust.gm1 <- aggregate(dat.3.gm[, 1:21468], list(dat.3.gm$active, dat.3.gm$Sex, dat.3.gm$Eday,dat.3.gm$Sex.day,dat.3.gm$orig.ident), mean) Sex.di.gene.noclust.gm <- aggregate(dat.3.gm[, 1:21468], list(dat.3.gm$active, dat.3.gm$Sex, dat.3.gm$Eday,dat.3.gm$Sex.day), mean) # specify columns to match the prepuce data Sex.di.gene.noclust.gm$Group.5 <-Sex.di.gene.noclust.gm$Group.1 Sex.di.gene.noclust.gm1$Group.6 <-Sex.di.gene.noclust.gm1$Group.1 # combine the prepuce and glans data into one sex.di.gene.noclust.tot <- rbind(sex.di.gene.noclustrb,Sex.di.gene.noclust.gm) sex.di.gene.noclust.tot1 <- rbind(sex.di.gene.noclustrb1,Sex.di.gene.noclust.gm1) sex.di.gene.noclust.tot1$Group.7<-sex.di.gene.noclust.tot1$Group.6 sex.di.gene.noclust.tot$Group.7<-sex.di.gene.noclust.tot$Group.5 sex.di.gene.noclust.tot$Group.7 sex.di.gene.noclust.tot1$Group.3 sex.di.gene.noclust.tot1 <- sex.di.gene.noclust.tot1[sex.di.gene.noclust.tot1$Group.7 != '5',] ## remove a small undefined subcluster likely blood cells sex.di.gene.noclust.tot <- sex.di.gene.noclust.tot[sex.di.gene.noclust.tot$Group.7 != '5',] ## remove a small undefined subcluster likely blood cells sex.di.gene.noclust.tot1$Group.7 <- factor(sex.di.gene.noclust.tot1$Group.7, levels = c("1", "0", "3", "General","Lateral")) sex.di.gene.noclust.tot$Group.7 <- factor(sex.di.gene.noclust.tot$Group.7, levels = c("1", "0", "3", "General","Lateral")) #### sex.di.gene.noclust.tot and sex.di.gene.noclust.tot1 should be used in ggplot2 for plotting transcriptional relationships. ##### }