diff bdss_client_sra_se.Rmd @ 3:c707a4178832 draft

planemo upload for repository https://github.com/statonlab/docker-GRReport/tree/master/my_tools/rmarkdown_bdss_client commit ea6df97960569d247d64be1549aa90768c9786f4-dirty
author mingchen0919
date Wed, 11 Oct 2017 11:23:04 -0400
parents 614e9553f366
children efb1938c3020
line wrap: on
line diff
--- a/bdss_client_sra_se.Rmd	Tue Oct 10 20:22:55 2017 -0400
+++ b/bdss_client_sra_se.Rmd	Wed Oct 11 11:23:04 2017 -0400
@@ -39,18 +39,45 @@
 sra_accessions = sra_accessions[sra_accessions != '']
 # loop through SRA accessions to download and extract reads.
 for(id in sra_accessions) {
-  # build URL from SRA accession
-  url = paste0('ftp://ftp.ncbi.nlm.nih.gov/sra/sra-instant/reads/ByRun/sra/SRR/',
-               substr(id, 1, 6), '/', id, '/', id, '.sra')
-  # download sra file with bdss
-  bdss_command = paste0('/tool_deps/_conda/bin/bdss transfer -u ', url)
-  system(bdss_command, intern = TRUE)
-  # convert .sra to .fastq/.fasta
-  if('FORMAT' == 'fasta') {
-    command = paste0('fastq-dump --fasta ', '-O read_files_directory ', id)
+  ## if SRA_BOOLEAN is TRUE, download .sra file and then convert it to fastq/fasta
+  if (SRA_BOOLEAN) {
+    # build URL from SRA accession
+    url = paste0('ftp://ftp.ncbi.nlm.nih.gov/sra/sra-instant/reads/ByRun/sra/SRR/',
+                 substr(id, 1, 6), '/', id, '/', id, '.sra')
+    # download sra file with bdss
+    bdss_command = paste0('/tool_deps/_conda/bin/bdss transfer -u ', url)
+    system(bdss_command, intern = TRUE)
+    # convert .sra to .fastq/.fasta
+    if('FORMAT' == 'fasta') {
+      command = paste0('fastq-dump --fasta ', '-O read_files_directory ', id)
+    } else {
+      command = paste0('fastq-dump ', '-O read_files_directory ', id)
+    }
   } else {
-    command = paste0('fastq-dump ', '-O read_files_directory ', id)
+    # if SRA_BOOLEAN is FALSE, download fastq directly
+    # build URL for downloading fastq
+    url_base = paste0('ftp://ftp.sra.ebi.ac.uk/vol1/fastq/',
+                      substr(id, 1, 6), '/', id)
+    # list all fastq files
+    all_fastq_files = strsplit(getURL(url_base, dirlistonly = TRUE), split = '\n')[[1]]
+    if (length(all_fastq_files) == 1) {
+      # this is a single end SRA file. build url to download fastq
+      url = paste0(url_base, '/', all_fastq_files)
+      bdss_command = paste0('/tool_deps/_conda/bin/bdss transfer -u ', url)
+      run_bdss = system(bdss_command, intern = TRUE)
+      print(run_bdss)
+    } else {
+      print(paste0('Two fastq files found for this SRA accession: ', id))
+      print('Downloading skipped for ', id)
+      # url_1 = paste0(url_base, '/', all_fastq_files[1])
+      # bdss_command_1 = paste0('/tool_deps/_conda/bin/bdss transfer -u ', url_1)
+      # run_bdss_1 = system(bdss_command, intern = TRUE)
+      # url_2 = paste0(url_base, '/', all_fastq_files[1])
+      # bdss_command_2 = paste0('/tool_deps/_conda/bin/bdss transfer -u ', url_2)
+      # run_bdss_2 = system(bdss_command, intern = TRUE)
+    }
   }
+  
 }
 
 # remove all .sra file