Skip to content

Commit

Permalink
update paintor for finemapping
Browse files Browse the repository at this point in the history
  • Loading branch information
jeantristanb committed Nov 17, 2022
1 parent 362d83c commit f28aec6
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 24 deletions.
1 change: 1 addition & 0 deletions News.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
# What\'s new :

##V3.3.0
* finemapping, version 3.3.0 paintor install on docker singularity image, if paintor_bin=0, paintor will be discarded of workflow
* general :
*add nextflow.enable.dsl = 1 to all nf script for compatibility new version of nextflow.
* add control of arguments input of `assoc/main.nf`, `finemapping/main.nf`, `finemapping/cond-assos.nf`, `finemapping/finemap_region.nf` and `meta/main.nf`
Expand Down
23 changes: 14 additions & 9 deletions finemapping/bin/merge_finemapping_v2.r
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,8 @@ library("optparse")
library(data.table)
PlotRes<-function(datainwork,DataGenes2 , datagwascatchro,FilePdf,paintfile=NULL, listpval=c('bf_caviar', 'log10bf_fm', 'Posterior_Prob_paint'), listheadprint=c('caviar', 'fm', 'paint'), gwascat=NULL){
## defined c
if(paintfile %in% c('NOFILE',"0","00","01","02", "03","04","05"))paintfile=NULL
if(is.null(paintfile)) { paintfile=NULL } else{
if(paintfile %in% c('NOFILE',"0","00","01","02", "03","04","05"))paintfile=NULL}
ColI="blue";ColInitial=t_col(ColI,70)
ColGWASCat=t_col("red4",30);ColFineMap='black';ColCred<-t_col('grey',30)
datainworkplot<-datainwork
Expand All @@ -27,8 +28,9 @@ PlotRes<-function(datainwork,DataGenes2 , datagwascatchro,FilePdf,paintfile=NULL
if(!is.null(paintfile))layout(matrix(c(1,1,1,1,1,1,1,1,1,1,1,1,2,2,3,3,4,4), 9, 2, byrow = TRUE)) else layout(matrix(c(1,1,1,1,1,1,1,1,1,1,1,1,2,2,3,3), 8, 2, byrow = TRUE))
par(mar=c(0,5,2,1))
print(table(datainworkplot$IsSig))
#plot(datainworkplot$bp_cm[!datainworkplot$baldiff],-log10(datainworkplot$p[!datainworkplot$baldiff]), xlab='bp (cm)', ylab='-log10(Pi)', pch=datainworkplot$pch[!datainworkplot$baldiff], cex=1.2, bg=datainworkplot$col[!datainworkplot$baldiff], col=datainworkplot$col[!datainworkplot$baldiff], xaxt='n',ylim=range(-log10(datainworkplot$p))*1.1, frame.plot = FALSE, cex.axis=2,cex.lab=2)
# plot(datainworkplot$bp_cm[!datainworkplot$baldiff],-log10(datainworkplot$p[!datainworkplot$baldiff]), xlab='bp (cm)', ylab='-log10(Pi)', pch=datainworkplot$pch[!datainworkplot$baldiff], cex=1.2, bg=datainworkplot$col[!datainworkplot$baldiff], col=datainworkplot$col[!datainworkplot$baldiff], xaxt='n',ylim=range(-log10(datainworkplot$p))*1.1, frame.plot = FALSE, cex.axis=2,cex.lab=2)
plot(datainworkplot$bp_cm,-log10(datainworkplot$p), xlab='bp (cm)', ylab='-log10(Pi)', pch=datainworkplot$pch, cex=1.2, bg=datainworkplot$col, col=datainworkplot$col, xaxt='n',ylim=range(-log10(datainworkplot$p))*1.1, frame.plot = FALSE, cex.axis=2,cex.lab=2)

points(datainworkplot$bp_cm[datainworkplot$baldiff],-log10(datainworkplot$p[datainworkplot$baldiff]), pch=datainworkplot$pch, cex=1.5, bg=datainworkplot$col[datainworkplot$baldiff], col=datainworkplot$col[datainworkplot$baldiff])
if(any(datainworkplot$gwascat))text(datainworkplot$bp_cm[datainworkplot$gwascat], -log10(datainworkplot$p[datainworkplot$gwascat]), datainworkplot$rsid[datainworkplot$gwascat], srt=45,col=ColGWASCat, cex=0.8,pos=4)
text(datainworkplot$bp_cm[datainworkplot$IsSig], -log10(datainworkplot$p[datainworkplot$IsSig]), datainworkplot$rsid[datainworkplot$IsSig], srt=45,col='darkblue', cex=1.2,pos=4)
Expand Down Expand Up @@ -277,20 +279,22 @@ datainwork<-tmpfm[['data']]
listheadprint=c(listheadprint , 'fm (sss)')
listheadplot<-c(listheadplot,tmpfm[['listhead']])
##
infopaint<-getpaintor(datainwork, opt)
datainwork<-infopaint[['data']]
listheadprint=c(listheadprint ,'paintor')
listheadplot<-c(listheadplot, infopaint[['listhead']])

## data for gcta
headgcta=opt[['cojo']]
datagcta2<-read.table(headgcta,header=T)
datagcta2$logpJ<- -log10(datagcta2$pJ)
datainwork<-merge(datainwork,datagcta2[,c('Chr','SNP','bp', 'bJ','bJ_se','pJ','LD_r', 'logpJ')], by=c('rsid','chromosome','position'), by.y=c('SNP','Chr','bp'), all=T)
datainwork$IsSig[!is.na(datainwork$pJ)]<-T
if(!is.null(opt[['paintor']]) | !is.null(opt[['listpaintor']])){
infopaint<-getpaintor(datainwork, opt)
datainwork<-infopaint[['data']]
listheadprint=c(listheadprint ,'paintor')
listheadplot<-c(listheadplot, infopaint[['listhead']])
}

## data for gcta

if(!is.null(opt[['paintor_fileannot']]) & !(opt[['paintor_fileannot']] %in% c('NOFILE', "0","00","01"))){
if(!is.null(opt[['paintor_fileannot']])){
if(!(opt[['paintor_fileannot']] %in% c('NOFILE', "0","00","01"))){
DataAnnot<-read.table(opt[['paintor_fileannot']], header=T)
if(is.null(opt[['paintor_annot']])) HeadAnnot = names(DataAnnot)
else {
Expand All @@ -302,6 +306,7 @@ if(!is.null(opt[['paintor_fileannot']]) & !(opt[['paintor_fileannot']] %in% c('N
DataAnnot<-merge(datainwork[,c('num','rsid','chromosome','position')], DataAnnot[,c('num',HeadAnnot2)], by='num')
DataAnnotPerc<-data.frame(num=DataAnnot[,c('num')], PercAnnot=apply(DataAnnot[,-c(1:4)],1, function(x)sum(x)/length(x)*100))
datainwork=merge(datainwork,DataAnnotPerc, by='num', all=T)
}
}
datainwork$is_cred<-F
if(!is.null(opt[['listfinemap_cred']])){
Expand Down
32 changes: 17 additions & 15 deletions finemapping/main.nf
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ def checkparams(param, namesparam, type, min=null, max=null, possibleval=null, n
if(possibleval && !(param in possibleval))messageerror+="\nerro : --"+namesparam +" must be one the value :"+possibleval.join(',')
}
}
errormess(messageerror,-1)
errormess(messageerror,3)
}


Expand All @@ -67,7 +67,7 @@ def checkmultiparam(params, listparams, type, min=null, max=null, possibleval=nu
messageerror+="param :"+param+" not initialize\n"
}
}
errormess(messageerror, -1)
errormess(messageerror, 2)
}


Expand Down Expand Up @@ -280,7 +280,7 @@ params.each { parm ->

checkmultiparam(params,allowed_params_input, java.lang.String, min=null, max=null, possibleval=null, notpossibleval=null)
checkmultiparam(params,allowed_params_memory, java.lang.String, min=null, max=null, possibleval=null, notpossibleval=null)
checkmultiparam(params,allowed_params_bin, java.lang.String, min=null, max=null, possibleval=null, notpossibleval=null)
//checkmultiparam(params,allowed_params_bin, java.lang.String, min=null, max=null, possibleval=null, notpossibleval=null)
checkmultiparam(params,allowed_params_cores, java.lang.Integer, min=1, max=null, possibleval=null, notpossibleval=null)
checkmultiparam(params,allowed_params_intother, java.lang.Integer, min=0, max=null, possibleval=null, notpossibleval=null)
checkmultiparam(params,allowed_params_bolother, java.lang.Integer, min=0, max=null, possibleval=[0,1], notpossibleval=null)
Expand Down Expand Up @@ -556,6 +556,7 @@ process paintor_format{
file(finem) from paintor_gwas_annot_2
output :
tuple val(pos), path(finem) into paintor_gwas_annot
val(pos) into (list_pos_paint_ch1, list_pos_paint_ch2)
script :
spl=finem.baseName.split('_')
pos=spl[0]+'_'+spl[1]
Expand All @@ -566,11 +567,11 @@ process paintor_format{


NCausalSnp=Channel.from(1..params.n_causal_snp)
if(params.paintor_bin!="0" & params.paintor_bin!=0){
baliseannotpaint=0
baliseannotpaint=0
if(params.paintor_bin!="0" & params.paintor_bin!=0 & params.paintor_bin!=""){
if(params.paintor_fileannot!=""){
paintor_fileannot=Channel.fromPath(params.paintor_fileannot)
paintor_fileannotplot=Channel.fromPath(params.paintor_fileannot)
paintor_fileannot=pos_tonalyse_ch_1.combine(Channel.fromPath("${dummy_dir}/01", checkIfExists:true))
paintor_fileannotplot=pos_tonalyse_ch_2.combine(Channel.fromPath("${dummy_dir}/02"))
baliseannotpaint=1
}else{
if(params.paintor_listfileannot!=""){
Expand Down Expand Up @@ -606,7 +607,7 @@ if(params.paintor_bin!="0" & params.paintor_bin!=0){
pos_tonalyse_ch_1=postonanalyse_tmp1.flatMap { list_str -> list_str.split() }
paintor_fileannot=pos_tonalyse_ch_1.combine(Channel.fromPath("${dummy_dir}/00", checkIfExists:true))
pos_tonalyse_ch_2=postonanalyse_tmp2.flatMap { list_str -> list_str.split() }
paintor_fileannotplot=pos_tonalyse_ch_2.combine(Channel.fromPath("${dummy_dir}/00"))
paintor_fileannotplot=pos_tonalyse_ch_2.combine(Channel.fromPath("${dummy_dir}/01"))
pos_tonalyse_ch_3=postonanalyse_tmp3.flatMap { list_str -> list_str.split() }
annotname=pos_tonalyse_ch_3.combine(Channel.value("N"))
}
Expand Down Expand Up @@ -662,25 +663,26 @@ paintor_gwas_2=paintor_gwas_i.flatMap{it}
"""
}
}else{
ld_paintor_group=ld_paintor.join(paintor_gwas)
ld_paintor_group=ld_paintor.combine(channel.from("00"))
process ComputedPaintor_null{
input :
set val(pos), file(ld),file(filez) from ld_paintor_group
output :
set val(pos),file("${output}.results") into res_paintor_ch
set val(pos),file(FileInfo) into infores_paintor_ch
set val(pos), file(BayesFactor) into res_paintor_ch_bf
script :
output=pos+"_paintor_null"
FileInfo=output+".info"
BayesFactor=output+".BayesFactor"
BayesFactor=output+".BayesFactor"
"""
touch $output".results"
touch $BayesFactor
touch $FileInfo
"""
}
paintor_fileannot=file("${dummy_dir}/00")
paintor_fileannotplot=file("${dummy_dir}/00")
paintor_fileannot=list_pos_paint_ch1.combine(channel.fromPath("${dummy_dir}/02"))
paintor_fileannotplot=list_pos_paint_ch2.combine(channel.fromPath("${dummy_dir}/03"))
annotname=Channel.from("N")

}
Expand Down Expand Up @@ -773,16 +775,16 @@ process MergeResult{
script :
out=params.output+'_'+pos
infopaint=infopaintor.join(" ")
pfileannot= (baliseannotpaint=="0" | params.paintor_bin==0) ? "":" --paintor_fileannot $pfileannoti "
paintor = (params.paintor_bin=="0") ? "" : "--listpaintor infopaintori"
pfileannot= (baliseannotpaint=="0" | params.paintor_bin==0 | params.paintor_bin=="" ) ? "":" --paintor_fileannot $pfileannoti "
paintor = (params.paintor_bin==0 | params.paintor_bin=="") ? "" : "--listpaintor infopaintor"

"""
cat $infopaintor > infopaintor
echo "sss $fmsss" > infofinemap
echo "sss $fmssscred" > infofinemapcred
echo "cond $fmcond" >> infofinemap
echo "cond $fmcondcred" >> infofinemapcred
merge_finemapping_v2.r --out $out --listpaintor infopaintor --cojo $cojo --datai $datai --caviarbf $caviarbf --list_genes $genes --gwascat $gwascat --headbp_gc ${headgc_bp} --headchr_gc ${headgc_chr} --listfinemap infofinemap $pfileannot --listfinemap_cred infofinemapcred
merge_finemapping_v2.r --out $out $paintor --cojo $cojo --datai $datai --caviarbf $caviarbf --list_genes $genes --gwascat $gwascat --headbp_gc ${headgc_bp} --headchr_gc ${headgc_chr} --listfinemap infofinemap $pfileannot --listfinemap_cred infofinemapcred
echo "merge_finemapping_v2.r --out $out --listpaintor infopaintor --cojo $cojo --datai $datai --caviarbf $caviarbf --list_genes $genes --gwascat $gwascat --headbp_gc ${headgc_bp} --headchr_gc ${headgc_chr} --listfinemap infofinemap $pfileannot --listfinemap_cred infofinemapcred" > run.bash
"""
}
Expand Down

0 comments on commit f28aec6

Please sign in to comment.