I have log2 transformed gene expression data set.

        Condition1-A Condition1-B Condition1-A Condition1-B Condition1-A  Condition2-B Condition2-B  Condition2-A   Condition2-A  Condition2-A 
    G1  7.208092    6.750469    8.075674    7.013972    7.449042    7.171538    6.978883    6.952459    7.151522    7.279471
    G2  3.0738758   1.9639700   2.5514604   2.5976361   1.9519020   2.9587819   0.9509838   1.3255526   3.2792520   2.4635816
    G3  -3.292569   -3.144790   1.540046    -3.596165   -3.584326   -3.204754   -3.293944   1.372275    -3.421160   -3.022793
    G4  5.935161    5.486081    5.441551    5.629999    5.265330    5.526397    5.353094    5.236713    5.404589    5.780409
    G5  5.105139    5.219205    4.789138    5.304543    5.033632    5.236399    5.367262    5.017811    4.819554    4.609520
    G6  2.610378    2.390324    3.307976    2.589459    2.670613    1.651612    2.806704    -3.319884   1.309417    2.552799

There are two groups A and B from two different conditions Condition1 and Condition2.

I want to identify those genes that are differentially expressed between A and B in condition1 but these genes should not be differentially expressed in condition2 or should be oppositely regulated in condition2 compared to condition1.

I tried different contrasts like : Condition1(A-B) - Condition2(A-B) using limma package in R. But this constrast is not working and instead giving me those genes that are differentially expressed between two groups (A-B) in both the conditions.

Is there a method by which I can achieve the problem mentioned above? Any help is very much appreciated. Thanks.

Edited : I used the model : Condition + Group + Group*Condition

Group : A and B

Condition : 1 and 2

The contrast that I was using was : Condition1.GroupA-Condition1.GroupB - Condition2.GroupA-Condition2.GroupB The contrast :


Code :

des <- model.matrix(0 ~ Condition*Group)
fit2<-contrasts.fit(fit,contrasts = c(0,0,-1,0))

topgenes <- topTable(fit2, coef=c(1:2), adjust="fdr", sort.by="B", number=Inf)
  • 1
    $\begingroup$ What is your question? Eg, I don't see a "?" anywhere. $\endgroup$ Commented May 12, 2016 at 11:15
  • $\begingroup$ Edited the question...rather asked the question :) . Thanks. $\endgroup$ Commented May 12, 2016 at 11:19
  • $\begingroup$ Could you explain why you have 3 columns of Condition1-A and Condition2-A, but two columns of Condition1-B and Condition2-B. It may be helpful to also show the code you tried using limma. $\endgroup$
    – Randel
    Commented May 16, 2016 at 15:11
  • $\begingroup$ Actually I have three replicates each for Condition1-GroupA, Condition2-GroupA and Condition1-GroupB and Condition2-GroupB. Last two columns might have been missed while copy pasting. Sorry about that. $\endgroup$ Commented May 17, 2016 at 4:25
  • $\begingroup$ Is A and B two different groups of people? Do G1...G6 means six different genes? Why do you have three columns for each condition-group combination, what do these three columns mean? $\endgroup$
    – user31264
    Commented May 20, 2016 at 1:53

1 Answer 1


I'm not sure that any single contrast will accomplish what you want. Why not just address directly the requirements that you specify?

First, determine all the genes differentially expressed, under condition 1, between groups A and B. Call that group GeneSet1. Then determine which of those genes are differentially expressed, in the same directions between groups A and B, under condition 2. Call that GeneSet2. Remove from GeneSet1 all the genes in GeneSet2. You are then left with the genes that meet your specification: differentially expressed in condition 1 but not differentially expressed or differential in the opposite direction under condition 2.

You should in any event double-check how you specify the model matrix and the contrasts in the limma package, following examples in the vignettes or other references. It's been several years since I've tried to use that package, but at first glance it seems that your "contrast" doesn't do anything besides provide the negative of gene-expression values under condition 2 versus condition 1. It doesn't seem to take the Groups into account at all.

  • $\begingroup$ But how do you propose I should remove the genes from GeneSet1 all the genes in GeneSet2? I don't want to use set intersection. $\endgroup$ Commented May 23, 2016 at 11:30
  • $\begingroup$ What's the problem with removing the set intersection from GeneSet1? That seems to be what you are asking for: "genes that are differentially expressed between A and B in condition1 but these genes should not be differentially expressed in condition2 or should be oppositely regulated in condition2 compared to condition1." $\endgroup$
    – EdM
    Commented May 23, 2016 at 12:06
  • $\begingroup$ If I use set interstion that I might loose on genes that are there significant in both GeneSet1 and GeneSet2 but with opposite direction. Also, how will I determine the statistical significance using set intersection method(e.g using setdiff() function in R) ?? $\endgroup$ Commented May 23, 2016 at 12:22
  • $\begingroup$ All the genes you start in with GeneSet1 are "significant" at the specified fdr; you are simply removing some "significant" genes from further consideration. I would work with dataframes returned by topTable directly rather than using setdiff. Start with the table for GeneSet1, with gene names as rownames. Then obtain the topTable for genes differentially expressed in Condition 2. For each rowname of the GeneSet1 table, look in the second table, and delete its row from the GeneSet1 table if the gene appears in the second table with the same sign in both logFC columns. $\endgroup$
    – EdM
    Commented May 23, 2016 at 15:19

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.