This is a test version of Biostars. For the public version, visit https://www.biostars.org.
Extracting differentially expressed genes in R

Hi,

I know it is too naive but when I tried to extract genes with fold-change >2.0 or <0.5 alterations I faced error.

I tried so

results <- t[which(abs(t$logFC) > 1 & t$adj.P.Val < 0.05),]

This gives me only fold-change >2.0 , then how I add fold-change < 0.5 to this code please??

Thank you

r software error rna-seq gene

Try if following works:

> subset(t, adj.P.Val<0.05 & abs(logFC)>2.0| abs(logFC)<0.5)

I am not sure if it is good to filter the genes by statistical significance and fc at the same time.

Sorry, do you mean I should first filter for statistical significance and then FC or vice versa instead of performing both at the same time????

Thank you, you are saving me from re-performing because today morning I had completed filtering based on both

2 answers

Thank you so much,

Always helpful quickly. happy new year to you and biostars.

Thank you, in Iran we don't celebrate Christmas!! our holiday is in March (Iranian New Year) but I know that nowadays there is holiday most parts of the world. Hope you and all health and happiness in 2018.

Just a comment, be careful while using filters on logFC vs FC. If you just want to filter on FC, you need to convert that to appropriate log value while filtering.

Sorry, because I want to extract genes with Fold Change > 2 then I must extract genes with logFC > 1. I hope I am not wrong

Thank you, with this head of my data

ID  adj.P.Val   P.Value logFC   Gene.symbol
201289_at   6.95E-11    1.27E-15    -5.94112291 CYR61
202768_at   2.43E-09    1.01E-13    -6.95512411 FOSB
209189_at   2.43E-09    1.33E-13    -5.22397202 FOS
201694_s_at 4.67E-09    3.42E-13    -4.0543598  EGR1
210764_s_at 5.41E-09    4.95E-13    -6.53075681 CYR61
201041_s_at 4.39E-07    5.35E-11    -2.45413476 DUSP1
227404_s_at 4.39E-07    5.63E-11    -4.47587421 EGR1
223316_at   1.94E-06    2.83E-10    -4.59230998 CCDC3
201693_s_at 2.42E-06    3.98E-10    -3.41023566 EGR1
220276_at   5.81E-06    1.06E-09    -5.13632928 RERGL
201466_s_at 9.97E-06    2.01E-09    -2.08223261 JUN
222162_s_at 1.48E-05    3.25E-09    -4.94468905 ADAMTS1

In your code I just replace 2.0 with 1.0 to get Fold Change

t[which(abs(t$logFC>1.0 & t$adj.P.Val<0.05) | (t$logFC<0.25 & t$adj.P.Val<0.05)), ]

Moreover, I tried statistical significance and Fold Change at the same time and step by step, this is number of genes;

At_the_same_time=t[which(abs(t$logFC>1.0 & t$adj.P.Val<0.05) | (t$logFC<0.25 & t$adj.P.Val<0.05)), ]

Step-By_Step=subset(t, adj.P.Val<0.05)

Step-By_Step=subset(Step-By_Step,abs(logFC)>1.0| abs(logFC)<0.25)

at the same time produced 2656 genes VS step by step with 2382 genes

Thank you, you prevented me to do whole of work wrongly.

Actually I am just doing as mentioned in a paper so "

To identify differentially expressed genes (DEGs) in each dataset, statistical analyses were performed,
which reported statistically significant (adjusted p-value < 0.01 and fold-change >2.0 or <0.5) alterations

Thank you again for your time

Excuse me, Although weird and non-sense, I ask this question here for which I afraid to create a new post as this question sounds pretty unrelated to this forum. As much as I googled I got confused; Between research associate (grade 7 X2) and postdoctoral researcher (grade 7) which one is preferable (at the same salary)??? Thanks a lot in advance

Thanks a lot for your kind word. I am doing well. Now I understood these definitions. Thanks once again

IMO, first filter by statistical significance and then by fc. Double filtering (using both p-value and fc at the same time) in microarray analysis is contested multiple times and infact Limma toptable function (for microarray analysis) suggests not to filter by fc and p-value at the same time (https://www.rdocumentation.org/packages/limma/versions/3.28.14/topics/toptable). Double filtering (filtering by fc and p-value from statistical test simultaneous) issue is discussed clearly, way back (PMID:19995439 PMCID:PMC2801685). Here is a long discussion on this on researchgate: https://www.researchgate.net/post/FDR_or_log_fold_change_which_one_is_the_priority_for_selecting_the_DEGs. Here (https://support.bioconductor.org/p/62286/) and here (https://support.bioconductor.org/p/64787/), Gordon Smyth (from EdgeR) discourages filtering by FC and P-value simultaneously (unless I misunderstood the post) for RNAseq data and microarray data. One should be filtering (by fc) within some statistical limits (frame)

In addition, In most of the RNAseq, Exon arrays and Microarray data analysis (recently), I have seen filtering/sorting by p-values first, followed by fc. Please note that this doesn't mean that what you are doing is incorrect and should not do what you are doing. But there is enough literature to support filter the results by (adj)p-values first.

Thank you, I am working with seven independent microarray GSE series with limma top tables in my hand, now I am going to filter first by adj.P.Val then by fold change.

if you are using limma toptable function, read about treat and toptreat. Copy/pasted from toptable function:

Users wanting to use fold change thresholding are usually recommended to use treat and topTreat instead.

Thanks a lot both of you Kevin and cpad0112 for your time and considerations.

Log in to answer this question.