if(!require("pacman"))
install.packages("pacman")
## Loading required package: pacman
library("pacman")
p_load("pheatmap",#crearlos heatmaps
"RColorBrewer",
"ggplot2",
"dplyr",
"vroom",
"FactoMineR",
"factoextra",
"tibble")
Datos_PCR <- vroom("https://raw.githubusercontent.com/ManuelLaraMVZ/Heatmaps/refs/heads/main/miRNA_qPCR_Ct_Data_20g.csv")
## `curl` package not installed, falling back to using `url()`
## 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)
## # 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>
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>
DCt <- Datos_PCR %>%
filter(Condition == "Target") %>%
select(-2) %>%
mutate(across(-1,
~ -(. - Ref_gen_prom[[cur_column()]]),
.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>
miRNA_escalado <- DCt %>%
column_to_rownames(var = "Gene") %>%
scale(center = TRUE,
scale = TRUE) %>%
as.data.frame()
head(miRNA_escalado)
## DCt_Control_1 DCt_Control_2 DCt_Control_3 DCt_Control_4 DCt_Tratamiento_1
## Gen_1 1.0273615 0.97484827 0.12356681 0.8860403 -0.81362577
## Gen_2 -0.6633067 -0.71178341 -1.42820012 -1.0075153 0.81618925
## Gen_3 0.4047056 2.02664135 0.62271304 1.1988019 -0.09855941
## Gen_4 -0.6996741 0.03993184 -1.20330127 -0.8886735 1.73541997
## Gen_5 0.1709725 0.30352416 0.55271855 0.5302002 -1.06726846
## Gen_6 -0.6586858 -0.85578969 0.02116144 -2.0489848 0.33403296
## DCt_Tratamiento_2 DCt_Tratamiento_3 DCt_Tratamiento_4
## Gen_1 -1.5553515 -1.2834728 -0.2403860
## Gen_2 0.6936251 1.1523470 -0.2686596
## Gen_3 -0.6111724 -0.3817826 -0.5320576
## Gen_4 0.1352706 0.5566628 0.8639210
## Gen_5 -0.6874003 -0.8184264 -0.7215950
## Gen_6 1.2962613 1.0595921 0.9572610
paleta_colores <- colorRampPalette(c("#1a62d2","#ffffff","#b241b7"))(100)
Heatmap <- pheatmap(miRNA_escalado,color = paleta_colores,
cluster_rows = T,
cluster_cols = T,
show_rownames = T,
show_colnames = T,
fontsize_row = 5,
fontsize_col = 8,
border_color = "black",
main = "Heatmap de expresión de miRNAs",
fontface_row = "bold")
Heatmap

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.09e-16
## Proportion of Variance 0.00e+00
## Cumulative Proportion 1.00e+00
fviz_eig(PCA_resultados,
addlabels = T,
barfill = "#c883e7",
barcolor = "#1c0b63")

PCA_df <- as.data.frame(PCA_resultados$x)
PCA_df$Sample <- row.names(PCA_df)
PCA_plot <- ggplot(PCA_df,
aes(x = PC1,
y = PC2)) +
geom_point(size = 4, aes(color = Sample)) +
#geom_text(aes(label = Sample), 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 miRNA",
x = "PC1",
y = "PC2") +
theme_minimal()
PCA_plot

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 = "#c883e7",
barcolor = "#1c0b63")

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 miRNA",
x = "PC1",
y = "PC2") +
theme_minimal()
PCA_plot_genes
