# HG changeset patch # User mingchen0919 # Date 1514669979 18000 # Node ID 629323b5fc0c1fa383032cde313d2ae906644c79 # Parent c1f718dd6c7a04b4e9e7ca862fc818da271d55eb update tool diff -r c1f718dd6c7a -r 629323b5fc0c rmarkdown_deseq2_count_matrix.Rmd --- a/rmarkdown_deseq2_count_matrix.Rmd Sat Dec 30 00:25:38 2017 -0500 +++ b/rmarkdown_deseq2_count_matrix.Rmd Sat Dec 30 16:39:39 2017 -0500 @@ -16,24 +16,92 @@ ``` -## User input +# User input ```{r 'user input'} df = data.frame(name = names(opt)[-1], value = unlist(opt)) -df +datatable(df, rownames = FALSE) ``` -## Count Matrix +# Count Matrix + +Display the first 100 rows of count data matrix. ```{r 'count matrix'} count_data = read.table(opt$count_data) -head(count_data, 10) +col_names = trimws(strsplit(opt$count_matrix_column_names, ',')[[1]])[1:ncol(count_data)] +col_names = col_names[!is.na(col_names)] +colnames(count_data)[1:length(col_names)] = col_names +datatable(head(count_data, 100)) +``` + +# Column Data + +```{r 'column data'} +col_data = read.table(opt$col_data, + stringsAsFactors = FALSE, sep=',', header = TRUE, row.names = 1) +datatable(col_data) +``` + +# Match sample names + +The goal of this step is to rearrange the rows of the column data matrix so that the samples rows in the count data matrix and the sample columns in the count data matrix are in the same order. + +```{r 'match sample names'} +col_data = col_data[col_names, ] +datatable(col_data) ``` -```{r 'ste[ 2'} +# DESeqDataSet + +```{r 'DeseqDataSet'} +dds = DESeqDataSetFromMatrix(countData = count_data, + colData = col_data, + design = formula(opt$design_formula)) +dds +``` + +Pre-filter low count genes +```{r 'pre-filtering'} +keep = rowSums(counts(dds)) >= 10 +dds = dds[keep, ] +dds +``` + +# Differential expression analysis + +```{r 'differential expression analysis'} +dds = DESeq(dds) +# res = results(dds, contrast = c(opt$contrast_condition, opt$treatment, opt$control)) +res = results(dds) +resultsNames(dds) +if(nrow(res) > 500) { + cat('The result table has more than 500 rows. Only 500 rows are randomly selected to dispaly.') + datatable(as.data.frame(res)[sample(1:nrow(res), 500), ]) +} else { + datatable(as.data.frame(res)) +} ``` + +```{r 'write results into csv'} +#Write results into a CSV file. +write.csv(res, 'differential_genes.csv') +``` + +# MAplot + +```{r} +plotMA(res) +``` + + +```{r 'save R objects'} +# Save R objects to a file +save(dds, opt, file = 'deseq2.RData') +``` + diff -r c1f718dd6c7a -r 629323b5fc0c rmarkdown_deseq2_count_matrix.xml --- a/rmarkdown_deseq2_count_matrix.xml Sat Dec 30 00:25:38 2017 -0500 +++ b/rmarkdown_deseq2_count_matrix.xml Sat Dec 30 16:39:39 2017 -0500 @@ -17,11 +17,12 @@ Rscript '${__tool_directory__}/rmarkdown_deseq2_count_matrix_render.R' -e $echo -c $count_data + -n '$count_matrix_column_names' -C $col_data -D '$design_formula' -k $contrast_condition -T $treatment - -k $control + -K $control -r $report -d $report.files_path -s $sink_message @@ -31,21 +32,32 @@ - + + + optional="False" value="~ condition_1 + condition_2"> + + + + + + + optional="False" value="treated"/> + optional="False" value="untreated"/> diff -r c1f718dd6c7a -r 629323b5fc0c rmarkdown_deseq2_count_matrix_render.R --- a/rmarkdown_deseq2_count_matrix_render.R Sat Dec 30 00:25:38 2017 -0500 +++ b/rmarkdown_deseq2_count_matrix_render.R Sat Dec 30 16:39:39 2017 -0500 @@ -2,6 +2,8 @@ library(rmarkdown) library(htmltools) library(dplyr) +library(DT) +library(DESeq2) ##============ Sink warnings and errors to a file ============== ## use the sink() function to wrap all code within it. @@ -31,8 +33,10 @@ #+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ args_list=list() ##------- 1. input data --------------------- - args_list$ECHO = c('echo', 'e', '1', 'character') + args_list$ECHO = c('echo', 'e', '1', 'logical') args_list$c = c('count_data', 'c', '1', 'character') + args_list$n = c('count_matrix_column_names', 'n', '1', 'character') + args_list$n = c('count_matrix_column_names', 'n', '1', 'character') args_list$C = c('col_data', 'C', '1', 'character') args_list$D = c('design_formula', 'D', '1', 'character') args_list$k = c('contrast_condition', 'k', '1', 'character')