-
Notifications
You must be signed in to change notification settings - Fork 10
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
6 changed files
with
185 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,72 @@ | ||
#' Concatenate split files | ||
#' | ||
#' Convenience function to concatenate a series of files specified in a file of file names. | ||
#' This function assumes all files have the same layout. | ||
#' @param fofn A file of file names to be concatenated | ||
#' @param inputdir Full path to where the input files are stored | ||
#' @param outfile Full path to where the output should be written | ||
#' @param haveHeader Boolean that specifies whether the input files have a header | ||
#' @author sd11 | ||
#' @export | ||
concat_files = function(fofn, inputdir, outfile, haveHeader) { | ||
|
||
inputdir = paste(inputdir,"/", sep="") | ||
list_of_files = read.table(fofn, stringsAsFactors=F, header=F)[,1] | ||
|
||
output = data.frame() | ||
for (infile in list_of_files) { | ||
infile = paste(inputdir, infile, sep="") | ||
# Check if file is there and it contains data | ||
if (file.exists(infile) & file.info(infile)$size != 0) { | ||
dat = read.delim(infile, header=haveHeader, quote=NULL, stringsAsFactors=F) | ||
output = rbind(output, dat) | ||
} | ||
} | ||
|
||
write.table(output, file=outfile, col.names=haveHeader, row.names=F, sep="\t", quote=F) | ||
} | ||
|
||
#' Split a file per chromosome | ||
#' | ||
#' Convenience function to split an input file per chromosome. All it requires is that | ||
#' the infile has as first column chromosome specification. The output files will be named | ||
#' outdir/prefixCHROMNUMBERpostfix | ||
#' @param infile The file to be split | ||
#' @param prefix Prefix of the output file | ||
#' @param postfix Postfix of the output file | ||
#' @param outdir Directory where the output files are to be written | ||
#' @param chrom_file A simple list of chromosomes to be considered | ||
#' @author sd11 | ||
#' @export | ||
split_by_chrom = function(infile, prefix, postfix, outdir, chrom_file) { | ||
outdir = paste(outdir, "/", sep="") | ||
|
||
# Check if there are lines in the file, otherwise it will crash this script | ||
if (file.info(infile)$size == 0) { | ||
print("No lines in loci file") | ||
q(save="no") | ||
} | ||
|
||
loci = read.delim(infile, stringsAsFactors=F, header=F) | ||
|
||
chroms = read.delim(chrom_file, stringsAsFactors=F, header=F) | ||
|
||
for (i in 1:nrow(chroms)) { | ||
selection = loci[loci[,1]==chroms[i,1],] | ||
chrom_id = chroms[i,2] | ||
write.table(selection, file=paste(outdir, prefix, chrom_id, postfix, sep=""), quote=F, row.names=F, col.names=F, sep="\t") | ||
} | ||
} | ||
|
||
#' Calculate power to call subclones. | ||
#' | ||
#' This function calculates the | ||
#' average number of reads per clonal chromosome copy. | ||
#' @param purity The sample purity | ||
#' @param ploidy The tumour ploidy | ||
#' @param coverage The tumour sample coverage | ||
#' @return The average reads per chromosome copy, a.k.a. power | ||
#' @author sd11 | ||
calc_power = function(purity, ploidy, coverage) { | ||
return(round((purity) / (purity*ploidy + (1-purity)*2) * coverage, 3)) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
% Generated by roxygen2 (4.1.1): do not edit by hand | ||
% Please edit documentation in R/util.R | ||
\name{calc_power} | ||
\alias{calc_power} | ||
\title{Calculate power to call subclones.} | ||
\usage{ | ||
calc_power(purity, ploidy, coverage) | ||
} | ||
\arguments{ | ||
\item{purity}{The sample purity} | ||
|
||
\item{ploidy}{The tumour ploidy} | ||
|
||
\item{coverage}{The tumour sample coverage} | ||
} | ||
\value{ | ||
The average reads per chromosome copy, a.k.a. power | ||
} | ||
\description{ | ||
This function calculates the | ||
average number of reads per clonal chromosome copy. | ||
} | ||
\author{ | ||
sd11 | ||
} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
% Generated by roxygen2 (4.1.1): do not edit by hand | ||
% Please edit documentation in R/qualitycontrol.R | ||
\name{createPng} | ||
\alias{createPng} | ||
\title{Create a PNG file} | ||
\usage{ | ||
createPng(p, filename, width, height) | ||
} | ||
\arguments{ | ||
\item{p}{The figure} | ||
|
||
\item{filename}{Where to save the image} | ||
|
||
\item{width}{Width} | ||
|
||
\item{height}{Height} | ||
} | ||
\description{ | ||
Create a PNG file | ||
} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
% Generated by roxygen2 (4.1.1): do not edit by hand | ||
% Please edit documentation in R/qualitycontrol.R | ||
\name{plot_ccf_hist} | ||
\alias{plot_ccf_hist} | ||
\title{Plot cancer cell fraction histogram} | ||
\usage{ | ||
plot_ccf_hist(data, samplename, outdir) | ||
} | ||
\arguments{ | ||
\item{data}{A DPClust input table} | ||
|
||
\item{samplename}{Name of the sample} | ||
|
||
\item{outdir}{Directory where the figure is to be stored} | ||
} | ||
\description{ | ||
Plot cancer cell fraction histogram | ||
} | ||
\author{ | ||
sd11 | ||
} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
% Generated by roxygen2 (4.1.1): do not edit by hand | ||
% Please edit documentation in R/qualitycontrol.R | ||
\name{plot_mcn_hist} | ||
\alias{plot_mcn_hist} | ||
\title{Plot mutation copy number histogram} | ||
\usage{ | ||
plot_mcn_hist(data, samplename, outdir) | ||
} | ||
\arguments{ | ||
\item{data}{A DPClust input table} | ||
|
||
\item{samplename}{Name of the sample} | ||
|
||
\item{outdir}{Directory where the figure is to be stored} | ||
} | ||
\description{ | ||
Plot mutation copy number histogram | ||
} | ||
\author{ | ||
sd11 | ||
} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
% Generated by roxygen2 (4.1.1): do not edit by hand | ||
% Please edit documentation in R/qualitycontrol.R | ||
\name{plot_vaf_hist} | ||
\alias{plot_vaf_hist} | ||
\title{Plot allele frequency histogram} | ||
\usage{ | ||
plot_vaf_hist(data, samplename, outdir) | ||
} | ||
\arguments{ | ||
\item{data}{A DPClust input table} | ||
|
||
\item{samplename}{Name of the sample} | ||
|
||
\item{outdir}{Directory where the figure is to be stored} | ||
} | ||
\description{ | ||
Plot allele frequency histogram | ||
} | ||
\author{ | ||
sd11 | ||
} | ||
|