Created
May 4, 2018 01:33
-
-
Save swsoyee/ab1be7dea8b9dd29c74e5da3f35a4c8f to your computer and use it in GitHub Desktop.
Input a RowCount data frame and group label vector, return a data frame of MA value.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| calMAValue <- function(data, data.cl){ | |
| group <- levels(factor(data.cl)) | |
| if (length(group) == 2) { | |
| #遺伝子ごとにG1群とG2の平均の対数を計算した結果 | |
| mean_G1 <- log2(apply(as.matrix(data[,data.cl==group[1]]), 1, mean)) | |
| mean_G2 <- log2(apply(as.matrix(data[,data.cl==group[2]]), 1, mean)) | |
| #「G1群の平均値」と「G2群の平均値」の平均をとったものがM-A plotのA(x軸の値)に相当する | |
| x_axis <- (mean_G1 + mean_G2)/2 | |
| #いわゆるlog比(logの世界での引き算)がM-A plotのM(y軸の値)に相当する | |
| y_axis <- mean_G2 - mean_G1 | |
| result <- data.frame('gene_id'=rownames(data), | |
| "a.value"=x_axis, | |
| "m.value"=y_axis) | |
| return(result) | |
| } else { | |
| stop("This function can not deal with multiple groups data now.") | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment