# 4. (DIFFICULT): Create a text-tabulated file with raw counts. Tip: assays(dds)$counts rawCounts <- assays(dds)$counts # ALTERNATIVE: rawCounts <- counts(dds, normalized=FALSE) write.table(data.frame(ID=row.names(dds),rawCounts), file="my_raw_counts.tsv", sep="\t", row.names=FALSE) # # 5. (DIFFICULT): Create a text-tabulated file with normalized counts. Tip: assays(dds)$mu # NOTE: It is illustrative to look at normalized counts of differentially # expressed genes with good pvalues. normCounts <- t(t(assays(dds)$counts)/sizeFactors(dds)) # ALTERNATIVE: normCounts <- counts(dds, normalized=TRUE) write.table(data.frame(ID=row.names(dds),normCounts), file="my_norm_counts.tsv", sep="\t", row.names=FALSE) # EXPLANATION (for experienced R users): # the "t()" function (transpose), swap rows by columns in a matrix. So: # t(assays(dds)$counts)/sizeFactors(dds) divides each former column (now, each row) by the corresponding sizeFactor. # Finally, by appying again t() to the result, we obtain the original row and column dimensions. # # # 6. (DIFFICULT): add columns with normalized counts to the FINAL table (create file). # (using "normCounts" calculated in the task #5) FINAL_P5C50vsP5C004_withNormCounts <- data.frame( GENEID = row.names(P5C50vsP5C004), log2BaseMean = log2(P5C50vsP5C004$baseMean), log2Ratio = P5C50vsP5C004$log2FoldChange, STDERR_log2Ratio = P5C50vsP5C004$lfcSE, pvalue = P5C50vsP5C004$pvalue, padjust = P5C50vsP5C004$padj, normCounts ) write.table(FINAL_P5C50vsP5C004_withNormCounts, file="RESULTS_P5C50vsP5C004_withNormCounts.tsv", sep="\t", row.names=FALSE)