Skip to content
Snippets Groups Projects
Commit 5eecffb5 authored by Gervaise Henry's avatar Gervaise Henry :cowboy:
Browse files

Add plotIdentGroup

parent e22cd175
No related merge requests found
......@@ -6,22 +6,16 @@ library(Seurat)
library(readr)
library(Matrix)
#Get Seurat object input
#Get param inputs
option_list=list(
make_option("--r",action="store",type='character',help="R data filename"),
make_option("--o",action="store",type='character',help="Seurat object name"),
make_option("--g",action="store",type='character',help="Seurat group ident"),
make_option("--p",action="store",type='integer',default=0,help="Sample quantity")
make_option("--g",action="store",type='character',help="Seurat group ident")
)
opt=parse_args(OptionParser(option_list=option_list))
rm(option_list)
#Create output folders
if (!dir.exists("./matrix")){
dir.create("./matrix")
}
#Load Seurat R data file and update
#Load Seurat R data file and cells and update
load(opt$r)
data <- get(opt$o)
rm(list=opt$o)
......@@ -30,12 +24,10 @@ try(
data <- UpdateSeuratObject(data)
}
)
cells <- read.table("./cells.csv",quote="\"")
#Downsample cells
if (opt$p != 0){
Idents(data) <- "ALL"
data <- subset(data,cells=WhichCells(data,downsample=opt$p,seed=1))
}
#Filter cells
data <- subset(data,cells=cells$V1)
#Write ident group file
write.table(data[[opt$g]],file=paste0("./matrix/group_",opt$g,".csv"),row.names=TRUE,col.names=FALSE,append=FALSE,sep=",")
\ No newline at end of file
write.table(data[[opt$g]],file=paste0("./group_",opt$g,".csv"),row.names=TRUE,col.names=FALSE,append=FALSE,sep=",")
\ No newline at end of file
......@@ -6,7 +6,7 @@ library(Seurat)
library(readr)
library(Matrix)
#Get Seurat object input
#Get param inputs
option_list=list(
make_option("--r",action="store",type='character',help="R data filename"),
make_option("--o",action="store",type='character',help="Seurat object name"),
......@@ -21,8 +21,11 @@ opt=parse_args(OptionParser(option_list=option_list))
rm(option_list)
#Create output folders
if (!dir.exists("./matrix.raw")){
dir.create("./matrix.raw")
if (!dir.exists("./matrix")){
dir.create("./matrix")
}
if (!dir.exists("./matrix/raw")){
dir.create("./matrix/raw")
}
#Load Seurat R data file and update
......@@ -45,14 +48,15 @@ if (opt$p != 0){
}
#Write cell/gene matrix files
writeMM(Matrix(GetAssayData(data,assay=opt$a,slot=opt$s),sparse=TRUE),file="./matrix.raw/expression.mtx")
write.table(rownames(data),file=paste0("./matrix.raw/genes.csv"),row.names=FALSE,col.names=FALSE,append=FALSE,sep=",")
write.table(colnames(data),file=paste0("./matrix.raw/cells.csv"),row.names=FALSE,col.names=FALSE,append=FALSE,sep=",")
writeMM(Matrix(GetAssayData(data,assay=opt$a,slot=opt$s),sparse=TRUE),file="./matrix/raw/expression.mtx")
write.table(rownames(data),file=paste0("./matrix/raw/genes.csv"),row.names=FALSE,col.names=FALSE,append=FALSE,sep=",")
write.table(colnames(data),file=paste0("./matrix/raw/cells.csv"),row.names=FALSE,col.names=FALSE,append=FALSE,sep=",")
write.table(colnames(data),file=paste0("./cells.csv"),row.names=FALSE,col.names=FALSE,append=FALSE,sep=",")
#Write dimentionality reduction
if (opt$t){
write.table(Embeddings(data,reduction="tsne"),file=paste0("./matrix.raw/tSNE.csv"),row.names=TRUE,col.names=NA,append=FALSE,sep=",")
write.table(Embeddings(data,reduction="tsne"),file=paste0("./matrix/raw/dr_tSNE.csv"),row.names=TRUE,col.names=NA,append=FALSE,sep=",")
}
if (opt$u){
write.table(Embeddings(data,reduction="umap"),file=paste0("./matrix.raw/UMAP.csv"),row.names=TRUE,col.names=NA,append=FALSE,sep=",")
write.table(Embeddings(data,reduction="umap"),file=paste0("./matrix/raw/dr_UMAP.csv"),row.names=TRUE,col.names=NA,append=FALSE,sep=",")
}
\ No newline at end of file
if ("optparse" %in% row.names(installed.packages()) == FALSE){
install.packages("optparse",repos="http://cran.us.r-project.org")
}
library(optparse)
library(readr)
library(ggplot2)
library(cowplot)
#Get param inputs
option_list=list(
make_option("--g",action="store",type='character',help="Seurat group ident"),
make_option("--t",action="store",type='logical',default=TRUE,help="tSNE calculated?"),
make_option("--u",action="store",type='logical',default=FALSE,help="UMAP calculated?")
)
opt=parse_args(OptionParser(option_list=option_list))
rm(option_list)
#Load group
id <- read.csv(paste0("./group_",opt$g,".csv"),header=FALSE)
names(id)[2] <- opt$g
#Load dr
if (opt$t == TRUE){
dr.tsne <- read.csv(paste0("./dr_tSNE.csv"),header=TRUE)
colnames(dr.tsne)[1] <- "Cells"
dr.tsne <- merge(x=dr.tsne,y=id,by.x="Cells",by.y="V1",all.x=TRUE)
png(paste0("ClusterGroup_tSNE_",opt$g,".png"),width=400,height=400,bg="white")
plot(ggplot(dr.tsne,aes_string(x="tSNE_1",y="tSNE_2",col=opt$g))+geom_point(size=2)+labs(col="ID")+theme_cowplot())
dev.off()
}
if (opt$u == TRUE){
dr.umap <- read.csv(paste0("./dr_UMAP.csv"),header=TRUE)
colnames(dr.umap)[1] <- "Cells"
dr.umap <- merge(x=dr.umap,y=id,by.x="Cells",by.y="V1",all.x=TRUE)
png(paste0("ClusterGroup_UMAP_",opt$g,".png"),width=400,height=400,bg="white")
plot(ggplot(dr.umap,aes_string(x="UMAP_1",y="UMAP_2",col=opt$g))+geom_point(size=2)+labs(col="ID")+theme_cowplot())
dev.off()
}
\ No newline at end of file
......@@ -5,20 +5,15 @@ library(optparse)
library(readr)
library(Matrix)
#Get Seurat object input
#Get param inputs
option_list=list(
make_option("--g",action="store",type='character',help="NCBI conversion filename")
)
opt=parse_args(OptionParser(option_list=option_list))
rm(option_list)
#Create output folders
if (!dir.exists("./matrix")){
dir.create("./matrix")
}
#Load genes and conversion files
genes <- read.table("./matrix.raw/genes.csv",quote="\"")
genes <- read.table("./raw/genes.csv",quote="\"")
convert <- read.delim(paste0("../../../workflow/files/",opt$g,".to.NCBI.txt"))
#Filter gene to good conversions
......@@ -32,18 +27,16 @@ genes.noambig.filtered <- genes.noambig[genes.noambig$V1 %in% genes$V1,]
colnames(genes.noambig.filtered) <- c("GeneName","EntrezGene.ID")
#Load matrix
exp <- readMM("./matrix.raw/expression.mtx")
exp <- readMM("./raw/expression.mtx")
exp <- as.data.frame(as.matrix(exp))
exp$gene <- genes$V1
#Filter matrix
exp.new <- merge(y=genes.noambig.filtered,x=exp,by.y="GeneName",by.x="gene",all.y=TRUE)
exp.new <- as.data.frame(exp.new)
#convert.final <- exp.new[,c(1,ncol(exp.new))]
exp.new <- exp.new[,-1]
#Write matrix and gene list
write.table(as.character(exp.new$EntrezGene.ID),file="./matrix/genes.csv",append=FALSE,quote=TRUE,sep=",",row.names=FALSE,col.names=FALSE)
write.table(as.character(exp.new$EntrezGene.ID),file="./genes.csv",append=FALSE,quote=TRUE,sep=",",row.names=FALSE,col.names=FALSE)
exp.new.mm <- as(as.matrix(exp.new[,-ncol(exp.new)]),"dgTMatrix")
writeMM(exp.new.mm,file="./matrix/expression.mtx")
#write.table(convert.final,file="./analysis/matrix/convert.final.csv",append=FALSE,quote=TRUE,sep=",",row.names=FALSE,col.names=TRUE)
\ No newline at end of file
writeMM(exp.new.mm,file="./expression.mtx")
\ No newline at end of file
......@@ -15,24 +15,23 @@ params.convert = "GRCh38p5"
params.outDir = "${baseDir}/../output"
// Parse input variables
rda = Channel
.fromPath(params.rda)
.ifEmpty { exit 1, "r data file not found: ${params.rda}" }
rda = Channel.fromPath(params.rda)
rda.into {
rda_createMatrix
rda_createGroup
}
seurat_createMatrix = params.seurat
seurat_createGroup = params.seurat
tsne = params.tsne
umap = params.umap
tsne_createMatrix = params.tsne
tsne_plotIdentGroup = params.tsne
umap_createMatrix = params.umap
umap_plotIdentGroup = params.umap
assay = params.assay
slot = params.slot
scale = params.scale
sample_createMatrix = params.sample
sample_createGroup = params.sample
groups = file(params.groups)
.readLines()
sample = params.sample
groups_createGroup = file(params.groups).readLines()
groups_plotIdentGroup = file(params.groups).readLines()
convert = params.convert
outDir = params.outDir
......@@ -47,48 +46,47 @@ process createMatrix {
input:
file rda_createMatrix
val seurat_createMatrix
val tsne
val umap
val tsne_createMatrix
val umap_createMatrix
val assay
val slot
val scale
val sample_createMatrix
val sample
output:
file("*") into matrixRaw
file("matrix/*") into matrixRaw
file("cells.csv") into cells
script:
"""
hostname
ulimit -a
module load seurat/3.0.0
seurat-Rscript ${baseDir}/scripts/createMatrix.R --r ${rda_createMatrix} --o ${seurat_createMatrix} --t ${tsne} --u ${umap} --a ${assay} --s ${slot} --l ${scale} --p ${sample_createMatrix}
seurat-Rscript ${baseDir}/scripts/createMatrix.R --r ${rda_createMatrix} --o ${seurat_createMatrix} --t ${tsne_createMatrix} --u ${umap_createMatrix} --a ${assay} --s ${slot} --l ${scale} --p ${sample}
"""
}
/*
* createGroup: extract ident groups from Seurat object
*/
process createGroup {
tag "${group}"
publishDir "${outDir}", mode: 'copy'
tag "${group_createGroup}"
publishDir "${outDir}/matrix", mode: 'copy', overwrite: true
input:
file rda_createGroup
val seurat_createGroup
each group from groups
val sample_createGroup
each group_createGroup from groups_createGroup
file cells
output:
file("*") into id
file("*") into id_plotIdentGroup
script:
"""
hostname
ulimit -a
module load seurat/3.0.0
seurat-Rscript ${baseDir}/scripts/createGroup.R --r ${rda_createGroup} --o ${seurat_createGroup} --g ${group} --p ${sample_createGroup}
seurat-Rscript ${baseDir}/scripts/createGroup.R --r ${rda_createGroup} --o ${seurat_createGroup} --g ${group_createGroup}
"""
}
......@@ -97,32 +95,61 @@ process createGroup {
*/
process renameGenes {
tag "NCBI"
publishDir "${outDir}", mode: 'copy'
publishDir "${outDir}/matrix", mode: 'copy', overwrite: false
input:
file ("*") from matrixRaw.collect()
file matrixRaw
val convert
output:
file("*") into matrixFinal
file("*") into matrix_plotIdentGroup
script:
if (convert == "NO"){
"""
hostname
ulimit -a
mkdir matrix
cp -R ./matrix.raw/*.mtx ./matrix
cp -R ./matrix.raw/*.csv ./matrix
cp -R ./raw/*.mtx .
cp -R ./raw/*.csv .
"""
} else {
"""
hostname
ulimit -a
mkdir matrix
cp -R ./matrix.raw/*.csv ./matrix
cp -R ./raw/*.csv .
module load seurat/3.0.0
seurat-Rscript ${baseDir}/scripts/renameGenes.R --g ${convert}
"""
}
}
// Duplicate matrix files
/*
matrixFinal.into {
matrix_plotIdentGroup
}
*/
/*
* plotIdentGroup: plot identity groups in reduced dimensions
*/
process plotIdentGroup {
tag "${group_plotIdentGroup}"
publishDir "${outDir}/png/IdentGroup", mode: 'copy', overwrite: true
input:
each group_plotIdentGroup from groups_plotIdentGroup
file matrix_plotIdentGroup
file("*") from id_plotIdentGroup.collect()
output:
file("*.png") into plotsIdentGroup
script:
"""
hostname
ulimit -a
module load seurat/3.0.0
seurat-Rscript ${baseDir}/scripts/plotIdentGroup.R --g ${group_plotIdentGroup}
"""
}
\ No newline at end of file
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment