R/printFunctions.R

Defines functions print.fixationPath print.indelPath print.fixationIndels print.paraFixSites print.sitePara print.parallelSites print.sitePath print.fixationSites print.sitesMinEntropy print.SNPsites print.lineagePath print.phyMSAmatched

#' @export
print.phyMSAmatched <- function(x, ...) {
    cat("This is a 'phyMSAmatched' object.\n")
}

#' @export
print.lineagePath <- function(x, ...) {
    cat(
        "This is a 'lineagePath' object.\n\n",
        length(x),
        " lineage paths using ",
        attr(x, "minSize"),
        " as \"major SNP\" threshold \n",
        sep = ""
    )
}

#' @export
print.SNPsites <- function(x, ...) {
    x <- as.integer(x)
    print(x)
}

#' @export
print.sitesMinEntropy <- function(x, ...) {
    cat("This is a 'sitesMinEntropy' object.", "\n")
}

#' @export
print.fixationSites <- function(x, ...) {
    cat("This is a 'fixationSites' object.\n\nResult for",
        length(attr(x, "paths")),
        "paths:\n\n")
    if (length(x) == 0) {
        cat("No multi-fixation found\n")
    } else {
        cat(paste(names(x), collapse = " "), "\n")
        refSeqName <- attr(x, "reference")
        if (is.null(refSeqName)) {
            cat("No reference sequence specified.",
                "Using alignment numbering\n")
        } else {
            cat("Reference sequence: ", refSeqName, "\n", sep = "")
        }
    }
}

#' @export
print.sitePath <- function(x, ...) {
    cat("Site",
        attr(x, "site"),
        "may experience fixation on",
        length(x),
        "path(s):\n\n")
    # A 'sitePath' consists of all the fixation paths for a single site. So each
    # 'm' represent a single fixation path
    for (m in x) {
        if (length(m) == 2) {
            mutName <-
                paste0(attr(m[[1]], "AA"), attr(x, "site"), attr(m[[2]], "AA"))
            cat(mutName,
                paste0("(", length(m[[1]]), "->", length(m[[2]]), ")"),
                "\n")
        } else {
            mutName <- character(0)
            for (tips in m) {
                aa <- attr(tips, "AA")
                mutName <-
                    c(mutName, paste0(aa, "(", length(tips), ")"))
            }
            cat(paste0(mutName, collapse = " -> "), "\n")
        }
    }
    cat("\nIn the bracket are the number of tips",
        "involved before and after the fixation\n")
}

#' @export
print.parallelSites <- function(x, ...) {
    cat("This is a 'parallelSites' object.\n\nResult for",
        length(attr(x, "paths")),
        "paths:\n\n")
    if (length(x) == 0) {
        cat("No parallel site found\n")
    } else {
        cat(paste(names(x), collapse = " "), "\n")
        refSeqName <- attr(x, "reference")
        if (is.null(refSeqName)) {
            cat("No reference sequence specified.",
                "Using alignment numbering\n")
        } else {
            cat("Reference sequence: ", refSeqName, "\n", sep = "")
        }
    }
}

#' @export
print.sitePara <- function(x, ...) {
    cat(
        "This is a 'sitePara' object.\n\nSite",
        attr(x, "site"),
        "may have parallel mutation on",
        length(x),
        "pair of paths:\n\n"
    )
    mutSummary <- table(vapply(
        X = extractTips.sitePara(x),
        FUN = function(mutTips) {
            attr(mutTips, "mutName")[4]
        },
        FUN.VALUE = character(1)
    ))
    mutInfo <- character()
    for (mutName in names(mutSummary)) {
        mutInfo <-
            c(mutInfo, paste0(mutName, "(", mutSummary[[mutName]], ")"))
    }
    cat(
        paste0(mutInfo, collapse = ", "),
        "\n\nIn the bracket are the number of tips",
        "involved in the mutation\n"
    )
}

#' @export
print.paraFixSites <- function(x, ...) {
    sites <- as.integer(x)
    if (length(sites)) {
        print(sites)
    } else {
        cat("No qualified sites found.\n")
    }
}

#' @export
print.fixationIndels <- function(x, ...) {
    cat("This is a 'fixationIndels' object.\n\nResult for",
        length(attr(x, "paths")),
        "paths:\n\n")
    if (length(x) == 0) {
        cat("No multi-fixation found\n")
    } else {
        cat(paste(names(x), collapse = " "), "\n")
        refSeqName <- attr(x, "reference")
        if (is.null(refSeqName)) {
            cat("No reference sequence specified.",
                "Using alignment numbering\n")
        } else {
            cat("Reference sequence: ", refSeqName, "\n", sep = "")
        }
    }
}

#' @export
print.indelPath <- function(x, ...) {
    cat("Site(s)",
        attr(x, "indelSites"),
        "may experience fixation on",
        length(x),
        "group(s) of tips:\n\n")
    for (i in x) {
        cat("(", length(i), ") ", sep = "")
    }
    cat("\nIn the bracket are the number of tips",
        "involved in the fixation\n")
}

#' @export
print.fixationPath <- function(x, ...) {
    print(names(x))
}

Try the sitePath package in your browser

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

sitePath documentation built on April 17, 2021, 6:05 p.m.