annotate rmarkdown_report.Rmd @ 10:4b73dbd97a0e draft default tip

planemo upload for repository https://github.com/feltus/BDSS
author mingchen0919
date Tue, 12 Jun 2018 12:30:21 -0400
parents 39831b70aabb
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
0
759232961286 planemo upload for repository https://github.com/feltus/BDSS
mingchen0919
parents:
diff changeset
1 ---
9
39831b70aabb planemo upload for repository https://github.com/feltus/BDSS
mingchen0919
parents: 8
diff changeset
2 title: 'BDSS download from SRA'
0
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
9
39831b70aabb planemo upload for repository https://github.com/feltus/BDSS
mingchen0919
parents: 8
diff changeset
56 # Job script
0
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
4
c062782a7534 planemo upload for repository https://github.com/feltus/BDSS
mingchen0919
parents: 3
diff changeset
77 bdss_command = paste0('bdss transfer -u ', url, '>> ${REPORT_FILES_PATH}/log.txt 2>&1')
0
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 # convert .sra to .fastq/.fasta
759232961286 planemo upload for repository https://github.com/feltus/BDSS
mingchen0919
parents:
diff changeset
80 if(opt$X_f == 'fasta') {
5
a1dfadeb3b59 planemo upload for repository https://github.com/feltus/BDSS
mingchen0919
parents: 4
diff changeset
81 command = paste0('fastq-dump --fasta -O ', se_dir, ' ', id, '.sra')
0
759232961286 planemo upload for repository https://github.com/feltus/BDSS
mingchen0919
parents:
diff changeset
82 } else {
5
a1dfadeb3b59 planemo upload for repository https://github.com/feltus/BDSS
mingchen0919
parents: 4
diff changeset
83 command = paste0('fastq-dump -O ', se_dir, ' ', id, '.sra')
0
759232961286 planemo upload for repository https://github.com/feltus/BDSS
mingchen0919
parents:
diff changeset
84 }
759232961286 planemo upload for repository https://github.com/feltus/BDSS
mingchen0919
parents:
diff changeset
85 command_stdout = system(command, intern = TRUE)
759232961286 planemo upload for repository https://github.com/feltus/BDSS
mingchen0919
parents:
diff changeset
86 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
87 }
759232961286 planemo upload for repository https://github.com/feltus/BDSS
mingchen0919
parents:
diff changeset
88
759232961286 planemo upload for repository https://github.com/feltus/BDSS
mingchen0919
parents:
diff changeset
89 # download and extract reads (paired end)
3
cf17a4199861 planemo upload for repository https://github.com/feltus/BDSS
mingchen0919
parents: 1
diff changeset
90 sra_ids_pe = strsplit(gsub(',', ' ', opt$X_p), ' ')[[1]]
0
759232961286 planemo upload for repository https://github.com/feltus/BDSS
mingchen0919
parents:
diff changeset
91 sra_ids_pe = sra_ids_pe[sra_ids_pe != '']
759232961286 planemo upload for repository https://github.com/feltus/BDSS
mingchen0919
parents:
diff changeset
92 # loop through SRA accessions to download and extract reads.
759232961286 planemo upload for repository https://github.com/feltus/BDSS
mingchen0919
parents:
diff changeset
93 for(id in sra_ids_pe) {
759232961286 planemo upload for repository https://github.com/feltus/BDSS
mingchen0919
parents:
diff changeset
94 # build URL from SRA id
759232961286 planemo upload for repository https://github.com/feltus/BDSS
mingchen0919
parents:
diff changeset
95 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
96 substr(id, 1, 3), '/',
759232961286 planemo upload for repository https://github.com/feltus/BDSS
mingchen0919
parents:
diff changeset
97 substr(id, 1, 6), '/', id, '/', id, '.sra')
759232961286 planemo upload for repository https://github.com/feltus/BDSS
mingchen0919
parents:
diff changeset
98 # download sra file with bdss
4
c062782a7534 planemo upload for repository https://github.com/feltus/BDSS
mingchen0919
parents: 3
diff changeset
99 bdss_command = paste0('bdss transfer -u ', url, '>> ${REPORT_FILES_PATH}/log.txt 2>&1')
0
759232961286 planemo upload for repository https://github.com/feltus/BDSS
mingchen0919
parents:
diff changeset
100 command_stdout = system(bdss_command, intern = TRUE)
759232961286 planemo upload for repository https://github.com/feltus/BDSS
mingchen0919
parents:
diff changeset
101 # convert .sra to .fastq/.fasta
759232961286 planemo upload for repository https://github.com/feltus/BDSS
mingchen0919
parents:
diff changeset
102 if(opt$X_f == 'fasta') {
6
9dabaecf12ff planemo upload for repository https://github.com/feltus/BDSS
mingchen0919
parents: 5
diff changeset
103 command = paste0('fastq-dump --fasta --split-files -O ', pe_dir, ' ', id, '.sra')
0
759232961286 planemo upload for repository https://github.com/feltus/BDSS
mingchen0919
parents:
diff changeset
104 } else {
6
9dabaecf12ff planemo upload for repository https://github.com/feltus/BDSS
mingchen0919
parents: 5
diff changeset
105 command = paste0('fastq-dump --split-files -O ', pe_dir, ' ', id, '.sra')
0
759232961286 planemo upload for repository https://github.com/feltus/BDSS
mingchen0919
parents:
diff changeset
106 }
759232961286 planemo upload for repository https://github.com/feltus/BDSS
mingchen0919
parents:
diff changeset
107 command_stdout = system(command, intern = TRUE)
759232961286 planemo upload for repository https://github.com/feltus/BDSS
mingchen0919
parents:
diff changeset
108 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
109 }
759232961286 planemo upload for repository https://github.com/feltus/BDSS
mingchen0919
parents:
diff changeset
110
10
4b73dbd97a0e planemo upload for repository https://github.com/feltus/BDSS
mingchen0919
parents: 9
diff changeset
111 ```
4b73dbd97a0e planemo upload for repository https://github.com/feltus/BDSS
mingchen0919
parents: 9
diff changeset
112
4b73dbd97a0e planemo upload for repository https://github.com/feltus/BDSS
mingchen0919
parents: 9
diff changeset
113 ```{r echo=FALSE}
0
759232961286 planemo upload for repository https://github.com/feltus/BDSS
mingchen0919
parents:
diff changeset
114 # rename files for paired end reads
5
a1dfadeb3b59 planemo upload for repository https://github.com/feltus/BDSS
mingchen0919
parents: 4
diff changeset
115 old_files = list.files(path = pe_dir, full.names = TRUE)
0
759232961286 planemo upload for repository https://github.com/feltus/BDSS
mingchen0919
parents:
diff changeset
116 new_files = gsub('_1', '_forward', old_files)
759232961286 planemo upload for repository https://github.com/feltus/BDSS
mingchen0919
parents:
diff changeset
117 new_files = gsub('_2', '_reverse', new_files)
10
4b73dbd97a0e planemo upload for repository https://github.com/feltus/BDSS
mingchen0919
parents: 9
diff changeset
118 res = file.rename(old_files, new_files)
0
759232961286 planemo upload for repository https://github.com/feltus/BDSS
mingchen0919
parents:
diff changeset
119 ```
10
4b73dbd97a0e planemo upload for repository https://github.com/feltus/BDSS
mingchen0919
parents: 9
diff changeset
120