rm(list=ls())
library("DNAcopy")
setwd("~/aCGH/")
convert_rawdata <- function (raw_file)
{
temp.file <- read.table(file = raw_file, skip = 9,
header=T, stringsAsFactors =FALSE)
usable <- grep("chr",temp.file$SystematicName)
temp.pos = as.vector(sapply(strsplit
(as.character(temp.file[usable,]$SystematicName),":"), "[", 2))
final.pos = sapply(strsplit(temp.pos,"-"),"[",1)
temp.chr = as.vector(sapply(strsplit(as.character(
temp.file[usable,]$SystematicName),":"), "[", 1))
final.chr <- gsub("chr", "", temp.chr)
obj_df <- data.frame(logR=temp.file[usable,]$LogRatio,
Chr=final.chr,
Pos=as.numeric(final.pos)/1000)
return(obj_df)
}
data_1 <- convert_rawdata("Cy5_mutant1_vs_Cy3_WT.txt")
data_2 <- convert_rawdata("Cy5_mutant2_vs_Cy3_WT.txt")
CNA.object <- CNA(cbind(data_1$logR,
data_2$logR),
data_1$Chr,
as.numeric(data_1$Pos),
data.type="logratio",
sampleid=c("mutant1","mutant2")
)
smotthed.CNA.object <- smooth.CNA(CNA.object)
segment.smoothed.CNA.object <- segment(smotthed.CNA.object, verbose = 1)
plot(segment.smoothed.CNA.object,plot.type="s")
segments <- segment.smoothed.CNA.object$output
signal_data <- as.data.frame(segment.smoothed.CNA.object$data)
colnames(segments)
segments$loc.start = segments$loc.start*1000
segments$loc.end = segments$loc.end*1000
signal_data$maploc = signal_data$maploc*1000
signal_data[,c(3,4)] <- log2(10)*signal_data[,c(3,4)]
segments$seg.mean <- log2(10)*segments$seg.mean
write.csv(segments, file="segmentation.csv")