DESeq2 counts error in as.data.frame
1
0
Entering edit mode
ali reza • 0
@aba4ca8c
Last seen 2.5 years ago
iran

Hi everyone. I have a problem with DESeq2 counts in r.

when I use this code:

raw_readcount <- fread("raw read counts.txt", header = TRUE, sep = "\t")

design <- fread("Design.txt", header = TRUE, sep = "\t")

define effects the model should account for (animals, patients, batch effects etc.)

model_factors <- c("Patient")

define factors to test for DEG to use with model_factors

test_factors <- c("Timepoint")

run normalization and DEG for every combination of modelling and testing factors

dds_list <- list(test_factors)

res_list <- list(model_factors)

for (i in test_factors) {
  dds_list[[paste("dds_", paste(model_factors, sep = "+"), "_", i, sep = "")]] <- DESeqDataSetFromMatrix(data.frame(raw_readcount, row.names = 1),design,as.formula(paste("~", paste(model_factors, sep = "+"), "+", i)))
  dds_list[[paste("dds_", paste(model_factors, sep = "+"), "_", i, sep = "")]] <- DESeq(dds_list[[paste("dds_", paste(model_factors, sep = "+"), "_", i, sep = "")]], parallel = T)

  DEG_levels <- combn(sort(unique(get(i,design))),2)
  for (j in 1:ncol(DEG_levels)) {
    res_list[[paste("res", paste(model_factors, sep = "+"), i, DEG_levels[1,j], DEG_levels[2,j],  sep = "_")]] <- results(dds_list[[paste("dds_", paste(model_factors, sep = "+"), "_", i, sep = "")]], contrast=c(i, DEG_levels[1,j], DEG_levels[2,j]), parallel = T)
    res_list[[paste("res", paste(model_factors, sep = "+"), i, DEG_levels[1,j], DEG_levels[2,j],  sep = "_")]] <- res_list[[paste("res", paste(model_factors, sep = "+"), i, DEG_levels[1,j], DEG_levels[2,j],  sep = "_")]][order(res_list[[paste("res", paste(model_factors, sep = "+"), i, DEG_levels[1,j], DEG_levels[2,j],  sep = "_")]]$padj), ]
  }
}

generate normalized count lists

normalized_reads_list <- list(dds_list)

mean_normalized_reads_list <- list(dds_list)

normalized_reads_list <- list(res_list)

mean_normalized_reads_list <- list(res_list)

for (i in names(dds_list)) {
  normalized_reads_list[[sub("dds", "normalized_reads", i)]] <- as.data.frame(counts(dds_list[[i]], normalized=TRUE, replaced = T))
  normalized_reads_list[[sub("dds", "normalized_reads", i)]]$Geneid <- row.names(normalized_reads_list[[sub("dds", "normalized_reads", i)]])

  setcolorder(normalized_reads_list[[sub("dds", "normalized_reads", i)]], neworder = "Geneid")
  mm <- match(names(normalized_reads_list[[sub("dds", "normalized_reads", i)]][-(1)]), design$Sample)
  mean_reads <- normalized_reads_list[[sub("dds", "normalized_reads", i)]][,-c(1)]
  names(mean_reads)[!is.na(mm)] <- as.character(design[ , get(sub(paste(paste(model_factors, sep = "+"),"_", sep = ""), "", sub("dds_", "", i)))][na.omit(mm)])
  mean_normalized_reads_list[[sub("dds", "mean_normalized_reads", i)]] <- data.frame("Geneid" = rownames(mean_reads),lapply(split(as.list(mean_reads),f = colnames(mean_reads)),function(x) Reduce(`+`,x) / length(x)))

}

I'm getting this error:

Error in h(simpleError(msg, call)) : 
  error in evaluating the argument 'x' in selecting a method for function 'as.data.frame': unable to find an inherited method for function ‘counts’ for signature ‘"NULL"’
DESeq2 • 1.2k views
ADD COMMENT
0
Entering edit mode

These's my DATA (all cells separate with tab):

Design File:

