Previous changeset 13:9d3586701985 (2017-10-16) Next changeset 15:d1d20f341632 (2017-10-19) |
Commit message:
upgrade fastqc_report |
modified:
fastqc_report.Rmd fastqc_report.xml fastqc_report_render.R |
added:
fastqc_report_ori.Rmd fastqc_report_render_ori.R |
b |
diff -r 9d3586701985 -r 2efa46ce2c4c fastqc_report.Rmd --- a/fastqc_report.Rmd Mon Oct 16 21:33:31 2017 -0400 +++ b/fastqc_report.Rmd Wed Oct 18 22:06:39 2017 -0400 |
[ |
b'@@ -1,383 +1,72 @@\n ---\n-title: "Fastqc report: short reads quality evaluation"\n-author: "Ming Chen"\n-output: html_document\n+title: \'HTML report title\'\n+output:\n+ html_document:\n+ number_sections: true\n+ toc: true\n+ theme: cosmo\n+ highlight: tango\n ---\n \n-```{r setup, include=FALSE}\n-knitr::opts_chunk$set(echo=ECHO, warning=FALSE, message=FALSE)\n-library(plyr)\n-library(stringr)\n-library(dplyr)\n-library(highcharter)\n-library(DT)\n-library(reshape2)\n-library(plotly)\n-library(formattable)\n-library(htmltools)\n+```{r setup, include=FALSE, warning=FALSE, message=FALSE}\n+knitr::opts_chunk$set(\n+ echo = ECHO\n+)\n ```\n \n \n-```{bash \'create output directory\', echo=FALSE}\n-# create extra files directory. very important!\n-mkdir REPORT_OUTPUT_DIR\n-```\n+# Fastqc Analysis\n \n-# Fastqc analysis\n-```{bash \'copy data to working directory\', echo=FALSE}\n-# Copy uploaded data to the working directory\n+* Copy fastq files to job working directory\n+\n+```{bash \'copy files\'}\n for f in $(echo READS | sed "s/,/ /g")\n do\n cp $f ./\n done\n ```\n \n+* Run fastqc\n \n-```{bash \'run fastqc\', echo=FALSE}\n+```{bash \'run fastqc\'}\n for r in $(ls *.dat)\n do\n- fastqc -o REPORT_OUTPUT_DIR $r > /dev/null 2>&1\n+ fastqc -o REPORT_DIR $r > /dev/null 2>&1\n done\n ```\n \n-## Fastqc html reports\n+* Create links to original HTML reports\n \n-Below are links to ***Fastqc*** original html reports.\n ```{r \'html report links\'}\n html_report_list = list()\n-html_files = list.files(\'REPORT_OUTPUT_DIR\', pattern = \'.*html\')\n+html_files = list.files(\'REPORT_DIR\', pattern = \'.*html\')\n for (i in html_files) {\n html_report_list[[i]] = tags$li(tags$a(href=i, i))\n }\n tags$ul(html_report_list)\n ```\n \n-\n-## Parsing fastqc data\n-\n-```{bash echo=FALSE}\n-##==== copy fastqc generated zip files from report output directory to job work directory ==\n-cp -r REPORT_OUTPUT_DIR/*zip ./\n-\n-# create a file to store data file paths\n-echo "sample_id,file_path" > PWF_file_paths.txt # Pass, Warning, Fail\n-echo "sample_id,file_path" > PBQS_file_paths.txt # Per Base Quality Score\n-echo "sample_id,file_path" > PSQS_file_paths.txt # Per Sequence Quality Score\n-echo "sample_id,file_path" > PSGC_file_paths.txt # Per Sequence GC Content\n-echo "sample_id,file_path" > PBSC_file_paths.txt # Per Base Sequence Content\n-echo "sample_id,file_path" > PBNC_file_paths.txt # Per Base N Content\n-echo "sample_id,file_path" > SDL_file_paths.txt # Sequence Duplication Level\n-echo "sample_id,file_path" > SLD_file_paths.txt # Sequence Length Distribution\n-echo "sample_id,file_path" > KMC_file_paths.txt # Kmer Content\n-\n-for i in $(ls *.zip)\n-do\n- BASE=$(echo $i | sed \'s/\\(.*\\)\\.zip/\\1/g\')\n- echo $BASE\n- unzip ${BASE}.zip > /dev/null 2>&1\n- \n- ##====== pass,warning,fail (WSF) =============\n- awk \'/^>>/ {print}\' "$BASE"/fastqc_data.txt | grep -v \'END_MODULE\' | sed \'s/>>//\' > "$BASE"-PWF.txt\n- echo "${BASE},${BASE}-PWF.txt" >> PWF_file_paths.txt\n+# Fastqc output summary\n \n- ##====== per base quality scores (PBQS) ======\n- awk \'/^>>Per base sequence quality/ {flag=1; next} /END_MODULE/ {flag=0} flag\' "$BASE"/fastqc_data.txt >"$BASE"-PBQS.txt\n- echo "${BASE},${BASE}-PBQS.txt" >> PBQS_file_paths.txt\n-\n- ##====== per sequence quality scores (PSQS)\n- awk \'/^>>Per sequence quality scores/ {flag=1; next} /END_MODULE/ {flag=0} flag\' "$BASE"/fastqc_data.txt >"$BASE"-PSQS.txt\n- echo "${BASE},${BASE}-PSQS.txt" >> PSQS_file_paths.txt\n-\n- ##====== Per sequence GC content (PSGC)\n- awk \'/^>>Per sequence GC content/ {flag=1; next} /END_MODULE/ {flag=0} flag\' "$BASE"/fastqc_data.txt >"$BASE"-PSGC.txt\n- echo "${BASE},${BASE}-PSGC.txt" >> PSGC_file_paths.txt\n- \n- ##====== Per Base Sequence Content (PBSC)\n- awk \'/^>>Per base sequence content/ {flag=1; next} /END_MODULE/ {flag=0} flag\' "$BASE"/fastqc_data.txt >"$BASE"-PBSC.txt\n- echo "${BASE},${BASE}-PBSC.txt" >> PBSC_file_paths.txt\n- \n- ##====== Per Base N Content (PBNC)\n- awk \'/^>>Per base N content/ {flag=1; n'..b'df))\n- PSQS_df = rbind(PSQS_df, psqs_df)\n-}\n+```{r \'session info\'}\n+sessionInfo()\n ```\n \n-\n-```{r}\n-max_phred = max(PSQS_df$X.Quality) + 5\n-hchart(PSQS_df, "line", hcaes(x = X.Quality, y = Count, group = sample_id)) %>%\n- hc_title(\n- text = "Per Sequence Quality Score"\n- ) %>%\n- hc_xAxis(\n- title = list(text = "Mean Sequence Quality Score"),\n- min = 0,\n- max = max_phred,\n- plotLines = list(\n- list(label = list(text = "Phred Score = 27"),\n- width = 2,\n- dashStyle = "dash",\n- color = "green",\n- value = 27),\n- list(label = list(text = "Phred Score = 20"),\n- width = 2,\n- color = "red",\n- value = 20)\n- )\n- ) %>% \n- hc_exporting(enabled = TRUE)\n-```\n-\n-\n-## Per Sequence GC Content\n-\n-\n-```{r}\n-PSGC_df = data.frame()\n-PSGC_file_paths = read.csv(\'PSGC_file_paths.txt\', \n- header = TRUE, stringsAsFactors = FALSE)\n-for(i in 1:nrow(PSGC_file_paths)) {\n- # file_path = paste0(\'REPORT_OUTPUT_DIR/\', PSGC_file_paths[i,2])\n- file_path = PSGC_file_paths[i,2]\n- psgc_df = read.csv(file_path,\n- sep=\'\\t\', header=TRUE, stringsAsFactors = FALSE) \n- psgc_df$sample_id = rep(PSGC_file_paths[i,1], nrow(psgc_df))\n- PSGC_df = rbind(PSGC_df, psgc_df)\n-}\n-```\n-\n-\n-```{r}\n-max_phred = max(PSGC_df$Count) + 5\n-hchart(PSGC_df, "line", hcaes(x = X.GC.Content, y = Count, group = sample_id)) %>%\n- hc_title(\n- text = "Per Sequence GC Content"\n- ) %>%\n- hc_xAxis(\n- title = list(text = "% GC")\n- ) %>%\n- hc_exporting(enabled = TRUE)\n-```\n-\n-\n-## Per Base Sequence Content\n-\n-```{r}\n-PBSC_df = data.frame()\n-PBSC_file_paths = read.csv(\'PBSC_file_paths.txt\',\n- header = TRUE, stringsAsFactors = FALSE)\n-for(i in 1:nrow(PBSC_file_paths)) {\n- # file_path = paste0(\'REPORT_OUTPUT_DIR/\', PBSC_file_paths[i,2])\n- file_path = PBSC_file_paths[i,2]\n- pbsc_df = read.csv(file_path,\n- sep=\'\\t\', header=TRUE, stringsAsFactors = FALSE) %>%\n- mutate(Base1=as.numeric(str_split_fixed(X.Base, \'-\', 2)[,1]),\n- Base2=as.numeric(str_split_fixed(X.Base, \'-\', 2)[,2])) %>%\n- (function (df) {\n- df1 = select(df, -Base2)\n- df2 = select(df, -Base1) %>% filter(Base2 != \'\')\n- colnames(df1) = c(colnames(df1)[1:5], \'Base\')\n- colnames(df2) = c(colnames(df2)[1:5], \'Base\')\n- res = rbind(df1, df2) %>% arrange(Base)\n- return(res)\n- })\n- pbsc_df$sample_id = rep(PBSC_file_paths[i,1], nrow(pbsc_df))\n- PBSC_df = rbind(PBSC_df, pbsc_df)\n-}\n-```\n-\n-\n-```{r out.width="100%"}\n-PBSC_df_2 = select(PBSC_df, -X.Base) %>%\n- melt(id = c(\'Base\', \'sample_id\'), value.name = \'base_percentage\')\n-p = ggplot(data = PBSC_df_2, aes(x = Base, y = base_percentage, group = variable, color = variable)) +\n- geom_line() +\n- facet_wrap(~ sample_id)\n-ggplotly(p)\n-```\n-\n-\n-## References\n-\n-* Andrews, Simon. "FastQC: a quality control tool for high throughput sequence data." (2010): 175-176.\n-* Goecks, Jeremy, Anton Nekrutenko, and James Taylor. "Galaxy: a comprehensive approach for supporting accessible, reproducible, and transparent computational research in the life sciences." Genome biology 11.8 (2010): R86.\n-* Afgan, Enis, et al. "The Galaxy platform for accessible, reproducible and collaborative biomedical analyses: 2016 update." Nucleic acids research (2016): gkw343.\n-* Highcharts. https://www.highcharts.com/. (access by May 26, 2017).\n-* R Core Team (2017). R: A language and environment for statistical computing. R Foundation for Statistical Computing, Vienna, Austria. URL https://www.R-project.org/.\n-* Joshua Kunst (2017). highcharter: A Wrapper for the \'Highcharts\' Library. R package version 0.5.0. https://CRAN.R-project.org/package=highcharter\n-* Carson Sievert, Chris Parmer, Toby Hocking, Scott Chamberlain, Karthik Ram, Marianne Corvellec and Pedro Despouy (2017). plotly: Create Interactive Web Graphics via \'plotly.js\'. R package version 4.6.0. https://CRAN.R-project.org/package=plotly\n' |
b |
diff -r 9d3586701985 -r 2efa46ce2c4c fastqc_report.xml --- a/fastqc_report.xml Mon Oct 16 21:33:31 2017 -0400 +++ b/fastqc_report.xml Wed Oct 18 22:06:39 2017 -0400 |
[ |
@@ -1,4 +1,4 @@ -<tool id="fastqc_report" name="Fastqc report" version="1.0.1"> +<tool id="fastqc_report" name="Fastqc report" version="2.0.0"> <description> Implements FastQC analysis and display results in R Markdown html. </description> @@ -6,7 +6,7 @@ <requirement type="package" version="1.15.0.6-0">pandoc</requirement> <requirement type="package" version="1.14.1">bioconductor-deseq2</requirement> <requirement type="package" version="1.20.0">r-getopt</requirement> - <requirement type="package" version="1.2">r-rmarkdown</requirement> + <requirement type="package" version="1.3">r-rmarkdown</requirement> <requirement type="package" version="1.8.4">r-plyr</requirement> <requirement type="package" version="1.1.0">r-stringr</requirement> <requirement type="package" version="0.5.0">r-highcharter</requirement> @@ -18,38 +18,35 @@ <requirement type="package" version="0.11.5">fastqc</requirement> </requirements> <stdio> - <regex match="Execution halted" - source="both" - level="fatal" - description="Execution halted." /> - <regex match="Error in" - source="both" - level="fatal" - description="An undefined error occured, please check your intput carefully and contact your administrator." /> - <regex match="Fatal error" - source="both" - level="fatal" - description="An undefined error occured, please check your intput carefully and contact your administrator." /> + <!--redirecting stderr to a file. "XXX" is used to match with nothing so that tool running won't be interrupted during testing--> + <regex match="XXX" + source="stderr" + level="warning" + description="Check the warnings_and_errors.txt file for more details."/> </stdio> <command> <![CDATA[ Rscript '${__tool_directory__}/fastqc_report_render.R' + -e $echo -r $reads - -p '${__tool_directory__}/fastqc_report.Rmd' + -o $report -d $report.files_path + -s $sink_message - -e $echo - + -p '${__tool_directory__}/fastqc_report.Rmd' ]]> </command> <inputs> - <param format="fastq,fastq.gz,fastq.bz2,bam,sam" name="reads" type="data" label="Short reads data from history" /> - <param type="boolean" name="echo" truevalue="TRUE" falsevalue="FALSE" checked="false" label="Display analysis code in report?" /> + <param format="fastq,fastq.gz,fastq.bz2,bam,sam" name="reads" type="data" + label="Short reads data from history"/> + <param type="boolean" name="echo" truevalue="TRUE" falsevalue="FALSE" checked="false" + label="Display analysis code in report?"/> </inputs> <outputs> - <data format="html" name="report" label="fastqc report" /> + <data format="html" name="report" label="fastqc report"/> + <data format="txt" name="sink_message" label="Warnings and Errors" from_work_dir="warnings_and_errors.txt"/> </outputs> <citations> <citation type="bibtex"> @@ -62,7 +59,8 @@ <citation type="bibtex"> @article{allaire2016rmarkdown, title={rmarkdown: Dynamic Documents for R, 2016}, - author={Allaire, J and Cheng, Joe and Xie, Yihui and McPherson, Jonathan and Chang, Winston and Allen, Jeff and Wickham, Hadley and Atkins, Aron and Hyndman, Rob}, + author={Allaire, J and Cheng, Joe and Xie, Yihui and McPherson, Jonathan and Chang, Winston and Allen, Jeff + and Wickham, Hadley and Atkins, Aron and Hyndman, Rob}, journal={R package version 0.9}, volume={6}, year={2016} @@ -80,7 +78,8 @@ <citation type="bibtex"> @misc{plotly2017, title = {plotly: Create Interactive Web Graphics via 'plotly.js'}, - author = {Carson Sievert and Chris Parmer and Toby Hocking and Scott Chamberlain and Karthik Ram and Marianne Corvellec and Pedro Despouy}, + author = {Carson Sievert and Chris Parmer and Toby Hocking and Scott Chamberlain and Karthik Ram and + Marianne Corvellec and Pedro Despouy}, year = {2017}, note = {R package version 4.6.0}, url = {https://CRAN.R-project.org/package=plotly}, |
b |
diff -r 9d3586701985 -r 2efa46ce2c4c fastqc_report_ori.Rmd --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/fastqc_report_ori.Rmd Wed Oct 18 22:06:39 2017 -0400 |
[ |
b'@@ -0,0 +1,381 @@\n+---\n+title: "Fastqc report: short reads quality evaluation"\n+author: "Ming Chen"\n+output: html_document\n+---\n+\n+```{r setup, include=FALSE}\n+knitr::opts_chunk$set(echo=ECHO, warning=FALSE, message=FALSE)\n+library(plyr)\n+library(stringr)\n+library(dplyr)\n+library(highcharter)\n+library(DT)\n+library(reshape2)\n+library(plotly)\n+library(formattable)\n+library(htmltools)\n+```\n+\n+\n+```{bash \'create output directory\', echo=FALSE}\n+# create extra files directory. very important!\n+mkdir REPORT_OUTPUT_DIR\n+```\n+\n+# Fastqc analysis\n+```{bash \'copy data to working directory\', echo=FALSE}\n+# Copy uploaded data to the working directory\n+for f in $(echo READS | sed "s/,/ /g")\n+do\n+ cp $f ./\n+done\n+```\n+\n+\n+```{bash \'run fastqc\', echo=FALSE}\n+for r in $(ls *.dat)\n+do\n+ fastqc -o REPORT_OUTPUT_DIR $r > /dev/null 2>&1\n+done\n+```\n+\n+## Fastqc html reports\n+\n+Below are links to ***Fastqc*** original html reports.\n+```{r \'html report links\'}\n+html_report_list = list()\n+html_files = list.files(\'REPORT_OUTPUT_DIR\', pattern = \'.*html\')\n+for (i in html_files) {\n+ html_report_list[[i]] = tags$li(tags$a(href=i, i))\n+}\n+tags$ul(html_report_list)\n+```\n+\n+\n+## Parsing fastqc data\n+\n+```{bash echo=FALSE}\n+##==== copy fastqc generated zip files from report output directory to job work directory ==\n+cp -r REPORT_OUTPUT_DIR/*zip ./\n+\n+# create a file to store data file paths\n+echo "sample_id,file_path" > PWF_file_paths.txt # Pass, Warning, Fail\n+echo "sample_id,file_path" > PBQS_file_paths.txt # Per Base Quality Score\n+echo "sample_id,file_path" > PSQS_file_paths.txt # Per Sequence Quality Score\n+echo "sample_id,file_path" > PSGC_file_paths.txt # Per Sequence GC Content\n+echo "sample_id,file_path" > PBSC_file_paths.txt # Per Base Sequence Content\n+echo "sample_id,file_path" > PBNC_file_paths.txt # Per Base N Content\n+echo "sample_id,file_path" > SDL_file_paths.txt # Sequence Duplication Level\n+echo "sample_id,file_path" > SLD_file_paths.txt # Sequence Length Distribution\n+echo "sample_id,file_path" > KMC_file_paths.txt # Kmer Content\n+\n+for i in $(ls *.zip)\n+do\n+ BASE=$(echo $i | sed \'s/\\(.*\\)\\.zip/\\1/g\')\n+ echo $BASE\n+ unzip ${BASE}.zip > /dev/null 2>&1\n+ \n+ ##====== pass,warning,fail (WSF) =============\n+ awk \'/^>>/ {print}\' "$BASE"/fastqc_data.txt | grep -v \'END_MODULE\' | sed \'s/>>//\' > "$BASE"-PWF.txt\n+ echo "${BASE},${BASE}-PWF.txt" >> PWF_file_paths.txt\n+\n+ ##====== per base quality scores (PBQS) ======\n+ awk \'/^>>Per base sequence quality/ {flag=1; next} /END_MODULE/ {flag=0} flag\' "$BASE"/fastqc_data.txt >"$BASE"-PBQS.txt\n+ echo "${BASE},${BASE}-PBQS.txt" >> PBQS_file_paths.txt\n+\n+ ##====== per sequence quality scores (PSQS)\n+ awk \'/^>>Per sequence quality scores/ {flag=1; next} /END_MODULE/ {flag=0} flag\' "$BASE"/fastqc_data.txt >"$BASE"-PSQS.txt\n+ echo "${BASE},${BASE}-PSQS.txt" >> PSQS_file_paths.txt\n+\n+ ##====== Per sequence GC content (PSGC)\n+ awk \'/^>>Per sequence GC content/ {flag=1; next} /END_MODULE/ {flag=0} flag\' "$BASE"/fastqc_data.txt >"$BASE"-PSGC.txt\n+ echo "${BASE},${BASE}-PSGC.txt" >> PSGC_file_paths.txt\n+ \n+ ##====== Per Base Sequence Content (PBSC)\n+ awk \'/^>>Per base sequence content/ {flag=1; next} /END_MODULE/ {flag=0} flag\' "$BASE"/fastqc_data.txt >"$BASE"-PBSC.txt\n+ echo "${BASE},${BASE}-PBSC.txt" >> PBSC_file_paths.txt\n+ \n+ ##====== Per Base N Content (PBNC)\n+ awk \'/^>>Per base N content/ {flag=1; next} /END_MODULE/ {flag=0} flag\' "$BASE"/fastqc_data.txt >"$BASE"-PBNC.txt\n+ echo "${BASE},${BASE}-PBNC.txt" >> PBNC_file_paths.txt\n+ \n+ ##====== Sequence Duplication Level (SDL)\n+ awk \'/^>>Sequence Duplication Levels/ {flag=1; next} /END_MODULE/ {flag=0} flag\' "$BASE"/fastqc_data.txt >"$BASE"-SDL.txt\n+ echo "${BASE},${BASE}-SDL.txt" >> SDL_file_paths.txt\n+ \n+ ##====== Sequence Length Distribution (SLD)\n+ awk \'/^>>Sequence Length Distribution/ {flag=1; next} /END_MODULE/ {flag=0} flag\' "$BASE"/fastqc_data.txt >"$BASE"-'..b')\n+ PBNC_df = rbind(PBNC_df, pbnc_df)\n+}\n+```\n+\n+\n+```{r}\n+PBNC_df$N.Count = PBNC_df$N.Count * 100\n+max_phred = max(PBNC_df$N.Count) + 5\n+hchart(PBNC_df, "line", hcaes(x = as.character(Base), y = N.Count, group = sample_id)) %>%\n+ hc_title(\n+ text = "Per Base N Content"\n+ ) %>%\n+ hc_xAxis(\n+ title = list(text = "Base Position")\n+ ) %>%\n+ hc_yAxis(\n+ title = list(text = "N %"),\n+ plotLines = list(\n+ list(label = list(text = "N = 5%"),\n+ width = 2,\n+ dashStyle = "dash",\n+ color = "red",\n+ value = 5)\n+ )\n+ ) %>% \n+ hc_exporting(enabled = TRUE)\n+```\n+\n+\n+\n+\n+## Per Sequence Quality Scores\n+\n+```{r}\n+PSQS_df = data.frame()\n+PSQS_file_paths = read.csv(\'PSQS_file_paths.txt\', \n+ header = TRUE, stringsAsFactors = FALSE)\n+for(i in 1:nrow(PSQS_file_paths)) {\n+ # file_path = paste0(\'REPORT_OUTPUT_DIR/\', PSQS_file_paths[i,2])\n+ file_path = PSQS_file_paths[i,2]\n+ psqs_df = read.csv(file_path,\n+ sep=\'\\t\', header=TRUE, stringsAsFactors = FALSE) \n+ psqs_df$sample_id = rep(PSQS_file_paths[i,1], nrow(psqs_df))\n+ PSQS_df = rbind(PSQS_df, psqs_df)\n+}\n+```\n+\n+\n+```{r}\n+max_phred = max(PSQS_df$X.Quality) + 5\n+hchart(PSQS_df, "line", hcaes(x = X.Quality, y = Count, group = sample_id)) %>%\n+ hc_title(\n+ text = "Per Sequence Quality Score"\n+ ) %>%\n+ hc_xAxis(\n+ title = list(text = "Mean Sequence Quality Score"),\n+ min = 0,\n+ max = max_phred,\n+ plotLines = list(\n+ list(label = list(text = "Phred Score = 27"),\n+ width = 2,\n+ dashStyle = "dash",\n+ color = "green",\n+ value = 27),\n+ list(label = list(text = "Phred Score = 20"),\n+ width = 2,\n+ color = "red",\n+ value = 20)\n+ )\n+ ) %>% \n+ hc_exporting(enabled = TRUE)\n+```\n+\n+\n+## Per Sequence GC Content\n+\n+\n+```{r}\n+PSGC_df = data.frame()\n+PSGC_file_paths = read.csv(\'PSGC_file_paths.txt\', \n+ header = TRUE, stringsAsFactors = FALSE)\n+for(i in 1:nrow(PSGC_file_paths)) {\n+ # file_path = paste0(\'REPORT_OUTPUT_DIR/\', PSGC_file_paths[i,2])\n+ file_path = PSGC_file_paths[i,2]\n+ psgc_df = read.csv(file_path,\n+ sep=\'\\t\', header=TRUE, stringsAsFactors = FALSE) \n+ psgc_df$sample_id = rep(PSGC_file_paths[i,1], nrow(psgc_df))\n+ PSGC_df = rbind(PSGC_df, psgc_df)\n+}\n+```\n+\n+\n+```{r}\n+max_phred = max(PSGC_df$Count) + 5\n+hchart(PSGC_df, "line", hcaes(x = X.GC.Content, y = Count, group = sample_id)) %>%\n+ hc_title(\n+ text = "Per Sequence GC Content"\n+ ) %>%\n+ hc_xAxis(\n+ title = list(text = "% GC")\n+ ) %>%\n+ hc_exporting(enabled = TRUE)\n+```\n+\n+\n+## Per Base Sequence Content\n+\n+```{r}\n+PBSC_df = data.frame()\n+PBSC_file_paths = read.csv(\'PBSC_file_paths.txt\',\n+ header = TRUE, stringsAsFactors = FALSE)\n+for(i in 1:nrow(PBSC_file_paths)) {\n+ # file_path = paste0(\'REPORT_OUTPUT_DIR/\', PBSC_file_paths[i,2])\n+ file_path = PBSC_file_paths[i,2]\n+ pbsc_df = read.csv(file_path,\n+ sep=\'\\t\', header=TRUE, stringsAsFactors = FALSE) %>%\n+ mutate(Base1=as.numeric(str_split_fixed(X.Base, \'-\', 2)[,1]),\n+ Base2=as.numeric(str_split_fixed(X.Base, \'-\', 2)[,2])) %>%\n+ (function (df) {\n+ df1 = select(df, -Base2)\n+ df2 = select(df, -Base1) %>% filter(Base2 != \'\')\n+ colnames(df1) = c(colnames(df1)[1:5], \'Base\')\n+ colnames(df2) = c(colnames(df2)[1:5], \'Base\')\n+ res = rbind(df1, df2) %>% arrange(Base)\n+ return(res)\n+ })\n+ pbsc_df$sample_id = rep(PBSC_file_paths[i,1], nrow(pbsc_df))\n+ PBSC_df = rbind(PBSC_df, pbsc_df)\n+}\n+```\n+\n+\n+```{r out.width="100%"}\n+PBSC_df_2 = select(PBSC_df, -X.Base) %>%\n+ melt(id = c(\'Base\', \'sample_id\'), value.name = \'base_percentage\')\n+p = ggplot(data = PBSC_df_2, aes(x = Base, y = base_percentage, group = variable, color = variable)) +\n+ geom_line() +\n+ facet_wrap(~ sample_id)\n+ggplotly(p)\n+```\n+\n+\n+# Session Info\n+\n+```{r \'session info\'}\n+sessionInfo()\n+```\n+\n+\n' |
b |
diff -r 9d3586701985 -r 2efa46ce2c4c fastqc_report_render.R --- a/fastqc_report_render.R Mon Oct 16 21:33:31 2017 -0400 +++ b/fastqc_report_render.R Wed Oct 18 22:06:39 2017 -0400 |
[ |
@@ -1,87 +1,88 @@ -##======= Handle arguments from command line ======== -# setup R error handline to go to stderr -options(show.error.messages=FALSE, - error=function(){ - cat(geterrmessage(), file=stderr()) - quit("no", 1, F) - }) - -# we need that to not crash galaxy with an UTF8 error on German LC settings. -loc = Sys.setlocale("LC_MESSAGES", "en_US.UTF-8") - -# suppress warning -options(warn = -1) - -options(stringsAsFactors=FALSE, useFancyQuotes=FALSE) -args = commandArgs(trailingOnly=TRUE) +library(getopt) +library(rmarkdown) +library(htmltools) +library(plyr) +library(dplyr) +library(stringr) +library(highcharter) +library(DT) +library(reshape2) +library(plotly) +library(formattable) -suppressPackageStartupMessages({ - library(getopt) - library(tools) -}) - -# column 1: the long flag name -# column 2: the short flag alias. A SINGLE character string -# column 3: argument mask -# 0: no argument -# 1: argument required -# 2: argument is optional -# column 4: date type to which the flag's argument shall be cast. -# possible values: logical, integer, double, complex, character. -spec_list=list() -spec_list$READS = c('reads', 'r', '1', 'character') -spec_list$ECHO = c('echo', 'e', '1', 'character') -spec_list$FASTQC_TPL = c('fastqc_tpl', 'p', 1, 'character') -spec_list$REPORT = c('report', 'o', '1', 'character') -spec_list$REPORT_OUTPUT_DIR = c('report_output_dir', 'd', '1', 'character') +##============ Sink warnings and errors to a file ============== +## use the sink() function to wrap all code within it. +##============================================================== +zz = file('warnings_and_errors.txt') +sink(zz) +sink(zz, type = 'message') + ##---------below is the code for rendering .Rmd templates----- + + ##=============STEP 1: handle command line arguments========== + ## + ##============================================================ + # column 1: the long flag name + # column 2: the short flag alias. A SINGLE character string + # column 3: argument mask + # 0: no argument + # 1: argument required + # 2: argument is optional + # column 4: date type to which the flag's argument shall be cast. + # possible values: logical, integer, double, complex, character. + #------------------------------------------------------------- + #++++++++++++++++++++ Best practice ++++++++++++++++++++++++++ + # 1. short flag alias should match the flag in the command section in the XML file. + # 2. long flag name can be any legal R variable names + # 3. two names in args_list can have common string but one name should not be a part of another name. + # for example, one name is "ECHO", if another name is "ECHO_XXX", it will cause problems. + #+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ + args_list=list() + ##------- 1. input data --------------------- + args_list$ECHO = c('echo', 'e', '1', 'character') + args_list$READS = c('reads', 'r', '1', 'character') + ##--------2. output report and outputs -------------- + args_list$REPORT_HTML = c('report_html', 'r', '1', 'character') + args_list$REPORT_DIR = c('report_dir', 'd', '1', 'character') + args_list$SINK_MESSAGE = c('sink_message', 's', '1', 'character') + ##--------3. .Rmd templates in the tool directory ---------- + args_list$FASTQC_REPORT_RMD = c('fastqc_report_rmd', 't', '1', 'character') + ##----------------------------------------------------------- + opt = getopt(t(as.data.frame(args_list))) -spec = t(as.data.frame(spec_list)) - -opt = getopt(spec) -# arguments are accessed by long flag name (the first column in the spec matrix) -# NOT by element name in the spec_list -# example: opt$help, opt$expression_file -##====== End of arguments handling ========== - + + ##=======STEP 2: create report directory (optional)========== + ## + ##=========================================================== + dir.create(opt$report_dir) + + ##=STEP 3: replace placeholders in .Rmd with argument values= + ## + ##=========================================================== + #++ need to replace placeholders with args values one by one+ + readLines(opt$fastqc_report_rmd) %>% + (function(x) { + gsub('ECHO', opt$echo, x) + }) %>% + (function(x) { + gsub('READS', opt$reads, x) + }) %>% + (function(x) { + gsub('REPORT_DIR', opt$output_dir, x) + }) %>% + (function(x) { + fileConn = file('fastqc_report.Rmd') + writeLines(x, con=fileConn) + close(fileConn) + }) + -mgsub = function(pattern, replacement, x) { - if(length(pattern) != length(replacement) ) { - stop("pattern and replacement have to be the same in length") - } - - result = x - - for(i in 1:length(pattern)) { - result = try( gsub(pattern[i], replacement[i], x = result) ) - } - - result -} + ##=============STEP 4: render .Rmd templates================= + ## + ##=========================================================== + render('fastqc_report.Rmd', output_file = opt$report_html) -##====== replace variables in tpl file ====== -p = c('READS', - 'ECHO', - 'FASTQC_TPL', - 'REPORT_OUTPUT_DIR', - 'REPORT') -r = c(opt$reads, - opt$echo, - opt$fastqc_tpl, - opt$report_output_dir, - opt$report) - -fastqc_report_tpl = mgsub(p, r, readLines(opt$fastqc_tpl)) - -##====== write replaced text into Rmd file === -fileConn = file('fastqc_report.Rmd') -writeLines(fastqc_report_tpl, con=fileConn) -close(fileConn) - -##====== render Rmd files ==================== -rmarkdown::render('fastqc_report.Rmd') -file.copy('fastqc_report.html', opt$report, recursive=TRUE) -paste0('cp -r ./* ', opt$report_output_dir) %>% - system() - + ##--------end of code rendering .Rmd templates---------------- +sink() +##=========== End of sinking output============================= \ No newline at end of file |
b |
diff -r 9d3586701985 -r 2efa46ce2c4c fastqc_report_render_ori.R --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/fastqc_report_render_ori.R Wed Oct 18 22:06:39 2017 -0400 |
[ |
@@ -0,0 +1,87 @@ +##======= Handle arguments from command line ======== +# setup R error handline to go to stderr +options(show.error.messages = FALSE, +error = function(){ + cat(geterrmessage(), file = stderr()) + quit("no", 1, F) +}) + +# we need that to not crash galaxy with an UTF8 error on German LC settings. +loc = Sys.setlocale("LC_MESSAGES", "en_US.UTF-8") + +# suppress warning +options(warn = - 1) + +options(stringsAsFactors = FALSE, useFancyQuotes = FALSE) +args = commandArgs(trailingOnly = TRUE) + +suppressPackageStartupMessages({ + library(getopt) + library(tools) +}) + +# column 1: the long flag name +# column 2: the short flag alias. A SINGLE character string +# column 3: argument mask +# 0: no argument +# 1: argument required +# 2: argument is optional +# column 4: date type to which the flag's argument shall be cast. +# possible values: logical, integer, double, complex, character. +spec_list = list() +spec_list$READS = c('reads', 'r', '1', 'character') +spec_list$ECHO = c('echo', 'e', '1', 'character') +spec_list$FASTQC_TPL = c('fastqc_tpl', 'p', 1, 'character') +spec_list$REPORT = c('report', 'o', '1', 'character') +spec_list$REPORT_OUTPUT_DIR = c('report_output_dir', 'd', '1', 'character') + + +spec = t(as.data.frame(spec_list)) + +opt = getopt(spec) +# arguments are accessed by long flag name (the first column in the spec matrix) +# NOT by element name in the spec_list +# example: opt$help, opt$expression_file +##====== End of arguments handling ========== + + +mgsub = function(pattern, replacement, x) { + if (length(pattern) != length(replacement)) { + stop("pattern and replacement have to be the same in length") + } + + result = x + + for (i in 1 : length(pattern)) { + result = try(gsub(pattern[i], replacement[i], x = result)) + } + + result +} + + +##====== replace variables in tpl file ====== +p = c('READS', +'ECHO', +'FASTQC_TPL', +'REPORT_OUTPUT_DIR', +'REPORT') +r = c(opt$reads, +opt$echo, +opt$fastqc_tpl, +opt$report_output_dir, +opt$report) + +fastqc_report_tpl = mgsub(p, r, readLines(opt$fastqc_tpl)) + +##====== write replaced text into Rmd file === +fileConn = file('fastqc_report.Rmd') +writeLines(fastqc_report_tpl, con = fileConn) +close(fileConn) + +##====== render Rmd files ==================== +rmarkdown::render('fastqc_report.Rmd') +file.copy('fastqc_report.html', opt$report, recursive = TRUE) +paste0('cp -r ./* ', opt$report_output_dir) %>% +system() + |