Carga de paquetes
if (!require("pacman"))
install.packages("pacman")
## Loading required package: pacman
library ("pacman")
p_load("pheatmap", "RColorBrewer", "ggplot2", "dplyr","vroom", "FactoMineR", "factoextra", "tibble")
llamar base de datos
datos_PCR <- vroom("https://raw.githubusercontent.com/ManuelLaraMVZ/Heatmaps/refs/heads/main/Ejemplo%206x4.csv")
## `curl` package not installed, falling back to using `url()`
## Rows: 8 Columns: 8
## ── Column specification ────────────────────────────────────────────────────────
## Delimiter: ","
## chr (2): Gene, Condition
## dbl (6): Control_1, Control_2, Control_3, Tratamiento_1, Tratamiento_2, Trat...
##
## ℹ 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: 8 × 8
## Gene Condition Control_1 Control_2 Control_3 Tratamiento_1 Tratamiento_2
## <chr> <chr> <dbl> <dbl> <dbl> <dbl> <dbl>
## 1 Gen_1 Target 31.0 29.3 29.3 26.7 25.8
## 2 Gen_2 Target 30.1 29.1 29.5 28.8 26.3
## 3 Gen_3 Target 30.3 29.0 29.9 27.6 26.6
## 4 Gen_4 Target 25.4 26.5 25.5 32.1 28.7
## 5 Gen_5 Target 29.2 28.5 26.8 29.3 30.3
## 6 Gen_6 Target 27.9 27.9 27.8 30.6 29.9
## 7 Ref_1 Reference 26.0 24.9 25.5 24.6 25.6
## 8 Ref_2 Reference 25.9 24.1 25.0 24.9 25.1
## # ℹ 1 more variable: Tratamiento_3 <dbl>
Sacar genes de referencia
Ref_gen_prom <- datos_PCR %>%
filter(Condition == "Reference") %>%
select(-1,-2) %>%
summarize (across(everything(), mean, na.ra=T))
## Warning: There was 1 warning in `summarize()`.
## ℹ In argument: `across(everything(), mean, na.ra = 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 × 6
## Control_1 Control_2 Control_3 Tratamiento_1 Tratamiento_2 Tratamiento_3
## <dbl> <dbl> <dbl> <dbl> <dbl> <dbl>
## 1 25.9 24.5 25.2 24.8 25.3 25.6
DCT
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_"))
DCT
## # A tibble: 6 × 7
## Gene DCT_Control_1 DCT_Control_2 DCT_Control_3 DCT_Tratamiento_1
## <chr> <dbl> <dbl> <dbl> <dbl>
## 1 Gen_1 -5.06 -4.81 -4.07 -1.93
## 2 Gen_2 -4.18 -4.57 -4.27 -4.06
## 3 Gen_3 -4.39 -4.51 -4.64 -2.78
## 4 Gen_4 0.543 -1.99 -0.295 -7.32
## 5 Gen_5 -3.25 -4.05 -1.52 -4.51
## 6 Gen_6 -1.95 -3.39 -2.58 -5.77
## # ℹ 2 more variables: DCT_Tratamiento_2 <dbl>, DCT_Tratamiento_3 <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_Tratamiento_1
## Gen_1 -0.97752739 -0.8723021 -0.6770509 1.25561926
## Gen_2 -0.54697365 -0.6467906 -0.7908920 0.17018773
## Gen_3 -0.65099203 -0.5891507 -1.0048539 0.82332900
## Gen_4 1.74092214 1.7982681 1.4987164 -1.49023458
## Gen_5 -0.09595052 -0.1547234 0.7918299 -0.05709921
## Gen_6 0.53052145 0.4646988 0.1822505 -0.70180220
## DCT_Tratamiento_2 DCT_Tratamiento_3
## Gen_1 1.1138058 1.0531109
## Gen_2 0.8211332 1.0172933
## Gen_3 0.6773042 0.5261629
## Gen_4 -0.3957910 -1.3353215
## Gen_5 -1.1902479 -0.6502495
## Gen_6 -1.0262043 -0.6109962
color
p_colores <- colorRampPalette(c("red", "green", "#000370"))(100)
Construir Heatmap
Heatmap <- pheatmap(miRNA_escalado,
color = p_colores,
cluster_rows = T,
cluster_cols = T,
show_rownames = F,
show_colnames = T,
fontsize_row = 8,
fontsize_col = 14,
border_color = "black",
main = "Heatmap de expressión de miRNAs",
fontface_row = "bold")
Heatmap
PCA
datos_PCR2 <- vroom("https://raw.githubusercontent.com/ManuelLaraMVZ/Heatmaps/refs/heads/main/miRNA_qPCR_Ct_Data_1550_miRNAs3.csv")
## `curl` package not installed, falling back to using `url()`
## Rows: 1552 Columns: 10
## ── Column specification ────────────────────────────────────────────────────────
## Delimiter: ","
## chr (2): Gene, Condition
## dbl (8): Control_1, Control_2, Control_3, Control_4, Treatment_1, Treatment_...
##
## ℹ 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.
Ref_gen_prom2 <- datos_PCR2 %>%
filter(Condition == "Reference") %>%
select(-1,-2) %>%
summarize (across(everything(), mean, na.ra=T))
DCT2 <- datos_PCR2 %>%
filter(Condition == "Target") %>%
select(-2) %>%
mutate(across(-1, ~ -(. -Ref_gen_prom2[[cur_column()]][[1]]),
.names = ("DCT_{.col}"))) %>%
select(Gene, starts_with("DCT_"))
miRNA_escalado2 <- DCT2 %>%
column_to_rownames(var = "Gene") %>%
scale(center = T,
scale = T) %>%
as.data.frame()
Heatmap2 <- pheatmap(miRNA_escalado2,
color = p_colores,
cluster_rows = T,
cluster_cols = T,
show_rownames = F,
show_colnames = T,
fontsize_row = 8,
fontsize_col = 14,
border_color = "black",
main = "Heatmap de expressión de miRNAs",
fontface_row = "bold")
Heatmap2
Analisis de PCA
PCA_Resultados <- prcomp(t(miRNA_escalado2),
center = T,
scale. = T)
summary(PCA_Resultados)
## Importance of components:
## PC1 PC2 PC3 PC4 PC5 PC6 PC7
## Standard deviation 38.7928 2.87800 2.79848 2.76461 2.72127 2.65848 2.62467
## Proportion of Variance 0.9709 0.00534 0.00505 0.00493 0.00478 0.00456 0.00444
## Cumulative Proportion 0.9709 0.97623 0.98129 0.98622 0.99100 0.99556 1.00000
## PC8
## Standard deviation 3.474e-15
## Proportion of Variance 0.000e+00
## Cumulative Proportion 1.000e+00
ScreePlot
fviz_eig(PCA_Resultados,
addlabels = T,
barfill = "#890551",
barcolor = "#440434")
Grafica PCA
PCA_df <- as.data.frame(PCA_Resultados$x)
PCA_df$Sample <- rownames(PCA_df)
PCA_plot <- ggplot(PCA_df,
aes(x = PC1,
y = PC2,
label = Sample))+
geom_point(size = 4,
aes(color = Sample))+
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 expressión de miRNAs",
x = "PC1",
y = "PC2",)+
theme_minimal()
PCA_plot
PCA_Resultados_genes <- prcomp(miRNA_escalado2,
center = T,
scale. = T)
summary(PCA_Resultados_genes)
## Importance of components:
## PC1 PC2 PC3 PC4 PC5 PC6 PC7
## Standard deviation 2.7806 0.20838 0.20321 0.19693 0.19657 0.19219 0.18799
## Proportion of Variance 0.9665 0.00543 0.00516 0.00485 0.00483 0.00462 0.00442
## Cumulative Proportion 0.9665 0.97188 0.97704 0.98189 0.98672 0.99134 0.99575
## PC8
## Standard deviation 0.18430
## Proportion of Variance 0.00425
## Cumulative Proportion 1.00000
fviz_eig(PCA_Resultados_genes,
addlabels = T,
barfill = "#890551",
barcolor = "#440434")
PCA_df_genes <- as.data.frame(PCA_Resultados_genes$x)
PCA_df_genes$Gene <- rownames(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 expressión de miRNAs",
x = "PC1",
y = "PC2",)+
theme_minimal()
PCA_plot_Genes
datos_PCR3 <- 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.
Ref_gen_prom3 <- datos_PCR3 %>%
filter(Condition == "Reference") %>%
select(-1,-2) %>%
summarize (across(everything(), mean, na.ra=T))
DCT3 <- datos_PCR3 %>%
filter(Condition == "Target") %>%
select(-2) %>%
mutate(across(-1, ~ -(. -Ref_gen_prom3[[cur_column()]][[1]]),
.names = ("DCT_{.col}"))) %>%
select(Gene, starts_with("DCT_"))
miRNA_escalado3 <- DCT3 %>%
column_to_rownames(var = "Gene") %>%
scale(center = T,
scale = T) %>%
as.data.frame()
p_colores2 <- colorRampPalette(c("#e84c28", "white", "#4696db"))(100)
Heatmap3 <- pheatmap(miRNA_escalado3,
color = p_colores2,
cluster_rows = T,
cluster_cols = T,
show_rownames = T,
show_colnames = T,
fontsize_row = 8,
fontsize_col = 8,
border_color = "black",
main = "Heatmap de expressión de miRNAs",
fontface_row = "bold")
Heatmap3
PCA_Resultados2 <- prcomp(t(miRNA_escalado3),
center = T,
scale. = T)
summary(PCA_Resultados2)
## 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_Resultados2,
addlabels = T,
barfill = "#890551",
barcolor = "#440434")
PCA_df2 <- as.data.frame(PCA_Resultados2$x)
PCA_df2$Sample <- rownames(PCA_df2)
PCA_plot2 <- ggplot(PCA_df2,
aes(x = PC1,
y = PC2,
label = Sample))+
geom_point(size = 4,
aes(color = Sample))+
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 expressión de miRNAs",
x = "PC1",
y = "PC2",)+
theme_minimal()
PCA_plot2
PCA_Resultados_genes2 <- prcomp(miRNA_escalado3,
center = T,
scale. = T)
summary(PCA_Resultados_genes2)
## 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_genes2,
addlabels = T,
barfill = "#890551",
barcolor = "#440434")
PCA_df_genes2 <- as.data.frame(PCA_Resultados_genes2$x)
PCA_df_genes2$Gene <- rownames(PCA_df_genes2)
PCA_plot_Genes2 <- ggplot(PCA_df_genes2,
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 expressión de miRNAs",
x = "PC1",
y = "PC2",)+
theme_minimal()
PCA_plot_Genes2