view fastq_dump_pe.Rmd @ 17:cf1233051a9b draft

planemo upload for repository https://github.com/statonlab/docker-GRReport/tree/master/my_tools/rmarkdown_fastq_dump commit e6035405141d63626702084eacd02089f816cdc7-dirty
author mingchen0919
date Wed, 27 Sep 2017 17:12:39 -0400
parents 66bc1016ec2a
children dcd0e0b6fcaf
line wrap: on
line source

---
title: 'Fastq-dump: download and extract paired end reads into FASTQ/FASTA file'
output:
    html_document:
      number_sections: true
      toc: true
      theme: cosmo
      highlight: tango
---

```{r setup, include=FALSE, warning=FALSE, message=FALSE}
knitr::opts_chunk$set(
  echo = ECHO
)
```

# Command line arguments

```{r 'command line arguments'}
str(opt)
```

# Download and extract reads

```{r 'download and extract reads'}
# create a directory to store read files
dir.create('read_files_directory')
# download and extract reads
sra_accessions = strsplit(gsub(',', ' ', 'SRA_ACCESSION'), ' ')[[1]]
sra_accessions = sra_accessions[sra_accessions != '']
# loop through SRA accessions to download and extract reads.
for(id in sra_accessions) {
  if('FORMAT' == 'fasta') {
    command = paste0('fastq-dump --fasta --split_files ', '-O read_files_directory ')
  } else {
    command = paste0('fastq-dump --fastq --split_files ', '-O read_files_directory ')
  }
  
  print(command)
  system(command = command)
}
```

# Rename files

```{r}
old_files = paste0('./read_files_directory/', list.files('./read_files_directory'))
new_files = gsub('_1', '_forward', old_files)
new_files = gsub('_2', '_reverse', new_files)
file.copy('./read_files_directory/')
```