Extract genes with highest loadings

hi_loadings(
  pcaobj,
  whichpc = 1,
  topN = 10,
  exprTable = NULL,
  annotation = NULL,
  title = "Top/bottom loadings"
)

Arguments

pcaobj

A prcomp object

whichpc

An integer number, corresponding to the principal component of interest

topN

Integer, number of genes with top and bottom loadings

exprTable

A matrix object, e.g. the counts of a DESeq2::DESeqDataSet(). If not NULL, returns the counts matrix for the selected genes

annotation

A data.frame object, with row.names as gene identifiers (e.g. ENSEMBL ids) and a column, gene_name, containing e.g. HGNC-based gene symbols

title

The title of the plot

Value

A ggplot2 object, or a matrix, if exprTable is not null

Examples

dds <- makeExampleDESeqDataSet_multifac(betaSD = 3, betaSD_tissue = 1)
rlt <- DESeq2::rlogTransformation(dds)
pcaobj <- prcomp(t(SummarizedExperiment::assay(rlt)))
hi_loadings(pcaobj, topN = 20)

hi_loadings(pcaobj, topN = 10, exprTable = dds)
#> class: DESeqDataSet 
#> dim: 20 12 
#> metadata(1): version
#> assays(1): counts
#> rownames(20): gene581 gene426 ... gene115 gene280
#> rowData names(4): trueIntercept trueBeta_condition trueBeta_tissue
#>   trueDisp
#> colnames(12): sample1 sample2 ... sample11 sample12
#> colData names(2): condition tissue
hi_loadings(pcaobj, topN = 10, exprTable = counts(dds))
#>         sample1 sample2 sample3 sample4 sample5 sample6 sample7 sample8 sample9
#> gene581       1       9       6      18      13       3     651     393    1936
#> gene426      10      21       0      27      38      36    5112     795    2181
#> gene853      27      36      19     116     200      60    6906    3141    4588
#> gene171       6      35      49      16      58      31   10801    6918   10332
#> gene904      13      14      13      45      19       8    6564    4084    1688
#> gene498      33      25      25      10      32      20    8275    6536    8335
#> gene251       5       7       4       8       1      11    5941    3281    1098
#> gene901       1       7       2       2       2       1    1946    1029    2166
#> gene330      23      56      11       9       7       4    6884   17151    5819
#> gene179      11      18      17       4       5       1    5566    3776    3417
#> gene695      69     113     212      66      99     108       0       1       0
#> gene731     100      87     109      65     195     157       0       2       0
#> gene283      90      81      88     102     134     217       0       1       2
#> gene208     131     130     154     108      76     155       0       0       1
#> gene497      68      59      94     226     213     142       1       1       0
#> gene374      73      85     156      86     127      67       2       0       0
#> gene245      48      77      78     376     554     275       2       1       2
#> gene709      49      48      29      85      63     202       2       1       0
#> gene115      63      49      72      57      12      23       0       2       0
#> gene280      35      17      59      68      84      69       0       1       1
#>         sample10 sample11 sample12
#> gene581      852     1349     1960
#> gene426     2947     2934     5641
#> gene853    21473    43639    26752
#> gene171    11320    11922     5176
#> gene904     5193    10201    10899
#> gene498     8388     8675    14914
#> gene251     3145     2443     1077
#> gene901     1991      643      419
#> gene330     4038     7566     2040
#> gene179     3222     2816     2721
#> gene695        0        1        1
#> gene731        1        2        0
#> gene283        0        0        5
#> gene208        2        1        6
#> gene497        8        0        4
#> gene374        1        1        6
#> gene245        8        6        2
#> gene709        3        1        0
#> gene115        0        0        0
#> gene280        1        1        0