Sample  Patient Timepoint
P1_T1   P1  T1
P1_T2   P1  T2
P1_T3   P1  T3
P1_T4   P1  T4
P1_T6   P1  T6
P1_T7   P1  T7
P1_T8   P1  T8
P1_T9   P1  T9
P1_T10  P1  T10
P1_T11  P1  T11
P1_T12  P1  T12
P1_T13  P1  T13
P2_T1   P2  T1
P2_T2   P2  T2
P2_T3   P2  T3
P2_T4   P2  T4
P2_T6   P2  T6
P2_T7   P2  T7
P2_T8   P2  T8
P2_T9   P2  T9
P2_T10  P2  T10
P2_T11  P2  T11
P2_T12  P2  T12
P2_T13  P2  T13
P3_T1   P3  T1
P3_T2   P3  T2
P3_T3   P3  T3
P3_T4   P3  T4
P3_T6   P3  T6
P3_T7   P3  T7
P3_T8   P3  T8
P3_T9   P3  T9
P3_T10  P3  T10
P3_T11  P3  T11
P3_T12  P3  T12
P3_T13  P3  T13
P5_T1   P5  T1
P5_T2   P5  T2
P5_T3   P5  T3
P5_T4   P5  T4
P5_T6   P5  T6
P5_T7   P5  T7
P5_T8   P5  T8
P5_T9   P5  T9
P5_T10  P5  T10
P5_T11  P5  T11
P5_T12  P5  T12
P5_T13  P5  T13
P6_T1   P6  T1
P6_T2   P6  T2
P6_T3   P6  T3
P6_T4   P6  T4
P6_T6   P6  T6
P6_T7   P6  T7
P6_T8   P6  T8
P6_T9   P6  T9
P6_T10  P6  T10
P6_T11  P6  T11
P6_T12  P6  T12
P6_T13  P6  T13
P7_T1   P7  T1
P7_T2   P7  T2
P7_T3   P7  T3
P7_T4   P7  T4
P7_T6   P7  T6
P7_T7   P7  T7
P7_T8   P7  T8
P7_T9   P7  T9
P7_T10  P7  T10
P7_T11  P7  T11
P7_T12  P7  T12
P7_T13  P7  T13
P8_T1   P8  T1
P8_T2   P8  T2
P8_T3   P8  T3
P8_T4   P8  T4
P8_T6   P8  T6
P8_T7   P8  T7
P8_T8   P8  T8
P8_T9   P8  T9
P8_T10  P8  T10
P8_T11  P8  T11
P8_T12  P8  T12
P8_T13  P8  T13
P9_T1   P9  T1
P9_T2   P9  T2
P9_T3   P9  T3
P9_T4   P9  T4
P9_T6   P9  T6
P9_T7   P9  T7
P9_T8   P9  T8
P9_T9   P9  T9
P9_T10  P9  T10
P9_T11  P9  T11
P9_T12  P9  T12
P9_T13  P9  T13
P10_T1  P10 T1
P10_T2  P10 T2
P10_T3  P10 T3
P10_T4  P10 T4
P10_T6  P10 T6
P10_T7  P10 T7
P10_T8  P10 T8
P10_T9  P10 T9
P10_T10 P10 T10
P10_T11 P10 T11
P10_T12 P10 T12
P10_T13 P10 T13

raw read counts File:

