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