R/AssemblyStats.R

Defines functions N90 N50 NXX

Documented in N50 N90

### -----------------------------------------------------------------
### N50 calculation for a assembly
### Exported!
NXX <- function(filepath, XX=50){
  if(file_ext(filepath) == "2bit"){
    lengths <- seqlengths(TwoBitFile(filepath))
  }else if(file_ext(filepath) %in% c("fa", "fasta")){
    lengths <- fasta.seqlengths(filepath)
  }else{
    stop("The suffix can only be .2bit, .fa, .fasta!")
  }
  lengths <- as.numeric(sort(lengths, decreasing=TRUE))
  index <- which(cumsum(lengths) / sum(lengths) >= XX/100)[1]
  return(lengths[index])
}

N50 <- function(fn){
  return(NXX(fn, XX=50))
}

N90 <- function(fn){
  return(NXX(fn, XX=90))
}

Try the CNEr package in your browser

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

CNEr documentation built on Nov. 8, 2020, 5:36 p.m.