Geneid  P1_T1   P1_T2   P1_T3   P1_T4   P1_T6   P1_T7   P1_T8   P1_T9   P1_T10  P1_T11  P1_T12  P1_T13  P2_T1   P2_T2   P2_T3   P2_T4   P2_T6   P2_T7   P2_T8   P2_T9   P2_T10  P2_T11  P2_T12  P2_T13  P3_T1   P3_T2   P3_T3   P3_T4   P3_T6   P3_T7   P3_T8   P3_T9   P3_T10  P3_T11  P3_T12  P3_T13  P5_T1   P5_T2   P5_T3   P5_T4   P5_T6   P5_T7   P5_T8   P5_T9   P5_T10  P5_T11  P5_T12  P5_T13  P6_T1   P6_T2   P6_T3   P6_T4   P6_T6   P6_T7   P6_T8   P6_T9   P6_T10  P6_T11  P6_T12  P6_T13  P7_T1   P7_T2   P7_T3   P7_T4   P7_T6   P7_T7   P7_T8   P7_T9   P7_T10  P7_T11  P7_T12  P7_T13  P8_T1   P8_T2   P8_T3   P8_T4   P8_T6   P8_T7   P8_T8   P8_T9   P8_T10  P8_T11  P8_T12  P8_T13  P9_T1   P9_T2   P9_T3   P9_T4   P9_T6   P9_T7   P9_T8   P9_T9   P9_T10  P9_T11  P9_T12  P9_T13  P10_T1  P10_T2  P10_T3  P10_T4  P10_T6  P10_T7  P10_T8  P10_T9  P10_T10 P10_T11 P10_T12 P10_T13
ENSG00000000003.15  1   1   0   4   1   1   2   2   4   1   2   0   3   3   2   2   4   2   6   4   3   3   4   4   8   15  4   20  27  6   15  5   7   2   8   4   2   2   2   7   6   4   4   4   5   5   7   2   0   4   0   6   0   0   8   0   1   0   0   0   1   1   0   2   3   1   3   0   1   1   1   1   3   2   2   7   6   4   6   1   5   1   4   5   6   4   2   3   0   0   5   3   21  7   5   6   2   7   4   10  9   3   10  4   9   2   6   6
ENSG00000000005.6   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0
ENSG00000000419.14  40  72  45  81  52  56  59  29  120 68  67  72  56  132 111 112 208 96  227 218 88  110 157 158 147 290 67  512 695 144 336 158 217 59  185 141 80  104 80  113 200 175 171 189 146 182 186 143 123 291 169 496 110 72  592 75  256 35  40  30  41  85  37  109 94  70  152 53  76  45  100 93  124 86  123 196 135 166 184 69  221 92  136 245 89  167 76  60  95  56  102 99  510 224 51  93  63  111 98  256 167 113 138 77  162 57  224 130
ENSG00000000457.14  75  94  79  96  106 91  107 56  172 99  105 104 105 159 164 190 237 81  207 131 144 166 158 205 186 327 106 468 499 146 297 171 269 116 212 206 141 179 163 205 197 188 205 150 247 176 198 181 108 299 261 325 98  42  426 57  211 23  80  75  133 202 144 224 193 167 220 164 163 108 231 208 143 131 162 155 141 180 196 114 198 101 184 224 172 160 124 100 112 128 166 134 630 181 132 216 171 221 226 257 191 187 221 171 248 179 208 242
ENSG00000000460.17  54  64  82  53  63  53  80  59  149 73  61  55  40  61  51  72  100 37  92  44  61  78  78  94  72  163 63  201 229 58  147 70  130 56  108 85  103 126 129 181 149 105 159 81  214 111 122 128 44  168 158 162 59  13  226 26  138 10  45  46  47  82  58  84  64  63  76  68  58  55  76  66  70  74  80  86  101 116 134 92  131 72  134 148 92  92  113 59  68  82  101 68  401 104 117 194 111 97  119 85  75  88  82  114 109 117 104 135
ENSG00000000938.13  2293    2710    3798    2470    3462    2903    3208    2626    4178    3242    3394    3013    4297    4876    6295    6162    5548    3294    3627    3012    4883    4609    4563    5514    5707    9596    5897    10753   9487    4730    6375    5161    7708    5797    6445    9504    5772    4707    6903    5441    3945    4865    4222    4915    5519    4787    3963    4816    3200    9021    12154   6072    2483    1217    11831   1831    5689    697 4483    5193    6787    7135    8857    6088    5792    7425    5530    8041    5389    5747    7125    7216    6093    5900    7342    4343    5344    6055    4323    5527    4923    3841    5229    4658    5806    4482    4697    3237    3093    5009    5048    3703    13173   4546    4095    6464    5599    4681    7017    3884    3454    6313    3588    5577    4586    6798    3920    5188
ENSG00000000971.17  0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0
ENSG00000001036.14  55  75  95  99  103 81  105 70  155 100 112 94  138 143 196 190 179 135 140 188 131 170 142 177 85  146 96  206 209 76  118 80  105 78  78  108 172 121 141 153 115 108 151 110 172 120 121 91  93  268 222 254 80  41  323 52  163 21  91  86  144 212 181 179 167 140 202 142 157 122 215 170 124 123 114 125 105 132 130 111 139 90  146 152 150 105 140 74  70  111 139 110 433 171 108 164 138 140 198 192 130 172 172 155 195 170 198 190
ENSG00000001084.13  41  47  43  63  48  41  60  34  128 50  80  75  42  74  75  81  140 55  140 96  88  86  110 145 75  134 38  172 209 52  121 59  86  32  84  63  53  77  71  102 119 98  109 84  124 91  126 103 55  129 161 153 52  20  216 27  123 13  32  24  58  84  60  124 99  67  119 64  100 48  119 103 69  75  66  74  70  97  111 43  89  34  92  119 107 89  69  64  67  61  99  84  379 109 85  137 63  78  90  101 74  75  100 69  133 54  115 117
.
.
.
ADD REPLY
1
Entering edit mode

There is this 10101 botton to highlight code, please use it. This wall of code and data is barely readable.

ADD REPLY
0
Entering edit mode

Thanks a lot.

ADD REPLY
0
Entering edit mode
jeroen.gilis ▴ 90
@jeroengilis-21551
Last seen 12 months ago
Belgium

The error likely arises because at least one of i elements of your object dds_list has an empty count matrix (NULL). Maybe you can start checking the contents of dds_list or the individual elements dds_list[[i]].

That said, your code is very verbose, making it hard to read at a glance. It is therefore not really clear to me what you are aiming for in the part "run normalization and DEG for every combination of modelling and testing factors". What biological question are you trying to solve?

ADD COMMENT
0
Entering edit mode

Yes, that's right, my dds_list NAMES is NULL. this code isn't for me. I need to compare all timepoint (T...) together -(T1 to T2, T1 to T3, ..., T11 to T12)- for one person to find non-oscillating genes and compare all findings in all persons together for validation.

ADD REPLY
0
Entering edit mode

While it seems that you were able to resolve your issue, I still believe your code is way to verbose/complex for the analysis you want to perform, making the analysis error prone. If I understand correctly, you simply have a time course experiment with multiple patients. In this case, it should be possible to analyze the data with a ~ patient + time design matrix and subsequently making comparisons between combinations of timepoints by correctly specifying the contrast matrix in the testing phase. This is all very well document in the package vignettes of edgeR, limma and DESeq2. In the edgeR vignette, relevant parts for you could be 3.4.2 and 4.8.

Alternatively, the data may lend itself to a mixed model analysis, with patient random effects. This Bioconductor forum post provides one way of performing such analysis: Time series DE gene analysis with edgeR where specific timepoints have NA levels across different patients.

Kind regards,

Jeroen

ADD REPLY

Login before adding your answer.

Traffic: 449 users visited in the last hour
Help About
FAQ
Access RSS
API
Stats

Use of this site constitutes acceptance of our User Agreement and Privacy Policy.

Powered by the version 2.3.6