[Patchwork-commits] r84 - pkg/patchwork/R

noreply at r-forge.r-project.org noreply at r-forge.r-project.org
Wed Feb 8 15:08:32 CET 2012


Author: mayrhofer
Date: 2012-02-08 15:08:31 +0100 (Wed, 08 Feb 2012)
New Revision: 84

Modified:
   pkg/patchwork/R/patchwork.CNA.r
   pkg/patchwork/R/patchwork.alleledata.r
   pkg/patchwork/R/patchwork.applyref.r
Log:
Introduced optional use of matched normal in patchwork (without testing or debugging)

Modified: pkg/patchwork/R/patchwork.CNA.r
===================================================================
--- pkg/patchwork/R/patchwork.CNA.r	2012-02-08 13:22:28 UTC (rev 83)
+++ pkg/patchwork/R/patchwork.CNA.r	2012-02-08 14:08:31 UTC (rev 84)
@@ -1,4 +1,4 @@
-patchwork.CNA <- function(BamFile,Pileup,reference,Alpha=0.0001,SD=1)
+patchwork.CNA <- function(BamFile,Pileup,reference,normal.bam=NULL,normal.pileup=NULL,Alpha=0.0001,SD=1)
 	{
 	#library(patchwork)
 	#patchwork.CNA("cancer.bam","pile.up",reference="illumina")
@@ -20,7 +20,8 @@
 	if(length(alf) == 0)
 		{
 		cat("Initiating Allele Data Generation \n")
-		alf = patchwork.alleledata(Pileup)
+		normalalf <- ifelse(is.null(normal.pileup), NULL, patchwork.alleledata(normal.pileup))
+		alf = patchwork.alleledata(Pileup, normalalf=normalalf)
 		cat("Allele Data Generation Complete \n")
 		save(alf,file="pile.alleles.Rdata")
 		}
@@ -55,12 +56,36 @@
 		save(data,file='data.Rdata')
 		}
 	#after this, no further normalization was done on reference sequences.
+
+	#If matched normal bam file was defined, load and normalize it the same way.
+	if (!is.null(normal.bam)) 
+		{
+		normaldata=NULL
+		try ( load('normaldata.Rdata'), silent=TRUE )
+		if(is.null(normaldata))
+			{
+			cat("Initiating Read Chroms (matched normal) \n")
+			normaldata = patchwork.readChroms(BamFile,chroms)
+			cat("Read Chroms Complete (matched normal) \n")
+			save(normaldata,file='normaldata.Rdata')
+			}
+		}
+		if(length(normaldata) < 7)
+			{
+			cat("Initiating Gc Normalization (matched normal) \n")
+			normaldata = patchwork.GCNorm(normaldata)
+			cat("GC Normalization Complete \n")
+			save(normaldata,file='normaldata.Rdata')
+		}
+
+
+
 		
 	#Apply normal reference to data.
 	if(length(data) < 9)
 		{
 		cat("Initiating Application of Reference \n")
-		data = patchwork.applyref(data,reference)
+		if (!is.null(normal.bam)) data <- patchwork.applyref(data,reference=reference) else data <- patchwork.applyref(data,normaldata=normaldata)
 		cat("Application of Reference Complete \n")
 		save(data,file='data.Rdata')
 		}

Modified: pkg/patchwork/R/patchwork.alleledata.r
===================================================================
--- pkg/patchwork/R/patchwork.alleledata.r	2012-02-08 13:22:28 UTC (rev 83)
+++ pkg/patchwork/R/patchwork.alleledata.r	2012-02-08 14:08:31 UTC (rev 84)
@@ -1,4 +1,4 @@
-patchwork.alleledata <- function(Pileup)
+patchwork.alleledata <- function(Pileup, normalalf=NULL)
 	{
 	
 	#Load data included in package
@@ -50,6 +50,13 @@
 		i = "Y"
 		alf$achr[alf$achr == as.character(i)] = paste("chr",as.character(i),sep="")
 		}
-		
+	
+	
+	#Finally, if a matched normal was available, remove SNPs that were not (somewhat) heterozygous there.
+	if (!is.null(normalalf)) {
+		normalalf <- normalalf[normalalf$amin/normalalf$atot > 0.2,]
+		alf <- merge(normalalf[,1:2],alf,by=1:2,all=F)
+	}
+	
 	return(alf)
 	}

Modified: pkg/patchwork/R/patchwork.applyref.r
===================================================================
--- pkg/patchwork/R/patchwork.applyref.r	2012-02-08 13:22:28 UTC (rev 83)
+++ pkg/patchwork/R/patchwork.applyref.r	2012-02-08 14:08:31 UTC (rev 84)
@@ -1,7 +1,7 @@
-patchwork.applyref <- function(data,reference)
+patchwork.applyref <- function(data,reference=NULL,normaldata=NULL)
 	{
 
-	load(reference)
+	if (!is.null(reference)) load(reference)
 		
 	data <- merge(data[,1:7],normaldata,all=F,by=1:2)
 	#data$ratio <- data$norm / data$norm_mean



More information about the Patchwork-commits mailing list