Skip to content

Commit

Permalink
refactor: fix inputs of post jabba processes
Browse files Browse the repository at this point in the history
  • Loading branch information
shihabdider committed May 7, 2024
1 parent 17be003 commit 2b0deb6
Show file tree
Hide file tree
Showing 23 changed files with 2,678 additions and 276 deletions.
2 changes: 1 addition & 1 deletion bin/Events.R
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ withAutoprint(
min.span = 1e6,
max.small = 1e4)
newtic = tic
overwritefun("newtic", "tic", "gGnome")
# overwritefun("newtic", "tic", "gGnome")


## call complex events
Expand Down
50 changes: 50 additions & 0 deletions bin/Fusions.R
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
withAutoprint(
{
library(optparse)
options(bitmapType = "cairo")

options(error = function() {
traceback(2)
quit("no", 1)
})
if (!exists("opt")) {
option_list <- list(
make_option(c("-i", "--id"), type = "character", help = "sample id"),
make_option(c("-g", "--gGraph"), type = "character", help = "an RDS file contains a gGraph or JaBbA graph with cn annotation on nodes and edges"),
make_option(c("-r", "--gencode"), type = "character", help = "an RDS or GTF file of GENCODE"),
make_option(c("-o", "--outdir"), type = "character", default = "./", help = "Directory to dump output into"),
make_option(c("--cores"), type = "integer", default = 1L, help = "Number of cores")
)
parseobj <- OptionParser(option_list = option_list)
opt <- parse_args(parseobj)
saveRDS(opt, paste(opt$outdir, "cmd.args.rds", sep = "/"))
}

library(gGnome)
library(gUtils)
library(parallel) ## needed for mc.cores

## setDTthreads(10)
if (grepl(".rds$", opt$gencode)) {
gencode <- readRDS(as.character(opt$gencode))
} else {
gencode <- rtracklayer::import(opt$gencode)
}


## call complex events
## fus = fusions(gG(jab = opt$gGraph), gencode, verbose = TRUE, opt$cores)
fus <- fusions(gG(jab = opt$gGraph), gencode, verbose = TRUE, mc.cores = opt$cores)

## update events with sample id
if (length(fus)) {
fus$set(id = opt$id)
fus$set(mincn = fus$eval(edge = min(cn, na.rm = TRUE)))
}

saveRDS(fus, paste0(opt$outdir, "/", "fusions.rds"))

quit("no", 0)
},
echo = FALSE
)
2 changes: 1 addition & 1 deletion bin/cbsFH.R
Original file line number Diff line number Diff line change
Expand Up @@ -8506,7 +8506,7 @@ ppgrid = function(
else ## only row, only go left right
M = (NLLc < NLLcl & NLLc < NLLcr)[-c(1, nrow(NLLc)), -c(1, ncol(NLLc)), drop = FALSE]

if (length(M)>1)
if (length(M)>1 & any(M, na.rm=TRUE))
{
ix = which(M, arr.ind= T);
if (nrow(ix)>1)
Expand Down
2,371 changes: 2,365 additions & 6 deletions bin/lp_phased_balance.R

Large diffs are not rendered by default.

40 changes: 39 additions & 1 deletion bin/non_integer_balance.R
Original file line number Diff line number Diff line change
Expand Up @@ -41,8 +41,46 @@
library(skitools)
library(JaBbA)
library(gGnome)
library(zitools)
## devtools::load_all("~/git/gGnome") ## noninteger capacity now added to master branch
devtools::load_all("~/git/zitools")

#' @name grab.hets
#' @title grab.hets
#'
#' @description
#'
#' returns allele gtrack given sites.txt from het pileup
#'
#' @param agt.fname (character) path to sites.txt
#' @param min.frac (numeric) between 0 and 1, min frequency in normal to count as het site
#' @param max.frac (numeric) between 0 and 1, max frequency in normal to count as het site
#'
#' @return allele gTrack
grab.hets = function(agt.fname = NULL,
min.frac = 0.2,
max.frac = 0.8)
{
if (is.null(agt.fname) || !file.exists(agt.fname)) {
stop("agt.fname does not exist")
}

## prepare and filter
agt.dt = fread(agt.fname)[alt.frac.n > min.frac & alt.frac.n < max.frac,]
## add major and minor
agt.dt[, which.major := ifelse(alt.count.t > ref.count.t, "alt", "ref")]
agt.dt[, major.count := ifelse(which.major == "alt", alt.count.t, ref.count.t)]
agt.dt[, minor.count := ifelse(which.major == "alt", ref.count.t, alt.count.t)]

## melt the data frame
agt.melted = rbind(agt.dt[, .(seqnames, start, end, count = major.count, allele = "major")],
agt.dt[, .(seqnames, start, end, count = minor.count, allele = "minor")]
)

## make GRanges
agt.gr = dt2gr(agt.melted[, .(seqnames, start, end, count, allele)])

return (agt.gr)
}

#' @name grab.hets.from.maf
#' @title grab.hets.from.maf
Expand Down
6 changes: 3 additions & 3 deletions conf/igenomes.config
Original file line number Diff line number Diff line change
Expand Up @@ -48,10 +48,10 @@ params {
hapmap_sites = "${params.igenomes_base}/Homo_sapiens/GATK/GRCh37/Annotation/GATKBundle/hapmap_3.3.b37.vcf.gz"
pon_dryclean = "${params.mski_base}/dryclean/pon/hg19/fixed.detergent.rds"
blacklist_coverage_jabba = "${params.mski_base}/JaBbA/blacklist_coverage/hg19/maskA_re.rds"
gencode_fusions = "${params.mski_base}/fusions/gencode/hg19/gencode.bed"
gencode_fusions = "${params.mski_base}/fusions/hg19/gencode.v29lift37.annotation.nochr.rds"
build_non_integer_balance = "hg19"
mask_non_integer_balance = "${params.mski_base}/allelic_cn/non_integer_balance/hg19/mask_with_segdups.rds"
mask_lp_phased_balance = "${params.mski_base}/allelic_cn/lp_phased_balance/maskA_re.rds"
mask_lp_phased_balance = "${params.mski_base}/allelic_cn/lp_phased_balance/lp_phased_balance_maskA_re.rds"
}
'GATK.GRCh38' {
fasta = "${params.igenomes_base}/Homo_sapiens/GATK/GRCh38/Sequence/WholeGenomeFasta/Homo_sapiens_assembly38.fasta"
Expand Down Expand Up @@ -95,7 +95,7 @@ params {
blacklist_coverage_jabba = "${params.mski_base}/JaBbA/blacklist_coverage/hg38/hg38.coverage.mask.rds"
build_non_integer_balance = "hg38"
mask_non_integer_balance = "${params.mski_base}/allelic_cn/non_integer_balance/hg38/mask_with_segdups.rds"
mask_lp_phased_balance = "${params.mski_base}/allelic_cn/lp_phased_balance/maskA_re.rds"
mask_lp_phased_balance = "${params.mski_base}/allelic_cn/lp_phased_balance/lp_phased_balance_maskA_re.rds"
}

'GRCh37' {
Expand Down
36 changes: 0 additions & 36 deletions conf/modules/alleic_cn.config
Original file line number Diff line number Diff line change
Expand Up @@ -23,24 +23,6 @@ process {
]
}

withName: 'MSKILABORG_NFJABBA:NFJABBA:ALLEIC_CN:NON_INTEGER_BALANCE_WITH_GRIDSS' {
ext.when = { params.tools && params.tools.split(',').contains('alleic_cn') }
publishDir = [
mode: params.publish_dir_mode,
path: { "${params.outdir}/alleic_cn/non_integer_balance_with_gridss/${meta.id}/" },
pattern: "*{.rds*,.command.*}"
]
}

withName: 'MSKILABORG_NFJABBA:NFJABBA:ALLEIC_CN:NON_INTEGER_BALANCE_WITH_SVABA' {
ext.when = { params.tools && params.tools.split(',').contains('alleic_cn') }
publishDir = [
mode: params.publish_dir_mode,
path: { "${params.outdir}/alleic_cn/non_integer_balance_with_svaba/${meta.id}/" },
pattern: "*{.rds*,.command.*}"
]
}

withName: 'MSKILABORG_NFJABBA:NFJABBA:ALLEIC_CN:LP_PHASED_BALANCE' {
ext.when = { params.tools && params.tools.split(',').contains('alleic_cn') }
publishDir = [
Expand All @@ -49,22 +31,4 @@ process {
pattern: "*{.rds*,.command.*}"
]
}

withName: 'MSKILABORG_NFJABBA:NFJABBA:ALLEIC_CN:LP_PHASED_BALANCE_WITH_GRIDSS' {
ext.when = { params.tools && params.tools.split(',').contains('alleic_cn') }
publishDir = [
mode: params.publish_dir_mode,
path: { "${params.outdir}/alleic_cn/lp_phased_balance_with_gridss/${meta.id}/" },
pattern: "*{.rds*,.command.*}"
]
}

withName: 'MSKILABORG_NFJABBA:NFJABBA:ALLEIC_CN:LP_PHASED_BALANCE_WITH_SVABA' {
ext.when = { params.tools && params.tools.split(',').contains('alleic_cn') }
publishDir = [
mode: params.publish_dir_mode,
path: { "${params.outdir}/alleic_cn/lp_phased_balance_with_svaba/${meta.id}/" },
pattern: "*{.rds*,.command.*}"
]
}
}
70 changes: 70 additions & 0 deletions conf/modules/allelic_cn.config
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
/*
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Config file for defining DSL2 per module options and publishing paths
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Available keys to override module options:
ext.args = Additional arguments appended to command in module.
ext.args2 = Second set of arguments appended to command in module (multi-tool modules).
ext.args3 = Third set of arguments appended to command in module (multi-tool modules).
ext.prefix = File name prefix for output files.
ext.when = When to run the module.
----------------------------------------------------------------------------------------
*/
// ALLEIC_CN configs

process {

withName: 'MSKILABORG_NFJABBA:NFJABBA:ALLEIC_CN:NON_INTEGER_BALANCE' {
ext.when = { params.tools && params.tools.split(',').contains('alleic_cn') }
publishDir = [
mode: params.publish_dir_mode,
path: { "${params.outdir}/alleic_cn/non_integer_balance/${meta.id}/" },
pattern: "*{.rds*,.command.*}"
]
}

withName: 'MSKILABORG_NFJABBA:NFJABBA:ALLEIC_CN:NON_INTEGER_BALANCE_WITH_GRIDSS' {
ext.when = { params.tools && params.tools.split(',').contains('alleic_cn') }
publishDir = [
mode: params.publish_dir_mode,
path: { "${params.outdir}/alleic_cn/non_integer_balance_with_gridss/${meta.id}/" },
pattern: "*{.rds*,.command.*}"
]
}

withName: 'MSKILABORG_NFJABBA:NFJABBA:ALLEIC_CN:NON_INTEGER_BALANCE_WITH_SVABA' {
ext.when = { params.tools && params.tools.split(',').contains('alleic_cn') }
publishDir = [
mode: params.publish_dir_mode,
path: { "${params.outdir}/alleic_cn/non_integer_balance_with_svaba/${meta.id}/" },
pattern: "*{.rds*,.command.*}"
]
}

withName: 'MSKILABORG_NFJABBA:NFJABBA:ALLEIC_CN:LP_PHASED_BALANCE' {
ext.when = { params.tools && params.tools.split(',').contains('alleic_cn') }
publishDir = [
mode: params.publish_dir_mode,
path: { "${params.outdir}/alleic_cn/lp_phased_balance/${meta.id}/" },
pattern: "*{.rds*,.command.*}"
]
}

withName: 'MSKILABORG_NFJABBA:NFJABBA:ALLEIC_CN:LP_PHASED_BALANCE_WITH_GRIDSS' {
ext.when = { params.tools && params.tools.split(',').contains('alleic_cn') }
publishDir = [
mode: params.publish_dir_mode,
path: { "${params.outdir}/alleic_cn/lp_phased_balance_with_gridss/${meta.id}/" },
pattern: "*{.rds*,.command.*}"
]
}

withName: 'MSKILABORG_NFJABBA:NFJABBA:ALLEIC_CN:LP_PHASED_BALANCE_WITH_SVABA' {
ext.when = { params.tools && params.tools.split(',').contains('alleic_cn') }
publishDir = [
mode: params.publish_dir_mode,
path: { "${params.outdir}/alleic_cn/lp_phased_balance_with_svaba/${meta.id}/" },
pattern: "*{.rds*,.command.*}"
]
}
}
4 changes: 4 additions & 0 deletions main.nf
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,10 @@ params.build_dryclean = WorkflowMain.getGenomeAttribute(params, 'build_dr
params.hapmap_sites = WorkflowMain.getGenomeAttribute(params, 'hapmap_sites')
params.pon_dryclean = WorkflowMain.getGenomeAttribute(params, 'pon_dryclean')
params.blacklist_coverage_jabba = WorkflowMain.getGenomeAttribute(params, 'blacklist_coverage_jabba')
params.gencode_fusions = WorkflowMain.getGenomeAttribute(params, 'gencode_fusions')
params.build_non_integer_balance = WorkflowMain.getGenomeAttribute(params, 'build_non_integer_balance')
params.mask_non_integer_balance = WorkflowMain.getGenomeAttribute(params, 'mask_non_integer_balance')
params.mask_lp_phased_balance = WorkflowMain.getGenomeAttribute(params, 'mask_lp_phased_balance')
//params.blacklist_junctions_jabba = WorkflowMain.getGenomeAttribute(params, 'blacklist_junctions_jabba')

/*
Expand Down
24 changes: 15 additions & 9 deletions modules/local/allelic_cn/main.nf
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@ process NON_INTEGER_BALANCE {
label 'process_medium'

container "${ workflow.containerEngine == 'singularity' && !task.ext.singularity_pull_docker_container ?
'docker://mskilab/allelic_cn:latest':
'mskilab/allelic_cn:latest' }"
'/gpfs/commons/groups/imielinski_lab/home/sdider/Projects/nf-jabba/tests/test_runs/work/singularity/jabba_cplex_latest.sif':
'mskilab/jabba:latest' }"

input:
tuple val(meta), path(jabba_rds), path(decomposed_cov), path(het_pileups_wgs)
Expand All @@ -23,6 +23,8 @@ process NON_INTEGER_BALANCE {
val(tilim)
val(gurobi)
path(fasta) // path to decoy fasta
path(fasta_fai) // path to decoy fasta
path(bwa_index)
val(pad)

output:
Expand All @@ -37,9 +39,11 @@ process NON_INTEGER_BALANCE {
def args = task.ext.args ?: ''
def prefix = task.ext.prefix ?: "${meta.id}"
def id = "${meta.sample}"
def bwa = bwa_index ? "ln -nfs \$(readlink -f ${bwa_index})/* \$(dirname \$(readlink -f $fasta))/" : ""
def VERSION = '0.1' // WARN: Version information not provided by tool on CLI. Please update this string when bumping container versions.

"""
${bwa}
export RSCRIPT_PATH=\$(echo "${baseDir}/bin/non_integer_balance.R")
Expand All @@ -49,12 +53,12 @@ process NON_INTEGER_BALANCE {
--cov $decomposed_cov \\
--field $field \\
--hets $het_pileups_wgs \\
--hets-thresh $hets_thresh \\
--hets_thresh $hets_thresh \\
--mask $mask \\
--overwrite $overwrite \\
--lambda $lambda \\
--allin $allin \\
--fix_thresh $fix_thres \\
--fix_thresh $fix_thresh \\
--nodebounds $nodebounds \\
--ism $ism \\
--build $build \\
Expand Down Expand Up @@ -85,12 +89,12 @@ process NON_INTEGER_BALANCE {

process LP_PHASED_BALANCE {

tag "$id"
tag "$meta.id"
label 'process_medium'

container "${ workflow.containerEngine == 'singularity' && !task.ext.singularity_pull_docker_container ?
'docker://mskilab/allelic_cn:latest':
'mskilab/allelic_cn:latest' }"
'/gpfs/commons/groups/imielinski_lab/home/sdider/Projects/nf-jabba/tests/test_runs/work/singularity/jabba_cplex_latest.sif':
'mskilab/jabba:latest' }"

input:
tuple val(meta), path(hets_gg), path(hets) // output from non_integer_balance, sites.txt from hetpileups
Expand Down Expand Up @@ -123,7 +127,9 @@ process LP_PHASED_BALANCE {
def VERSION = '0.1' // WARN: Version information not provided by tool on CLI. Please update this string when bumping container versions.

"""
Rscript \${baseDir}/bin/lp_phased_balance.R \\
export RSCRIPT_PATH=\$(echo "${baseDir}/bin/lp_phased_balance.R")
Rscript \$RSCRIPT_PATH \\
--id $id \\
--jab $hets_gg \\
--hets $hets \\
Expand All @@ -146,7 +152,7 @@ process LP_PHASED_BALANCE {
cat <<-END_VERSIONS > versions.yml
"${task.process}":
non_integer_balance: ${VERSION}
lp_phased_balance: ${VERSION}
END_VERSIONS
"""
}
2 changes: 1 addition & 1 deletion modules/local/ascat/main.nf
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ process ASCAT_SEG {
'mskilab/ascat_seg:latest' }"

input:
tuple val(meta), path(hets), path(cbs_cov) // channel: [mandatory] [ meta, hets ]
tuple val(meta), path(hets), path(cbs_cov) // channel: [mandatory] [ meta, hets, cbs_cov ]
val(field) // channel: [mandatory] "foreground" for dryclean/ "ratio"
val(hets_thresh) // channel: cutoff for hetpileups; default=0.2
val(penalty) // channel: penalty for ASCAT; default=70
Expand Down
1 change: 0 additions & 1 deletion modules/local/cbs/main.nf
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,6 @@ process CBS {
def VERSION = '0.1' // WARN: Version information not provided by tool on CLI. Please update this string when bumping container versions.

"""
#RSCRIPT_PATH=\$(if [[ ${workflow.containerEngine} == "singularity" && !task.ext.singularity_pull_docker_container ]]; then echo "/cbsFH.R"; else echo "\${baseDir}/bin/cbsFH.R"; fi)
export RSCRIPT_PATH=\$(echo "${baseDir}/bin/cbsFH.R")
Rscript \$RSCRIPT_PATH \\
-t ${tumor_dryclean_cov} \
Expand Down
Loading

0 comments on commit 2b0deb6

Please sign in to comment.