BridgeRNormalization: Normalize relative RPKM (0h = 1)

Description Usage Arguments Details Value Note Author(s) References Examples

View source: R/Z4_normalization.r

Description

Normalize relative RPKM (0h = 1)

Usage

1
BridgeRNormalization(filename, group, hour, InforColumn = 4, SelectNormFactor = T, NormFactor = "BridgeR_3_Normalizaion_factor_dataset", OutputFile = "BridgeR_4_Normalized_expression_data.txt")

Arguments

filename

File path/name

group

Vector(string)

hour

Vector(number)

InforColumn

Integer

SelectNormFactor

Bool(True or False)

NormFactor

File path/name

OutputFile

File path/name

Details

Normalize relative RPKM (0h = 1)

Value

text file

Note

2015-11-05

Author(s)

Naoto Imamachi

References

https://github.com/Naoto-Imamachi/BRIC-seq_data_analysis/tree/master/BridgeR

Examples

  1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
##---- Should be DIRECTLY executable !! ----
##-- ==>  Define data, use random,
##--	or do  help(data=index)  for the standard data sets.
#inputfile <- "BridgeR_1_Relative_expression_dataset.txt"
#nf <- "BridgeR_3_Normalizaion_factor"
#outputfile <- "BridgeR_4_Normalized_expression_dataset.txt"
#group <- c("Control","knockdown1","knockdown2")
#hour <- c(0,1,2,4,8,12)

#BridgeRNormalization(filename=inputfile, group=group, hour=hour, NormFactor=nf, OutputFile=outputfile)

## The function is currently defined as
function (filename, group, hour, InforColumn = 4, SelectNormFactor = T, 
    NormFactor = "BridgeR_3_Normalizaion_factor_dataset", OutputFile = "BridgeR_4_Normalized_expression_data.txt") 
{
    group_number <- length(group)
    time_points <- length(hour)
    nf_st <- 2
    nf_ed <- time_points + 1
    nf_99 <- NULL
    nf_95 <- NULL
    for (a in 1:group_number) {
        NormFactor_name <- paste(NormFactor, "_", group[a], ".txt", 
            sep = "")
        normalization_factor <- fread(NormFactor_name, header = T)[, 
            nf_st:nf_ed, with = F]
        if (is.null(nf_99) && is.null(nf_95)) {
            nf_99 <- as.vector(as.matrix(normalization_factor[1, 
                ]))
            nf_95 <- as.vector(as.matrix(normalization_factor[2, 
                ]))
        }
        else {
            nf_99 <- append(nf_99, as.vector(as.matrix(normalization_factor[1, 
                ])))
            nf_95 <- append(nf_95, as.vector(as.matrix(normalization_factor[2, 
                ])))
        }
    }
    input_file <- fread(filename, header = T)
    output_file <- OutputFile
    cat("", file = output_file)
    hour_label <- NULL
    for (a in 1:group_number) {
        if (!is.null(hour_label)) {
            cat("\t", file = output_file, append = T)
        }
        hour_label <- NULL
        for (x in hour) {
            label <- x
            if (x < 10) {
                label <- paste("0", x, sep = "")
            }
            hour_label <- append(hour_label, paste("T", label, 
                "_", a, sep = ""))
        }
        infor_st <- 1 + (a - 1) * (time_points + InforColumn)
        infor_ed <- (InforColumn) * a + (a - 1) * time_points
        infor <- colnames(input_file)[infor_st:infor_ed]
        cat(infor, hour_label, sep = "\t", file = output_file, 
            append = T)
    }
    cat("\n", sep = "", file = output_file, append = T)
    gene_number <- length(input_file[[1]])
    for (x in 1:gene_number) {
        data <- as.vector(as.matrix(input_file[x, ]))
        for (a in 1:group_number) {
            if (a != 1) {
                cat("\t", sep = "", file = output_file, append = T)
            }
            infor_st <- 1 + (a - 1) * (time_points + InforColumn)
            infor_ed <- (InforColumn) * a + (a - 1) * time_points
            exp_st <- infor_ed + 1
            exp_ed <- infor_ed + time_points
            gene_infor <- data[infor_st:infor_ed]
            exp <- as.numeric(data[exp_st:exp_ed])
            nf_99_st <- (time_points) * (a - 1) + 1
            nf_99_ed <- (time_points) * a
            nf_99_exp <- nf_99[nf_99_st:nf_99_ed]
            nf_95_st <- (time_points) * (a - 1) + 1
            nf_95_ed <- (time_points) * a
            nf_95_exp <- nf_95[nf_95_st:nf_95_ed]
            normalized_exp <- NULL
            if (SelectNormFactor == TRUE) {
                if (exp[2] >= nf_95_exp[2] & exp[3] >= nf_95_exp[3]) {
                  normalized_exp <- exp/nf_99_exp
                }
                else {
                  normalized_exp <- exp/nf_95_exp
                }
            }
            else {
                normalized_exp <- exp/nf_95_exp
            }
            cat(gene_infor, sep = "\t", file = output_file, append = T)
            cat("\t", sep = "\t", file = output_file, append = T)
            cat(normalized_exp, sep = "\t", file = output_file, 
                append = T)
        }
        cat("\n", sep = "\t", file = output_file, append = T)
    }
  }

Naoto-Imamachi/BridgeR documentation built on May 7, 2019, 6:05 p.m.