# install.packages("devtools")
library(devtools)
install_github("nathanskene/ewce")
## Skipping install of 'EWCE' from a github remote, the SHA1 (d6666356) has not changed since last install.
## Use `force = TRUE` to force installation
library(EWCE)
library(PatchseqMap)
Patch-seq is a useful technique for obtaining both electrophysiology and mRNA from single cells. One of the primary purposes for collecting the mRNA is to be able to infer the underlying celltype. Generally fairly low amounts of mRNA are obtained. For demonstration purposes, let’s generate some simulated patchseq data based on the cortex/hippocampus single cell transcriptome data. We assume that there are 3x fewer reads through patchseq, sampled from the scRNA-Seq data with a poisson distribution.
# First reduce the cortex_mrna dataset to just interneurons
data(cortex_mrna)
int_annot = cortex_mrna$annot[cortex_mrna$annot$level1class=="interneurons",]
int_exp = cortex_mrna$exp[,int_annot$cell_id]
# Use the cortex_mrna dataset to simulate patchseq data
downsample_expression <- function(x){
y = round(rpois(length(x),x/4))
return(y)
}
simulated_patchdata = apply(int_exp,2,downsample_expression)
rownames(simulated_patchdata) = rownames(int_exp)
simulated_patchdata = simulated_patchdata[apply(simulated_patchdata,1,sum)>0,]
MedianReadsPerCell = median(apply(simulated_patchdata,2,sum))
print(sprintf("Median reads per simulated cell: %s",MedianReadsPerCell))
## [1] "Median reads per simulated cell: 4306.5"
# Generate celltype data for just the cortex/hippocampus data
exp_CortexOnly_DROPPED = drop.uninformative.genes(exp=cortex_mrna$exp,level2annot = cortex_mrna$annot$level2class)
fNames_CortexOnly = generate.celltype.data(exp=exp_CortexOnly_DROPPED,level1class=cortex_mrna$annot$level1class,level2class=cortex_mrna$annot$level2class,groupName="kiCortexOnly",thresh=0,trim=0)
print(fNames_CortexOnly)
## [1] "CellTypeData_kiCortexOnly.rda"
fNames_CortexOnly = filter.genes.without.1to1.homolog(fNames_CortexOnly)
print(fNames_CortexOnly)
## [1] "CellTypeData_kiCortexOnly.rda"
## [2] "CellTypeData_kiCortexOnly_1to1only.rda"
load(fNames_CortexOnly[1])
# Because the simulated patchseq data is just for interneurons, restrict the celltype specificity data to interneurons
ctd[[2]]$specificity = ctd[[2]]$specificity[,grep("^Int",colnames(ctd[[2]]$specificity))]
As ever, you should start by correcting the MGI symbols in your patchseq data:
simulated_patchdata_corrected = fix.bad.mgi.symbols(simulated_patchdata)
## [1] "845 rows do not have proper MGI symbols"
## [1] "2310042E22Rik" "BC005764" "C130030K03Rik" "Stmn1-rs1"
## [5] "Gm9846" "E130309F12Rik" "Fam211b" "AI848285"
## [9] "Acpl2" "9630033F20Rik" "Adrbk2" "Syne1_loc2"
## [13] "Adc" "Dlx1os" "LOC106740" "Pdxp"
## [17] "Atp6v0c-ps2" "2900056M20Rik" "Epb4.1l1" "A330050F15Rik"
## Warning in fix.bad.mgi.symbols(simulated_patchdata): Possible presence of
## excel corrupted date-like genes: Sepw1, Sepp1, Sept15, Sepn1
## [1] "6 poorly annotated genes are replicates of existing genes. These are: "
## [1] "B3gnt2" "Bhlhe40" "Hjurp" "Naa38" "Bcor" "Ubl4a"
## [1] "480 rows should have been corrected by checking synonms"
## [1] "373 rows STILL do not have proper MGI symbols"
reps=100
allRes = map.patchseq(ctd,simulated_patchdata_corrected[,1:20],sdThresh=1,annotLevel=2,useSDthresh=TRUE,reps=reps)
## [1] "Int1"
## [1] "Int10"
## [1] "Int11"
## [1] "Int12"
## [1] "Int13"
## [1] "Int14"
## [1] "Int15"
## [1] "Int16"
## [1] "Int2"
## [1] "Int3"
## [1] "Int4"
## [1] "Int5"
## [1] "Int6"
## [1] "Int7"
## [1] "Int8"
## [1] "Int9"
## [1] "Int10"
## [1] "Int11"
## [1] "Int14"
## [1] "Int5"
## [1] "Int6"
## [1] "Int7"
## [1] "Int9"
## [1] "loop"
## [1] "Int10"
## [1] "Int6"
## [1] "loop"
## Int12 Int10 Int1 Int16 Int8 Int15 Int13 Int5 Int9 Int11 Int3 Int6
## 0.11 0.13 0.37 0.38 0.50 0.77 0.82 0.86 0.89 0.91 0.93 0.95
## Int14 Int2 Int4 Int7
## 1.00 1.00 1.00 1.00
## [1] "Int12"
## [1] 1
## [1] "Int1"
## [1] "Int10"
## [1] "Int11"
## [1] "Int12"
## [1] "Int13"
## [1] "Int14"
## [1] "Int15"
## [1] "Int16"
## [1] "Int2"
## [1] "Int3"
## [1] "Int4"
## [1] "Int5"
## [1] "Int6"
## [1] "Int7"
## [1] "Int8"
## [1] "Int9"
## [1] "Int10"
## [1] "Int11"
## [1] "Int5"
## [1] "Int6"
## [1] "Int7"
## [1] "Int9"
## [1] "loop"
## Int10 Int12 Int16 Int6 Int3 Int8 Int9 Int15 Int13 Int5 Int14 Int1
## 0.02 0.14 0.15 0.16 0.18 0.23 0.29 0.44 0.66 0.82 0.94 0.95
## Int2 Int11 Int4 Int7
## 0.97 0.98 0.99 0.99
## [1] "Int10"
## [1] 2
## [1] "Int1"
## [1] "Int10"
## [1] "Int11"
## [1] "Int12"
## [1] "Int13"
## [1] "Int14"
## [1] "Int15"
## [1] "Int16"
## [1] "Int2"
## [1] "Int3"
## [1] "Int4"
## [1] "Int5"
## [1] "Int6"
## [1] "Int7"
## [1] "Int8"
## [1] "Int9"
## [1] "Int10"
## [1] "Int12"
## [1] "Int5"
## [1] "Int6"
## [1] "Int7"
## [1] "Int8"
## [1] "Int9"
## [1] "loop"
## [1] "Int5"
## [1] "Int6"
## [1] "loop"
## Int6 Int10 Int11 Int16 Int15 Int14 Int8 Int13 Int9 Int1 Int7 Int3
## 0.09 0.15 0.22 0.43 0.62 0.69 0.71 0.77 0.84 0.91 0.93 0.94
## Int5 Int12 Int2 Int4
## 0.96 0.99 1.00 1.00
## [1] "Int6"
## [1] 3
## [1] "Int1"
## [1] "Int10"
## [1] "Int11"
## [1] "Int12"
## [1] "Int13"
## [1] "Int14"
## [1] "Int15"
## [1] "Int16"
## [1] "Int2"
## [1] "Int3"
## [1] "Int4"
## [1] "Int5"
## [1] "Int6"
## [1] "Int7"
## [1] "Int8"
## [1] "Int9"
## [1] "Int10"
## [1] "Int11"
## [1] "Int12"
## [1] "Int16"
## [1] "Int6"
## [1] "Int7"
## [1] "Int9"
## [1] "loop"
## [1] "Int10"
## [1] "Int6"
## [1] "loop"
## Int10 Int5 Int8 Int3 Int15 Int9 Int13 Int14 Int11 Int7 Int1 Int2
## 0.02 0.15 0.20 0.25 0.45 0.50 0.80 0.80 0.82 0.89 0.94 0.98
## Int6 Int12 Int16 Int4
## 0.99 1.00 1.00 1.00
## [1] "Int10"
## [1] 4
## [1] "Int1"
## [1] "Int10"
## [1] "Int11"
## [1] "Int12"
## [1] "Int13"
## [1] "Int14"
## [1] "Int15"
## [1] "Int16"
## [1] "Int2"
## [1] "Int3"
## [1] "Int4"
## [1] "Int5"
## [1] "Int6"
## [1] "Int7"
## [1] "Int8"
## [1] "Int9"
## [1] "Int10"
## [1] "Int11"
## [1] "Int12"
## [1] "Int16"
## [1] "Int5"
## [1] "Int6"
## [1] "Int7"
## [1] "Int9"
## [1] "loop"
## [1] "Int10"
## [1] "Int6"
## [1] "Int9"
## [1] "loop"
## Int9 Int13 Int8 Int14 Int10 Int4 Int15 Int3 Int12 Int11 Int1 Int2
## 0.00 0.49 0.54 0.55 0.62 0.70 0.80 0.80 0.87 0.92 0.98 0.99
## Int16 Int5 Int6 Int7
## 1.00 1.00 1.00 1.00
## [1] "Int9"
## [1] 5
## [1] "Int1"
## [1] "Int10"
## [1] "Int11"
## [1] "Int12"
## [1] "Int13"
## [1] "Int14"
## [1] "Int15"
## [1] "Int16"
## [1] "Int2"
## [1] "Int3"
## [1] "Int4"
## [1] "Int5"
## [1] "Int6"
## [1] "Int7"
## [1] "Int8"
## [1] "Int9"
## [1] "Int10"
## [1] "Int11"
## [1] "Int12"
## [1] "Int16"
## [1] "Int5"
## [1] "Int6"
## [1] "Int7"
## [1] "Int9"
## [1] "loop"
## [1] "Int10"
## [1] "Int9"
## [1] "loop"
## Int9 Int3 Int8 Int14 Int13 Int15 Int4 Int6 Int7 Int11 Int5 Int16
## 0.03 0.16 0.43 0.44 0.45 0.48 0.78 0.78 0.78 0.92 0.93 0.96
## Int10 Int12 Int2 Int1
## 0.97 0.97 0.98 1.00
## [1] "Int9"
## [1] 6
## [1] "Int1"
## [1] "Int10"
## [1] "Int11"
## [1] "Int12"
## [1] "Int13"
## [1] "Int14"
## [1] "Int15"
## [1] "Int16"
## [1] "Int2"
## [1] "Int3"
## [1] "Int4"
## [1] "Int5"
## [1] "Int6"
## [1] "Int7"
## [1] "Int8"
## [1] "Int9"
## [1] "Int10"
## [1] "Int14"
## [1] "Int16"
## [1] "Int6"
## [1] "Int7"
## [1] "Int9"
## [1] "loop"
## Int10 Int11 Int5 Int12 Int6 Int15 Int13 Int9 Int8 Int3 Int4 Int16
## 0.00 0.11 0.14 0.15 0.16 0.40 0.42 0.49 0.59 0.79 0.80 0.94
## Int14 Int7 Int2 Int1
## 0.96 0.96 0.98 1.00
## [1] "Int10"
## [1] 7
## [1] "Int1"
## [1] "Int10"
## [1] "Int11"
## [1] "Int12"
## [1] "Int13"
## [1] "Int14"
## [1] "Int15"
## [1] "Int16"
## [1] "Int2"
## [1] "Int3"
## [1] "Int4"
## [1] "Int5"
## [1] "Int6"
## [1] "Int7"
## [1] "Int8"
## [1] "Int9"
## [1] "Int10"
## [1] "Int11"
## [1] "Int12"
## [1] "Int16"
## [1] "Int5"
## [1] "Int6"
## [1] "Int7"
## [1] "Int8"
## [1] "Int9"
## [1] "loop"
## [1] "Int10"
## [1] "Int7"
## [1] "Int9"
## [1] "loop"
## Int9 Int4 Int13 Int14 Int3 Int2 Int15 Int7 Int12 Int8 Int1 Int5
## 0.06 0.11 0.14 0.17 0.24 0.37 0.44 0.63 0.64 0.82 0.87 0.88
## Int6 Int10 Int11 Int16
## 0.89 0.92 0.94 0.96
## [1] "Int9"
## [1] 8
## [1] "Int1"
## [1] "Int10"
## [1] "Int11"
## [1] "Int12"
## [1] "Int13"
## [1] "Int14"
## [1] "Int15"
## [1] "Int16"
## [1] "Int2"
## [1] "Int3"
## [1] "Int4"
## [1] "Int5"
## [1] "Int6"
## [1] "Int7"
## [1] "Int8"
## [1] "Int9"
## [1] "Int10"
## [1] "Int5"
## [1] "Int6"
## [1] "Int7"
## [1] "Int9"
## [1] "loop"
## Int10 Int11 Int8 Int13 Int16 Int12 Int14 Int15 Int9 Int3 Int6 Int4
## 0.00 0.11 0.13 0.27 0.31 0.47 0.51 0.56 0.63 0.69 0.72 0.78
## Int1 Int7 Int2 Int5
## 0.93 0.97 0.99 0.99
## [1] "Int10"
## [1] 9
## [1] "Int1"
## [1] "Int10"
## [1] "Int11"
## [1] "Int12"
## [1] "Int13"
## [1] "Int14"
## [1] "Int15"
## [1] "Int16"
## [1] "Int2"
## [1] "Int3"
## [1] "Int4"
## [1] "Int5"
## [1] "Int6"
## [1] "Int7"
## [1] "Int8"
## [1] "Int9"
## [1] "Int10"
## [1] "Int11"
## [1] "Int12"
## [1] "Int5"
## [1] "Int6"
## [1] "Int7"
## [1] "Int8"
## [1] "Int9"
## [1] "loop"
## Int10 Int6 Int16 Int4 Int8 Int13 Int1 Int14 Int7 Int15 Int3 Int5
## 0.01 0.19 0.21 0.27 0.27 0.34 0.35 0.40 0.40 0.46 0.47 0.59
## Int2 Int11 Int9 Int12
## 0.82 0.88 0.97 1.00
## [1] "Int10"
## [1] 10
## [1] "Int1"
## [1] "Int10"
## [1] "Int11"
## [1] "Int12"
## [1] "Int13"
## [1] "Int14"
## [1] "Int15"
## [1] "Int16"
## [1] "Int2"
## [1] "Int3"
## [1] "Int4"
## [1] "Int5"
## [1] "Int6"
## [1] "Int7"
## [1] "Int8"
## [1] "Int9"
## [1] "Int10"
## [1] "Int5"
## [1] "Int6"
## [1] "Int7"
## [1] "Int8"
## [1] "loop"
## Int10 Int9 Int6 Int13 Int8 Int15 Int5 Int11 Int3 Int4 Int1 Int16
## 0.16 0.16 0.37 0.51 0.60 0.64 0.67 0.72 0.77 0.80 0.81 0.81
## Int12 Int7 Int14 Int2
## 0.85 0.89 0.93 0.94
## [1] "Int10"
## [1] 11
## [1] "Int1"
## [1] "Int10"
## [1] "Int11"
## [1] "Int12"
## [1] "Int13"
## [1] "Int14"
## [1] "Int15"
## [1] "Int16"
## [1] "Int2"
## [1] "Int3"
## [1] "Int4"
## [1] "Int5"
## [1] "Int6"
## [1] "Int7"
## [1] "Int8"
## [1] "Int9"
## [1] "Int1"
## [1] "Int2"
## [1] "Int4"
## [1] "loop"
## Int1 Int2 Int3 Int8 Int13 Int5 Int7 Int15 Int14 Int16 Int11 Int12
## 0.00 0.24 0.31 0.32 0.61 0.62 0.76 0.87 0.97 0.97 0.98 0.99
## Int6 Int10 Int4 Int9
## 0.99 1.00 1.00 1.00
## [1] "Int1"
## [1] 12
## [1] "Int1"
## [1] "Int10"
## [1] "Int11"
## [1] "Int12"
## [1] "Int13"
## [1] "Int14"
## [1] "Int15"
## [1] "Int16"
## [1] "Int2"
## [1] "Int3"
## [1] "Int4"
## [1] "Int5"
## [1] "Int6"
## [1] "Int7"
## [1] "Int8"
## [1] "Int9"
## [1] "Int1"
## [1] "Int2"
## [1] "Int4"
## [1] "loop"
## Int1 Int4 Int11 Int14 Int7 Int15 Int16 Int3 Int5 Int13 Int2 Int8
## 0.21 0.26 0.76 0.76 0.81 0.85 0.89 0.89 0.90 0.92 0.93 0.93
## Int9 Int12 Int10 Int6
## 0.98 0.99 1.00 1.00
## [1] "Int1"
## [1] 13
## [1] "Int1"
## [1] "Int10"
## [1] "Int11"
## [1] "Int12"
## [1] "Int13"
## [1] "Int14"
## [1] "Int15"
## [1] "Int16"
## [1] "Int2"
## [1] "Int3"
## [1] "Int4"
## [1] "Int5"
## [1] "Int6"
## [1] "Int7"
## [1] "Int8"
## [1] "Int9"
## [1] "Int1"
## [1] "Int2"
## [1] "Int4"
## [1] "loop"
## Int1 Int2 Int3 Int7 Int13 Int8 Int5 Int15 Int11 Int16 Int14 Int10
## 0.01 0.27 0.68 0.80 0.84 0.84 0.87 0.96 0.98 0.98 0.99 1.00
## Int12 Int4 Int6 Int9
## 1.00 1.00 1.00 1.00
## [1] "Int1"
## [1] 14
## [1] "Int1"
## [1] "Int10"
## [1] "Int11"
## [1] "Int12"
## [1] "Int13"
## [1] "Int14"
## [1] "Int15"
## [1] "Int16"
## [1] "Int2"
## [1] "Int3"
## [1] "Int4"
## [1] "Int5"
## [1] "Int6"
## [1] "Int7"
## [1] "Int8"
## [1] "Int9"
## [1] "Int1"
## [1] "Int2"
## [1] "Int4"
## [1] "loop"
## Int1 Int14 Int7 Int3 Int16 Int5 Int11 Int15 Int12 Int13 Int2 Int8
## 0.00 0.30 0.86 0.89 0.90 0.94 0.95 0.95 0.97 0.97 0.97 0.97
## Int10 Int4 Int6 Int9
## 1.00 1.00 1.00 1.00
## [1] "Int1"
## [1] 15
## [1] "Int1"
## [1] "Int10"
## [1] "Int11"
## [1] "Int12"
## [1] "Int13"
## [1] "Int14"
## [1] "Int15"
## [1] "Int16"
## [1] "Int2"
## [1] "Int3"
## [1] "Int4"
## [1] "Int5"
## [1] "Int6"
## [1] "Int7"
## [1] "Int8"
## [1] "Int9"
## [1] "Int1"
## [1] "Int2"
## [1] "Int4"
## [1] "loop"
## Int1 Int7 Int3 Int2 Int13 Int8 Int11 Int14 Int5 Int10 Int15 Int16
## 0.00 0.74 0.79 0.84 0.87 0.89 0.91 0.92 0.96 0.98 0.98 0.99
## Int6 Int12 Int4 Int9
## 0.99 1.00 1.00 1.00
## [1] "Int1"
## [1] 16
## [1] "Int1"
## [1] "Int10"
## [1] "Int11"
## [1] "Int12"
## [1] "Int13"
## [1] "Int14"
## [1] "Int15"
## [1] "Int16"
## [1] "Int2"
## [1] "Int3"
## [1] "Int4"
## [1] "Int5"
## [1] "Int6"
## [1] "Int7"
## [1] "Int8"
## [1] "Int9"
## [1] "Int1"
## [1] "Int2"
## [1] "Int3"
## [1] "Int4"
## [1] "loop"
## [1] "Int1"
## [1] "Int2"
## [1] "loop"
## Int2 Int5 Int13 Int7 Int8 Int14 Int15 Int16 Int6 Int1 Int11 Int10
## 0.13 0.15 0.16 0.28 0.31 0.66 0.74 0.79 0.80 0.84 0.86 1.00
## Int12 Int3 Int4 Int9
## 1.00 1.00 1.00 1.00
## [1] "Int2"
## [1] 17
## [1] "Int1"
## [1] "Int10"
## [1] "Int11"
## [1] "Int12"
## [1] "Int13"
## [1] "Int14"
## [1] "Int15"
## [1] "Int16"
## [1] "Int2"
## [1] "Int3"
## [1] "Int4"
## [1] "Int5"
## [1] "Int6"
## [1] "Int7"
## [1] "Int8"
## [1] "Int9"
## [1] "Int1"
## [1] "Int13"
## [1] "Int16"
## [1] "Int2"
## [1] "Int3"
## [1] "Int4"
## [1] "Int5"
## [1] "Int7"
## [1] "Int8"
## [1] "loop"
## [1] "Int1"
## [1] "Int2"
## [1] "loop"
## Int2 Int14 Int11 Int15 Int13 Int12 Int8 Int5 Int6 Int7 Int1 Int10
## 0.04 0.11 0.41 0.59 0.77 0.78 0.91 0.96 0.96 0.97 0.99 1.00
## Int16 Int3 Int4 Int9
## 1.00 1.00 1.00 1.00
## [1] "Int2"
## [1] 18
## [1] "Int1"
## [1] "Int10"
## [1] "Int11"
## [1] "Int12"
## [1] "Int13"
## [1] "Int14"
## [1] "Int15"
## [1] "Int16"
## [1] "Int2"
## [1] "Int3"
## [1] "Int4"
## [1] "Int5"
## [1] "Int6"
## [1] "Int7"
## [1] "Int8"
## [1] "Int9"
## Int3 Int13 Int1 Int8 Int2 Int5 Int15 Int14 Int10 Int11 Int12 Int16
## 0.05 0.36 0.38 0.45 0.54 0.77 0.91 0.98 1.00 1.00 1.00 1.00
## Int4 Int6 Int7 Int9
## 1.00 1.00 1.00 1.00
## [1] "Int3"
## [1] 19
## [1] "Int1"
## [1] "Int10"
## [1] "Int11"
## [1] "Int12"
## [1] "Int13"
## [1] "Int14"
## [1] "Int15"
## [1] "Int16"
## [1] "Int2"
## [1] "Int3"
## [1] "Int4"
## [1] "Int5"
## [1] "Int6"
## [1] "Int7"
## [1] "Int8"
## [1] "Int9"
## [1] "Int13"
## [1] "Int14"
## [1] "Int15"
## [1] "Int16"
## [1] "Int5"
## [1] "Int8"
## [1] "loop"
## [1] "Int13"
## [1] "Int8"
## [1] "loop"
## Int13 Int3 Int1 Int2 Int15 Int7 Int5 Int4 Int8 Int11 Int12 Int14
## 0.14 0.30 0.37 0.42 0.52 0.56 0.73 0.84 0.87 0.88 0.98 0.98
## Int6 Int10 Int16 Int9
## 0.98 1.00 1.00 1.00
## [1] "Int13"
## [1] 20
print(data.frame(Actual=int_annot$level2class[1:20],Assigned=allRes$assigned))
## Actual Assigned
## 1 Int10 Int12
## 2 Int10 Int10
## 3 Int6 Int6
## 4 Int10 Int10
## 5 Int9 Int9
## 6 Int9 Int9
## 7 Int10 Int10
## 8 Int9 Int9
## 9 Int10 Int10
## 10 Int10 Int10
## 11 Int10 Int10
## 12 Int2 Int1
## 13 Int4 Int1
## 14 Int2 Int1
## 15 Int1 Int1
## 16 Int1 Int1
## 17 Int2 Int2
## 18 Int2 Int2
## 19 Int3 Int3
## 20 Int13 Int13
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.