I generated a DBA object with multiple distinct contrasts, all with differentially accessible peaks. I want to generate a data frame with all these peaks and fold changes to plot a fold change x fold change plot for 2 of the contrasts.
dat <- dba.contrast(dat, group1=dat$masks$CON.treated, group2=dat$masks$CON.saline, name1="CON.TRT", name2="CON.SAL")
dat <- dba.contrast(dat, group1=dat$masks$EXP.treated, group2=dat$masks$EXP.saline, name1="EXP.TRT", name2="EXP.SAL")
dat <- dba.analyze(dat, bSubControl = FALSE)
dat
dbSites <- dba.report(dat, bDB=TRUE)
In the dbSites$binding
I get the consensus peaks of both contrasts with the fold change. (also in dbSites$peaks
)
CHR START END CON.TRT_vs_CON.SAL EXP.TRT_vs_EXP.SAL
1 7395534 7395831 0.82 0.87
1 9547934 9548310 0.94 1.48
1 10105145 10105502 0.87 0.00
However, these are the absolute value of the fold change abs(rep$Fold)
head(dbSites$peaks[[1]])
Chr Start End abs(rep$Fold)
22 chr1 7395534 7395831 0.82
26 chr1 9547934 9548310 0.94
54 chr1 10105145 10105502 0.87
63 chr1 13153172 13153547 0.63
How can I get the Fold change with sign for direction? I ultimately would like to plot(dbSites$peaks[[1]]$abs(rep$Fold), dbSites$peaks[[2]]$abs(rep$Fold)
but with the correct directions.
Thanks for your fast reply, Rory! The ordering is not accurate even with the sort function so the plot makes an X shape which is not right. I think it is sorting the GRanges on the seqnames but not consistently between the 2 contrasts. (Contrast 1 starts with chr4 and ends with chr10, Contrast 2 starts with chr1 and ends with chrX). So the peak information on each row isn't the same between the 2 contrasts in the
consSites
. I found a work around. It is not as elegant as your 5 lines, but I think this works. I forgot aboutth=1
that made things easier and converted to dataframes withDataType = DBA_DATA_FRAME
, and luckily therow.names
are consistent across both contrasts. Yeah!Looks good! I tested my script on the sample data which only has one chromosome, so I missed this issue. I had considered merging by
row.name
, but I was trying to do it in fewer lines.It looks like you have a good idea of what is going on now!