-
Notifications
You must be signed in to change notification settings - Fork 0
/
write_rnk.r
23 lines (22 loc) · 973 Bytes
/
write_rnk.r
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
write_rnk = function(data = xx, filename="", pvalue.cutoff=1){
tmp = data;
tmp[tmp$symbol != '' & !is.na(tmp$log2FoldChange) & !is.na(tmp$pvalue) & tmp$pvalue < pvalue.cutoff, ] -> tmp;
tmp$gsea = sign(tmp$log2FoldChange) * (- log10(tmp$pvalue))
tmp = tmp[order(tmp$pvalue),]
#strsplit(as.character(tmp[,1]), "///") -> tt;
#lapply(tt, length) -> tt.len;
#unlist(tt.len) -> tt.len;
#Map(function(x,y){rep(x,each=y)}, tmp[,2], tt.len) -> xx;
#unlist(xx) -> xx;
#data.frame(tt = unlist(tt), xx) -> tmp2;
duplicated(tmp[,"symbol"]) -> dup;
tmp2 = tmp[!dup,];
if(is.infinite(tmp2$gsea[1])){
top = tmp2$gsea[is.infinite(tmp2$gsea)]
mm = max(abs(tmp2$gsea[!is.infinite(tmp2$gsea)])) +1
top_seq = seq(from = mm, by = 1, length.out = length(top))
top_seq = top_seq * sign(tmp$log2FoldChange[length(top):1])
tmp2$gsea[is.infinite(tmp2$gsea)] = top_seq
}
write.table(tmp2[,c("symbol", "gsea")], file=filename, quote=F, sep="\t", row.names=F, col.names=F);
}