install.packages("pacman")
## Installing package into '/cloud/lib/x86_64-pc-linux-gnu-library/4.3'
## (as 'lib' is unspecified)
library("pacman")
p_load("pheatmap", #crear los Heatmaps
"RColorBrewer",
"ggplot2",
"dplyr",
"vroom",
"FactoMineR", #analisis de componentes prncipales
"factoextra", #graficar los componentes principales
"tibble")
llamar a la base de datos
Datos_PCR <- vroom::vroom("https://raw.githubusercontent.com/ManuelLaraMVZ/Heatmaps/refs/heads/main/miRNA_qPCR_Ct_Data_20g.csv")
## Rows: 22 Columns: 10
## ── Column specification ────────────────────────────────────────────────────────
## Delimiter: ","
## chr (2): Gene, Condition
## dbl (8): Control_1, Control_2, Control_3, Control_4, Tratamiento_1, Tratamie...
##
## ℹ Use `spec()` to retrieve the full column specification for this data.
## ℹ Specify the column types or set `show_col_types = FALSE` to quiet this message.
Datos_PCR
## # A tibble: 22 × 10
## Gene Condition Control_1 Control_2 Control_3 Control_4 Tratamiento_1
## <chr> <chr> <dbl> <dbl> <dbl> <dbl> <dbl>
## 1 Gen_1 Target 26.4 26.8 28.6 27.1 30.1
## 2 Gen_2 Target 29.3 29.6 31.2 30.4 27.4
## 3 Gen_3 Target 27.5 25.0 27.7 26.5 28.9
## 4 Gen_4 Target 29.4 28.3 30.8 30.2 25.9
## 5 Gen_5 Target 27.9 27.9 27.8 27.7 30.6
## 6 Gen_6 Target 29.3 29.8 28.7 32.2 28.2
## 7 Gen_7 Target 27.8 26.9 27.3 27.0 30.0
## 8 Gen_8 Target 28.5 30.6 30.1 30.2 27.4
## 9 Gen_9 Target 25.9 27.3 27.4 27.1 30.9
## 10 Gen_10 Target 31.0 29.3 29.3 31.0 26.7
## # ℹ 12 more rows
## # ℹ 3 more variables: Tratamiento_2 <dbl>, Tratamiento_3 <dbl>,
## # Tratamiento_4 <dbl>
sacar los genes de referencia para poderlos utilizar como comparativos
if (!require("dplyr")) install.packages("dplyr")
library(dplyr)
Ref_gen_prom <- Datos_PCR %>%
filter(Condition == "Reference") %>%
select(-1, -2) %>%
summarise(across(everything(), mean, na.rm = T))
## Warning: There was 1 warning in `summarise()`.
## ℹ In argument: `across(everything(), mean, na.rm = T)`.
## Caused by warning:
## ! The `...` argument of `across()` is deprecated as of dplyr 1.1.0.
## Supply arguments directly to `.fns` through an anonymous function instead.
##
## # Previously
## across(a:b, mean, na.rm = TRUE)
##
## # Now
## across(a:b, \(x) mean(x, na.rm = TRUE))
Ref_gen_prom
## # A tibble: 1 × 8
## Control_1 Control_2 Control_3 Control_4 Tratamiento_1 Tratamiento_2
## <dbl> <dbl> <dbl> <dbl> <dbl> <dbl>
## 1 25.9 24.5 25.2 25.0 24.8 25.3
## # ℹ 2 more variables: Tratamiento_3 <dbl>, Tratamiento_4 <dbl>
Obtener el valor de Delta Ct
DCt <- Datos_PCR %>%
filter(Condition == "Target") %>%
select(-2) %>%
mutate(across(-1, ~ -(. -Ref_gen_prom[[cur_column()]][[1]]),
.names = "DCt_{.col}")) %>%
select(Gene, starts_with("DCt_"))
head(DCt)
## # A tibble: 6 × 9
## Gene DCt_Control_1 DCt_Control_2 DCt_Control_3 DCt_Control_4
## <chr> <dbl> <dbl> <dbl> <dbl>
## 1 Gen_1 -0.498 -2.29 -3.32 -2.12
## 2 Gen_2 -3.37 -5.07 -5.98 -5.41
## 3 Gen_3 -1.56 -0.550 -2.46 -1.57
## 4 Gen_4 -3.43 -3.83 -5.59 -5.20
## 5 Gen_5 -1.95 -3.39 -2.58 -2.73
## 6 Gen_6 -3.36 -5.31 -3.49 -7.21
## # ℹ 4 more variables: DCt_Tratamiento_1 <dbl>, DCt_Tratamiento_2 <dbl>,
## # DCt_Tratamiento_3 <dbl>, DCt_Tratamiento_4 <dbl>
Escalar los datos
miRNA_escalado <- DCt %>%
column_to_rownames(var = "Gene") %>%
scale(center = T,
scale = T) %>%
as.data.frame()
miRNA_escalado <- miRNA_escalado * 2
miRNA_escalado
## DCt_Control_1 DCt_Control_2 DCt_Control_3 DCt_Control_4
## Gen_1 2.0547231 1.94969655 0.24713362 1.77208069
## Gen_2 -1.3266135 -1.42356681 -2.85640023 -2.01503056
## Gen_3 0.8094111 4.05328271 1.24542607 2.39760386
## Gen_4 -1.3993483 0.07986368 -2.40660253 -1.77734696
## Gen_5 0.3419451 0.60704832 1.10543709 1.06040032
## Gen_6 -1.3173716 -1.71157938 0.04232288 -4.09796955
## Gen_7 0.4774523 1.77184749 1.76711627 1.88612691
## Gen_8 -0.3124324 -2.67168029 -1.57530642 -1.84938457
## Gen_9 2.6563783 1.30314553 1.54018685 1.79223394
## Gen_10 -3.3182531 -1.10430634 -0.62998154 -2.78154431
## Gen_11 1.3884396 1.20410848 2.49367055 1.11136292
## Gen_12 -1.7513025 -3.35516526 -2.58791762 -2.23215399
## Gen_13 -1.1785704 -0.18580909 2.33652488 3.03502003
## Gen_14 -1.0150687 -1.90890971 -0.51715700 0.31960720
## Gen_15 3.2989536 1.73816095 1.45728530 1.50652975
## Gen_16 -2.2732524 -0.81565273 -0.85989169 -1.30591289
## Gen_17 2.5270203 1.75723638 0.38005740 1.33342488
## Gen_18 -0.4161130 -2.85985725 -3.65403263 0.06165072
## Gen_19 3.2797189 2.31401063 3.76413114 1.06123329
## Gen_20 -2.5257163 -0.74187384 -1.29200239 -1.27793168
## DCt_Tratamiento_1 DCt_Tratamiento_2 DCt_Tratamiento_3 DCt_Tratamiento_4
## Gen_1 -1.6272515 -3.1107030 -2.56694570 -0.4807721
## Gen_2 1.6323785 1.3872501 2.30469401 -0.5373193
## Gen_3 -0.1971188 -1.2223449 -0.76356523 -1.0641153
## Gen_4 3.4708399 0.2705411 1.11332562 1.7278419
## Gen_5 -2.1345369 -1.3748007 -1.63685278 -1.4431901
## Gen_6 0.6680659 2.5925226 2.11918419 1.9145220
## Gen_7 -1.4215822 -2.7722487 -1.73411156 -3.5070279
## Gen_8 1.6576239 1.9860868 2.03467735 2.5150009
## Gen_9 -2.5745871 -3.4379788 -1.41239633 0.6551979
## Gen_10 2.4513662 2.6878755 1.41066367 1.5579208
## Gen_11 -1.2093926 -1.7593942 -3.33821130 -2.3306051
## Gen_12 1.8259597 2.1087666 -0.01968494 2.0598810
## Gen_13 -0.6241083 -1.6862272 -1.70873810 -1.4790156
## Gen_14 2.5654000 0.5976202 2.32835125 0.7453555
## Gen_15 -1.5990439 -0.8093851 -0.97738710 -0.7429022
## Gen_16 -0.0916139 2.1322547 1.34507013 1.3219896
## Gen_17 -1.5220566 -1.0225504 0.48230457 -3.0880098
## Gen_18 1.2727726 1.7515113 3.53729578 3.0547403
## Gen_19 -3.9816989 -0.1780002 -2.96332567 -2.6938395
## Gen_20 1.4385842 1.8592044 0.44565214 1.8143467
Definir los colores del Heatmap
paleta_colores <- colorRampPalette(c("#ff6f61", "#fefbd8", "#6b5b95"))(100)
construir el heatmap
Heatmap <- pheatmap(miRNA_escalado,
color = paleta_colores,
cluster_rows = T,
cluster_cols = T,
show_rownames = T, #T: para mostrar los nombres de los genes, F: para quitarlos
show_colnames = T,
fontsize_row = 5,
fontsize_col = 8,
border_color = "black",
main = "Heatmap de expresión de miRNAs",
fontface_row = "bold")
Heatmap
Análisis de PCA
Calcular el PCA
PCA_resultados <- prcomp(t(miRNA_escalado),
center = TRUE,
scale. = T)
summary(PCA_resultados)
## Importance of components:
## PC1 PC2 PC3 PC4 PC5 PC6 PC7
## Standard deviation 3.9273 1.0981 1.06384 0.93134 0.86565 0.63804 0.46315
## Proportion of Variance 0.7712 0.0603 0.05659 0.04337 0.03747 0.02035 0.01073
## Cumulative Proportion 0.7712 0.8315 0.88808 0.93145 0.96892 0.98927 1.00000
## PC8
## Standard deviation 2.09e-16
## Proportion of Variance 0.00e+00
## Cumulative Proportion 1.00e+00
Screenplot: varianza explicada por componente
fviz_eig(PCA_resultados,
addlabels = TRUE,
barfill = "#ffe600",
barcolor = "#ff6f61")
Gráfica de PCA (biplot)
PCA_df <- as.data.frame(PCA_resultados$x)
PCA_df$Sample <- rownames(PCA_df)
Grafica
PCA_plot <- ggplot(PCA_df,
aes(x = PC1,
y = PC2)) +
geom_point(size = 4, aes(color = Sample)) +
geom_hline(yintercept = 0, linetype = "solid", color = "black", linewidth = 1.5) +
geom_vline(xintercept = 0, linetype = "solid", color = "black", linewidth = 1.5) +
labs(title = "PCA de expresión de miRNAs",
x = "PC1",
y = "PC2") +
theme_minimal()
PCA_plot
Analizar el comportamiento de los genes
PCA_resultados_genes <- prcomp(miRNA_escalado,
center = T,
scale. = T)
summary(PCA_resultados_genes)
## Importance of components:
## PC1 PC2 PC3 PC4 PC5 PC6 PC7
## Standard deviation 2.4551 0.73337 0.68254 0.57125 0.50573 0.4317 0.3359
## Proportion of Variance 0.7534 0.06723 0.05823 0.04079 0.03197 0.0233 0.0141
## Cumulative Proportion 0.7534 0.82066 0.87890 0.91969 0.95166 0.9750 0.9891
## PC8
## Standard deviation 0.29582
## Proportion of Variance 0.01094
## Cumulative Proportion 1.00000
fviz_eig(PCA_resultados_genes, addlabels = T,
barfill = "#B7B5E4",
barcolor = "#515065")
PCA_df_genes <- as.data.frame(PCA_resultados_genes$x)
PCA_df_genes$Gene <- row.names(PCA_df_genes)
PCA_plot_genes <- ggplot(PCA_df_genes,
aes(x = PC1,
y = PC2,
label = Gene))+
geom_point(size = 4, aes(color = Gene), show.legend = F)+
geom_text(vjust = -0.05, size = 3)+
geom_hline(yintercept = 0, linetype = "solid", color = "black", linewidth = 1.5) +
geom_vline(xintercept = 0, linetype = "solid", color = "black", linewidth = 1.5) +
labs(title = "PCA de expresión de miRNAs",
x = "PC1",
y = "PC2") +
theme_minimal()
PCA_plot_genes