Skip to content

Commit

Permalink
extending dpclust master function to read from bb rho_psi files and a…
Browse files Browse the repository at this point in the history
…dding an example pipeline
  • Loading branch information
Stefan Dentro committed Nov 2, 2018
1 parent 6b7a6bc commit 9ec2a9f
Show file tree
Hide file tree
Showing 2 changed files with 66 additions and 10 deletions.
30 changes: 20 additions & 10 deletions R/preprocessing.R
Original file line number Diff line number Diff line change
Expand Up @@ -738,19 +738,29 @@ addVcfInfoCol = function(vcf, data, number, type, description, abbreviation) {
#' @param indeldatafiles A vector with indel DPClust input files (Default: NULL)
#' @author sd11
#' @export
createProjectFile = function(outputfile, donornames, samplenames, purities, sex, datafiles=paste(samplenames, "_allDirichletProcessInfo.txt", sep=""), cndatafiles=NULL, indeldatafiles=NULL) {
if (!all(c(length(samplenames), length(purities), length(sex), length(datafiles))==length(donornames))) {
stop("All provided vectors must be of the same length")
createProjectFile = function(outputfile, donornames, samplenames, sex, purities=NULL, rho_and_psi_files=NULL, datafiles=paste(samplenames, "_allDirichletProcessInfo.txt", sep=""), cndatafiles=NULL, indeldatafiles=NULL) {
if (is.null(purities) & is.null(rho_and_psi_files)) {
stop("Please provide either a vector of purities or a vector of Battenberg rho_and_psi files")
}
if (!is.null(cndatafiles)) {
if (length(cndatafiles)!=length(donornames)) {
stop("All provided vectors must be of the same length")

.checklength = function(a) {
if (!is.null(a)) {
if (length(a)!=length(donornames)) {
stop("All provided vectors must be of the same length")
}
}
}
if (!is.null(indeldatafiles)) {
if (length(indeldatafiles)!=length(donornames)) {
stop("All provided vectors must be of the same length")
}
.checklength(donornames)
.checklength(samplenames)
.checklength(sex)
.checklength(purities)
.checklength(rho_and_psi_files)
.checklength(datafiles)
.checklength(indeldatafiles)
.checklength(cndatafiles)

if (!is.null(rho_and_psi_files)) {
purities = unlist(lapply(rho_and_psi_files, GetCellularity))
}

output = data.frame(sample=donornames,
Expand Down
46 changes: 46 additions & 0 deletions inst/example/preproc_dpclust_master_file.R
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
#'
#' Simple pipeline that produces a DPClust master file
#'
#' v1.0 - 2018-11-02 - sd11 [at] sanger.ac.uk

library(dpclust3p)
library(optparse)

option_list = list(
make_option(c("-s", "--samplenames"), type="character", default=NULL, help="Comma separated list of samplenames", metavar="character"),
make_option(c("-d", "--donornames"), type="character", default=NULL, help="Comma separated list of donornames (use the same donor name to match multiple samples)", metavar="character"),
make_option(c("-p", "--purities"), type="character", default=NULL, help="Comma separated list of purities (supply -p or -r)", metavar="character"),
make_option(c("-r", "--rho_and_psi"), type="character", default=NULL, help="List of Battenberg rho and psi output files (supply -p or -r)", metavar="character"),
make_option(c("--sex"), type="character", default=NULL, help="Comma separated list of sex of the sample", metavar="character"),
make_option(c("-o", "--output"), type="character", default=NULL, help="Output file", metavar="character")
)

opt_parser = OptionParser(option_list=option_list)
opt = parse_args(opt_parser)

donornames = strsplit(opt$donornames, ",")
samplenames = strsplit(opt$samplenames, ",")
sex = strsplit(opt$sex, ",")
outputfile = opt$output

if (!is.null(opt$rho_and_psi)) {
rho_and_psi_files = strsplit(opt$rho_and_psi, ",")
} else {
rho_and_psi_files = NULL
}
if (!is.null(opt$purities)) {
purities = strsplit(opt$purities, ",")
} else {
purities = NULL
}

if (!all(sex %in% c("male", "female"))) {
stop("Provide male or female as sex")
}

createProjectFile(outputfile=outputfile,
donornames=donornames,
samplenames=samplenames,
sex=sex,
purities=purities,
rho_and_psi_files=rho_and_psi_files)

0 comments on commit 9ec2a9f

Please sign in to comment.