#Primero cargar paquetes usando pacman
if (!require("pacman")) install.packages("pacman")
## Loading required package: pacman
library(pacman)
p_load("pheatmap", # crear Heatmaps
"RColorBrewer",
"ggplot2",
"dplyr",
"vroom",
"FactoMineR",
"factoextra",
"tibble")
Llamar base de datos
Datos_PCR <- 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.
head(Datos_PCR) #Para visualizarlo
## # A tibble: 6 × 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
## # ℹ 3 more variables: Tratamiento_2 <dbl>, Tratamiento_3 <dbl>,
## # Tratamiento_4 <dbl>
Sacar los genes de referencia para poderlos usar como comparativos
Ref_gen_prom <- Datos_PCR %>%
filter(Condition == "Reference") %>%
select(-1, -2) %>%
summarise(across(everything (), mean, na.rm = TRUE))
## Warning: There was 1 warning in `summarise()`.
## ℹ In argument: `across(everything(), mean, na.rm = TRUE)`.
## 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))
head(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>
#Me da los promedios
Sacar el valor de Delta Ct (DCt) Asignar como objeto con la flechita
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
## DCt_Control_1 DCt_Control_2 DCt_Control_3 DCt_Control_4
## Gen_1 1.0273615 0.97484827 0.12356681 0.88604034
## Gen_2 -0.6633067 -0.71178341 -1.42820012 -1.00751528
## Gen_3 0.4047056 2.02664135 0.62271304 1.19880193
## Gen_4 -0.6996741 0.03993184 -1.20330127 -0.88867348
## Gen_5 0.1709725 0.30352416 0.55271855 0.53020016
## Gen_6 -0.6586858 -0.85578969 0.02116144 -2.04898477
## Gen_7 0.2387261 0.88592374 0.88355813 0.94306346
## Gen_8 -0.1562162 -1.33584014 -0.78765321 -0.92469228
## Gen_9 1.3281891 0.65157277 0.77009342 0.89611697
## Gen_10 -1.6591265 -0.55215317 -0.31499077 -1.39077216
## Gen_11 0.6942198 0.60205424 1.24683527 0.55568146
## Gen_12 -0.8756513 -1.67758263 -1.29395881 -1.11607700
## Gen_13 -0.5892852 -0.09290454 1.16826244 1.51751002
## Gen_14 -0.5075344 -0.95445486 -0.25857850 0.15980360
## Gen_15 1.6494768 0.86908048 0.72864265 0.75326487
## Gen_16 -1.1366262 -0.40782637 -0.42994585 -0.65295644
## Gen_17 1.2635102 0.87861819 0.19002870 0.66671244
## Gen_18 -0.2080565 -1.42992863 -1.82701632 0.03082536
## Gen_19 1.6398595 1.15700531 1.88206557 0.53061664
## Gen_20 -1.2628582 -0.37093692 -0.64600120 -0.63896584
## DCt_Tratamiento_1 DCt_Tratamiento_2 DCt_Tratamiento_3 DCt_Tratamiento_4
## Gen_1 -0.81362577 -1.55535151 -1.283472848 -0.2403860
## Gen_2 0.81618925 0.69362505 1.152347005 -0.2686596
## Gen_3 -0.09855941 -0.61117243 -0.381782614 -0.5320576
## Gen_4 1.73541997 0.13527056 0.556662808 0.8639210
## Gen_5 -1.06726846 -0.68740035 -0.818426389 -0.7215950
## Gen_6 0.33403296 1.29626131 1.059592095 0.9572610
## Gen_7 -0.71079112 -1.38612435 -0.867055780 -1.7535139
## Gen_8 0.82881193 0.99304339 1.017338673 1.2575005
## Gen_9 -1.28729356 -1.71898941 -0.706198163 0.3275990
## Gen_10 1.22568310 1.34393777 0.705331833 0.7789604
## Gen_11 -0.60469632 -0.87969712 -1.669105648 -1.1653025
## Gen_12 0.91297985 1.05438330 -0.009842471 1.0299405
## Gen_13 -0.31205414 -0.84311362 -0.854369049 -0.7395078
## Gen_14 1.28270001 0.29881009 1.164175623 0.3726777
## Gen_15 -0.79952197 -0.40469254 -0.488693550 -0.3714511
## Gen_16 -0.04580695 1.06612733 0.672535063 0.6609948
## Gen_17 -0.76102830 -0.51127520 0.241152286 -1.5440049
## Gen_18 0.63638628 0.87575564 1.768647889 1.5273701
## Gen_19 -1.99084945 -0.08900012 -1.481662833 -1.3469197
## Gen_20 0.71929209 0.92960218 0.222826070 0.9071733
Definir los colores del Heatmap
paleta_colores <- colorRampPalette(c("#f7acda", "#7392cd", "#b9e18f"))(100)
Construir el Heatmap
Heatmap <- pheatmap(miRNA_escalado,
color= paleta_colores,
cluster_rows = T,
cluster_cols = T,
show_rownames = T, #TRUE para mostrar los nombres de los genes, FALSE para quitarlos
show_colnames= T,
fontsize_row = 8,
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 = T,
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.064e-16
## Proportion of Variance 0.000e+00
## Cumulative Proportion 1.000e+00
Screenplot: Varianzaexplicada por componente
fviz_eig(PCA_resultados,
addlabels = T,
barfill = "#9fd3b7",
barcolor = "#307653")
Gráfica de PCA (biplot)
PCA_df <- as.data.frame(PCA_resultados$x)
PCA_df$Sample <- rownames(PCA_df)
Graficarlo
PCA_plot <- ggplot(PCA_df,
aes(x = PC1,
y = PC2)) +
geom_point(size = 4, aes(color = Sample)) +
# geom_text(vjust = -0.1, 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") +
scale_x_continuous(breaks = seq(floor(min(PCA_df$PC1)), ceiling(max(PCA_df$PC1)), by = 0.5)) +
scale_y_continuous(breaks = seq(floor(min(PCA_df$PC2)), ceiling(max(PCA_df$PC2)), by = 0.5)) +
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 = "#9fd3b7",
barcolor = "#307653")
PCA_df_genes <- as.data.frame(PCA_resultados_genes$x)
PCA_df_genes$Gene <- row.names(PCA_df_genes)
Gráfica
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.5, 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