R/misc.R

Defines functions N50

Documented in N50

### Some miscellaneous stuff

N50 <- function(csizes)
{
    if (!is.numeric(csizes))
        stop("'csizes' must be a vector containing the contig sizes")
    #If only integer, then genome size maxes out at 2.1Gbp, so coerce to double:
    if(is.integer(csizes))
        csizes <- as.numeric(csizes)
    decreasing_csizes <- sort(csizes, decreasing=TRUE)
    tmp <- cumsum(decreasing_csizes)
    total_size <- tmp[length(tmp)]
    N50 <- decreasing_csizes[which(tmp >= total_size/2)[1]]
    return(N50)
}

Try the Biostrings package in your browser

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

Biostrings documentation built on Nov. 8, 2020, 11:12 p.m.