Thank you for your reply. Please have look at the below and let me know your view. The code I used to join two data frames:
lines <- inner_join(results_EXT_sig_dn, reads)
Joining, by = c("chr", "start", "end")
line 5 from two tables:
results_EXT_sig_dn:
"chr" "start" "end" "logFC" "logCPM" "PValue" "FDR"
"chr22" "46897721" "46897850" "-1.74851077922428" "3.73415308103011" "0.000241053755340764" "0.00400083166912345"
reads:
"chr" "start" "end" "reads_A" "reads_B"
"chr22" "46897721" "46897850" "86" "92"
norm.factors
group A: 1.06
group B: 0.94
# code to generate normalized reads (reads multiplied with norm.factors)
lines <- mutate(lines, reads_A_s = reads_A * 1.06, reads_B_s = reads_B * 0.94)
# exactTest source code (edgeR)
abundanceA <- mglmOneGroup(y1+matrix(prior.count[j1],ntags,n1,byrow=TRUE),offset=offset.aug[j1],dispersion=dispersion)
abundanceB <- mglmOneGroup(y2+matrix(prior.count[j2],ntags,n2,byrow=TRUE),offset=offset.aug[j2],dispersion=dispersion)
logFC <- (abundanceB-abundanceA)/log(2)
The logFC calculation by exactTest uses 4 variables: dispersion, offset, prior count, and reads. Dispersion depends on BCV (0.2). Offset and prior.count values are dependent on the library size and norm.factors. Reads are as provided in the table.
I tried my code with another set of data (RNAseq with no replicates) and I did not find this anomaly. This gives me confidence that my code works. I am not able to comprehend why this anomaly is happening to certain regions in the downregulated. Other regions in the downregulated and all upregulated regions' logFC direction (positive or negative) is in coherence with the reads (more or less reads in B).