view fastq_dump_pe.Rmd @ 19:42e154ba2d35 draft

planemo upload for repository https://github.com/statonlab/docker-GRReport/tree/master/my_tools/rmarkdown_fastq_dump commit c4beda20972367ab7d47a058a01a5f6fe492255d-dirty
author mingchen0919
date Wed, 27 Sep 2017 21:15:56 -0400
parents dcd0e0b6fcaf
children 2167f32cf379
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 ', id)
  } else {
    command = paste0('fastq-dump --split-files ', '-O read_files_directory ', id)
  }
}
```

* `fastq-dump` command
```{r}
print(command)
```

* `command line stdout`

```{r}
system(command = command, intern = TRUE)
```


# 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.rename(old_files, new_files)
```