R/AAStringSet-functions.R

Defines functions readAAStringSet

##' .readAAStringSet
##' Same as Biostrings::readAAStringSet but adds some more metadata to mcols
##' @param filenames fasta filenames
##' @param ... further Arguments passed to Biostrings::readAAStringSet
##' @return AAStringSet
##' @noRd
.readAAStringSet <- function(filenames, ...) {
    isExistingFile <- file.exists(filenames)

    if (any(!isExistingFile)) {
      stop("The file(s) ", paste0(sQuote(filenames[!isExistingFile]),
                                  collapse = ","), " do(es) not exist!")
    }

    ## readAAStringSet can handle multiple input files but we want to know which
    ## entry belongs to which file (and this information is not stored).
    aa <- lapply(filenames, readAAStringSet, ...)
    filenames <- Rle(factor(filenames), lengths = lengths(aa))

    aa <- do.call(c, aa)
    aa <- .addFastaInformation2mcol(aa, fastacomments = names(aa),
                                    filenames = filenames)

    ## we reorder the new Proteins object by the seqnames (AccessionNumber)
    names(aa) <- mcols(aa)$AccessionNumber
    aa <- aa[order(names(aa))]
    aa
}

Try the Pbase package in your browser

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

Pbase documentation built on Nov. 17, 2017, 9:03 a.m.