Yes, was just generating an answer myself. That function should work for Python.
Here is another way in R Programming Language, and some proof:
log2fcs <- c(2, -2, 4, -4)
ifelse(log2fcs > 0, 2 ^ log2fcs, -1 / (2 ^ log2fcs))
[1] 4 -4 16 -16
If you want to ignore negative values in the linear fold change altogether, and are happy with fractions, then use:
ifelse(log2fcs > 0, 2 ^ log2fcs, 1 / (2 ^ abs(log2fcs)))
[1] 4.0000 0.2500 16.0000 0.0625
log2(0.0625)
[1] -4
log2(0.25)
[1] -2
• 0 views
•
link