@@ -891,8 +891,8 @@ samprank_sep <- function(genotype_matrix,cnv_matrix,cnvtype,sample=NULL)
891891}
892892
893893# #Plot of intensities across cohorts##
894- plotJPG <- function (genotype_matrix , cnv_matrix , chr , start , end , cnvID , sampleIDs , outputname ,
895- cnvtype , plotK , plotfamily , famfile , outFolder , pad = 0 , orig_start , orig_end ) {
894+ plotJPG <- function (genotype_matrix ,cnv_matrix ,chr ,start ,end ,cnvID ,sampleIDs ,outputname ,cnvtype , plotK , plotfamily , famfile , outFolder , pad = 0 , orig_start , orig_end )
895+ {
896896 samplesPrior <- unlist(strsplit(as.character(sampleIDs )," ," ))
897897 samplenames <- colnames(genotype_matrix )
898898
@@ -924,8 +924,8 @@ plotJPG <- function(genotype_matrix, cnv_matrix, chr, start, end, cnvID, sampleI
924924
925925 # ##Add proper size abbr. for larger events
926926 size <- orig_end - orig_start
927- if (size < 10000 ) {mysize <- prettyNum(paste(" (" , size , " bp)" , sep = " " ), big.mark = " ," )}
928- else if (size < 1000000 ) {mysize <- prettyNum(paste(" (" , signif(size / 1000 , 3 ), " kb)" , sep = " " ), big.mark = " ," )}
927+ if (size < 10000 ) {mysize <- prettyNum(paste(" (" , size , " bp)" , sep = " " ), big.mark = " ," )}
928+ else if (size < 1000000 ) {mysize <- prettyNum(paste(" (" , signif(size / 1000 , 3 ), " kb)" , sep = " " ), big.mark = " ," )}
929929 else {mysize <- prettyNum(paste(" (" , signif(size / 1000000 , 3 ), " Mb)" , sep = " " ), big.mark = " ," )}
930930
931931 # #Formating##
@@ -950,6 +950,7 @@ plotJPG <- function(genotype_matrix, cnv_matrix, chr, start, end, cnvID, sampleI
950950 columnstoshift <- which(colnames(genotype_matrix ) %in% unlist(strsplit(as.character(samplesPrior ),split = " ," )))
951951 plot_colormatrix <- cbind(matrix (genotype_matrix [,- columnstoshift ],nrow = 1 ),matrix (genotype_matrix [,columnstoshift ],nrow = 1 ))
952952 endcolnormal <- ncol(plot_colormatrix )- (length(samplesPrior ))
953+ plot_linematrix <- cbind(matrix (genotype_matrix [,- columnstoshift ],nrow = 1 ),matrix (genotype_matrix [,columnstoshift ],nrow = 1 ))
953954
954955 # Determine indices for the event calls based on the original (non-padded) data
955956 event_range <- (ncol(plot_colormatrix ) - length(samplesPrior ) + 1 ): ncol(plot_colormatrix )
@@ -958,39 +959,46 @@ plotJPG <- function(genotype_matrix, cnv_matrix, chr, start, end, cnvID, sampleI
958959
959960 # #Blue if Dup; Red if Del
960961 if ( plotK == TRUE ) {
962+ # keep plot_colormatrix
961963 main1 = paste(chr ," :" ,prettyNum(start ,big.mark = " ," )," -" ,prettyNum(end ,big.mark = " ," )," (hg19)" ,sep = " " )
962964 mainText = paste(main1 , " \n " , " Copy Estimate" ," " , mysize , sep = " " )
965+ plot_linematrix [,5 : ncol(plot_linematrix )]<- " 0.5"
963966 } else if (toupper(cnvtype ) == " DEL" ) {
964- plot_colormatrix [, active_event_cols ] <- " red"
965- plot_colormatrix [, setdiff(1 : ncol(plot_colormatrix ), active_event_cols )] <- " grey"
967+ plot_colormatrix [, (endcolnormal + 1 ): ncol(plot_colormatrix )] <- " red"
968+ plot_colormatrix [,5 : endcolnormal ]<- " grey"
969+ plot_linematrix [, (endcolnormal + 1 ): ncol(plot_colormatrix )] <- " 3"
970+ plot_linematrix [,5 : endcolnormal ]<- " 0.5"
966971 } else if (toupper(cnvtype ) == " DUP" ) {
967- plot_colormatrix [, active_event_cols ] <- " blue"
968- plot_colormatrix [, setdiff(1 : ncol(plot_colormatrix ), active_event_cols )] <- " grey"
969- }
972+ plot_colormatrix [, (endcolnormal + 1 ): ncol(plot_colormatrix )] <- " blue"
973+ plot_colormatrix [,5 : endcolnormal ]<- " grey"
974+ plot_linematrix [, (endcolnormal + 1 ): ncol(plot_colormatrix )] <- " 3"
975+ plot_linematrix [,5 : endcolnormal ]<- " 0.5"
976+ }
970977
971978 # #Plotting Command##
972979 plot(as.zoo(plot_cnvmatrix ),
973- plot.type = " single" ,
974- col = " grey" ,
975- main = mainText ,
976- cex.main = maxcexXh ,
977- xlab = " Position (bp)" ,
978- xaxt = ' n' ,
979- ann = FALSE ,
980- ylab = " Intensity" ,
981- lwd = 0.5
980+ plot.type = " single" ,
981+ col = " grey" ,
982+ main = mainText ,
983+ cex.main = maxcexXh ,
984+ xlab = " Position (bp)" ,
985+ xaxt = ' n' ,
986+ ann = FALSE ,
987+ ylab = " Intensity" ,
988+ lwd = 0.5
982989 )
983990
984- # Compute plotting coordinates for the event region rectangle
985- if (missing(orig_start )) { orig_start <- start }
986- if (missing(orig_end )) { orig_end <- end }
987991 n_bins <- nrow(plot_cnvmatrix )
988- x_axis_positions <- seq(start , end , length.out = n_bins )
989- rect_index_left <- 1 + (n_bins - 1 ) * (orig_start - start ) / (end - start )
990- rect_index_right <- 1 + (n_bins - 1 ) * (orig_end - start ) / (end - start )
992+
993+ if (pad > 0 ) {
994+ # Compute plotting coordinates for the event region rectangle
995+ x_axis_positions <- seq(start , end , length.out = n_bins )
996+ rect_index_left <- 1 + (n_bins - 1 ) * (orig_start - start ) / (end - start )
997+ rect_index_right <- 1 + (n_bins - 1 ) * (orig_end - start ) / (end - start )
991998
992- # Add light blue rectangle for the event region
993- rect(rect_index_left , par(" usr" )[3 ], rect_index_right , par(" usr" )[4 ], col = adjustcolor(" azure3" , alpha.f = 0.3 ), border = NA )
999+ # Add light blue rectangle for the event region
1000+ rect(rect_index_left , par(" usr" )[3 ], rect_index_right , par(" usr" )[4 ], col = adjustcolor(" azure3" , alpha.f = 0.3 ), border = NA )
1001+ }
9941002
9951003 # Overlay the lines after the rectangle
9961004 for (j in (ncol(plot_cnvmatrix ) - length(samplesPrior ) + 1 ): ncol(plot_cnvmatrix )) {
@@ -1344,7 +1352,7 @@ runRdTest<-function(bed)
13441352 plotK = FALSE , plotfamily = FALSE , famfile , outFolder , pad = opt $ padding , orig_start = orig_start , orig_end = orig_end )
13451353 } else {
13461354 plotJPG(genotype_matrix , cnv_matrix , chr , start , end , cnvID , sampleIDs , outputname , cnvtype ,
1347- plotK = FALSE , plotfamily = FALSE , famfile , outFolder )
1355+ plotK = FALSE , plotfamily = FALSE , famfile , outFolder , orig_start = start , orig_end = end )
13481356 }
13491357 }
13501358
0 commit comments