[Patchwork-commits] r134 - pkg/patchworkCG/R
noreply at r-forge.r-project.org
noreply at r-forge.r-project.org
Mon Jun 25 13:53:55 CEST 2012
Author: mayrhofer
Date: 2012-06-25 13:53:55 +0200 (Mon, 25 Jun 2012)
New Revision: 134
Modified:
pkg/patchworkCG/R/patchwork.CG.copynumbers.r
Log:
Updated CN calculation @ X and Y.
Modified: pkg/patchworkCG/R/patchwork.CG.copynumbers.r
===================================================================
--- pkg/patchworkCG/R/patchwork.CG.copynumbers.r 2012-06-04 13:17:56 UTC (rev 133)
+++ pkg/patchworkCG/R/patchwork.CG.copynumbers.r 2012-06-25 11:53:55 UTC (rev 134)
@@ -1,4 +1,4 @@
-patchwork.CG.copynumbers = function(cn2,delta,het,hom,maxCn=8,ceiling=1,name="copynumbers_",CGfile=NULL,forcedelta=F)
+patchwork.CG.copynumbers = function(cn2,delta,het,hom,maxCn=8,ceiling=1,name="copynumbers_",CGfile=NULL,forcedelta=F,male.sample=F,male2femref=T)
{
data(ideogram,package="patchworkCG")
@@ -294,6 +294,35 @@
tumor_percentDNA <- xdelta / expected_delta
tumor_percent <- tumor_percentDNA/(meanCn/2) / ( tumor_percentDNA/(meanCn/2) + (1-tumor_percentDNA) )
+ ## Fix sex chromosomes in case of male sample.
+ if (male.sample) {
+ ix <- which(!is.autosome(regions$chr))
+ regions$mCn[ix] <- 0
+ ## Treats differently depending on sex of the reference
+ if (!male2femref) {
+ # X and Y (originally cn1) were compared to cn1 (matched normal or male references).
+ # Unchanged copy number (=1) is expected at relative coverage 1.
+ # Gains/loss are expected at xdelta (the delta of the autosomes)*2.
+ rawcopychange <- (regions$median[ix]-1) / (xdelta*2)
+ regions$Cn[ix] <- round(1+rawcopychange)
+ regions$fullCN[ix] <- paste('cn',round(1+rawcopychange),'m0')
+ } else
+ {
+ # X and Y (originally cn1) were compared to cn2 (female references).
+ # Unchanged copy number (=1) is expected at relative coverage 1/2.
+ # Gains/loss are expected at xdelta from there.
+ rawcopychange <- (regions$median[ix]-1/2) / (xdelta)
+ regions$Cn[ix] <- round(1+rawcopychange)
+ regions$fullCN[ix] <- paste('cn',round(1+rawcopychange),'m0')
+ }
+ }
+ ## And a small fix on female samples
+ if (!male.sample) {
+ ix <- which(regions$chr=='chrY')
+ regions$mCn[ix] <- regions$Cn[ix] <- 0
+ }
+
+
regions$meanCn <- meanCn
regions$tumor_percent <- tumor_percent
More information about the Patchwork-commits
mailing list