WES_CNV_stat.r.bak 1.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455
  1. args<- commandArgs(TRUE)
  2. sam <- args[1]
  3. sam_data <- read.table(file=paste(sam,".cov",sep=""),header = TRUE,sep="\t",as.is=TRUE)
  4. ncols<-dim(sam_data)[2]
  5. if (ncols ==5 ) {
  6. sam_data <- sam_data[,c(1,5)]
  7. }else if (ncols ==10 ) {
  8. sam_data <- sam_data[,c(1,7)]
  9. }else{
  10. q(save = FALSE)
  11. }
  12. names(sam_data) <- c('contig',sam)
  13. sam_m <- mean(sam_data[,2])
  14. sam_sd<- sd(sam_data[,2])
  15. vals<-sam_data[,sam]
  16. vals=vals/sam_m
  17. vals[vals < 0.07] <- 0.07
  18. sam_data$Mean <- vals
  19. Y_median<-fivenum(sam_data[sam_data$contig=='Y',sam])[3]
  20. fivenum(sam_data[sam_data$contig=='Y',sam])
  21. y_mean <- mean(sam_data[sam_data$contig=='Y','Mean'])
  22. y_mean
  23. sex <- 'F'
  24. if(y_mean > 0.5){
  25. sex <- 'M'
  26. }
  27. pdf(file=paste(sam,sex,"QC_plot.pdf",sep="_"),width = 10)
  28. hist(sam_data[,sam],breaks=1000,xlim=c(0,500),col='lightblue',
  29. xlab='Counts',main=paste(sam,' Counts/Bin. Mean= ',
  30. round(sam_m,0),' SD=',round(sam_sd,0),sep=''),freq = F)
  31. hist(sam_data[,'Mean'],breaks=1000,xlim=c(0,3),col='lightblue',
  32. xlab='Copy-Ratio',main=paste(sam,' Bin Copy-Ratio Distributions',sep=''),freq = F)
  33. hist(sam_data[sam_data$contig =='X' |sam_data$contig =='Y',sam],breaks=1000,xlim=c(0,500),col='lightblue',
  34. xlab='Counts',main=paste(sam,' XY Counts/Bin. Mean= ',
  35. round(sam_m,0),' SD=',round(sam_sd,0),sep=''),freq = F)
  36. hist(sam_data[sam_data$contig =='X' |sam_data$contig =='Y','Mean'],breaks=1000,xlim=c(0,3),col='lightblue',
  37. xlab='Copy-Ratio',main=paste(sam,' XY Bin Copy-Ratio Distributions',sep=''),freq = F)
  38. boxplot(sam_data[,sam] ~ ordered(sam_data$contig,levels=c(1:22,'X','Y')),ylim=c(0,500),
  39. main=paste(sam,'-Boxplot of Counts/Bin. Mean=',round(sam_m,0),
  40. 'SD/Mean=',round(sam_sd/sam_m,2),sep=' ') )
  41. lines(rep(sam_m,24),col='red')
  42. boxplot(sam_data[,'Mean'] ~ ordered(sam_data$contig,levels=c(1:22,'X','Y')),ylim=c(0,3),
  43. main=paste(sam,'-Boxplot of Copy-Ratio.',sep=' '))
  44. lines(rep(1,24),col='red')
  45. dev.off()