@@ -288,8 +288,23 @@ gc.correct.wgs = function(Tumour_LogR_file, outfile, correlations_outfile, gc_co
288288
289289 GCcorrected = Tumor_LogR [! flag_NA ,]
290290 GCcorrected [,3 ] = model $ residuals
291-
291+ rm(Tumor_LogR )
292+
292293 corr = data.frame (windowsize = names(corr ), correlation = corr )
293- write.table(corr , file = correlations_outfile , sep = " \t " , quote = F , row.names = F )
294+ write.table(corr , file = gsub( " .txt " , " _beforeCorrection.txt " , correlations_outfile ) , sep = " \t " , quote = F , row.names = F )
294295 write.table(GCcorrected , file = outfile , sep = " \t " , quote = F , row.names = F )
296+
297+ # Recalculate the correlations to see how much there is left
298+ snps_gccorrected = paste(GCcorrected [,1 ], GCcorrected [,2 ], sep = " _" )
299+ snps_gcdata = paste(GC_data [,1 ], GC_data [,2 ], sep = " _" )
300+ snps_intersect = intersect(snps_gccorrected , snps_gcdata )
301+ GCcorrected = GCcorrected [snps_gccorrected %in% snps_intersect , ]
302+ GC_data = GC_data [snps_gcdata %in% snps_intersect , ]
303+
304+ flag_nona = is.finite(GCcorrected [,3 ])
305+ corr = cor(GC_data [flag_nona , 3 : ncol(GC_data )], GCcorrected [flag_nona ,3 ], use = " complete.obs" )
306+ length = nrow(GCcorrected )
307+ corr = apply(corr , 1 , function (x ) sum(abs(x * length ))/ sum(length ))
308+ corr = data.frame (windowsize = names(corr ), correlation = corr )
309+ write.table(corr , file = gsub(" .txt" , " _afterCorrection.txt" , correlations_outfile ), sep = " \t " , quote = F , row.names = F )
295310}
0 commit comments