1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950 |
- args<- commandArgs(TRUE)
- sam <- args[1]
- sam_data <- read.table(file=paste(sam,".cov",sep=""),header = FALSE,sep="\t",as.is=TRUE)
- ncols<-dim(sam_data)[2]
- if (ncols ==5 ) {
- SRY<-sam_data[ sam_data[1]=='Y' & sam_data[2]< 2700000 ,c(5)]
- sam_data <- sam_data[,c(1,5)]
- }else if (ncols ==10 ) {
- SRY<-sam_data[ sam_data[1]=='Y' & sam_data[2]< 2700000 ,c(7)]
- sam_data <- sam_data[,c(1,7)]
- }else{
- q(save = FALSE)
- }
- names(sam_data) <- c('contig',sam)
- sam_m <- median(sam_data[,2])
- sam_sd<- sd(sam_data[,2])
- sam_data$Mean <- sam_data[,sam]/sam_m
- sry_mean<-mean(SRY/sam_m)
- sex <- 'F'
- if(sry_mean > 0.04){
- sex <- 'M'
- }
- pdf(file=paste(sam,sex,"QC_plot.pdf",sep="_"),width = 10)
- hist(sam_data[,sam],breaks=1000,xlim=c(0,500),col='lightblue',
- xlab='Counts',main=paste(sam,' Counts/Bin. Mean= ',
- round(sam_m,0),' SD=',round(sam_sd,0),sep=''),freq = F)
- hist(sam_data[,'Mean'],breaks=1000,xlim=c(0,3),col='lightblue',
- xlab='Copy-Ratio',main=paste(sam,' Bin Copy-Ratio Distributions',sep=''),freq = F)
- hist(sam_data[sam_data$contig =='X' |sam_data$contig =='Y',sam],breaks=1000,xlim=c(0,500),col='lightblue',
- xlab='Counts',main=paste(sam,' XY Counts/Bin. Mean= ',
- round(sam_m,0),' SD=',round(sam_sd,0),sep=''),freq = F)
- hist(sam_data[sam_data$contig =='X' |sam_data$contig =='Y','Mean'],breaks=1000,xlim=c(0,3),col='lightblue',
- xlab='Copy-Ratio',main=paste(sam,' XY Bin Copy-Ratio Distributions',sep=''),freq = F)
- boxplot(sam_data[,sam] ~ ordered(sam_data$contig,levels=c(1:22,'X','Y')),ylim=c(0,600),
- main=paste(sam,'-Boxplot of Counts/Bin. Mean=',round(sam_m,0),
- 'SD/Mean=',round(sam_sd/sam_m,2),sep=' '),xlab="Chr",ylab="Counts" )
- lines(rep(sam_m,24),col='red')
- boxplot(sam_data[,'Mean'] ~ ordered(sam_data$contig,levels=c(1:22,'X','Y')),ylim=c(0,3),
- main=paste(sam,'-Boxplot of Copy-Ratio.SRY=',round(sry_mean,2),sep=' '),xlab="Chr",ylab="Copy-Ratio")
- lines(rep(1,24),col='red')
- dev.off()
|