Skip to contents

[Experimental]

The correlate() method can calculate the correlation matrix between the sample vectors of counts from a specified assay. This produces a HermesDataCor object, which is an extension of a matrix with additional quality flags in the slot flag_data (containing the tech_failure_flag and low_depth_flag columns describing the original input samples).

An autoplot() method then afterwards can produce the corresponding heatmap.

Usage

# S4 method for class 'AnyHermesData'
correlate(object, assay_name = "counts", method = "pearson", ...)

# S4 method for class 'HermesDataCor'
autoplot(
  object,
  flag_colors = c(`FALSE` = "green", `TRUE` = "red"),
  cor_colors = circlize::colorRamp2(c(0, 0.5, 1), c("red", "yellow", "green")),
  ...
)

Arguments

object

(AnyHermesData)
object to calculate the correlation.

assay_name

(string)
the name of the assay to use.

method

(string)
the correlation method, see stats::cor() for details.

...

other arguments to be passed to ComplexHeatmap::Heatmap().

flag_colors

(named character)
a vector that specifies the colors for TRUE and FALSE flag values.

cor_colors

(function)
color scale function for the correlation values in the heatmap, produced by circlize::colorRamp2().

Value

A HermesDataCor object.

Functions

  • autoplot(HermesDataCor): This autoplot() method uses the ComplexHeatmap::Heatmap() function to plot the correlations between samples saved in a HermesDataCor object.

Examples

object <- hermes_data

