R/similarities.R

#' @include aaa.R
#' @include pgFull.R
#' @include pgLM.R
NULL

#' @describeIn kmerSimilarity Kmer based similarities for pgVirtual subclasses
#' 
#' @param lowMem logical. Should low memory footprint be ensured over 
#' computation speed
#' 
#' @param kmerSize The size of kmers to use for similarity calculations.
#' 
#' @param lowerLimit The lower threshold for similarity below which it is set to
#' 0
#' 
#' @param rescale Should Similarities be normalised between lowerLimit and 1
#' 
#' @param transform Transformation function to apply to similarities
#' 
#' @param pParam An optional BiocParallelParam object that defines the workers 
#' used for parallelisation.
#' 
#' @importFrom kebabs spectrumKernel getExRep linearKernel
#' @importFrom BiocParallel SerialParam bpnworkers
#' 
setMethod(
    'kmerSimilarity', 'pgVirtual',
    function(object, lowMem, kmerSize, lowerLimit, rescale, transform, pParam) {
        .fillDefaults(defaults(object))
        
        if (lowMem) {
            if (missing(pParam)) {
                pParam <- SerialParam()
                nSplits <- nOrganisms(object)
            } else {
                nSplits <- bpnworkers(pParam)
            }
            res <- lkParallelLM(object, kmerSize, pParam, nSplits, 
                                lowerLimit = lowerLimit)
        } else {
            kernel <- spectrumKernel(kmerSize)
            er <- getExRep(genes(object), kernel, sparse = TRUE)
            if (missing(pParam)) {
                res <- linearKernel(er, sparse = TRUE, diag = FALSE, 
                                    lowerLimit = lowerLimit)
            } else {
                res <- lkParallel(er, pParam, bpnworkers(pParam), 
                                  lowerLimit = lowerLimit)
            }
        }
        transformSim(res, lowerLimit, rescale, transform)
    }
)

Try the FindMyFriends package in your browser

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

FindMyFriends documentation built on Nov. 8, 2020, 6:46 p.m.