gene_exon_transcript_count: VM_QC_correlations_only_expressed_genes.R

File VM_QC_correlations_only_expressed_genes.R, 1.7 KB (added by rick, 10 years ago)
Line 
1RNA=read.table('/virdir/Backup/run_1_gene_counts/combined_gene_count_run_1.txt',sep='\t',header=TRUE)
2# save(RNA,file='/virdir/Backup/run_1_gene_counts/combined_gene_count_run_1_R_object')
3# load('/virdir/Backup/run_1_gene_counts/combined_gene_count_run_1_R_object')
4
5## get # zero counts per genes
6
7ind=which(RNA==0,arr.ind = TRUE)
8h=hist(ind[,1],breaks=0:dim(RNA)[1],plot=FALSE)
9nz=h$counts # for each gene, # samples with zero counts
10
11 length(which(nz==0))
12[1] 3
13 length(which(nz==1))
14[1] 326
15 length(which(nz==2))
16[1] 15692
17
18RNA_0=RNA[which(nz==2),]
19
20## get IDs amsterdam sample
21
22id=as.character(read.table('/home/rjansen/NTR_ID_mapping.txt',sep='\t')[,2])
23m=match(id,colnames(RNA));length(which(is.na(m)))
24
25RNA_0_A = RNA_0[,m]  # Amsterdam samples
26
27
28## spearman  correlation
29
30Cs=cor(RNA_0,method='spearman')
31mCs= apply(Cs, 2, median,na.rm = TRUE)
32mCsa=mCs[m] # Amsterdam
33mCsna=mCs[setdiff(1:length(mCs),m)] # non Amsterdam
34
35# Within a-dam:
36Cs=cor(RNA_0_A,method='spearman')
37mCsa_w = apply(Cs, 2, median)
38
39t.test(mCsna,mCsa)
40t.test(mCsna,mCsa_w)
41
42
43png('Histogram_Mean_correlations_A-dam_non_A-dam_Spear_0_within')
44hist(mCsa_w,30, col="blue",freq=FALSE,xlim=c(0.8,1),xlab='Spearman correlations, for Amsterdam computed only within Amsterdam ',main='')
45hist(mCsna,300, col='#FF000080' ,add=TRUE,transparant=1,freq=FALSE)
46legend('top',c('A-dam','Non A-dam'),bty='n',fill=c("blue",'#FF000080'))
47dev.off()
48
49
50png('Histogram_Mean_correlations_A-dam_non_A-dam_Spear_0')
51hist(mCsa,30, col="blue",freq=FALSE,xlim=c(0.8,1),xlab='Spearman correlations',main='')
52hist(mCsna,300, col='#FF000080' ,add=TRUE,transparant=1,freq=FALSE)
53legend('top',c('A-dam','Non A-dam'),bty='n',fill=c("blue",'#FF000080'))
54dev.off()