# Calculate the sample correlation matrix.
correlate(object)
#> An object of class "HermesDataCor"
#>                06520011B0023R 06520067C0018R 06520063C0043R 06520105C0017R
#> 06520011B0023R      1.0000000      0.9609738      0.6473003      0.3904017
#> 06520067C0018R      0.9609738      1.0000000      0.6758462      0.4167789
#> 06520063C0043R      0.6473003      0.6758462      1.0000000      0.7742640
#> 06520105C0017R      0.3904017      0.4167789      0.7742640      1.0000000
#> 06520092C0017R      0.6633748      0.6604377      0.6113716      0.4520703
#> 06520103C0017R      0.9079581      0.8775734      0.5978126      0.4172803
#> 06520001B0023R      0.8818454      0.8570700      0.6658466      0.5111085
#> 06520022C0017R      0.9117386      0.9142934      0.8104461      0.6131335
#> 06520062C0017R      0.6753364      0.7157011      0.8896542      0.7652040
#> 06520046C0018R      0.3208473      0.3148823      0.4431801      0.3814626
#> 06520101B0017R      0.9314543      0.9041533      0.6417565      0.4319133
#> 06520047C0017R      0.6815391      0.6707660      0.5759576      0.4652142
#> 06520024B0014R      0.5835149      0.5819907      0.6588440      0.5231136
#> 06520080B0023R      0.5168947      0.5524994      0.8949026      0.8217901
#> 06520093C0017R      0.4138013      0.4497814      0.7953623      0.7202175
#> 06520070C0018R      0.4697837      0.5046432      0.8295754      0.8553639
#> 06520023C0018R      0.4033409      0.4404680      0.8266231      0.8575140
#> 06520099B0017R      0.4224672      0.4766716      0.7936238      0.6681055
#> 06520015C0016R      0.8093514      0.8036729      0.7640655      0.6482306
#> 06520019C0023R      0.6139914      0.6389785      0.8583166      0.8280060
#>                06520092C0017R 06520103C0017R 06520001B0023R 06520022C0017R
#> 06520011B0023R      0.6633748      0.9079581      0.8818454      0.9117386
#> 06520067C0018R      0.6604377      0.8775734      0.8570700      0.9142934
#> 06520063C0043R      0.6113716      0.5978126      0.6658466      0.8104461
#> 06520105C0017R      0.4520703      0.4172803      0.5111085      0.6131335
#> 06520092C0017R      1.0000000      0.7033489      0.6871754      0.7101840
#> 06520103C0017R      0.7033489      1.0000000      0.9863276      0.9000953
#> 06520001B0023R      0.6871754      0.9863276      1.0000000      0.9227436
#> 06520022C0017R      0.7101840      0.9000953      0.9227436      1.0000000
#> 06520062C0017R      0.5895186      0.5725651      0.6362937      0.8010688
#> 06520046C0018R      0.2638231      0.1279450      0.1317451      0.3080865
#> 06520101B0017R      0.7254041      0.9743803      0.9576231      0.9137366
#> 06520047C0017R      0.5043505      0.5349226      0.5188468      0.6281087
#> 06520024B0014R      0.4709462      0.4768380      0.5041802      0.6294704
#> 06520080B0023R      0.5609389      0.4894940      0.5836644      0.7307929
#> 06520093C0017R      0.6241234      0.4080609      0.4799501      0.6398497
#> 06520070C0018R      0.5547028      0.5587841      0.6561649      0.7291685
#> 06520023C0018R      0.5100178      0.4636074      0.5662647      0.6677198
#> 06520099B0017R      0.5000248      0.3018044      0.3613744      0.5875554
#> 06520015C0016R      0.6949487      0.9262604      0.9682275      0.9302252
#> 06520019C0023R      0.6235283      0.6475062      0.7162892      0.8016153
#>                06520062C0017R 06520046C0018R 06520101B0017R 06520047C0017R
#> 06520011B0023R      0.6753364      0.3208473      0.9314543      0.6815391
#> 06520067C0018R      0.7157011      0.3148823      0.9041533      0.6707660
#> 06520063C0043R      0.8896542      0.4431801      0.6417565      0.5759576
#> 06520105C0017R      0.7652040      0.3814626      0.4319133      0.4652142
#> 06520092C0017R      0.5895186      0.2638231      0.7254041      0.5043505
#> 06520103C0017R      0.5725651      0.1279450      0.9743803      0.5349226
#> 06520001B0023R      0.6362937      0.1317451      0.9576231      0.5188468
#> 06520022C0017R      0.8010688      0.3080865      0.9137366      0.6281087
#> 06520062C0017R      1.0000000      0.4747608      0.6236545      0.6631752
#> 06520046C0018R      0.4747608      1.0000000      0.2381617      0.7655772
#> 06520101B0017R      0.6236545      0.2381617      1.0000000      0.6128255
#> 06520047C0017R      0.6631752      0.7655772      0.6128255      1.0000000
#> 06520024B0014R      0.6813321      0.4423075      0.5302252      0.5880107
#> 06520080B0023R      0.8997510      0.4212484      0.5343559      0.5282159
#> 06520093C0017R      0.7530101      0.3954200      0.5019182      0.4276193
#> 06520070C0018R      0.8248334      0.3424986      0.5564180      0.4850496
#> 06520023C0018R      0.8045479      0.4105629      0.4729066      0.5008448
#> 06520099B0017R      0.7839665      0.5424584      0.4246231      0.5237444
#> 06520015C0016R      0.7306067      0.1605127      0.8992993      0.5037995
#> 06520019C0023R      0.8610609      0.4903751      0.6754787      0.6867600
#>                06520024B0014R 06520080B0023R 06520093C0017R 06520070C0018R
#> 06520011B0023R      0.5835149      0.5168947      0.4138013      0.4697837
#> 06520067C0018R      0.5819907      0.5524994      0.4497814      0.5046432
#> 06520063C0043R      0.6588440      0.8949026      0.7953623      0.8295754
#> 06520105C0017R      0.5231136      0.8217901      0.7202175      0.8553639
#> 06520092C0017R      0.4709462      0.5609389      0.6241234      0.5547028
#> 06520103C0017R      0.4768380      0.4894940      0.4080609      0.5587841
#> 06520001B0023R      0.5041802      0.5836644      0.4799501      0.6561649
#> 06520022C0017R      0.6294704      0.7307929      0.6398497      0.7291685
#> 06520062C0017R      0.6813321      0.8997510      0.7530101      0.8248334
#> 06520046C0018R      0.4423075      0.4212484      0.3954200      0.3424986
#> 06520101B0017R      0.5302252      0.5343559      0.5019182      0.5564180
#> 06520047C0017R      0.5880107      0.5282159      0.4276193      0.4850496
#> 06520024B0014R      1.0000000      0.6059874      0.5317071      0.5407754
#> 06520080B0023R      0.6059874      1.0000000      0.8384252      0.8961184
#> 06520093C0017R      0.5317071      0.8384252      1.0000000      0.7933036
#> 06520070C0018R      0.5407754      0.8961184      0.7933036      1.0000000
#> 06520023C0018R      0.5403914      0.8941102      0.8082247      0.9658703
#> 06520099B0017R      0.5677268      0.8092670      0.8884675      0.6897805
#> 06520015C0016R      0.5410291      0.7177895      0.6165727      0.8088963
#> 06520019C0023R      0.6251164      0.8780061      0.7894097      0.9381035
#>                06520023C0018R 06520099B0017R 06520015C0016R 06520019C0023R
#> 06520011B0023R      0.4033409      0.4224672      0.8093514      0.6139914
#> 06520067C0018R      0.4404680      0.4766716      0.8036729      0.6389785
#> 06520063C0043R      0.8266231      0.7936238      0.7640655      0.8583166
#> 06520105C0017R      0.8575140      0.6681055      0.6482306      0.8280060
#> 06520092C0017R      0.5100178      0.5000248      0.6949487      0.6235283
#> 06520103C0017R      0.4636074      0.3018044      0.9262604      0.6475062
#> 06520001B0023R      0.5662647      0.3613744      0.9682275      0.7162892
#> 06520022C0017R      0.6677198      0.5875554      0.9302252      0.8016153
#> 06520062C0017R      0.8045479      0.7839665      0.7306067      0.8610609
#> 06520046C0018R      0.4105629      0.5424584      0.1605127      0.4903751
#> 06520101B0017R      0.4729066      0.4246231      0.8992993      0.6754787
#> 06520047C0017R      0.5008448      0.5237444      0.5037995      0.6867600
#> 06520024B0014R      0.5403914      0.5677268      0.5410291      0.6251164
#> 06520080B0023R      0.8941102      0.8092670      0.7177895      0.8780061
#> 06520093C0017R      0.8082247      0.8884675      0.6165727      0.7894097
#> 06520070C0018R      0.9658703      0.6897805      0.8088963      0.9381035
#> 06520023C0018R      1.0000000      0.7296291      0.7286448      0.9323267
#> 06520099B0017R      0.7296291      1.0000000      0.4846711      0.7380609
#> 06520015C0016R      0.7286448      0.4846711      1.0000000      0.8240416
#> 06520019C0023R      0.9323267      0.7380609      0.8240416      1.0000000
#> Slot "flag_data":
#> DataFrame with 20 rows and 2 columns
#>                tech_failure_flag low_depth_flag
#>                        <logical>      <logical>
#> 06520011B0023R             FALSE          FALSE
#> 06520067C0018R             FALSE          FALSE
#> 06520063C0043R             FALSE           TRUE
#> 06520105C0017R             FALSE          FALSE
#> 06520092C0017R             FALSE          FALSE
#> ...                          ...            ...
#> 06520070C0018R             FALSE          FALSE
#> 06520023C0018R             FALSE          FALSE
#> 06520099B0017R             FALSE          FALSE
#> 06520015C0016R             FALSE          FALSE
#> 06520019C0023R             FALSE          FALSE
#> 

# We can specify another correlation coefficient to be calculated.
result <- correlate(object, method = "spearman")

# Plot the correlation matrix.
autoplot(result)


# We can customize the heatmap.
autoplot(result, show_column_names = FALSE, show_row_names = FALSE)


# Including changing the axis label text size.
autoplot(
  result,
  row_names_gp = grid::gpar(fontsize = 8),
  column_names_gp = grid::gpar(fontsize = 8)
)