annotate fastqc_report.Rmd @ 4:3073b7bd0807 draft

planemo upload for repository https://github.com/statonlab/docker-GRReport/tree/master/my_tools/rmarkdown_fastqc_report commit ddb1f6aca7619aea2e660b1729367841b56ba4c9
author mingchen0919
date Tue, 08 Aug 2017 09:36:33 -0400
parents 0374e090e38e
children e629c2288316
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
2
0374e090e38e Uploaded
mingchen0919
parents:
diff changeset
1 ---
0374e090e38e Uploaded
mingchen0919
parents:
diff changeset
2 title: "Fastqc report: short reads quality evaluation"
0374e090e38e Uploaded
mingchen0919
parents:
diff changeset
3 author: "Ming Chen"
0374e090e38e Uploaded
mingchen0919
parents:
diff changeset
4 output: html_document
0374e090e38e Uploaded
mingchen0919
parents:
diff changeset
5 ---
0374e090e38e Uploaded
mingchen0919
parents:
diff changeset
6
0374e090e38e Uploaded
mingchen0919
parents:
diff changeset
7 ```{r setup, include=FALSE}
0374e090e38e Uploaded
mingchen0919
parents:
diff changeset
8 knitr::opts_chunk$set(echo=ECHO, warning=FALSE, message=FALSE)
0374e090e38e Uploaded
mingchen0919
parents:
diff changeset
9 library(plyr)
0374e090e38e Uploaded
mingchen0919
parents:
diff changeset
10 library(stringr)
0374e090e38e Uploaded
mingchen0919
parents:
diff changeset
11 library(dplyr)
0374e090e38e Uploaded
mingchen0919
parents:
diff changeset
12 library(highcharter)
0374e090e38e Uploaded
mingchen0919
parents:
diff changeset
13 library(DT)
0374e090e38e Uploaded
mingchen0919
parents:
diff changeset
14 library(reshape2)
0374e090e38e Uploaded
mingchen0919
parents:
diff changeset
15 # library(Kmisc)
0374e090e38e Uploaded
mingchen0919
parents:
diff changeset
16 library(plotly)
0374e090e38e Uploaded
mingchen0919
parents:
diff changeset
17 library(formattable)
0374e090e38e Uploaded
mingchen0919
parents:
diff changeset
18 library(htmltools)
0374e090e38e Uploaded
mingchen0919
parents:
diff changeset
19 ```
0374e090e38e Uploaded
mingchen0919
parents:
diff changeset
20
0374e090e38e Uploaded
mingchen0919
parents:
diff changeset
21
0374e090e38e Uploaded
mingchen0919
parents:
diff changeset
22 ```{bash 'create output directory', echo=FALSE}
0374e090e38e Uploaded
mingchen0919
parents:
diff changeset
23 # create extra files directory. very important!
0374e090e38e Uploaded
mingchen0919
parents:
diff changeset
24 mkdir REPORT_OUTPUT_DIR
0374e090e38e Uploaded
mingchen0919
parents:
diff changeset
25 ```
0374e090e38e Uploaded
mingchen0919
parents:
diff changeset
26
0374e090e38e Uploaded
mingchen0919
parents:
diff changeset
27 # Fastqc analysis
0374e090e38e Uploaded
mingchen0919
parents:
diff changeset
28 ```{bash 'copy data to working directory', echo=FALSE}
0374e090e38e Uploaded
mingchen0919
parents:
diff changeset
29 # Copy uploaded data to the working directory
0374e090e38e Uploaded
mingchen0919
parents:
diff changeset
30 for f in $(echo READS | sed "s/,/ /g")
0374e090e38e Uploaded
mingchen0919
parents:
diff changeset
31 do
0374e090e38e Uploaded
mingchen0919
parents:
diff changeset
32 cp $f ./
0374e090e38e Uploaded
mingchen0919
parents:
diff changeset
33 done
0374e090e38e Uploaded
mingchen0919
parents:
diff changeset
34 ```
0374e090e38e Uploaded
mingchen0919
parents:
diff changeset
35
0374e090e38e Uploaded
mingchen0919
parents:
diff changeset
36
0374e090e38e Uploaded
mingchen0919
parents:
diff changeset
37 ```{bash 'run fastqc', echo=FALSE}
0374e090e38e Uploaded
mingchen0919
parents:
diff changeset
38 for r in $(ls *.dat)
0374e090e38e Uploaded
mingchen0919
parents:
diff changeset
39 do
0374e090e38e Uploaded
mingchen0919
parents:
diff changeset
40 fastqc -o REPORT_OUTPUT_DIR $r > /dev/null 2>&1
0374e090e38e Uploaded
mingchen0919
parents:
diff changeset
41 done
0374e090e38e Uploaded
mingchen0919
parents:
diff changeset
42 ```
0374e090e38e Uploaded
mingchen0919
parents:
diff changeset
43
0374e090e38e Uploaded
mingchen0919
parents:
diff changeset
44 ## Fastqc html reports
0374e090e38e Uploaded
mingchen0919
parents:
diff changeset
45
0374e090e38e Uploaded
mingchen0919
parents:
diff changeset
46 Below are links to ***Fastqc*** original html reports.
0374e090e38e Uploaded
mingchen0919
parents:
diff changeset
47 ```{r 'html report links'}
0374e090e38e Uploaded
mingchen0919
parents:
diff changeset
48 html_report_list = list()
0374e090e38e Uploaded
mingchen0919
parents:
diff changeset
49 html_files = list.files('REPORT_OUTPUT_DIR', pattern = '.*html')
0374e090e38e Uploaded
mingchen0919
parents:
diff changeset
50 for (i in html_files) {
0374e090e38e Uploaded
mingchen0919
parents:
diff changeset
51 html_report_list[[i]] = tags$li(tags$a(href=i, i))
0374e090e38e Uploaded
mingchen0919
parents:
diff changeset
52 }
0374e090e38e Uploaded
mingchen0919
parents:
diff changeset
53 tags$ul(html_report_list)
0374e090e38e Uploaded
mingchen0919
parents:
diff changeset
54 ```
0374e090e38e Uploaded
mingchen0919
parents:
diff changeset
55
0374e090e38e Uploaded
mingchen0919
parents:
diff changeset
56
0374e090e38e Uploaded
mingchen0919
parents:
diff changeset
57 ## Parsing fastqc data
0374e090e38e Uploaded
mingchen0919
parents:
diff changeset
58
0374e090e38e Uploaded
mingchen0919
parents:
diff changeset
59 ```{bash echo=FALSE}
0374e090e38e Uploaded
mingchen0919
parents:
diff changeset
60 ##==== copy fastqc generated zip files from report output directory to job work directory ==
0374e090e38e Uploaded
mingchen0919
parents:
diff changeset
61 cp -r REPORT_OUTPUT_DIR/*zip ./
0374e090e38e Uploaded
mingchen0919
parents:
diff changeset
62
0374e090e38e Uploaded
mingchen0919
parents:
diff changeset
63 # create a file to store data file paths
0374e090e38e Uploaded
mingchen0919
parents:
diff changeset
64 echo "sample_id,file_path" > PWF_file_paths.txt # Pass, Warning, Fail
0374e090e38e Uploaded
mingchen0919
parents:
diff changeset
65 echo "sample_id,file_path" > PBQS_file_paths.txt # Per Base Quality Score
0374e090e38e Uploaded
mingchen0919
parents:
diff changeset
66 echo "sample_id,file_path" > PSQS_file_paths.txt # Per Sequence Quality Score
0374e090e38e Uploaded
mingchen0919
parents:
diff changeset
67 echo "sample_id,file_path" > PSGC_file_paths.txt # Per Sequence GC Content
0374e090e38e Uploaded
mingchen0919
parents:
diff changeset
68 echo "sample_id,file_path" > PBSC_file_paths.txt # Per Base Sequence Content
0374e090e38e Uploaded
mingchen0919
parents:
diff changeset
69 echo "sample_id,file_path" > PBNC_file_paths.txt # Per Base N Content
0374e090e38e Uploaded
mingchen0919
parents:
diff changeset
70 echo "sample_id,file_path" > SDL_file_paths.txt # Sequence Duplication Level
0374e090e38e Uploaded
mingchen0919
parents:
diff changeset
71 echo "sample_id,file_path" > SLD_file_paths.txt # Sequence Length Distribution
0374e090e38e Uploaded
mingchen0919
parents:
diff changeset
72 echo "sample_id,file_path" > KMC_file_paths.txt # Kmer Content
0374e090e38e Uploaded
mingchen0919
parents:
diff changeset
73
0374e090e38e Uploaded
mingchen0919
parents:
diff changeset
74 for i in $(ls *.zip)
0374e090e38e Uploaded
mingchen0919
parents:
diff changeset
75 do
0374e090e38e Uploaded
mingchen0919
parents:
diff changeset
76 BASE=$(echo $i | sed 's/\(.*\)\.zip/\1/g')
0374e090e38e Uploaded
mingchen0919
parents:
diff changeset
77 echo $BASE
0374e090e38e Uploaded
mingchen0919
parents:
diff changeset
78 unzip ${BASE}.zip > /dev/null 2>&1
0374e090e38e Uploaded
mingchen0919
parents:
diff changeset
79
0374e090e38e Uploaded
mingchen0919
parents:
diff changeset
80 ##====== pass,warning,fail (WSF) =============
0374e090e38e Uploaded
mingchen0919
parents:
diff changeset
81 awk '/^>>/ {print}' "$BASE"/fastqc_data.txt | grep -v 'END_MODULE' | sed 's/>>//' > "$BASE"-PWF.txt
0374e090e38e Uploaded
mingchen0919
parents:
diff changeset
82 echo "${BASE},${BASE}-PWF.txt" >> PWF_file_paths.txt
0374e090e38e Uploaded
mingchen0919
parents:
diff changeset
83
0374e090e38e Uploaded
mingchen0919
parents:
diff changeset
84 ##====== per base quality scores (PBQS) ======
0374e090e38e Uploaded
mingchen0919
parents:
diff changeset
85 awk '/^>>Per base sequence quality/ {flag=1; next} /END_MODULE/ {flag=0} flag' "$BASE"/fastqc_data.txt >"$BASE"-PBQS.txt
0374e090e38e Uploaded
mingchen0919
parents:
diff changeset
86 echo "${BASE},${BASE}-PBQS.txt" >> PBQS_file_paths.txt
0374e090e38e Uploaded
mingchen0919
parents:
diff changeset
87
0374e090e38e Uploaded
mingchen0919
parents:
diff changeset
88 ##====== per sequence quality scores (PSQS)
0374e090e38e Uploaded
mingchen0919
parents:
diff changeset
89 awk '/^>>Per sequence quality scores/ {flag=1; next} /END_MODULE/ {flag=0} flag' "$BASE"/fastqc_data.txt >"$BASE"-PSQS.txt
0374e090e38e Uploaded
mingchen0919
parents:
diff changeset
90 echo "${BASE},${BASE}-PSQS.txt" >> PSQS_file_paths.txt
0374e090e38e Uploaded
mingchen0919
parents:
diff changeset
91
0374e090e38e Uploaded
mingchen0919
parents:
diff changeset
92 ##====== Per sequence GC content (PSGC)
0374e090e38e Uploaded
mingchen0919
parents:
diff changeset
93 awk '/^>>Per sequence GC content/ {flag=1; next} /END_MODULE/ {flag=0} flag' "$BASE"/fastqc_data.txt >"$BASE"-PSGC.txt
0374e090e38e Uploaded
mingchen0919
parents:
diff changeset
94 echo "${BASE},${BASE}-PSGC.txt" >> PSGC_file_paths.txt
0374e090e38e Uploaded
mingchen0919
parents:
diff changeset
95
0374e090e38e Uploaded
mingchen0919
parents:
diff changeset
96 ##====== Per Base Sequence Content (PBSC)
0374e090e38e Uploaded
mingchen0919
parents:
diff changeset
97 awk '/^>>Per base sequence content/ {flag=1; next} /END_MODULE/ {flag=0} flag' "$BASE"/fastqc_data.txt >"$BASE"-PBSC.txt
0374e090e38e Uploaded
mingchen0919
parents:
diff changeset
98 echo "${BASE},${BASE}-PBSC.txt" >> PBSC_file_paths.txt
0374e090e38e Uploaded
mingchen0919
parents:
diff changeset
99
0374e090e38e Uploaded
mingchen0919
parents:
diff changeset
100 ##====== Per Base N Content (PBNC)
0374e090e38e Uploaded
mingchen0919
parents:
diff changeset
101 awk '/^>>Per base N content/ {flag=1; next} /END_MODULE/ {flag=0} flag' "$BASE"/fastqc_data.txt >"$BASE"-PBNC.txt
0374e090e38e Uploaded
mingchen0919
parents:
diff changeset
102 echo "${BASE},${BASE}-PBNC.txt" >> PBNC_file_paths.txt
0374e090e38e Uploaded
mingchen0919
parents:
diff changeset
103
0374e090e38e Uploaded
mingchen0919
parents:
diff changeset
104 ##====== Sequence Duplication Level (SDL)
0374e090e38e Uploaded
mingchen0919
parents:
diff changeset
105 awk '/^>>Sequence Duplication Levels/ {flag=1; next} /END_MODULE/ {flag=0} flag' "$BASE"/fastqc_data.txt >"$BASE"-SDL.txt
0374e090e38e Uploaded
mingchen0919
parents:
diff changeset
106 echo "${BASE},${BASE}-SDL.txt" >> SDL_file_paths.txt
0374e090e38e Uploaded
mingchen0919
parents:
diff changeset
107
0374e090e38e Uploaded
mingchen0919
parents:
diff changeset
108 ##====== Sequence Length Distribution (SLD)
0374e090e38e Uploaded
mingchen0919
parents:
diff changeset
109 awk '/^>>Sequence Length Distribution/ {flag=1; next} /END_MODULE/ {flag=0} flag' "$BASE"/fastqc_data.txt >"$BASE"-SLD.txt
0374e090e38e Uploaded
mingchen0919
parents:
diff changeset
110 echo "${BASE},${BASE}-SLD.txt" >> SLD_file_paths.txt
0374e090e38e Uploaded
mingchen0919
parents:
diff changeset
111
0374e090e38e Uploaded
mingchen0919
parents:
diff changeset
112 ##====== Kmer Content ============
0374e090e38e Uploaded
mingchen0919
parents:
diff changeset
113 awk '/^>>Kmer Content/ {flag=1; next} /END_MODULE/ {flag=0} flag' "$BASE"/fastqc_data.txt >"$BASE"-KMC.txt
0374e090e38e Uploaded
mingchen0919
parents:
diff changeset
114 echo "${BASE},${BASE}-KMC.txt" >> KMC_file_paths.txt
0374e090e38e Uploaded
mingchen0919
parents:
diff changeset
115
0374e090e38e Uploaded
mingchen0919
parents:
diff changeset
116 done
0374e090e38e Uploaded
mingchen0919
parents:
diff changeset
117 ```
0374e090e38e Uploaded
mingchen0919
parents:
diff changeset
118
0374e090e38e Uploaded
mingchen0919
parents:
diff changeset
119
0374e090e38e Uploaded
mingchen0919
parents:
diff changeset
120 ## Evaluation Overview
0374e090e38e Uploaded
mingchen0919
parents:
diff changeset
121
0374e090e38e Uploaded
mingchen0919
parents:
diff changeset
122 ```{r 'overview'}
0374e090e38e Uploaded
mingchen0919
parents:
diff changeset
123 PWF_file_paths = read.csv('PWF_file_paths.txt',
0374e090e38e Uploaded
mingchen0919
parents:
diff changeset
124 header = TRUE, stringsAsFactors = FALSE)
0374e090e38e Uploaded
mingchen0919
parents:
diff changeset
125 rm('PWF_df')
0374e090e38e Uploaded
mingchen0919
parents:
diff changeset
126 for(i in 1:nrow(PWF_file_paths)) {
0374e090e38e Uploaded
mingchen0919
parents:
diff changeset
127 file_path = PWF_file_paths[i,2]
0374e090e38e Uploaded
mingchen0919
parents:
diff changeset
128 pwf_df = read.csv(file_path,
0374e090e38e Uploaded
mingchen0919
parents:
diff changeset
129 sep='\t', header=FALSE, stringsAsFactors = FALSE)
0374e090e38e Uploaded
mingchen0919
parents:
diff changeset
130 colnames(pwf_df) = c('item', PWF_file_paths[i,1])
0374e090e38e Uploaded
mingchen0919
parents:
diff changeset
131 if (!exists('PWF_df')) {
0374e090e38e Uploaded
mingchen0919
parents:
diff changeset
132 PWF_df = pwf_df
0374e090e38e Uploaded
mingchen0919
parents:
diff changeset
133 } else {
0374e090e38e Uploaded
mingchen0919
parents:
diff changeset
134 PWF_df = cbind(PWF_df, pwf_df[,2,drop=FALSE])
0374e090e38e Uploaded
mingchen0919
parents:
diff changeset
135 }
0374e090e38e Uploaded
mingchen0919
parents:
diff changeset
136 }
0374e090e38e Uploaded
mingchen0919
parents:
diff changeset
137 ```
0374e090e38e Uploaded
mingchen0919
parents:
diff changeset
138
0374e090e38e Uploaded
mingchen0919
parents:
diff changeset
139 ```{r}
0374e090e38e Uploaded
mingchen0919
parents:
diff changeset
140 my_icon = c('ok', 'remove', 'star')
0374e090e38e Uploaded
mingchen0919
parents:
diff changeset
141 names(my_icon) = c('pass', 'fail', 'warn')
0374e090e38e Uploaded
mingchen0919
parents:
diff changeset
142 evaluate_list = list()
0374e090e38e Uploaded
mingchen0919
parents:
diff changeset
143 for (i in colnames(PWF_df)[-1]) {
0374e090e38e Uploaded
mingchen0919
parents:
diff changeset
144 evaluate_list[[i]] = formatter(
0374e090e38e Uploaded
mingchen0919
parents:
diff changeset
145 "span",
0374e090e38e Uploaded
mingchen0919
parents:
diff changeset
146 style = x ~ style("background-color" = ifelse(x =='pass', '#9CD027', ifelse(x == 'fail', '#CC0000', '#FF4E00')),
0374e090e38e Uploaded
mingchen0919
parents:
diff changeset
147 "color" = "white",
0374e090e38e Uploaded
mingchen0919
parents:
diff changeset
148 "width" = "50px",
0374e090e38e Uploaded
mingchen0919
parents:
diff changeset
149 "float" = "left",
0374e090e38e Uploaded
mingchen0919
parents:
diff changeset
150 "padding-right" = "5px")
0374e090e38e Uploaded
mingchen0919
parents:
diff changeset
151 )
0374e090e38e Uploaded
mingchen0919
parents:
diff changeset
152 }
0374e090e38e Uploaded
mingchen0919
parents:
diff changeset
153
0374e090e38e Uploaded
mingchen0919
parents:
diff changeset
154 formattable(PWF_df, evaluate_list)
0374e090e38e Uploaded
mingchen0919
parents:
diff changeset
155 ```
0374e090e38e Uploaded
mingchen0919
parents:
diff changeset
156
0374e090e38e Uploaded
mingchen0919
parents:
diff changeset
157
0374e090e38e Uploaded
mingchen0919
parents:
diff changeset
158 ## Per Base Quality Scores
0374e090e38e Uploaded
mingchen0919
parents:
diff changeset
159
0374e090e38e Uploaded
mingchen0919
parents:
diff changeset
160 ```{r}
0374e090e38e Uploaded
mingchen0919
parents:
diff changeset
161 PBQS_df = data.frame()
0374e090e38e Uploaded
mingchen0919
parents:
diff changeset
162 PBQS_file_paths = read.csv('PBQS_file_paths.txt',
0374e090e38e Uploaded
mingchen0919
parents:
diff changeset
163 header = TRUE, stringsAsFactors = FALSE)
0374e090e38e Uploaded
mingchen0919
parents:
diff changeset
164 for(i in 1:nrow(PBQS_file_paths)) {
0374e090e38e Uploaded
mingchen0919
parents:
diff changeset
165 # file_path = paste0('REPORT_OUTPUT_DIR/', PBQS_file_paths[i,2])
0374e090e38e Uploaded
mingchen0919
parents:
diff changeset
166 file_path = PBQS_file_paths[i,2]
0374e090e38e Uploaded
mingchen0919
parents:
diff changeset
167 pbqs_df = read.csv(file_path,
0374e090e38e Uploaded
mingchen0919
parents:
diff changeset
168 sep='\t', header=TRUE, stringsAsFactors = FALSE) %>%
0374e090e38e Uploaded
mingchen0919
parents:
diff changeset
169 mutate(Base1=as.numeric(str_split_fixed(X.Base, '-', 2)[,1]),
0374e090e38e Uploaded
mingchen0919
parents:
diff changeset
170 Base2=as.numeric(str_split_fixed(X.Base, '-', 2)[,2])) %>%
0374e090e38e Uploaded
mingchen0919
parents:
diff changeset
171 (function (df) {
0374e090e38e Uploaded
mingchen0919
parents:
diff changeset
172 df1 = select(df, -Base2)
0374e090e38e Uploaded
mingchen0919
parents:
diff changeset
173 df2 = select(df, -Base1) %>% filter(Base2 != '')
0374e090e38e Uploaded
mingchen0919
parents:
diff changeset
174 colnames(df1) = c(colnames(df1)[1:7], 'Base')
0374e090e38e Uploaded
mingchen0919
parents:
diff changeset
175 colnames(df2) = c(colnames(df2)[1:7], 'Base')
0374e090e38e Uploaded
mingchen0919
parents:
diff changeset
176 res = rbind(df1, df2) %>% arrange(Base)
0374e090e38e Uploaded
mingchen0919
parents:
diff changeset
177 return(res)
0374e090e38e Uploaded
mingchen0919
parents:
diff changeset
178 })
0374e090e38e Uploaded
mingchen0919
parents:
diff changeset
179 pbqs_df$sample_id = rep(PBQS_file_paths[i,1], nrow(pbqs_df))
0374e090e38e Uploaded
mingchen0919
parents:
diff changeset
180 PBQS_df = rbind(PBQS_df, pbqs_df)
0374e090e38e Uploaded
mingchen0919
parents:
diff changeset
181 }
0374e090e38e Uploaded
mingchen0919
parents:
diff changeset
182 ```
0374e090e38e Uploaded
mingchen0919
parents:
diff changeset
183
0374e090e38e Uploaded
mingchen0919
parents:
diff changeset
184
0374e090e38e Uploaded
mingchen0919
parents:
diff changeset
185 ```{r}
0374e090e38e Uploaded
mingchen0919
parents:
diff changeset
186 # datatable(PBQS_df)
0374e090e38e Uploaded
mingchen0919
parents:
diff changeset
187 max_phred = max(PBQS_df$Mean) + 10
0374e090e38e Uploaded
mingchen0919
parents:
diff changeset
188 hchart(PBQS_df, "line", hcaes(x = Base, y = Mean, group = sample_id)) %>%
0374e090e38e Uploaded
mingchen0919
parents:
diff changeset
189 hc_title(
0374e090e38e Uploaded
mingchen0919
parents:
diff changeset
190 text = "Per Base Quality Score"
0374e090e38e Uploaded
mingchen0919
parents:
diff changeset
191 ) %>%
0374e090e38e Uploaded
mingchen0919
parents:
diff changeset
192 hc_yAxis(
0374e090e38e Uploaded
mingchen0919
parents:
diff changeset
193 title = list(text = "Mean Base Quality Score"),
0374e090e38e Uploaded
mingchen0919
parents:
diff changeset
194 min = 0,
0374e090e38e Uploaded
mingchen0919
parents:
diff changeset
195 max = max_phred,
0374e090e38e Uploaded
mingchen0919
parents:
diff changeset
196 plotLines = list(
0374e090e38e Uploaded
mingchen0919
parents:
diff changeset
197 list(label = list(text = "Phred Score = 27"),
0374e090e38e Uploaded
mingchen0919
parents:
diff changeset
198 width = 2,
0374e090e38e Uploaded
mingchen0919
parents:
diff changeset
199 dashStyle = "dash",
0374e090e38e Uploaded
mingchen0919
parents:
diff changeset
200 color = "green",
0374e090e38e Uploaded
mingchen0919
parents:
diff changeset
201 value = 27),
0374e090e38e Uploaded
mingchen0919
parents:
diff changeset
202 list(label = list(text = "Phred Score = 20"),
0374e090e38e Uploaded
mingchen0919
parents:
diff changeset
203 width = 2,
0374e090e38e Uploaded
mingchen0919
parents:
diff changeset
204 color = "red",
0374e090e38e Uploaded
mingchen0919
parents:
diff changeset
205 value = 20)
0374e090e38e Uploaded
mingchen0919
parents:
diff changeset
206 )
0374e090e38e Uploaded
mingchen0919
parents:
diff changeset
207 ) %>%
0374e090e38e Uploaded
mingchen0919
parents:
diff changeset
208 hc_exporting(enabled = TRUE)
0374e090e38e Uploaded
mingchen0919
parents:
diff changeset
209 ```
0374e090e38e Uploaded
mingchen0919
parents:
diff changeset
210
0374e090e38e Uploaded
mingchen0919
parents:
diff changeset
211
0374e090e38e Uploaded
mingchen0919
parents:
diff changeset
212 ## Per Base N Content
0374e090e38e Uploaded
mingchen0919
parents:
diff changeset
213
0374e090e38e Uploaded
mingchen0919
parents:
diff changeset
214 ```{r}
0374e090e38e Uploaded
mingchen0919
parents:
diff changeset
215 PBNC_df = data.frame()
0374e090e38e Uploaded
mingchen0919
parents:
diff changeset
216 PBNC_file_paths = read.csv('PBNC_file_paths.txt',
0374e090e38e Uploaded
mingchen0919
parents:
diff changeset
217 header = TRUE, stringsAsFactors = FALSE)
0374e090e38e Uploaded
mingchen0919
parents:
diff changeset
218 for(i in 1:nrow(PBNC_file_paths)) {
0374e090e38e Uploaded
mingchen0919
parents:
diff changeset
219 # file_path = paste0('REPORT_OUTPUT_DIR/', PBNC_file_paths[i,2])
0374e090e38e Uploaded
mingchen0919
parents:
diff changeset
220 file_path = PBNC_file_paths[i,2]
0374e090e38e Uploaded
mingchen0919
parents:
diff changeset
221 pbnc_df = read.csv(file_path,
0374e090e38e Uploaded
mingchen0919
parents:
diff changeset
222 sep='\t', header=TRUE, stringsAsFactors = FALSE) %>%
0374e090e38e Uploaded
mingchen0919
parents:
diff changeset
223 mutate(Base1=as.numeric(str_split_fixed(X.Base, '-', 2)[,1]),
0374e090e38e Uploaded
mingchen0919
parents:
diff changeset
224 Base2=as.numeric(str_split_fixed(X.Base, '-', 2)[,2])) %>%
0374e090e38e Uploaded
mingchen0919
parents:
diff changeset
225 (function (df) {
0374e090e38e Uploaded
mingchen0919
parents:
diff changeset
226 df1 = select(df, -Base2)
0374e090e38e Uploaded
mingchen0919
parents:
diff changeset
227 df2 = select(df, -Base1) %>% filter(Base2 != '')
0374e090e38e Uploaded
mingchen0919
parents:
diff changeset
228 colnames(df1) = c(colnames(df1)[1:2], 'Base')
0374e090e38e Uploaded
mingchen0919
parents:
diff changeset
229 colnames(df2) = c(colnames(df2)[1:2], 'Base')
0374e090e38e Uploaded
mingchen0919
parents:
diff changeset
230 res = rbind(df1, df2) %>% arrange(Base)
0374e090e38e Uploaded
mingchen0919
parents:
diff changeset
231 return(res)
0374e090e38e Uploaded
mingchen0919
parents:
diff changeset
232 })
0374e090e38e Uploaded
mingchen0919
parents:
diff changeset
233 pbnc_df$sample_id = rep(PBNC_file_paths[i,1], nrow(pbnc_df))
0374e090e38e Uploaded
mingchen0919
parents:
diff changeset
234 PBNC_df = rbind(PBNC_df, pbnc_df)
0374e090e38e Uploaded
mingchen0919
parents:
diff changeset
235 }
0374e090e38e Uploaded
mingchen0919
parents:
diff changeset
236 ```
0374e090e38e Uploaded
mingchen0919
parents:
diff changeset
237
0374e090e38e Uploaded
mingchen0919
parents:
diff changeset
238
0374e090e38e Uploaded
mingchen0919
parents:
diff changeset
239 ```{r}
0374e090e38e Uploaded
mingchen0919
parents:
diff changeset
240 PBNC_df$N.Count = PBNC_df$N.Count * 100
0374e090e38e Uploaded
mingchen0919
parents:
diff changeset
241 max_phred = max(PBNC_df$N.Count) + 5
0374e090e38e Uploaded
mingchen0919
parents:
diff changeset
242 hchart(PBNC_df, "line", hcaes(x = as.character(Base), y = N.Count, group = sample_id)) %>%
0374e090e38e Uploaded
mingchen0919
parents:
diff changeset
243 hc_title(
0374e090e38e Uploaded
mingchen0919
parents:
diff changeset
244 text = "Per Base N Content"
0374e090e38e Uploaded
mingchen0919
parents:
diff changeset
245 ) %>%
0374e090e38e Uploaded
mingchen0919
parents:
diff changeset
246 hc_xAxis(
0374e090e38e Uploaded
mingchen0919
parents:
diff changeset
247 title = list(text = "Base Position")
0374e090e38e Uploaded
mingchen0919
parents:
diff changeset
248 ) %>%
0374e090e38e Uploaded
mingchen0919
parents:
diff changeset
249 hc_yAxis(
0374e090e38e Uploaded
mingchen0919
parents:
diff changeset
250 title = list(text = "N %"),
0374e090e38e Uploaded
mingchen0919
parents:
diff changeset
251 plotLines = list(
0374e090e38e Uploaded
mingchen0919
parents:
diff changeset
252 list(label = list(text = "N = 5%"),
0374e090e38e Uploaded
mingchen0919
parents:
diff changeset
253 width = 2,
0374e090e38e Uploaded
mingchen0919
parents:
diff changeset
254 dashStyle = "dash",
0374e090e38e Uploaded
mingchen0919
parents:
diff changeset
255 color = "red",
0374e090e38e Uploaded
mingchen0919
parents:
diff changeset
256 value = 5)
0374e090e38e Uploaded
mingchen0919
parents:
diff changeset
257 )
0374e090e38e Uploaded
mingchen0919
parents:
diff changeset
258 ) %>%
0374e090e38e Uploaded
mingchen0919
parents:
diff changeset
259 hc_exporting(enabled = TRUE)
0374e090e38e Uploaded
mingchen0919
parents:
diff changeset
260 ```
0374e090e38e Uploaded
mingchen0919
parents:
diff changeset
261
0374e090e38e Uploaded
mingchen0919
parents:
diff changeset
262
0374e090e38e Uploaded
mingchen0919
parents:
diff changeset
263
0374e090e38e Uploaded
mingchen0919
parents:
diff changeset
264
0374e090e38e Uploaded
mingchen0919
parents:
diff changeset
265 ## Per Sequence Quality Scores
0374e090e38e Uploaded
mingchen0919
parents:
diff changeset
266
0374e090e38e Uploaded
mingchen0919
parents:
diff changeset
267 ```{r}
0374e090e38e Uploaded
mingchen0919
parents:
diff changeset
268 PSQS_df = data.frame()
0374e090e38e Uploaded
mingchen0919
parents:
diff changeset
269 PSQS_file_paths = read.csv('PSQS_file_paths.txt',
0374e090e38e Uploaded
mingchen0919
parents:
diff changeset
270 header = TRUE, stringsAsFactors = FALSE)
0374e090e38e Uploaded
mingchen0919
parents:
diff changeset
271 for(i in 1:nrow(PSQS_file_paths)) {
0374e090e38e Uploaded
mingchen0919
parents:
diff changeset
272 # file_path = paste0('REPORT_OUTPUT_DIR/', PSQS_file_paths[i,2])
0374e090e38e Uploaded
mingchen0919
parents:
diff changeset
273 file_path = PSQS_file_paths[i,2]
0374e090e38e Uploaded
mingchen0919
parents:
diff changeset
274 psqs_df = read.csv(file_path,
0374e090e38e Uploaded
mingchen0919
parents:
diff changeset
275 sep='\t', header=TRUE, stringsAsFactors = FALSE)
0374e090e38e Uploaded
mingchen0919
parents:
diff changeset
276 psqs_df$sample_id = rep(PSQS_file_paths[i,1], nrow(psqs_df))
0374e090e38e Uploaded
mingchen0919
parents:
diff changeset
277 PSQS_df = rbind(PSQS_df, psqs_df)
0374e090e38e Uploaded
mingchen0919
parents:
diff changeset
278 }
0374e090e38e Uploaded
mingchen0919
parents:
diff changeset
279 ```
0374e090e38e Uploaded
mingchen0919
parents:
diff changeset
280
0374e090e38e Uploaded
mingchen0919
parents:
diff changeset
281
0374e090e38e Uploaded
mingchen0919
parents:
diff changeset
282 ```{r}
0374e090e38e Uploaded
mingchen0919
parents:
diff changeset
283 max_phred = max(PSQS_df$X.Quality) + 5
0374e090e38e Uploaded
mingchen0919
parents:
diff changeset
284 hchart(PSQS_df, "line", hcaes(x = X.Quality, y = Count, group = sample_id)) %>%
0374e090e38e Uploaded
mingchen0919
parents:
diff changeset
285 hc_title(
0374e090e38e Uploaded
mingchen0919
parents:
diff changeset
286 text = "Per Sequence Quality Score"
0374e090e38e Uploaded
mingchen0919
parents:
diff changeset
287 ) %>%
0374e090e38e Uploaded
mingchen0919
parents:
diff changeset
288 hc_xAxis(
0374e090e38e Uploaded
mingchen0919
parents:
diff changeset
289 title = list(text = "Mean Sequence Quality Score"),
0374e090e38e Uploaded
mingchen0919
parents:
diff changeset
290 min = 0,
0374e090e38e Uploaded
mingchen0919
parents:
diff changeset
291 max = max_phred,
0374e090e38e Uploaded
mingchen0919
parents:
diff changeset
292 plotLines = list(
0374e090e38e Uploaded
mingchen0919
parents:
diff changeset
293 list(label = list(text = "Phred Score = 27"),
0374e090e38e Uploaded
mingchen0919
parents:
diff changeset
294 width = 2,
0374e090e38e Uploaded
mingchen0919
parents:
diff changeset
295 dashStyle = "dash",
0374e090e38e Uploaded
mingchen0919
parents:
diff changeset
296 color = "green",
0374e090e38e Uploaded
mingchen0919
parents:
diff changeset
297 value = 27),
0374e090e38e Uploaded
mingchen0919
parents:
diff changeset
298 list(label = list(text = "Phred Score = 20"),
0374e090e38e Uploaded
mingchen0919
parents:
diff changeset
299 width = 2,
0374e090e38e Uploaded
mingchen0919
parents:
diff changeset
300 color = "red",
0374e090e38e Uploaded
mingchen0919
parents:
diff changeset
301 value = 20)
0374e090e38e Uploaded
mingchen0919
parents:
diff changeset
302 )
0374e090e38e Uploaded
mingchen0919
parents:
diff changeset
303 ) %>%
0374e090e38e Uploaded
mingchen0919
parents:
diff changeset
304 hc_exporting(enabled = TRUE)
0374e090e38e Uploaded
mingchen0919
parents:
diff changeset
305 ```
0374e090e38e Uploaded
mingchen0919
parents:
diff changeset
306
0374e090e38e Uploaded
mingchen0919
parents:
diff changeset
307
0374e090e38e Uploaded
mingchen0919
parents:
diff changeset
308 ## Per Sequence GC Content
0374e090e38e Uploaded
mingchen0919
parents:
diff changeset
309
0374e090e38e Uploaded
mingchen0919
parents:
diff changeset
310
0374e090e38e Uploaded
mingchen0919
parents:
diff changeset
311 ```{r}
0374e090e38e Uploaded
mingchen0919
parents:
diff changeset
312 PSGC_df = data.frame()
0374e090e38e Uploaded
mingchen0919
parents:
diff changeset
313 PSGC_file_paths = read.csv('PSGC_file_paths.txt',
0374e090e38e Uploaded
mingchen0919
parents:
diff changeset
314 header = TRUE, stringsAsFactors = FALSE)
0374e090e38e Uploaded
mingchen0919
parents:
diff changeset
315 for(i in 1:nrow(PSGC_file_paths)) {
0374e090e38e Uploaded
mingchen0919
parents:
diff changeset
316 # file_path = paste0('REPORT_OUTPUT_DIR/', PSGC_file_paths[i,2])
0374e090e38e Uploaded
mingchen0919
parents:
diff changeset
317 file_path = PSGC_file_paths[i,2]
0374e090e38e Uploaded
mingchen0919
parents:
diff changeset
318 psgc_df = read.csv(file_path,
0374e090e38e Uploaded
mingchen0919
parents:
diff changeset
319 sep='\t', header=TRUE, stringsAsFactors = FALSE)
0374e090e38e Uploaded
mingchen0919
parents:
diff changeset
320 psgc_df$sample_id = rep(PSGC_file_paths[i,1], nrow(psgc_df))
0374e090e38e Uploaded
mingchen0919
parents:
diff changeset
321 PSGC_df = rbind(PSGC_df, psgc_df)
0374e090e38e Uploaded
mingchen0919
parents:
diff changeset
322 }
0374e090e38e Uploaded
mingchen0919
parents:
diff changeset
323 ```
0374e090e38e Uploaded
mingchen0919
parents:
diff changeset
324
0374e090e38e Uploaded
mingchen0919
parents:
diff changeset
325
0374e090e38e Uploaded
mingchen0919
parents:
diff changeset
326 ```{r}
0374e090e38e Uploaded
mingchen0919
parents:
diff changeset
327 max_phred = max(PSGC_df$Count) + 5
0374e090e38e Uploaded
mingchen0919
parents:
diff changeset
328 hchart(PSGC_df, "line", hcaes(x = X.GC.Content, y = Count, group = sample_id)) %>%
0374e090e38e Uploaded
mingchen0919
parents:
diff changeset
329 hc_title(
0374e090e38e Uploaded
mingchen0919
parents:
diff changeset
330 text = "Per Sequence GC Content"
0374e090e38e Uploaded
mingchen0919
parents:
diff changeset
331 ) %>%
0374e090e38e Uploaded
mingchen0919
parents:
diff changeset
332 hc_xAxis(
0374e090e38e Uploaded
mingchen0919
parents:
diff changeset
333 title = list(text = "% GC")
0374e090e38e Uploaded
mingchen0919
parents:
diff changeset
334 ) %>%
0374e090e38e Uploaded
mingchen0919
parents:
diff changeset
335 hc_exporting(enabled = TRUE)
0374e090e38e Uploaded
mingchen0919
parents:
diff changeset
336 ```
0374e090e38e Uploaded
mingchen0919
parents:
diff changeset
337
0374e090e38e Uploaded
mingchen0919
parents:
diff changeset
338
0374e090e38e Uploaded
mingchen0919
parents:
diff changeset
339 ## Per Base Sequence Content
0374e090e38e Uploaded
mingchen0919
parents:
diff changeset
340
0374e090e38e Uploaded
mingchen0919
parents:
diff changeset
341 ```{r}
0374e090e38e Uploaded
mingchen0919
parents:
diff changeset
342 PBSC_df = data.frame()
0374e090e38e Uploaded
mingchen0919
parents:
diff changeset
343 PBSC_file_paths = read.csv('PBSC_file_paths.txt',
0374e090e38e Uploaded
mingchen0919
parents:
diff changeset
344 header = TRUE, stringsAsFactors = FALSE)
0374e090e38e Uploaded
mingchen0919
parents:
diff changeset
345 for(i in 1:nrow(PBSC_file_paths)) {
0374e090e38e Uploaded
mingchen0919
parents:
diff changeset
346 # file_path = paste0('REPORT_OUTPUT_DIR/', PBSC_file_paths[i,2])
0374e090e38e Uploaded
mingchen0919
parents:
diff changeset
347 file_path = PBSC_file_paths[i,2]
0374e090e38e Uploaded
mingchen0919
parents:
diff changeset
348 pbsc_df = read.csv(file_path,
0374e090e38e Uploaded
mingchen0919
parents:
diff changeset
349 sep='\t', header=TRUE, stringsAsFactors = FALSE) %>%
0374e090e38e Uploaded
mingchen0919
parents:
diff changeset
350 mutate(Base1=as.numeric(str_split_fixed(X.Base, '-', 2)[,1]),
0374e090e38e Uploaded
mingchen0919
parents:
diff changeset
351 Base2=as.numeric(str_split_fixed(X.Base, '-', 2)[,2])) %>%
0374e090e38e Uploaded
mingchen0919
parents:
diff changeset
352 (function (df) {
0374e090e38e Uploaded
mingchen0919
parents:
diff changeset
353 df1 = select(df, -Base2)
0374e090e38e Uploaded
mingchen0919
parents:
diff changeset
354 df2 = select(df, -Base1) %>% filter(Base2 != '')
0374e090e38e Uploaded
mingchen0919
parents:
diff changeset
355 colnames(df1) = c(colnames(df1)[1:5], 'Base')
0374e090e38e Uploaded
mingchen0919
parents:
diff changeset
356 colnames(df2) = c(colnames(df2)[1:5], 'Base')
0374e090e38e Uploaded
mingchen0919
parents:
diff changeset
357 res = rbind(df1, df2) %>% arrange(Base)
0374e090e38e Uploaded
mingchen0919
parents:
diff changeset
358 return(res)
0374e090e38e Uploaded
mingchen0919
parents:
diff changeset
359 })
0374e090e38e Uploaded
mingchen0919
parents:
diff changeset
360 pbsc_df$sample_id = rep(PBSC_file_paths[i,1], nrow(pbsc_df))
0374e090e38e Uploaded
mingchen0919
parents:
diff changeset
361 PBSC_df = rbind(PBSC_df, pbsc_df)
0374e090e38e Uploaded
mingchen0919
parents:
diff changeset
362 }
0374e090e38e Uploaded
mingchen0919
parents:
diff changeset
363 ```
0374e090e38e Uploaded
mingchen0919
parents:
diff changeset
364
0374e090e38e Uploaded
mingchen0919
parents:
diff changeset
365
0374e090e38e Uploaded
mingchen0919
parents:
diff changeset
366 ```{r out.width="100%"}
0374e090e38e Uploaded
mingchen0919
parents:
diff changeset
367 PBSC_df_2 = select(PBSC_df, -X.Base) %>%
0374e090e38e Uploaded
mingchen0919
parents:
diff changeset
368 melt(id = c('Base', 'sample_id'), value.name = 'base_percentage')
0374e090e38e Uploaded
mingchen0919
parents:
diff changeset
369 p = ggplot(data = PBSC_df_2, aes(x = Base, y = base_percentage, group = variable, color = variable)) +
0374e090e38e Uploaded
mingchen0919
parents:
diff changeset
370 geom_line() +
0374e090e38e Uploaded
mingchen0919
parents:
diff changeset
371 facet_wrap(~ sample_id)
0374e090e38e Uploaded
mingchen0919
parents:
diff changeset
372 ggplotly(p)
0374e090e38e Uploaded
mingchen0919
parents:
diff changeset
373 ```
0374e090e38e Uploaded
mingchen0919
parents:
diff changeset
374
0374e090e38e Uploaded
mingchen0919
parents:
diff changeset
375
0374e090e38e Uploaded
mingchen0919
parents:
diff changeset
376 ## References
0374e090e38e Uploaded
mingchen0919
parents:
diff changeset
377
0374e090e38e Uploaded
mingchen0919
parents:
diff changeset
378 * Andrews, Simon. "FastQC: a quality control tool for high throughput sequence data." (2010): 175-176.
0374e090e38e Uploaded
mingchen0919
parents:
diff changeset
379 * 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.
0374e090e38e Uploaded
mingchen0919
parents:
diff changeset
380 * Afgan, Enis, et al. "The Galaxy platform for accessible, reproducible and collaborative biomedical analyses: 2016 update." Nucleic acids research (2016): gkw343.
0374e090e38e Uploaded
mingchen0919
parents:
diff changeset
381 * Highcharts. https://www.highcharts.com/. (access by May 26, 2017).
0374e090e38e Uploaded
mingchen0919
parents:
diff changeset
382 * 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/.
0374e090e38e Uploaded
mingchen0919
parents:
diff changeset
383 * Joshua Kunst (2017). highcharter: A Wrapper for the 'Highcharts' Library. R package version 0.5.0. https://CRAN.R-project.org/package=highcharter
0374e090e38e Uploaded
mingchen0919
parents:
diff changeset
384 * 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