Skip to content

Commit

Permalink
current scripts
Browse files Browse the repository at this point in the history
  • Loading branch information
valeu committed Jun 7, 2017
1 parent c376126 commit d4c2a9f
Show file tree
Hide file tree
Showing 4 changed files with 329 additions and 37 deletions.
59 changes: 59 additions & 0 deletions scripts/_makeGraph_Chromosome.R
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
args <- commandArgs()

dataTable <-read.table(args[6], header=TRUE);
print( paste (args[6],"read"))
ratio<-data.frame(dataTable)
chr <- type.convert(args[4])
#chr <- 'X'
ploidy <- type.convert(args[5])

maxLevelToPlot <- 3
for (i in c(1:length(ratio$Ratio))) {
if (ratio$Ratio[i]>maxLevelToPlot) {
ratio$Ratio[i]=maxLevelToPlot;
}
}

png(filename = paste(args[6],".png",sep = ""), width = 1180, height = 1180,
units = "px", pointsize = 20, bg = "white", res = NA)
plot(1:10)
op <- par(mfrow = c(2,1))
i <- chr
tt <- which(ratio$Chromosome == i)
if (length(tt)>0) {
plot(ratio$Start[tt],ratio$Ratio[tt]*ploidy,ylim = c(0,maxLevelToPlot*ploidy),xlab = paste ("position, chr",i),ylab = "normalized copy number profile",pch = ".",col = colors()[88],cex=2)
tt <- which(ratio$Chromosome==i & ratio$CopyNumber>ploidy )
points(ratio$Start[tt],ratio$Ratio[tt]*ploidy,pch = ".",col = colors()[136],cex=2)
tt <- which(ratio$Chromosome==i & ratio$Ratio==maxLevelToPlot)
points(ratio$Start[tt],ratio$Ratio[tt]*ploidy,pch = ".",col = colors()[136],cex=4)
tt <- which(ratio$Chromosome==i & ratio$CopyNumber<ploidy )
points(ratio$Start[tt],ratio$Ratio[tt]*ploidy,pch = ".",col = colors()[461],cex=2)
tt <- which(ratio$Chromosome==i)
points(ratio$Start[tt],ratio$CopyNumber[tt], pch = ".", col = colors()[24],cex=2)
points(ratio$Start[tt],ratio$MedianRatio[tt]*ploidy, pch = ".", col = colors()[98],cex=4)
}
if (length(args)>=7) {
dataTable <-read.table(args[7], header=TRUE);
BAF<-data.frame(dataTable)
tt <- which(BAF$Chromosome==i)
lBAF <-BAF[tt,]
plot(lBAF$Position,lBAF$BAF,ylim = c(-0.1,1.1),xlab = paste ("position, chr",i),ylab = "BAF",pch = ".",col = colors()[1])
tt <- which(lBAF$A==0.5)
points(lBAF$Position[tt],lBAF$BAF[tt],pch = ".",col = colors()[92])
tt <- which(lBAF$A!=0.5 & lBAF$A>=0)
points(lBAF$Position[tt],lBAF$BAF[tt],pch = ".",col = colors()[450])
tt <- which(lBAF$B==1)
points(lBAF$Position[tt],lBAF$BAF[tt],pch = ".",col = colors()[62])
tt <- 1
pres <- 1
for (j in c(2:(length(lBAF$A)-pres-1))) {
if (lBAF$A[j]==lBAF$A[j+pres]) {
tt[length(tt)+1] <- j
}
}
points(lBAF$Position[tt],lBAF$A[tt],pch = ".",col = colors()[24],cex=4)
points(lBAF$Position[tt],lBAF$B[tt],pch = ".",col = colors()[24],cex=4)
print( paste (args[7],"read"))
}
dev.off()

35 changes: 35 additions & 0 deletions scripts/makeGraph.R
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,38 @@ dataTable <-read.table(args[5], header=TRUE);
ratio<-data.frame(dataTable)
ploidy <- type.convert(args[4])


