Beautiful Zebrafish visaulizations courtesy of Jeff Farrell (jfarrell@g.harvard.edu)
Before running these functions (those starting with zf.), or loading the rgl library, please make sure an X11 client (i.e. XQuartz) is installed
#load previous data object, enables you to start tutorial from Part 4.
library(rgl)
load("~/seurat_files/output_part3.Robj")

Draw inferred in situ patterns for a few known genes

zf.insitu.lateral(zf, "GSC",label=FALSE)

zf.insitu.lateral(zf, "SOX3",label=FALSE)

zf.insitu.lateral(zf, "VED",label=FALSE)


Draw inferred in situ patterns for a few new genes

zf.insitu.lateral(zf, "RIPPLY1",label=FALSE)

zf.insitu.lateral(zf, "DUSP4",label=FALSE)

zf.insitu.lateral(zf, "ETS2",label=FALSE)


Focused analysis of cells near the margin

zf.centroids=get.centroids(zf); colnames(zf.centroids)=c("bin.tier","bin.dv")
margin.cells=rownames(subset(zf.centroids,bin.tier>5))
zf.margin=subsetData(zf,cells.use = margin.cells)
#note, could replace the last three lines with: zf.margin=subsetData(zf,subset.name = "bin.tier",accept.low = 5)

zf.margin=pca(zf.margin,do.print = FALSE)
zf.margin <- jackStraw(zf.margin, num.replicate=1000, prop.freq=0.025)
zf.margin=project.pca(zf.margin,pcs.print = 3,genes.print = 8,do.center=FALSE)
## [1] "PC1"
## [1] "ID1"    "SOX3"   "CXCR4B" "SOX19A"
## [1] ""
## [1] "OSR1"   "GATA5"  "FSCN1A" "SNAI1A" "APLNRB"
## [1] ""
## [1] ""
## [1] "PC2"
## [1] "CHD"   "FRZB"  "GSC"   "OTX1A"
## [1] ""
## [1] "VED"    "HES6"   "VOX"    "EVE1"   "BAMBIA"
## [1] ""
## [1] ""
## [1] "PC3"
## [1] "ARL4AB"   "WNT11"    "SEBOX"    "GADD45BA"
## [1] ""
## [1] "SOX32"     "CXCR4A"    "MARCKSL1B" "RPL26"     "FGFR4"
## [1] ""
## [1] ""
kmeans.genes=pca.sig.genes(zf.margin,pcs.use = 1:3,pval.cut = 1e-3)
zf.margin=doKMeans(zf.margin,genes.use = kmeans.genes,k.genes = 7,k.cells = 8,pc.row.order=3,pc.col.order=3,rev.pc.order = TRUE,cexRow=0.5,cexCol=0.5)

#We can see high Gsc in cluster 5, and high Sox32 in cluster 1.
#Note that clusters (cells and genes) are ordered by average PC3 score, just for visualization.
endo.cells=which.cells(zf.margin,1)
plate.cells=which.cells(zf.margin,5)
zf.margin=set.ident(zf.margin,zf.margin@cell.names,"All")
zf.margin=set.ident(zf.margin,endo.cells,"Endoderm")
zf.margin=set.ident(zf.margin,plate.cells,"PCP")

pop.cols=c("#999999","#1B75BB","#37B34A")

#plot PCA, coloring cells by their status/ID (stored in zf@ident)
pca.plot(zf.margin,1,2,pt.size = 3.5,cols.use = pop.cols); 

pc.13=pca.plot(zf.margin,1,3,pt.size = 3.5,cols.use = pop.cols)

#gene-gene plot, again, coloring cells by their stat/ID
genePlot(zf.margin,"GSC","FRZB",col.use=pop.cols)


Define markers for Endodermal and PCP

#Uses DE test from McDavid et al, Bioinformatics, 2013
#since both the PCP and the Endoderm are on the lowest band of the margin, we will use Tier 8 cells as a control population
tier8.cells=rownames(subset(zf.centroids,bin.tier>=7))

#Note that find.markers accepts either a list of cells (plate.cells, endo.cells) or an identity class (e.g. "PCP, Endoderm")
#If the second argument is left blank (currently, tier8.cells), Seurat will test against all other cells in the object.
pcp.markers=find.markers(zf.margin,plate.cells,tier8.cells,test.use = "bimod",thresh.use = 2)
endoderm.markers=find.markers(zf.margin,"Endoderm",tier8.cells,test.use = "bimod",thresh.use=1)

subset(pcp.markers,avg_diff>0&p_val<0.01)[1:15,]
##                p_val avg_diff
## CHD     9.547918e-15 2.943094
## GSC     3.030909e-14 3.286884
## FRZB    4.094391e-12 3.963217
## OTX1A   3.260607e-10 2.768617
## SIX3B   5.692627e-10 3.567943
## OTX1B   6.307714e-09 2.344919
## FZD8B   7.194471e-08 3.220929
## PTF1A   3.134976e-06 2.357293
## KLF17   8.092226e-06 2.163173
## FOXA2   1.035091e-05 2.169620
## NOG1    3.920994e-05 2.657723
## RIPPLY1 9.916618e-05 2.457071
## FZD8A   9.997233e-05 2.800761
## PKDCCA  3.558458e-04 2.158920
## MDKA    9.999029e-04 2.105628
subset(endoderm.markers,avg_diff>0&p_val<0.01)[1:15,]
##               p_val avg_diff
## SOX32  1.110223e-16 3.108097
## DUSP4  2.413836e-11 1.051052
## RND1L  2.730669e-09 1.374688
## ID3    8.123768e-08 1.252125
## CPN1   1.464992e-07 2.316622
## CXCR4A 2.605308e-07 1.513439
## SP5A   2.698552e-07 1.057459
## PITX2  4.056477e-07 1.037928
## OTX1A  8.890598e-06 1.268134
## FLRT3  2.283447e-05 1.086111
## S1PR5A 6.873175e-05 2.009212
## HAS2   1.486919e-04 1.122929
## DCK    1.613253e-04 1.682489
## SYT4   2.406563e-04 1.002185
## PDF    2.968288e-04 1.451446

Draw violin plots of known and new markers

vlnPlot(zf.margin,c("GSC","SOX32","RIPPLY1","FRZB"),cols.use = pop.cols,nCol = 2)


Localize cellular populations

#prechordal plate
zf.cells.render(zf,plate.cells,do.rotate=FALSE,radius.use=0.0625,col.use=pop.cols[3],do.new=TRUE)

#endoderm progenitors
zf.cells.render(zf,endo.cells,do.rotate=FALSE,radius.use=0.0625,col.use=pop.cols[2],do.new=TRUE)