node_randomization =函数(path2genrev g, te, keep.random。文件= FALSE, nperm = 1000, n = NA, L = NA NA, search_d = NA, search_r = NA NA, cl = NA,输出。dir = NA,输出。RData = NA) {# # # path2generev = NA网络的初始化参数。文件= NA种子。文件= NA NA node.score方法。文件= NA walk_len = NA walk_iterN = NA shrink_d = NA mcl_status = NA如果(! is.na (g)){网络。其他文件= g}{打印(请提供 ");}如果(! is.na (te)){种子。其他文件= te}{打印(请提供 ”);}如果(! is.na (a))其他{方法=}{打印(“请指定方法,(“启发式”、“斯坦纳”,“kwalk”)”);}如果(! is.na (n)) {node.score。其他文件= n} {print(“基于node-weight随机化、节点需要分数文件!”);}如果(! is.na (L)) {walk_len = L}如果(! is.na (it)) {walk_iterN =}如果(! is.na (s)) {shrink_d = s}如果(! is.na (cl)) {mcl_status = cl} # # # cmd基本的初始化。cmd =粘贴(path2genrev、“/ GenRev”、“g”网络。文件,9 = " ")如果(! is.na (seed.file)){基本。cmd =粘贴(基本。cmd,“t”,种子。文件,9 = " ")}如果(! is.na (shrink_d)){基本。cmd =粘贴(基本。shrink_d cmd,“s”, 9 = " ")}如果(方法= = steiner){基本。cmd =粘贴(基本。cmd,“——”方法,9 = " ")}else if(方法= =“启发式”){基本。cmd =粘贴(基本。cmd,“——”方法,9 = " ")如果(! is.na (search_d)){基本。cmd =粘贴(基本。search_d cmd,“- d”, 9 = " ")}如果(! is.na (search_r)){基本。cmd =粘贴(基本。search_r cmd,“- r”, 9 = " ")}} else if(方法= =“启发式”){基本。cmd =粘贴(基本。cmd,“——”方法,9 = " ")如果(! is.na (walk_len)){基本。cmd =粘贴(基本。cmd,“- l”walk_len, 9 = " ")}如果(! is.na (walk_iterN)){基本。cmd =粘贴(基本。cmd, " -it ", walk_iterN, sep="")} } if(!is.na(mcl_status)) { basic.cmd = paste(basic.cmd, " -cl ", mcl_status, sep="") } ### cmd for real case real.cmd = paste(basic.cmd, " -n ", node.score.file, sep="") if(!is.na(output.dir)) { real.cmd = paste(real.cmd, " -o ", output.dir, sep="") if(grepl("/$", output.dir)){output.dir = substr(output.dir, 0, nchar(output.dir)-1)} ### remove "/" at the end of ourput.dir } else { output.dir = paste(getwd(), "/", format(Sys.time(), "%Y%b%d%H%M"), sep="") real.cmd = paste(real.cmd, " -o ", output.dir, sep="") } print(real.cmd) system(real.cmd) real.gene.ranks = read.table(paste(output.dir, "/gene_rank.txt", sep="")) real.gene.ranks = as.character(real.gene.ranks[,1]) ### randomization library(igraph) node.score = read.table(node.score.file) if(keep.random.file==FALSE) { random.gene.rank = list() print(paste("Warning: intermediate files of randomization results will be lost! However, randomized node score files are saved!")) for(ii in 1:nperm) { if(file.exists(paste(output.dir, "_random/", sep="")))unlink(paste(output.dir, "_random/", sep=""), recursive=T) random.node.score = data.frame(node=node.score[,1], score=sample(node.score[,2])) random.node.score.file = paste(output.dir, "/random",ii,".node.score.txt", sep="") write.table(random.node.score, file=random.node.score.file, row.names=F, col.names=F, quote=F, sep="\t") ### cmd for random case random.cmd = paste(basic.cmd, " -n ", random.node.score.file, sep="") random.output.dir = paste(output.dir, "_random/", sep="") random.cmd = paste(random.cmd, " -o ", random.output.dir, sep="") print(random.cmd) system(random.cmd) random.term = read.table(file=paste(output.dir, "_random/gene_rank.txt", sep="")) random.gene.rank[[ii]] = as.character(random.term[,1]) cat(paste("finish round ", ii, "\n", sep="")) } } else if(keep.random.file==TRUE) { print(paste("Warning: a large number of folders will be generated for randomization purpose!")) random.gene.rank = list() for(ii in 1:nperm) { if(file.exists(paste(output.dir, "_random_", ii, sep="")))unlink(paste(output.dir, "_random_", ii, sep=""), recursive=T) random.node.score = data.frame(node=node.score[,1], score=sample(node.score[,2])) random.node.score.file = paste(output.dir, "/random",ii,".node.score.txt", sep="") write.table(random.node.score, file=random.node.score.file, row.names=F, col.names=F, quote=F, sep="\t") random.cmd = paste(basic.cmd, " -n ", random.node.score.file, sep="") random.output.dir = paste(output.dir, "_random_", ii, sep="") random.cmd = paste(random.cmd, " -o ", random.output.dir, sep="") print(random.cmd) system(random.cmd) random.term = read.table(file=paste(output.dir, "_random_", ii, "/gene_rank.txt", sep="")) random.gene.rank[[ii]] = as.character(random.term[,1]) cat(paste("finish round ", ii, "\n", sep="")) } } if(is.na(output.RData)){ save(random.gene.rank, file="random.test.RData") } else { save(random.gene.rank, file=output.RData) } } #randomization(getwd(), network.file="/mnt/BSBL_2T/home/pjia/DATA/pina_symbol11242010.ppi", seed.file="Aaron/priorGenes151_pureGene.txt", method="steiner")
Baidu