png(filename = paste(args[5],".log2.png",sep = ""), width = 1180, height = 1180,
units = "px", pointsize = 20, bg = "white", res = NA)
plot(1:10)
op <- par(mfrow = c(5,5))

for (i in c(1:22,'X','Y')) {
tt <- which(ratio$Chromosome==i)
if (length(tt)>0) {
plot(ratio$Start[tt],log2(ratio$Ratio[tt]),xlab = paste ("position, chr",i),ylab = "normalized copy number profile (log2)",pch = ".",col = colors()[88])
tt <- which(ratio$Chromosome==i & ratio$CopyNumber>ploidy )
points(ratio$Start[tt],log2(ratio$Ratio[tt]),pch = ".",col = colors()[136])


tt <- which(ratio$Chromosome==i & ratio$CopyNumber<ploidy & ratio$CopyNumber!= -1)
points(ratio$Start[tt],log2(ratio$Ratio[tt]),pch = ".",col = colors()[461])
tt <- which(ratio$Chromosome==i)

#UNCOMMENT HERE TO SEE THE PREDICTED COPY NUMBER LEVEL:
#points(ratio$Start[tt],log2(ratio$CopyNumber[tt]/ploidy), pch = ".", col = colors()[24],cex=4)

}
tt <- which(ratio$Chromosome==i)

#UNCOMMENT HERE TO SEE THE EVALUATED MEDIAN LEVEL PER SEGMENT:
#points(ratio$Start[tt],log2(ratio$MedianRatio[tt]), pch = ".", col = colors()[463],cex=4)

}

dev.off()


