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

noreply at r-forge.r-project.org noreply at r-forge.r-project.org
Thu Feb 16 15:27:55 CET 2012


Author: mayrhofer
Date: 2012-02-16 15:27:55 +0100 (Thu, 16 Feb 2012)
New Revision: 96

Modified:
   pkg/patchwork/R/patchwork.CNA.r
   pkg/patchwork/R/patchwork.applyref.r
   pkg/patchwork/R/patchwork.smoothing.r
Log:
massa ?\195?\164ndringar

Modified: pkg/patchwork/R/patchwork.CNA.r
===================================================================
--- pkg/patchwork/R/patchwork.CNA.r	2012-02-15 16:37:07 UTC (rev 95)
+++ pkg/patchwork/R/patchwork.CNA.r	2012-02-16 14:27:55 UTC (rev 96)
@@ -1,4 +1,4 @@
-patchwork.CNA <- function(BamFile,Pileup,reference=NULL,normal.pileup=NULL,Alpha=0.0001,SD=1)
+patchwork.CNA <- function(BamFile,Pileup,reference=NULL,normal.bam=NULL,normal.pileup=NULL,Alpha=0.0001,SD=1)
 	{
 	#library(patchwork)
 	#patchwork.CNA("cancer.bam","pile.up",reference="illumina")
@@ -10,9 +10,6 @@
 	#load(paste(packagepath,"/data/ideogram.RData",sep=""))
 	#load(paste(packagepath,"/data/normaldata.RData",sep=""))
 	
-	#Check whether reference is a bam file.
-	normal.bam <- ifelse(length(grep('.bam',reference))>1, reference, NULL)
-
 	#Attempt to read file pile.alleles, incase its already been created.
 	alf <- normalalf <- NULL
 	try( load("pile.alleles.Rdata"), silent=TRUE )
@@ -59,34 +56,24 @@
 	#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)) {
+	if (!is.null(normal.bam) & is.null(reference)) {
 		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")
-		}
-	
-		if(length(normaldata) < 7) {
+		}	
+		if(length(normaldata) != 3) {
 			cat("Initiating Gc Normalization (matched normal) \n")
-			normaldata = patchwork.GCNorm(normaldata)
+			normaldata = patchwork.GCNorm(normaldata[,1:6])
 			cat("GC Normalization Complete \n")
+			normaldata <- data.frame(chr=normaldata$chr,pos=normaldata$pos,normal=normaldata$norm)
 			save(normaldata,file='normaldata.Rdata')
 		}
-		if (length(normaldata)>3) {
-			normaldata <- data.frame(chr=normaldata$chr,pos=normaldata$pos,reference=normaldata$norm)
-		}
-		save(normaldata,file='normaldata.Rdata')
-	} else load(reference)
-		
-	#Apply reference to data.
-	if(length(data) < 9) {
-		cat("Initiating Application of Reference \n")
-		data <- patchwork.applyref(data,reference=normaldata)
-		cat("Application of Reference Complete \n")
-		save(data,file='data.Rdata')
-	}
+		#save(normaldata,file='normaldata.Rdata')
+	} 
+
 	
 	#Apply smoothing to the data.
 	kbsegs = NULL
@@ -94,7 +81,7 @@
 	if(length(kbsegs) == 0)
 		{
 		cat("Initiating Smoothing \n")
-		kbsegs = patchwork.smoothing(data,chroms)
+		kbsegs = patchwork.smoothing(data,normaldata,reference,chroms)
 		save(kbsegs,file="smoothed.Rdata")
 		cat("Smoothing Complete \n")
 		}

Modified: pkg/patchwork/R/patchwork.applyref.r
===================================================================
--- pkg/patchwork/R/patchwork.applyref.r	2012-02-15 16:37:07 UTC (rev 95)
+++ pkg/patchwork/R/patchwork.applyref.r	2012-02-16 14:27:55 UTC (rev 96)
@@ -1,7 +1,9 @@
 patchwork.applyref <- function(data,reference=NULL)
 	{
 
-	data <- merge(data[,1:7],normaldata,all=F,by=1:2)
+	if (ncol(data)>7) data <- data[,1:7]
+
+	data <- merge(data,reference,all=F,by=1:2) ### Should change to all=T, but that must be fixed in smoothing.
 	colnames(data)[8] = 'reference'
 	data=data[order(data$pos),]
 	data=data[order(data$chr),]

Modified: pkg/patchwork/R/patchwork.smoothing.r
===================================================================
--- pkg/patchwork/R/patchwork.smoothing.r	2012-02-15 16:37:07 UTC (rev 95)
+++ pkg/patchwork/R/patchwork.smoothing.r	2012-02-16 14:27:55 UTC (rev 96)
@@ -1,12 +1,17 @@
-patchwork.smoothing <- function(data,chroms)
+patchwork.smoothing <- function(data,normaldata=NULL,reference=NULL,chroms)
 	{
 	#Load data included in package
 	#packagepath = system.file(package="patchwork")
 	#load(paste(packagepath,"/data/commonSnps132.RData",sep=""))
 	#load(paste(packagepath,"/data/ideogram.RData",sep=""))
 	#load(paste(packagepath,"/data/normaldata.RData",sep=""))
-	data(ideogram,package="patchworkData")
+	data(ideogram,package="patchworkData")	
 
+	reference=ifelse(length(reference)>1, reference, normaldata)
+	data <- merge(data,reference,all=T)
+	data <- data[order(data$pos),]; data <- data[order(data$chr),]
+	colnames(data)[8] <- 'reference'
+
 	# apply smoothing @ 10kb (~50 minibins)
 	seglength <- 10000
 	window <- seglength/200 



More information about the Patchwork-commits mailing list