R/sampP.R

sampP = function(tree, cell.line) {
    if (cell.line == TRUE) {
        P = tree$P
        colchange = sample.int(1, n = ncol(P))
        for (j in colchange) {
            rowchange = sample(2:nrow(P), 2)
            temp = sum(P[rowchange, j]) * 1000
            P[rowchange, j] = rmultinom(1, temp, prob = runif(length(rowchange), 
                0, 1))/1000
        }
        P = round(P, 3)
        if (ncol(P) == 1) {
            P[nrow(P), ] = 1 - colSums(as.matrix(P[1:(nrow(P) - 1), , drop = FALSE]))
        } else {
            P[nrow(P), ] = 1 - colSums(P[1:(nrow(P) - 1), , drop = FALSE])
        }
    } else if (cell.line == FALSE) {
        P = tree$P
        colchange = sample.int(1, n = ncol(P))
        for (j in colchange) {
            rowchange = sample(1:nrow(P), 2)
            temp = sum(P[rowchange, j]) * 1000
            P[rowchange, j] = rmultinom(1, temp, prob = runif(length(rowchange), 
                0, 1))/1000
        }
        P = round(P, 3)
        if (ncol(P) == 1) {
            P[nrow(P), ] = 1 - colSums(as.matrix(P[1:(nrow(P) - 1), , drop = FALSE]))
        } else {
            P[nrow(P), ] = 1 - colSums(P[1:(nrow(P) - 1), , drop = FALSE])
        }
    }
    return(P)
} 

Try the Canopy package in your browser

Any scripts or data that you put into this service are public.

Canopy documentation built on May 1, 2019, 7:59 p.m.