rabix.Rmd 2.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576
  1. ---
  2. title: "Dockerized R Markdown Document with Rabix Support"
  3. author: "Nan Xiao"
  4. date: "`r Sys.Date()`"
  5. output:
  6. html_document:
  7. highlight: pygments
  8. theme: cosmo
  9. liftr:
  10. from: "rocker/r-base:latest"
  11. maintainer: "Nan Xiao"
  12. maintainer_email: "[email protected]"
  13. syslib:
  14. - samtools
  15. biocpkg:
  16. - Rsamtools
  17. - Gviz
  18. rabix: true
  19. rabix_json: "https://s3.amazonaws.com/rabix/rabix-test/bwa-mem.json"
  20. rabix_d: "~/liftr_rabix/bwa/"
  21. rabix_args:
  22. - reference: "https://s3.amazonaws.com/rabix/rabix-test/chr20.fa"
  23. - reads: "https://s3.amazonaws.com/rabix/rabix-test/example_human_Illumina.pe_1.fastq"
  24. - reads: "https://s3.amazonaws.com/rabix/rabix-test/example_human_Illumina.pe_2.fastq"
  25. ---
  26. ## Alignment coverage visualization example
  27. This is an R Markdown document that could be rendered under a Docker container using `liftr`. It also contains information about a Rabix tool `bwa-mem.json`, which will be ran by Rabix before rendering the document in a Docker container. In this way, the output of the Rabix tool/workflow can be used and analyzed in the document.
  28. The document depends on the `samtools` software package in Ubuntu; `Rsamtools` and `Gviz` package on Bioconductor. `liftr` will:
  29. * Run the Rabix tool `bwa-mem.json` defined in the metadata;
  30. * Use `samtools` installed in the Docker container to convert the output of the tool, `output.sam` to a BAM file;
  31. * Use the Bioconductor packages `Rsamtools` and `Gviz` to index the BAM file and visualize the alignment coverage.
  32. ```{r samtools}
  33. # convert SAM file to BAM file directly using samtools
  34. system("samtools view -bS bwa/output.sam > bwa/output.bam")
  35. # sort the output bam file with samtools
  36. system("samtools sort bwa/output.bam bwa/output.sorted")
  37. ```
  38. ```{r Rsamtools}
  39. library("Rsamtools")
  40. indexBam("bwa/output.sorted.bam")
  41. ```
  42. ```{r bamplot}
  43. suppressMessages(library("Gviz"))
  44. bam = "bwa/output.sorted.bam"
  45. dtrack = DataTrack(range = bam, genome = "hg19",
  46. type = "l", name = "Coverage",
  47. window = -1, chromosome = "chr20")
  48. # plot alignment coverage at given position
  49. plotTracks(dtrack, from = 29622700, to = 29630000)
  50. ```
  51. ## Options of liftr in this document
  52. The document front-matter metadata includes the options for `liftr`, which is used for dockerizing the document and running the Rabix tool `bwa-mem.json`:
  53. ```{r liftrmeta}
  54. rmarkdown::metadata$liftr
  55. ```
  56. ## System and session information
  57. The location of `samtools` and R session information of the Docker container is shown below.
  58. ```{r session}
  59. Sys.which("samtools")
  60. sessionInfo()
  61. ```