annotate fastqc_report.Rmd @ 8:06d0fdd05cae draft

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