zoukankan      html  css  js  c++  java
  • 一些写R函数的技巧

    常常会写一些函数来分析Microarray。而每次使用函数所用的参数都不同,因此需要一些方法能够将每次这些不同的结果以及参数存储起来。

    首先使用一个R内置的时间函数Sys.time():

    Sys.time()
    [1] "2013-04-26 14:15:37 PDT"
    
    #这里更改设置,输出成自己喜欢的格式:
    format(Sys.time(), '_%Y_%b_%dth_%H_%M')
    [1] "_2013_Apr_26th_14_18"
    #因此,可以每次程序都能够新建一个以时间为名称的文件夹(避免重复问题) 
    dir = '/media/Research/RData/Gene_Data_Mining/'
    Gene_DIR
    = paste(dir, GeneName, format(Sys.time(), '_%Y_%b_%dth_%H_%M'),'/', sep = '')
    dir.create(Gene_DIR)
    setwd(Gene_DIR)

    接下来,使用一个sink函数,能够将该函数的参数记录下来:

    Gene_Integrate_Analysis = function(GeneName, NSF_Cut = 0.3, 
    Standardize = c('mean','none', 'median'), GO_hgCutoff = 0.001,KEGG_hgCutoff = 0.01, PFAM_hgCutoff = 0.01, QQ_Pos_Cut = 3.29, QQ_Neg_Cut = -3.29, Perm_Num = 10000, Perm_Pval_Cut = 0.001){ ...... setwd(Gene_DIR) #write the log file sink('log.txt') print(paste('Gene Name:', GeneName)) print(paste('Non-specific filtering cutoff:', NSF_Cut)) print(paste('Standardize method:', Standardize)) print(paste('GO Hypergeometric Test cutoff:', GO_hgCutoff )) print(paste('KEGG Hypergeometric Test cutoff:', KEGG_hgCutoff )) print(paste('PFAM Hypergeometric Test cutoff:', PFAM_hgCutoff )) print(paste('GSEA analysis QQ plot Positive Cutoff: ', QQ_Pos_Cut)) print(paste('GSEA analysis QQ plot Negative Cutoff: ', QQ_Neg_Cut)) print(paste('GSEA analysis Permutation Number:', Perm_Num)) print(paste('GSEA analysis Permutation Pvalue Cut:',Perm_Pval_Cut)) sink() }

    这样我们就能够把每一次运用函数的参数及其相应结果都保存下来!

  • 相关阅读:
    小工具
    git
    git如何做个人构建
    菜鸟教程
    Xftp和Xshell
    IDEA
    webStorm
    HBuilder
    chrome浏览器
    Vue-Server-Renderer
  • 原文地址:https://www.cnblogs.com/foreverycc/p/3046188.html
Copyright © 2011-2022 走看看