Mercurial > repos > mingchen0919 > aurora_bdss_sra
annotate rmarkdown_report.Rmd @ 3:cf17a4199861 draft
planemo upload for repository https://github.com/feltus/BDSS
author | mingchen0919 |
---|---|
date | Tue, 12 Jun 2018 09:49:08 -0400 |
parents | bd236d81187b |
children | c062782a7534 |
rev | line source |
---|---|
0
759232961286
planemo upload for repository https://github.com/feltus/BDSS
mingchen0919
parents:
diff
changeset
|
1 --- |
759232961286
planemo upload for repository https://github.com/feltus/BDSS
mingchen0919
parents:
diff
changeset
|
2 title: 'Aurora Tool Report' |
759232961286
planemo upload for repository https://github.com/feltus/BDSS
mingchen0919
parents:
diff
changeset
|
3 output: |
759232961286
planemo upload for repository https://github.com/feltus/BDSS
mingchen0919
parents:
diff
changeset
|
4 html_document: |
759232961286
planemo upload for repository https://github.com/feltus/BDSS
mingchen0919
parents:
diff
changeset
|
5 highlight: pygments |
759232961286
planemo upload for repository https://github.com/feltus/BDSS
mingchen0919
parents:
diff
changeset
|
6 --- |
759232961286
planemo upload for repository https://github.com/feltus/BDSS
mingchen0919
parents:
diff
changeset
|
7 |
759232961286
planemo upload for repository https://github.com/feltus/BDSS
mingchen0919
parents:
diff
changeset
|
8 ```{r setup, include=FALSE, warning=FALSE, message=FALSE} |
759232961286
planemo upload for repository https://github.com/feltus/BDSS
mingchen0919
parents:
diff
changeset
|
9 knitr::opts_chunk$set(error = TRUE, echo = FALSE) |
759232961286
planemo upload for repository https://github.com/feltus/BDSS
mingchen0919
parents:
diff
changeset
|
10 ``` |
759232961286
planemo upload for repository https://github.com/feltus/BDSS
mingchen0919
parents:
diff
changeset
|
11 |
759232961286
planemo upload for repository https://github.com/feltus/BDSS
mingchen0919
parents:
diff
changeset
|
12 ```{css echo=FALSE} |
759232961286
planemo upload for repository https://github.com/feltus/BDSS
mingchen0919
parents:
diff
changeset
|
13 # code chunks scrollable |
759232961286
planemo upload for repository https://github.com/feltus/BDSS
mingchen0919
parents:
diff
changeset
|
14 pre code, pre, code { |
759232961286
planemo upload for repository https://github.com/feltus/BDSS
mingchen0919
parents:
diff
changeset
|
15 white-space: pre !important; |
759232961286
planemo upload for repository https://github.com/feltus/BDSS
mingchen0919
parents:
diff
changeset
|
16 overflow-x: scroll !important; |
759232961286
planemo upload for repository https://github.com/feltus/BDSS
mingchen0919
parents:
diff
changeset
|
17 word-break: keep-all !important; |
759232961286
planemo upload for repository https://github.com/feltus/BDSS
mingchen0919
parents:
diff
changeset
|
18 word-wrap: initial !important; |
759232961286
planemo upload for repository https://github.com/feltus/BDSS
mingchen0919
parents:
diff
changeset
|
19 } |
759232961286
planemo upload for repository https://github.com/feltus/BDSS
mingchen0919
parents:
diff
changeset
|
20 ``` |
759232961286
planemo upload for repository https://github.com/feltus/BDSS
mingchen0919
parents:
diff
changeset
|
21 |
759232961286
planemo upload for repository https://github.com/feltus/BDSS
mingchen0919
parents:
diff
changeset
|
22 |
759232961286
planemo upload for repository https://github.com/feltus/BDSS
mingchen0919
parents:
diff
changeset
|
23 ```{r, echo=FALSE} |
759232961286
planemo upload for repository https://github.com/feltus/BDSS
mingchen0919
parents:
diff
changeset
|
24 # to make the css theme to work, <link></link> tags cannot be added directly |
759232961286
planemo upload for repository https://github.com/feltus/BDSS
mingchen0919
parents:
diff
changeset
|
25 # as <script></script> tags as below. |
759232961286
planemo upload for repository https://github.com/feltus/BDSS
mingchen0919
parents:
diff
changeset
|
26 # it has to be added using a code chunk with the htmltool functions!!! |
759232961286
planemo upload for repository https://github.com/feltus/BDSS
mingchen0919
parents:
diff
changeset
|
27 css_link = tags$link() |
759232961286
planemo upload for repository https://github.com/feltus/BDSS
mingchen0919
parents:
diff
changeset
|
28 css_link$attribs = list(rel="stylesheet", href="vakata-jstree-3.3.5/dist/themes/default/style.min.css") |
759232961286
planemo upload for repository https://github.com/feltus/BDSS
mingchen0919
parents:
diff
changeset
|
29 css_link |
759232961286
planemo upload for repository https://github.com/feltus/BDSS
mingchen0919
parents:
diff
changeset
|
30 ``` |
759232961286
planemo upload for repository https://github.com/feltus/BDSS
mingchen0919
parents:
diff
changeset
|
31 |
759232961286
planemo upload for repository https://github.com/feltus/BDSS
mingchen0919
parents:
diff
changeset
|
32 ```{r, eval=FALSE, echo=FALSE} |
759232961286
planemo upload for repository https://github.com/feltus/BDSS
mingchen0919
parents:
diff
changeset
|
33 # this code chunk is purely for adding comments |
759232961286
planemo upload for repository https://github.com/feltus/BDSS
mingchen0919
parents:
diff
changeset
|
34 # below is to add jQuery and jstree javascripts |
759232961286
planemo upload for repository https://github.com/feltus/BDSS
mingchen0919
parents:
diff
changeset
|
35 ``` |
759232961286
planemo upload for repository https://github.com/feltus/BDSS
mingchen0919
parents:
diff
changeset
|
36 <script src="https://code.jquery.com/jquery-3.3.1.min.js"></script> |
759232961286
planemo upload for repository https://github.com/feltus/BDSS
mingchen0919
parents:
diff
changeset
|
37 <script src="vakata-jstree-3.3.5/dist/jstree.min.js"></script> |
759232961286
planemo upload for repository https://github.com/feltus/BDSS
mingchen0919
parents:
diff
changeset
|
38 |
759232961286
planemo upload for repository https://github.com/feltus/BDSS
mingchen0919
parents:
diff
changeset
|
39 --- |
759232961286
planemo upload for repository https://github.com/feltus/BDSS
mingchen0919
parents:
diff
changeset
|
40 # javascript code below is to build the file tree interface |
759232961286
planemo upload for repository https://github.com/feltus/BDSS
mingchen0919
parents:
diff
changeset
|
41 # see this for how to implement opening hyperlink: https://stackoverflow.com/questions/18611317/how-to-get-i-get-leaf-nodes-in-jstree-to-open-their-hyperlink-when-clicked-when |
759232961286
planemo upload for repository https://github.com/feltus/BDSS
mingchen0919
parents:
diff
changeset
|
42 --- |
759232961286
planemo upload for repository https://github.com/feltus/BDSS
mingchen0919
parents:
diff
changeset
|
43 <script> |
759232961286
planemo upload for repository https://github.com/feltus/BDSS
mingchen0919
parents:
diff
changeset
|
44 $(function () { |
759232961286
planemo upload for repository https://github.com/feltus/BDSS
mingchen0919
parents:
diff
changeset
|
45 // create an instance when the DOM is ready |
759232961286
planemo upload for repository https://github.com/feltus/BDSS
mingchen0919
parents:
diff
changeset
|
46 $('#jstree').jstree().bind("select_node.jstree", function (e, data) { |
759232961286
planemo upload for repository https://github.com/feltus/BDSS
mingchen0919
parents:
diff
changeset
|
47 window.open( data.node.a_attr.href, data.node.a_attr.target ) |
759232961286
planemo upload for repository https://github.com/feltus/BDSS
mingchen0919
parents:
diff
changeset
|
48 }); |
759232961286
planemo upload for repository https://github.com/feltus/BDSS
mingchen0919
parents:
diff
changeset
|
49 }); |
759232961286
planemo upload for repository https://github.com/feltus/BDSS
mingchen0919
parents:
diff
changeset
|
50 </script> |
759232961286
planemo upload for repository https://github.com/feltus/BDSS
mingchen0919
parents:
diff
changeset
|
51 |
759232961286
planemo upload for repository https://github.com/feltus/BDSS
mingchen0919
parents:
diff
changeset
|
52 --- |
759232961286
planemo upload for repository https://github.com/feltus/BDSS
mingchen0919
parents:
diff
changeset
|
53 # ADD YOUR DATA ANALYSIS CODE AND MARKUP TEXT BELOW TO EXTEND THIS R MARKDOWN FILE |
759232961286
planemo upload for repository https://github.com/feltus/BDSS
mingchen0919
parents:
diff
changeset
|
54 --- |
759232961286
planemo upload for repository https://github.com/feltus/BDSS
mingchen0919
parents:
diff
changeset
|
55 |
759232961286
planemo upload for repository https://github.com/feltus/BDSS
mingchen0919
parents:
diff
changeset
|
56 # Download and extract reads |
759232961286
planemo upload for repository https://github.com/feltus/BDSS
mingchen0919
parents:
diff
changeset
|
57 |
759232961286
planemo upload for repository https://github.com/feltus/BDSS
mingchen0919
parents:
diff
changeset
|
58 ```{r echo=FALSE} |
759232961286
planemo upload for repository https://github.com/feltus/BDSS
mingchen0919
parents:
diff
changeset
|
59 # create two directories to store downloaded data |
759232961286
planemo upload for repository https://github.com/feltus/BDSS
mingchen0919
parents:
diff
changeset
|
60 se_dir = paste0(Sys.getenv('JOB_WORKING_DIR'), '/se_read_files_dir') |
759232961286
planemo upload for repository https://github.com/feltus/BDSS
mingchen0919
parents:
diff
changeset
|
61 pe_dir = paste0(Sys.getenv('JOB_WORKING_DIR'), '/pe_read_files_dir') |
759232961286
planemo upload for repository https://github.com/feltus/BDSS
mingchen0919
parents:
diff
changeset
|
62 ``` |
759232961286
planemo upload for repository https://github.com/feltus/BDSS
mingchen0919
parents:
diff
changeset
|
63 |
1
bd236d81187b
planemo upload for repository https://github.com/feltus/BDSS
mingchen0919
parents:
0
diff
changeset
|
64 ```{r 'download and extract reads', echo=-1} |
bd236d81187b
planemo upload for repository https://github.com/feltus/BDSS
mingchen0919
parents:
0
diff
changeset
|
65 Sys.setenv(PATH=paste0('/main/sites/galaxy/galaxy/tools/_conda/bin:', Sys.getenv('PATH'))) |
bd236d81187b
planemo upload for repository https://github.com/feltus/BDSS
mingchen0919
parents:
0
diff
changeset
|
66 |
0
759232961286
planemo upload for repository https://github.com/feltus/BDSS
mingchen0919
parents:
diff
changeset
|
67 # download and extract reads (single end) |
3
cf17a4199861
planemo upload for repository https://github.com/feltus/BDSS
mingchen0919
parents:
1
diff
changeset
|
68 sra_ids_se = strsplit(gsub(',', ' ', opt$X_s), ' ')[[1]] |
0
759232961286
planemo upload for repository https://github.com/feltus/BDSS
mingchen0919
parents:
diff
changeset
|
69 sra_ids_se = sra_ids_se[sra_ids_se != ''] |
759232961286
planemo upload for repository https://github.com/feltus/BDSS
mingchen0919
parents:
diff
changeset
|
70 # loop through SRA accessions to download and extract reads. |
759232961286
planemo upload for repository https://github.com/feltus/BDSS
mingchen0919
parents:
diff
changeset
|
71 for(id in sra_ids_se) { |
759232961286
planemo upload for repository https://github.com/feltus/BDSS
mingchen0919
parents:
diff
changeset
|
72 # build URL from SRA id |
759232961286
planemo upload for repository https://github.com/feltus/BDSS
mingchen0919
parents:
diff
changeset
|
73 url = paste0('ftp://ftp.ncbi.nlm.nih.gov/sra/sra-instant/reads/ByRun/sra/', |
759232961286
planemo upload for repository https://github.com/feltus/BDSS
mingchen0919
parents:
diff
changeset
|
74 substr(id, 1, 3), '/', |
759232961286
planemo upload for repository https://github.com/feltus/BDSS
mingchen0919
parents:
diff
changeset
|
75 substr(id, 1, 6), '/', id, '/', id, '.sra') |
759232961286
planemo upload for repository https://github.com/feltus/BDSS
mingchen0919
parents:
diff
changeset
|
76 # download sra file with bdss |
759232961286
planemo upload for repository https://github.com/feltus/BDSS
mingchen0919
parents:
diff
changeset
|
77 bdss_command = paste0('bdss transfer -u ', url) |
759232961286
planemo upload for repository https://github.com/feltus/BDSS
mingchen0919
parents:
diff
changeset
|
78 command_stdout = system(bdss_command, intern = TRUE) |
759232961286
planemo upload for repository https://github.com/feltus/BDSS
mingchen0919
parents:
diff
changeset
|
79 write(command_stdout, file = paste0(Sys.getenv('REPORT_FILES_PATH'), '/bdss-download.log.txt'), append = TRUE) |
759232961286
planemo upload for repository https://github.com/feltus/BDSS
mingchen0919
parents:
diff
changeset
|
80 # convert .sra to .fastq/.fasta |
759232961286
planemo upload for repository https://github.com/feltus/BDSS
mingchen0919
parents:
diff
changeset
|
81 if(opt$X_f == 'fasta') { |
759232961286
planemo upload for repository https://github.com/feltus/BDSS
mingchen0919
parents:
diff
changeset
|
82 command = paste0('fastq-dump --fasta -O se_read_files_dir ', id, '.sra') |
759232961286
planemo upload for repository https://github.com/feltus/BDSS
mingchen0919
parents:
diff
changeset
|
83 } else { |
759232961286
planemo upload for repository https://github.com/feltus/BDSS
mingchen0919
parents:
diff
changeset
|
84 command = paste0('fastq-dump -O se_read_files_dir ', id, '.sra') |
759232961286
planemo upload for repository https://github.com/feltus/BDSS
mingchen0919
parents:
diff
changeset
|
85 } |
759232961286
planemo upload for repository https://github.com/feltus/BDSS
mingchen0919
parents:
diff
changeset
|
86 cat('----convert SRA to fastq/fasta------\n') |
759232961286
planemo upload for repository https://github.com/feltus/BDSS
mingchen0919
parents:
diff
changeset
|
87 command_stdout = system(command, intern = TRUE) |
759232961286
planemo upload for repository https://github.com/feltus/BDSS
mingchen0919
parents:
diff
changeset
|
88 write(command_stdout, file = paste0(Sys.getenv('REPORT_FILES_PATH'), '/fastq-dump.log.txt'), append = TRUE) |
759232961286
planemo upload for repository https://github.com/feltus/BDSS
mingchen0919
parents:
diff
changeset
|
89 } |
759232961286
planemo upload for repository https://github.com/feltus/BDSS
mingchen0919
parents:
diff
changeset
|
90 |
759232961286
planemo upload for repository https://github.com/feltus/BDSS
mingchen0919
parents:
diff
changeset
|
91 # download and extract reads (paired end) |
3
cf17a4199861
planemo upload for repository https://github.com/feltus/BDSS
mingchen0919
parents:
1
diff
changeset
|
92 sra_ids_pe = strsplit(gsub(',', ' ', opt$X_p), ' ')[[1]] |
0
759232961286
planemo upload for repository https://github.com/feltus/BDSS
mingchen0919
parents:
diff
changeset
|
93 sra_ids_pe = sra_ids_pe[sra_ids_pe != ''] |
759232961286
planemo upload for repository https://github.com/feltus/BDSS
mingchen0919
parents:
diff
changeset
|
94 # loop through SRA accessions to download and extract reads. |
759232961286
planemo upload for repository https://github.com/feltus/BDSS
mingchen0919
parents:
diff
changeset
|
95 for(id in sra_ids_pe) { |
759232961286
planemo upload for repository https://github.com/feltus/BDSS
mingchen0919
parents:
diff
changeset
|
96 # build URL from SRA id |
759232961286
planemo upload for repository https://github.com/feltus/BDSS
mingchen0919
parents:
diff
changeset
|
97 url = paste0('ftp://ftp.ncbi.nlm.nih.gov/sra/sra-instant/reads/ByRun/sra/', |
759232961286
planemo upload for repository https://github.com/feltus/BDSS
mingchen0919
parents:
diff
changeset
|
98 substr(id, 1, 3), '/', |
759232961286
planemo upload for repository https://github.com/feltus/BDSS
mingchen0919
parents:
diff
changeset
|
99 substr(id, 1, 6), '/', id, '/', id, '.sra') |
759232961286
planemo upload for repository https://github.com/feltus/BDSS
mingchen0919
parents:
diff
changeset
|
100 # download sra file with bdss |
759232961286
planemo upload for repository https://github.com/feltus/BDSS
mingchen0919
parents:
diff
changeset
|
101 bdss_command = paste0('bdss transfer -u ', url) |
759232961286
planemo upload for repository https://github.com/feltus/BDSS
mingchen0919
parents:
diff
changeset
|
102 command_stdout = system(bdss_command, intern = TRUE) |
759232961286
planemo upload for repository https://github.com/feltus/BDSS
mingchen0919
parents:
diff
changeset
|
103 write(command_stdout, file = paste0(Sys.getenv('REPORT_FILES_PATH'), '/bdss-download.log.txt'), append = TRUE) |
759232961286
planemo upload for repository https://github.com/feltus/BDSS
mingchen0919
parents:
diff
changeset
|
104 # convert .sra to .fastq/.fasta |
759232961286
planemo upload for repository https://github.com/feltus/BDSS
mingchen0919
parents:
diff
changeset
|
105 if(opt$X_f == 'fasta') { |
759232961286
planemo upload for repository https://github.com/feltus/BDSS
mingchen0919
parents:
diff
changeset
|
106 command = paste0('fastq-dump --fasta --split-files -O pe_read_files_dir ', id, '.sra') |
759232961286
planemo upload for repository https://github.com/feltus/BDSS
mingchen0919
parents:
diff
changeset
|
107 } else { |
759232961286
planemo upload for repository https://github.com/feltus/BDSS
mingchen0919
parents:
diff
changeset
|
108 command = paste0('fastq-dump --split-files -O pe_read_files_dir ', id, '.sra') |
759232961286
planemo upload for repository https://github.com/feltus/BDSS
mingchen0919
parents:
diff
changeset
|
109 } |
759232961286
planemo upload for repository https://github.com/feltus/BDSS
mingchen0919
parents:
diff
changeset
|
110 cat('----convert SRA to fastq/fasta------\n') |
759232961286
planemo upload for repository https://github.com/feltus/BDSS
mingchen0919
parents:
diff
changeset
|
111 command_stdout = system(command, intern = TRUE) |
759232961286
planemo upload for repository https://github.com/feltus/BDSS
mingchen0919
parents:
diff
changeset
|
112 write(command_stdout, file = paste0(Sys.getenv('REPORT_FILES_PATH'), '/fastq-dump.log.txt'), append = TRUE) |
759232961286
planemo upload for repository https://github.com/feltus/BDSS
mingchen0919
parents:
diff
changeset
|
113 if(!(paste0(id, '_2.', opt$X_f) %in% list.files('pe_read_files_dir'))) { |
759232961286
planemo upload for repository https://github.com/feltus/BDSS
mingchen0919
parents:
diff
changeset
|
114 # this is not a paired end SRA file. The corresponding file will be deleted. |
759232961286
planemo upload for repository https://github.com/feltus/BDSS
mingchen0919
parents:
diff
changeset
|
115 cat(paste0(id, ' is not paired end SRA, the corresponding fastq/fasta file will deleted.')) |
759232961286
planemo upload for repository https://github.com/feltus/BDSS
mingchen0919
parents:
diff
changeset
|
116 command_stdout = system(paste0('rm pe_read_files_dir/', id, '_1.*'), intern = TRUE) |
759232961286
planemo upload for repository https://github.com/feltus/BDSS
mingchen0919
parents:
diff
changeset
|
117 } |
759232961286
planemo upload for repository https://github.com/feltus/BDSS
mingchen0919
parents:
diff
changeset
|
118 |
759232961286
planemo upload for repository https://github.com/feltus/BDSS
mingchen0919
parents:
diff
changeset
|
119 } |
759232961286
planemo upload for repository https://github.com/feltus/BDSS
mingchen0919
parents:
diff
changeset
|
120 |
759232961286
planemo upload for repository https://github.com/feltus/BDSS
mingchen0919
parents:
diff
changeset
|
121 |
759232961286
planemo upload for repository https://github.com/feltus/BDSS
mingchen0919
parents:
diff
changeset
|
122 cat('-----Renaming files------\n') |
759232961286
planemo upload for repository https://github.com/feltus/BDSS
mingchen0919
parents:
diff
changeset
|
123 # rename files for paired end reads |
759232961286
planemo upload for repository https://github.com/feltus/BDSS
mingchen0919
parents:
diff
changeset
|
124 old_files = paste0('./pe_read_files_dir/', list.files('./pe_read_files_dir')) |
759232961286
planemo upload for repository https://github.com/feltus/BDSS
mingchen0919
parents:
diff
changeset
|
125 new_files = gsub('_1', '_forward', old_files) |
759232961286
planemo upload for repository https://github.com/feltus/BDSS
mingchen0919
parents:
diff
changeset
|
126 new_files = gsub('_2', '_reverse', new_files) |
759232961286
planemo upload for repository https://github.com/feltus/BDSS
mingchen0919
parents:
diff
changeset
|
127 file.rename(old_files, new_files) |
759232961286
planemo upload for repository https://github.com/feltus/BDSS
mingchen0919
parents:
diff
changeset
|
128 ``` |