Cargar paquetes y base de datos

library("pacman") #esta función llama al paquete instalado

p_load("ggplot2", #para graficar
       "dplyr", #para facilitar el manejo de datos
       "vroom", "tidyr") #llamar repositorios

# Importar datos
Datos_curva <- vroom(file="https://raw.githubusercontent.com/ManuelLaraMVZ/Metabolomica_2026_1/refs/heads/main/Amplificacion_ambos%20grupos.csv")
## New names:
## Rows: 51 Columns: 10
## ── Column specification
## ──────────────────────────────────────────────────────── Delimiter: "," dbl
## (9): Cycle, 50 ng, 10 ng, 5 ng, 1 ng, 0.5 ng, 0.1 ng, G1-M, G2-M lgl (1): ...8
## ℹ 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.
## • `` -> `...8`

Modificar datos

Curva_1 <- Datos_curva %>%
  select(Cycle, `50 ng`:`G2-M`) %>%
  select(-`G1-M`,-`...8`)

Curva_1
## # A tibble: 51 × 8
##    Cycle `50 ng` `10 ng` `5 ng` `1 ng` `0.5 ng` `0.1 ng`  `G2-M`
##    <dbl>   <dbl>   <dbl>  <dbl>  <dbl>    <dbl>    <dbl>   <dbl>
##  1     1   21.3   35.9   -2.25    2.06   -1.78    -2.32  -0.184 
##  2     2   -3.99   1.39   2.61    8.66    5.96     2.18   8.29  
##  3     3   34.5   -0.660 11.4    12.2     5.94     2.34   3.73  
##  4     4   56.6    1.000  1.87    6.49    5.20     1.05   3.20  
##  5     5   65.2   -0.484 -1.18    1.77   -5.23     0.606  0.557 
##  6     6   72.3    1.44  -0.477   2.35   -0.958    4.81   0.0300
##  7     7   89.1   -5.10  -3.87   -4.93   -3.60    -4.87  -7.37  
##  8     8  101.    -1.67  -3.52   -3.31   -2.34     0.403 -6.98  
##  9     9  114.     2.66   5.35   -2.11   -1.40    -0.659 -3.63  
## 10    10  123.    13.6   10.4    -5.98    2.27     1.13  -1.16  
## # ℹ 41 more rows

Reordenar y agrupar datos

Curva_largo <- Curva_1 %>%
  pivot_longer(cols = `50 ng`:`G2-M`, 
               names_to = "Muestra", 
               values_to = "Fluorescencia")
Curva_largo
## # A tibble: 357 × 3
##    Cycle Muestra Fluorescencia
##    <dbl> <chr>           <dbl>
##  1     1 50 ng          21.3  
##  2     1 10 ng          35.9  
##  3     1 5 ng           -2.25 
##  4     1 1 ng            2.06 
##  5     1 0.5 ng         -1.78 
##  6     1 0.1 ng         -2.32 
##  7     1 G2-M           -0.184
##  8     2 50 ng          -3.99 
##  9     2 10 ng           1.39 
## 10     2 5 ng            2.61 
## # ℹ 347 more rows

Graficar

Umbral_fluor <- 25
Ct_tabla <- Curva_largo %>%
  group_by(Muestra) %>%
  summarise(Ct = min(Cycle[Fluorescencia >= Umbral_fluor], na.rm = TRUE))

Ct_tabla
## # A tibble: 7 × 2
##   Muestra    Ct
##   <chr>   <dbl>
## 1 0.1 ng     18
## 2 0.5 ng     17
## 3 1 ng       14
## 4 10 ng       1
## 5 5 ng       12
## 6 50 ng       3
## 7 G2-M       13
Grafica_curva <- ggplot(Curva_largo, aes(x = Cycle, y = Fluorescencia, color = Muestra)) +
  geom_point(alpha=0.6) +
  geom_line(size=1.2) +
  geom_hline(yintercept = Umbral_fluor, linetype="dashed", color="darkred", linewidth=1) +
  labs(x = "Ciclos", 
       y = "Fluorescencia", 
       title = "Práctica 2: Curva amplificación qPCR absoluta", 
       caption = "Yaniv Bar Yosef, Abril Nava, Valeria Plata") +
  theme_classic()
## Warning: Using `size` aesthetic for lines was deprecated in ggplot2 3.4.0.
## ℹ Please use `linewidth` instead.
## This warning is displayed once per session.
## Call `lifecycle::last_lifecycle_warnings()` to see where this warning was
## generated.
Grafica_curva