MahShaaban / pcr

Quality assessing, analyzing and testing the statistical significance of real-time quantitative PCR data
https://CRAN.R-project.org/package=pcr
GNU General Public License v3.0
27 stars 8 forks source link

something wrong with my data #37

Closed lmanchon closed 2 months ago

lmanchon commented 4 months ago

--Hi,

I obtain no results with my data (see attachment), and i don't know why. Can you check please if my input file is well formated ? Thank you.

ALL.txt

this is the code i used:

library(tidyverse)
library(reshape2)
library(pcr)
library(data.table)

dat <- read_tsv('./ALL.txt')
selected = c("P19", "P25", "P28", "T2", "HY03", "Culot")

clean_dat <- dat %>%
  mutate(abx = str_split(Sample_Name, '-', simplify = TRUE)[, 1],
         group = str_split(Sample_Name, '-', simplify = TRUE)[, 2]) %>%
         filter(abx %in% selected) %>%
           with({
    split(select(., group, Target, Ct), .$abx)
  }) %>%
  map(function(x) x %>%
        group_by(group, Target) %>%
        mutate(id = row_number()) %>%
        spread(Target, Ct) %>%
        select(-id) %>%
        ungroup)

res <- clean_dat %>%
  map(function(x) {
    group <- x$group
    ct <- select(x, -group)
    pcr::pcr_analyze(ct,
                     group_var = group,
                     reference_gene = 'B2M',
                     reference_group = 'FIBRO'
                     )
  }) %>% bind_rows(.id = 'abx')

table_ct = as.data.table(res)
print(as.data.frame(table_ct))
MahShaaban commented 4 months ago

Hi, Your file, as it stands, is missing important information that need to be added. And I suspect would make your life easier going forward. If the PCR reaction was run on material (cell culture, for example) for two or more probes this info need to be encoded in the file. Once you add this, I'd be happy to take a look.

# load library
library(tidyverse)
> # reading file
> read_tsv('ALL.txt') %>%
+   separate(Sample_Name, c('abx', 'group')) %>%
+   filter(abx == 'T2')
# A tibble: 48 x 4
   abx   group Target    Ct
   <chr> <chr> <chr>  <dbl>
 1 T2    FIBRO NANOG   28.5 # Plate 1
 2 T2    FIBRO NANOG   28.7
 3 T2    FIBRO NANOG   28.6
 4 T2    FIBRO B2M     16.8 # Plate 1
 5 T2    FIBRO B2M     16.6
 6 T2    FIBRO B2M     16.2
 7 T2    S     NANOG   26.6 # Plate 1
 8 T2    S     NANOG   26.9
 9 T2    S     NANOG   27.4
10 T2    S     B2M     17.0
# … with 38 more rows

The reason this is important, is to show how the values relate to each other which is needed in this model. Also, when you try to reshape your data, you'd get errors/warnings, which you tried to solve by using fake ids mutate(id = row_number()). Like below

> read_tsv('ALL.txt') %>%
+   separate(Sample_Name, c('abx', 'group')) %>%
+   filter(abx == 'T2') %>%
+   pivot_wider(names_from = 'Target', values_from = 'Ct')

# A tibble: 2 x 7
  abx   group NANOG     B2M        SOX2      POU5F1    DNMT3B   
  <chr> <chr> <list>    <list>     <list>    <list>    <list>   
1 T2    FIBRO <dbl [3]> <dbl [12]> <dbl [3]> <dbl [3]> <dbl [3]>
2 T2    S     <dbl [3]> <dbl [12]> <dbl [3]> <dbl [3]> <dbl [3]>

I read this as, 'B2M' was tested once with each gene of interest, three replicates in each run. But the relation between these replicates are missing.

Once you have a column for something like plate number, this problem should go a way. Idealy, the combination of group, Target and <plate_key> should be unique.