png(filename = paste(args[5],".png",sep = ""), width = 1180, height = 1180,
units = "px", pointsize = 20, bg = "white", res = NA)
plot(1:10)
Expand Down Expand Up @@ -45,6 +77,9 @@ for (i in c(1:22,'X','Y')) {

dev.off()




if (length(args)>5) {
dataTable <-read.table(args[6], header=TRUE);
BAF<-data.frame(dataTable)
Expand Down
134 changes: 134 additions & 0 deletions scripts/makeGraph.R~
Original file line number Diff line number Diff line change
@@ -0,0 +1,134 @@
args <- commandArgs()

dataTable <-read.table(args[5], header=TRUE);

ratio<-data.frame(dataTable)
ploidy <- type.convert(args[4])


png(filename = paste(args[5],".log2.png",sep = ""), width = 1180, height = 1180,
units = "px", pointsize = 20, bg = "white", res = NA)
plot(1:10)
op <- par(mfrow = c(5,5))

for (i in c(1:22,'X','Y')) {
tt <- which(ratio$Chromosome==i)
if (length(tt)>0) {
plot(ratio$Start[tt],log2(ratio$Ratio[tt]),xlab = paste ("position, chr",i),ylab = "normalized copy number profile (log2)",pch = ".",col = colors()[88])
tt <- which(ratio$Chromosome==i & ratio$CopyNumber>ploidy )
points(ratio$Start[tt],log2(ratio$Ratio[tt]),pch = ".",col = colors()[136])

tt <- which(ratio$Chromosome==i & ratio$Ratio==maxLevelToPlot & ratio$CopyNumber>ploidy)
points(ratio$Start[tt],log2(ratio$Ratio[tt]),pch = ".",col = colors()[136],cex=4)

tt <- which(ratio$Chromosome==i & ratio$CopyNumber<ploidy & ratio$CopyNumber!= -1)
points(ratio$Start[tt],log2(ratio$Ratio[tt]),pch = ".",col = colors()[461])
tt <- which(ratio$Chromosome==i)

#UNCOMMENT HERE TO SEE THE PREDICTED COPY NUMBER LEVEL:
#points(ratio$Start[tt],log2(ratio$CopyNumber[tt]/ploidy), pch = ".", col = colors()[24],cex=4)

}
tt <- which(ratio$Chromosome==i)

#UNCOMMENT HERE TO SEE THE EVALUATED MEDIAN LEVEL PER SEGMENT:
#points(ratio$Start[tt],log2(ratio$MedianRatio[tt]), pch = ".", col = colors()[463],cex=4)

}

dev.off()


png(filename = paste(args[5],".png",sep = ""), width = 1180, height = 1180,
units = "px", pointsize = 20, bg = "white", res = NA)
plot(1:10)
op <- par(mfrow = c(5,5))

maxLevelToPlot <- 3
for (i in c(1:length(ratio$Ratio))) {
if (ratio$Ratio[i]>maxLevelToPlot) {
ratio$Ratio[i]=maxLevelToPlot;
}
}


for (i in c(1:22,'X','Y')) {
tt <- which(ratio$Chromosome==i)
if (length(tt)>0) {
plot(ratio$Start[tt],ratio$Ratio[tt]*ploidy,ylim = c(0,maxLevelToPlot*ploidy),xlab = paste ("position, chr",i),ylab = "normalized copy number profile",pch = ".",col = colors()[88])
tt <- which(ratio$Chromosome==i & ratio$CopyNumber>ploidy )
points(ratio$Start[tt],ratio$Ratio[tt]*ploidy,pch = ".",col = colors()[136])

tt <- which(ratio$Chromosome==i & ratio$Ratio==maxLevelToPlot & ratio$CopyNumber>ploidy)
points(ratio$Start[tt],ratio$Ratio[tt]*ploidy,pch = ".",col = colors()[136],cex=4)

tt <- which(ratio$Chromosome==i & ratio$CopyNumber<ploidy & ratio$CopyNumber!= -1)
points(ratio$Start[tt],ratio$Ratio[tt]*ploidy,pch = ".",col = colors()[461])
tt <- which(ratio$Chromosome==i)

#UNCOMMENT HERE TO SEE THE PREDICTED COPY NUMBER LEVEL:
#points(ratio$Start[tt],ratio$CopyNumber[tt], pch = ".", col = colors()[24],cex=4)

}
tt <- which(ratio$Chromosome==i)

#UNCOMMENT HERE TO SEE THE EVALUATED MEDIAN LEVEL PER SEGMENT:
#points(ratio$Start[tt],ratio$MedianRatio[tt]*ploidy, pch = ".", col = colors()[463],cex=4)

}

dev.off()




if (length(args)>5) {
dataTable <-read.table(args[6], header=TRUE);
BAF<-data.frame(dataTable)

png(filename = paste(args[6],".png",sep = ""), width = 1180, height = 1180,
units = "px", pointsize = 20, bg = "white", res = NA)
plot(1:10)
op <- par(mfrow = c(5,5))

for (i in c(1:22,'X','Y')) {
tt <- which(BAF$Chromosome==i)
if (length(tt)>0){
lBAF <-BAF[tt,]
plot(lBAF$Position,lBAF$BAF,ylim = c(-0.1,1.1),xlab = paste ("position, chr",i),ylab = "BAF",pch = ".",col = colors()[1])

tt <- which(lBAF$A==0.5)
points(lBAF$Position[tt],lBAF$BAF[tt],pch = ".",col = colors()[92])
tt <- which(lBAF$A!=0.5 & lBAF$A>=0)
points(lBAF$Position[tt],lBAF$BAF[tt],pch = ".",col = colors()[62])
tt <- 1
pres <- 1

if (length(lBAF$A)>4) {
for (j in c(2:(length(lBAF$A)-pres-1))) {
if (lBAF$A[j]==lBAF$A[j+pres]) {
tt[length(tt)+1] <- j
}
}
points(lBAF$Position[tt],lBAF$A[tt],pch = ".",col = colors()[24],cex=4)
points(lBAF$Position[tt],lBAF$B[tt],pch = ".",col = colors()[24],cex=4)
}

tt <- 1
pres <- 1
if (length(lBAF$FittedA)>4) {
for (j in c(2:(length(lBAF$FittedA)-pres-1))) {
if (lBAF$FittedA[j]==lBAF$FittedA[j+pres]) {
tt[length(tt)+1] <- j
}
}
points(lBAF$Position[tt],lBAF$FittedA[tt],pch = ".",col = colors()[463],cex=4)
points(lBAF$Position[tt],lBAF$FittedB[tt],pch = ".",col = colors()[463],cex=4)
}

}

}
dev.off()

}
138 changes: 101 additions & 37 deletions scripts/makeGraph_Chromosome.R
Original file line number Diff line number Diff line change
@@ -1,48 +1,112 @@
args <- commandArgs()

dataTable <-read.table(args[6], header=TRUE);
print( paste (args[6],"read"))
path = "/data/tmp/cgurjao/Graphical_outputs/R\ scripts/FREEC_7.4/Single-end"
setwd(path)

args = c()
args[8] = 0
args[7] = 0
args[6] = "ratios_0.txt"
args[5] = 2
args[4] = 1

dataTable <-read.table(args[6], header=T, na.strings="NA");
print(paste (args[6],"read"))
ratio<-data.frame(dataTable)
chr <- type.convert(args[4])
#chr <- 'X'
ploidy <- type.convert(args[5])
ploidy <- type.convert(args[5])
CN_subc = ratio$Subclones

maxLevelToPlot <- 3
for (i in c(1:length(ratio$Ratio))) {
if (ratio$Ratio[i]>maxLevelToPlot) {
ratio$Ratio[i]=maxLevelToPlot;
}
}
max_value = 10#max(ratio$CopyNumber)

png(filename = paste(args[6],".png",sep = ""), width = 1180, height = 1180,
units = "px", pointsize = 20, bg = "white", res = NA)
plot(1:10)
op <- par(mfrow = c(2,1))
i <- chr
tt <- which(ratio$Chromosome == i)
if (length(tt)>0) {
plot(ratio$Start[tt],ratio$Ratio[tt]*ploidy,ylim = c(0,maxLevelToPlot*ploidy),xlab = paste ("position, chr",i),ylab = "normalized copy number profile",pch = ".",col = colors()[88],cex=2)
tt <- which(ratio$Chromosome==i & ratio$CopyNumber>ploidy )
points(ratio$Start[tt],ratio$Ratio[tt]*ploidy,pch = ".",col = colors()[136],cex=2)
tt <- which(ratio$Chromosome==i & ratio$Ratio==maxLevelToPlot)
points(ratio$Start[tt],ratio$Ratio[tt]*ploidy,pch = ".",col = colors()[136],cex=4)
tt <- which(ratio$Chromosome==i & ratio$CopyNumber<ploidy )
points(ratio$Start[tt],ratio$Ratio[tt]*ploidy,pch = ".",col = colors()[461],cex=2)
tt <- which(ratio$Chromosome==i)
points(ratio$Start[tt],ratio$CopyNumber[tt], pch = ".", col = colors()[24],cex=2)
points(ratio$Start[tt],ratio$MedianRatio[tt]*ploidy, pch = ".", col = colors()[98],cex=4)
}
if (length(args)>=7) {
dataTable <-read.table(args[7], header=TRUE);
plot(1:10)
even_odd = 0
even_odd2 = 0
par(mfrow = c(2,1))
for (i in c(1:11))
{
png(filename = paste(path, "/Results/","chr", i,".png",sep = ""), width = 1180, height = 1180,
units = "px", pointsize = 20, bg = "white", res = NA)
tt <- which(ratio$Chromosome==i)
if (length(tt)>0) {
tt <- which(ratio$Chromosome==i & ratio$CopyNumber==ploidy )
plot(ratio$Start[tt],ratio$Ratio[tt]*ploidy,ylim = c(0,max_value),xlab = paste ("position, chr",i),ylab = "normalized copy number profile",pch = ".",col = rgb(0,1,0, alpha = 0.2),cex=8)
tt <- which(ratio$Chromosome==i & ratio$CopyNumber>ploidy )
points(ratio$Start[tt],ratio$Ratio[tt]*ploidy,pch = ".",col = rgb(1,0,0, alpha = 0.2),cex=8)
tt <- which(ratio$Chromosome==i & ratio$CopyNumber<ploidy )
points(ratio$Start[tt],ratio$Ratio[tt]*ploidy,pch = ".",col = rgb(0,0,1, alpha = 0.2),cex=8)
tt <- which(ratio$Chromosome==i)
points(ratio$Start[tt],ratio$CopyNumber[tt], pch = ".", col = colors()[24],cex=8)
tt <- which(ratio$Chromosome==i)
for (k in c(1:length(levels(CN_subc))))
{
if (levels(CN_subc)[k] != "0/0" && length(CN_subc) > 0)
{
ttt <- which(ratio$Subclones == levels(CN_subc)[k] & ratio$Chromosome==i)
if (length(ttt)>0)
{
j = 1
CN = ''
pop = ''
while (substr(as.character(ratio$Subclones[ttt]),j,j)[1] != "/")
{
CN = paste(CN,substr(as.character(ratio$Subclones[ttt]),j,j))
j = j+1
}
j = 9
while (substr(as.character(ratio$Subclones[ttt]),j,j)[1] != "/" )
{
pop[j] = paste(pop,substr(as.character(ratio$Subclones[ttt]),j,j))
j = j-1
}

x = NA
y = NA
if (round(length(ttt)/2) > 0 && (-ratio$Start[ttt[1]] + ratio$Start[ttt[length(ttt)-1]]) > 10000000 )
{
if (even_odd %% 2 == 0) #(ratio$CopyNumber[ttt][round(length(ttt)/2)] > as.numeric(gsub(" ", "",CN[1])))
{
points(ratio$Start[ttt],CN, pch = ".", col = colors()[99],cex=8)
if (even_odd2 %% 2 == 0)
{x = as.numeric(ratio$Start[ttt][round(length(ttt)/3)])
y = as.numeric(CN[1]) - 0.25
even_odd2 = even_odd2 + 1}
else
{x = as.numeric(ratio$Start[ttt][round(length(ttt)/3)])
y = as.numeric(CN[1]) + 0.25
even_odd2 = even_odd2 + 1}
even_odd = even_odd +1
}
else
{
points(ratio$Start[ttt],CN, pch = ".", col = colors()[96],cex=8)
if (even_odd2 %% 2 != 0)
{
x = as.numeric(ratio$Start[ttt][round(length(ttt)/3)])
y = as.numeric(CN[1]) + 0.25
even_odd2 = even_odd2 + 1}
else
{x = as.numeric(ratio$Start[ttt][round(length(ttt)/3)])
y = as.numeric(CN[1]) - 0.25
even_odd2 = even_odd2 + 1}
even_odd = even_odd +1
}
}
pop = as.numeric(gsub("NA", "",gsub(",","",gsub(' ',"", toString(pop))))) * 100;
pop = paste(as.character(as.integer(pop)),"%")
text(x, y, as.character(pop), cex = 0.8, col = 'black')
}
}
}
}

if (args[7] != 0) {
dataTable <-read.table(args[7], header=TRUE);
BAF<-data.frame(dataTable)
tt <- which(BAF$Chromosome==i)
lBAF <-BAF[tt,]
plot(lBAF$Position,lBAF$BAF,ylim = c(-0.1,1.1),xlab = paste ("position, chr",i),ylab = "BAF",pch = ".",col = colors()[1])
lBAF <-BAF[tt,]
plot(lBAF$Position,lBAF$BAF, ylim = c(-0.1,1.1),xlab = paste ("position, chr",i),ylab = "BAF",pch = ".",col = colors()[1])
tt <- which(lBAF$A==0.5)
points(lBAF$Position[tt],lBAF$BAF[tt],pch = ".",col = colors()[92])
tt <- which(lBAF$A!=0.5 & lBAF$A>=0)
points(lBAF$Position[tt],lBAF$BAF[tt],pch = ".",col = colors()[450])
tt <- which(lBAF$B==1)
points(lBAF$Position[tt],lBAF$BAF[tt],pch = ".",col = colors()[62])
tt <- 1
pres <- 1
Expand All @@ -56,4 +120,4 @@ if (length(args)>=7) {
print( paste (args[7],"read"))
}
dev.off()

}

0 comments on commit d4c2a9f

Please sign in to comment.