720 |
11 Jun 08 |
jari |
# $Id$ |
720 |
11 Jun 08 |
jari |
2 |
|
720 |
11 Jun 08 |
jari |
3 |
###################################################################### |
720 |
11 Jun 08 |
jari |
################ MAIN PROGRAM ####################################### |
720 |
11 Jun 08 |
jari |
5 |
|
720 |
11 Jun 08 |
jari |
# Missing values should have the form of Na or NaN |
720 |
11 Jun 08 |
jari |
# [reporterId] [geneSymbol] [chromosome] [cytoBand] [startPosition] [endPosition] [assayData = M] |
720 |
11 Jun 08 |
jari |
8 |
|
720 |
11 Jun 08 |
jari |
aa<-scan("basematrix.txt",what="character",nlines=1) #aa is header! |
720 |
11 Jun 08 |
jari |
cc<-6 #related to format above! |
720 |
11 Jun 08 |
jari |
aa.s<-length(aa)-cc #number of samples |
720 |
11 Jun 08 |
jari |
my.colClasses<-c("numeric","character","character","character","numeric","numeric",rep("numeric",aa.s)) |
720 |
11 Jun 08 |
jari |
data<-read.table("basematrix.txt",colClasses=my.colClasses,header=TRUE,na.strings=c(NA)) |
720 |
11 Jun 08 |
jari |
data$chromosome<-as.integer(data$chromosome) |
720 |
11 Jun 08 |
jari |
15 |
|
720 |
11 Jun 08 |
jari |
nbrAssays<-aa.s |
720 |
11 Jun 08 |
jari |
17 |
|
720 |
11 Jun 08 |
jari |
assayNames<-read.table("assays.txt",colClasses="character",header=FALSE) |
720 |
11 Jun 08 |
jari |
19 |
|
720 |
11 Jun 08 |
jari |
## sort data and subdivide it |
720 |
11 Jun 08 |
jari |
ii<-order(data$chromosome,data$startPosition) |
720 |
11 Jun 08 |
jari |
data<-data[ii,] #reorder all data according to chromosom and then to start kb |
720 |
11 Jun 08 |
jari |
23 |
|
720 |
11 Jun 08 |
jari |
cloneInfo<-data[,c(seq(1,cc))] |
720 |
11 Jun 08 |
jari |
Log2matrix<-as.matrix(data[,-c(seq(1,cc))]) |
720 |
11 Jun 08 |
jari |
rm(data) |
720 |
11 Jun 08 |
jari |
27 |
|
720 |
11 Jun 08 |
jari |
for(h in 1:length(chromosomes)){ #foreach chromosome |
720 |
11 Jun 08 |
jari |
print(h) |
720 |
11 Jun 08 |
jari |
workingChrom<-chromosomes[h] |
720 |
11 Jun 08 |
jari |
## Foreach assay in my.assays |
720 |
11 Jun 08 |
jari |
for(u in 1:nbrAssays){ #foreach assay |
720 |
11 Jun 08 |
jari |
print(assayNames[u]) |
720 |
11 Jun 08 |
jari |
my.data<-Log2matrix[which(cloneInfo$chromosome==workingChrom),u] #ternary data sorted. |
720 |
11 Jun 08 |
jari |
my.info<-cloneInfo[which(cloneInfo$chromosome==workingChrom),] |
720 |
11 Jun 08 |
jari |
36 |
|
720 |
11 Jun 08 |
jari |
## separate data into p-arm and q-arm, then run each arm independently for gain and losses |
720 |
11 Jun 08 |
jari |
p.indexes<-grep("p",my.info$cytoBand) |
720 |
11 Jun 08 |
jari |
q.indexes<-grep("q",my.info$cytoBand) |
720 |
11 Jun 08 |
jari |
40 |
## |
720 |
11 Jun 08 |
jari |
41 |
|
720 |
11 Jun 08 |
jari |
## check length of the p.indexes and q.indexes !!! >0 . Bundling not a problem! |
720 |
11 Jun 08 |
jari |
if(length(p.indexes)>0){ |
720 |
11 Jun 08 |
jari |
x1<-c(-99,my.data[p.indexes]) |
720 |
11 Jun 08 |
jari |
x2<-c(my.data[p.indexes],-99) |
720 |
11 Jun 08 |
jari |
z<- x2-x1 #all non-zero values in z corresponds to the breakpoints in the profile |
720 |
11 Jun 08 |
jari |
non.zero.z<-which(z !=0) #all breakpoints as c(start1,start2,start3,...,length(data.subset)+1) |
720 |
11 Jun 08 |
jari |
48 |
|
720 |
11 Jun 08 |
jari |
start.i<-non.zero.z[1:length(non.zero.z)-1] |
720 |
11 Jun 08 |
jari |
stop.i<-non.zero.z-1 |
720 |
11 Jun 08 |
jari |
stop.i<-stop.i[-c(1)] |
720 |
11 Jun 08 |
jari |
status<-my.data[start.i] #all changes |
720 |
11 Jun 08 |
jari |
53 |
|
720 |
11 Jun 08 |
jari |
ii.g<-which(status==1) |
720 |
11 Jun 08 |
jari |
ii.l<-which(status== -1) |
720 |
11 Jun 08 |
jari |
56 |
|
720 |
11 Jun 08 |
jari |
57 |
######## |
720 |
11 Jun 08 |
jari |
## write the start stop for the altered states one at a time in a file for each sample |
720 |
11 Jun 08 |
jari |
59 |
|
720 |
11 Jun 08 |
jari |
60 |
} |
720 |
11 Jun 08 |
jari |
if(length(q.indexes)>0){ |
720 |
11 Jun 08 |
jari |
x1<-c(-99,my.data[p.indexes]) |
720 |
11 Jun 08 |
jari |
x2<-c(my.data[p.indexes],-99) |
720 |
11 Jun 08 |
jari |
z<- x2-x1 #all non-zero values in z corresponds to the breakpoints in the profile |
720 |
11 Jun 08 |
jari |
non.zero.z<-which(z !=0) #all breakpoints as c(start1,start2,start3,...,length(data.subset)+1) |
720 |
11 Jun 08 |
jari |
66 |
|
720 |
11 Jun 08 |
jari |
start.i<-non.zero.z[1:length(non.zero.z)-1] |
720 |
11 Jun 08 |
jari |
stop.i<-non.zero.z-1 |
720 |
11 Jun 08 |
jari |
stop.i<-stop.i[-c(1)] |
720 |
11 Jun 08 |
jari |
status<-my.data[start.i] #all changes |
720 |
11 Jun 08 |
jari |
71 |
|
720 |
11 Jun 08 |
jari |
ii.g<-which(status==1) |
720 |
11 Jun 08 |
jari |
ii.l<-which(status== -1) |
720 |
11 Jun 08 |
jari |
74 |
} |
720 |
11 Jun 08 |
jari |
75 |
|
720 |
11 Jun 08 |
jari |
76 |
|
720 |
11 Jun 08 |
jari |
#print end resultat to file |
720 |
11 Jun 08 |
jari |
78 |
|
720 |
11 Jun 08 |
jari |
79 |
} |
720 |
11 Jun 08 |
jari |
80 |
} |
720 |
11 Jun 08 |
jari |
81 |
|