Download from figshare

The following code downloads files from a fileset in figshare using rfigshare.

First we get the information from Figshare.

library('rfigshare')

## Authenticate if needed
# fs_auth()

## Find article
load('art_id.Rdata')

## Find article info
details <- fs_details(art_id, mine = FALSE)
## Authentication successful
## Get download URLs
down_info <- fs_download(art_id)

info <- data.frame(url = down_info[, 1], 
    name = sapply(details$files, '[[', 'name'), stringsAsFactors = FALSE)
info
##                                               url       name
## 1  https://ndownloader.figshare.com/files/4976605  HSB113.bw
## 2  https://ndownloader.figshare.com/files/4976649  pheno.tsv
## 3  https://ndownloader.figshare.com/files/4976647 counts.tsv
## 4  https://ndownloader.figshare.com/files/4976643   HSB97.bw
## 5  https://ndownloader.figshare.com/files/4976639   HSB92.bw
## 6  https://ndownloader.figshare.com/files/4976637  HSB178.bw
## 7  https://ndownloader.figshare.com/files/4976633  HSB159.bw
## 8  https://ndownloader.figshare.com/files/4976629  HSB153.bw
## 9  https://ndownloader.figshare.com/files/4976627  HSB145.bw
## 10 https://ndownloader.figshare.com/files/4976623  HSB136.bw
## 11 https://ndownloader.figshare.com/files/4976621  HSB135.bw
## 12 https://ndownloader.figshare.com/files/4976617  HSB130.bw
## 13 https://ndownloader.figshare.com/files/4976613  HSB126.bw
## 14 https://ndownloader.figshare.com/files/4976611  HSB123.bw
## 15 https://ndownloader.figshare.com/files/4976653  rse.Rdata

Next we can download the RangedSummarizedExperiment data.

## Download rse file
dir.create('downloaded', showWarnings = FALSE)
download.file(info$url[info$name == 'rse.Rdata'],
    destfile = file.path('downloaded', 'rse.Rdata'))

## Load it
library('SummarizedExperiment')
## Loading required package: GenomicRanges
## Loading required package: BiocGenerics
## Loading required package: parallel
## 
## Attaching package: 'BiocGenerics'
## The following objects are masked from 'package:parallel':
## 
##     clusterApply, clusterApplyLB, clusterCall, clusterEvalQ,
##     clusterExport, clusterMap, parApply, parCapply, parLapply,
##     parLapplyLB, parRapply, parSapply, parSapplyLB
## The following objects are masked from 'package:stats':
## 
##     IQR, mad, xtabs
## The following objects are masked from 'package:base':
## 
##     anyDuplicated, append, as.data.frame, cbind, colnames,
##     do.call, duplicated, eval, evalq, Filter, Find, get, grep,
##     grepl, intersect, is.unsorted, lapply, lengths, Map, mapply,
##     match, mget, order, paste, pmax, pmax.int, pmin, pmin.int,
##     Position, rank, rbind, Reduce, rownames, sapply, setdiff,
##     sort, table, tapply, union, unique, unsplit
## Loading required package: S4Vectors
## Loading required package: stats4
## 
## Attaching package: 'S4Vectors'
## The following objects are masked from 'package:base':
## 
##     colMeans, colSums, expand.grid, rowMeans, rowSums
## Loading required package: IRanges
## Loading required package: GenomeInfoDb
## Loading required package: Biobase
## Welcome to Bioconductor
## 
##     Vignettes contain introductory material; view with
##     'browseVignettes()'. To cite Bioconductor, see
##     'citation("Biobase")', and for packages 'citation("pkgname")'.
load(file.path('downloaded', 'rse.Rdata'))
rse
## class: RangedSummarizedExperiment 
## dim: 45 12 
## metadata(0):
## assays(1): counts
## rownames(45): 1 2 ... 44 45
## rowData names(6): value area ... cluster clusterL
## colnames(12): HSB113 HSB123 ... HSB92 HSB97
## colData names(8): gender lab ... group sample

We can also re-create the RangedSummarizedExperiment using derfinder.

## Identify bigwig files
files <- info$url[grep('bw', info$name)]
names(files) <- gsub('.bw', '', info$name[grep('bw', info$name)])

## Download files
dir.create('bigwigs', showWarnings = FALSE)
for(i in seq_len(length(files))) download.file(files[i],
    destfile = file.path('bigwigs', paste0(names(files)[i], '.bw')))


## Locate local files
library('derfinder')
bw_files <- rawFiles('bigwigs', samplepatt = 'bw', fileterm = NULL)
names(bw_files) <- gsub('.bw', '', names(bw_files))

## Re-order names in the same way that were used originally
bw_files <- bw_files[match(colData(rse)$sample, names(bw_files))]

## Load the data from disk 
fullCov <- fullCoverage(files = bw_files, chrs = 'chr21', verbose = FALSE)

## Get the region matrix of Expressed Regions (ERs)
regionMat <- regionMatrix(fullCov, cutoff = 30, L = 76, verbose = FALSE)

## Download the pheno data
download.file(info$url[info$name == 'pheno.tsv'],
    destfile = file.path('downloaded', 'pheno.tsv'))

## Load pheno data
pheno_new <- read.table(file.path('downloaded', 'pheno.tsv'), header = TRUE,
    sep = '\t', colClasses = c('factor', 'factor', 'numeric', 'character',
    'character', 'character', 'factor', 'character'))

## Make it so it matches the original pheno table
pheno_new$group <- relevel(pheno_new$group, 'fetal')
colData(rse)$lab <- droplevels(colData(rse)$lab)

## Round matrix
counts <- round(regionMat$chr21$coverageMatrix)

## Re-create RangedSummarizedExperiment
rse_new <- SummarizedExperiment(assays = list('counts' = counts),
    colData = DataFrame(pheno_new), rowRanges = regionMat$chr21$regions)

## Apparently they are not identical
identical(rse, rse_new)
## [1] FALSE
## But they are when looking closer
all(c(
    identical(assays(rse)$counts, assays(rse_new)$counts),
    identical(colData(rse), colData(rse_new)),
    identical(rowData(rse), rowData(rse_new)),
    identical(colnames(rse), colnames(rse_new)),
    identical(rownames(rse), rownames(rse_new))
))
## [1] TRUE

Reproducibility

library('knitcitations')
bib <- c('data' = read.bibtex('3187663.bib'), 
    'rfigshare' = citation('rfigshare'))

The data for this example is available via figshare (Collado-Torres, Nellore, and Leek, 2016) and was downloaded using rfigshare (Boettiger, Chamberlain, Ram, and Hart, ).

bibliography()

[1] C. Boettiger, S. Chamberlain, K. Ram, et al. rfigshare: An R Interface to ‘figshare’. R package version 0.3.7. <URL: https://CRAN.R-project.org/package=rfigshare>.

[2] L. Collado-Torres, A. Nellore and J. Leek. rfigshare upload test. Apr. 2016. <URL: 10.6084/m9.figshare.3187663.v1>.

## Reproducibility info
proc.time()
##    user  system elapsed 
##  18.150   1.218  60.822
message(Sys.time())
## 2016-04-20 18:49:05
options(width = 120)
devtools::session_info()
## Session info -----------------------------------------------------------------------------------------------------------
##  setting  value                                    
##  version  R version 3.3.0 alpha (2016-03-23 r70368)
##  system   x86_64, darwin13.4.0                     
##  ui       X11                                      
##  language (EN)                                     
##  collate  en_US.UTF-8                              
##  tz       America/New_York                         
##  date     2016-04-20
## Packages ---------------------------------------------------------------------------------------------------------------
##  package              * version  date       source        
##  acepack                1.3-3.3  2014-11-24 CRAN (R 3.3.0)
##  AnnotationDbi          1.33.12  2016-04-18 Bioconductor  
##  bibtex                 0.4.0    2014-12-31 CRAN (R 3.3.0)
##  Biobase              * 2.31.3   2016-01-14 Bioconductor  
##  BiocGenerics         * 0.17.5   2016-04-11 Bioconductor  
##  BiocParallel           1.5.21   2016-03-23 Bioconductor  
##  biomaRt                2.27.2   2016-01-14 Bioconductor  
##  Biostrings             2.39.14  2016-04-14 Bioconductor  
##  bitops                 1.0-6    2013-08-17 CRAN (R 3.3.0)
##  BSgenome               1.39.5   2016-04-12 Bioconductor  
##  bumphunter             1.11.5   2016-03-29 Bioconductor  
##  cluster                2.0.4    2016-04-18 CRAN (R 3.3.0)
##  codetools              0.2-14   2015-07-15 CRAN (R 3.3.0)
##  colorspace             1.2-6    2015-03-11 CRAN (R 3.3.0)
##  curl                   0.9.7    2016-04-10 CRAN (R 3.3.0)
##  DBI                    0.3.1    2014-09-24 CRAN (R 3.3.0)
##  derfinder            * 1.5.34   2016-04-19 Bioconductor  
##  derfinderHelper        1.5.3    2016-03-23 Bioconductor  
##  devtools               1.11.0   2016-04-12 CRAN (R 3.3.0)
##  digest                 0.6.9    2016-01-08 CRAN (R 3.3.0)
##  doRNG                  1.6      2014-03-07 CRAN (R 3.3.0)
##  evaluate               0.8.3    2016-03-05 CRAN (R 3.3.0)
##  foreach                1.4.3    2015-10-13 CRAN (R 3.3.0)
##  foreign                0.8-66   2015-08-19 CRAN (R 3.3.0)
##  formatR                1.3      2016-03-05 CRAN (R 3.3.0)
##  Formula                1.2-1    2015-04-07 CRAN (R 3.3.0)
##  GenomeInfoDb         * 1.7.6    2016-01-29 Bioconductor  
##  GenomicAlignments      1.7.21   2016-04-12 Bioconductor  
##  GenomicFeatures        1.23.30  2016-04-12 Bioconductor  
##  GenomicFiles           1.7.12   2016-04-17 Bioconductor  
##  GenomicRanges        * 1.23.27  2016-04-12 Bioconductor  
##  ggplot2                2.1.0    2016-03-01 CRAN (R 3.3.0)
##  gridExtra              2.2.1    2016-02-29 CRAN (R 3.3.0)
##  gtable                 0.2.0    2016-02-26 CRAN (R 3.3.0)
##  Hmisc                  3.17-3   2016-04-03 CRAN (R 3.3.0)
##  htmltools              0.3.5    2016-03-21 CRAN (R 3.3.0)
##  httpuv                 1.3.3    2015-08-04 CRAN (R 3.3.0)
##  httr                   1.1.0    2016-01-28 CRAN (R 3.3.0)
##  IRanges              * 2.5.46   2016-04-17 Bioconductor  
##  iterators              1.0.8    2015-10-13 CRAN (R 3.3.0)
##  knitcitations        * 1.0.7    2015-10-28 CRAN (R 3.3.0)
##  knitr                  1.12.3   2016-01-22 CRAN (R 3.3.0)
##  lattice                0.20-33  2015-07-14 CRAN (R 3.3.0)
##  latticeExtra           0.6-28   2016-02-09 CRAN (R 3.3.0)
##  locfit                 1.5-9.1  2013-04-20 CRAN (R 3.3.0)
##  lubridate              1.5.6    2016-04-06 CRAN (R 3.3.0)
##  magrittr               1.5      2014-11-22 CRAN (R 3.3.0)
##  Matrix                 1.2-5    2016-04-17 CRAN (R 3.3.0)
##  matrixStats            0.50.1   2015-12-15 CRAN (R 3.3.0)
##  memoise                1.0.0    2016-01-29 CRAN (R 3.3.0)
##  munsell                0.4.3    2016-02-13 CRAN (R 3.3.0)
##  nnet                   7.3-12   2016-02-02 CRAN (R 3.3.0)
##  openssl                0.9.2    2016-02-26 CRAN (R 3.3.0)
##  pkgmaker               0.22     2014-05-14 CRAN (R 3.3.0)
##  plyr                   1.8.3    2015-06-12 CRAN (R 3.3.0)
##  qvalue                 2.3.2    2016-01-14 Bioconductor  
##  R6                     2.1.2    2016-01-26 CRAN (R 3.3.0)
##  RColorBrewer           1.1-2    2014-12-07 CRAN (R 3.3.0)
##  Rcpp                   0.12.4.5 2016-04-16 local         
##  RCurl                  1.95-4.8 2016-03-01 CRAN (R 3.3.0)
##  RefManageR             0.10.13  2016-04-04 CRAN (R 3.3.0)
##  registry               0.3      2015-07-08 CRAN (R 3.3.0)
##  reshape2               1.4.1    2014-12-06 CRAN (R 3.3.0)
##  rfigshare            * 0.3.7    2015-06-15 CRAN (R 3.3.0)
##  RJSONIO                1.3-0    2014-07-28 CRAN (R 3.3.0)
##  rmarkdown            * 0.9.5    2016-02-22 CRAN (R 3.3.0)
##  rngtools               1.2.4    2014-03-06 CRAN (R 3.3.0)
##  rpart                  4.1-10   2015-06-29 CRAN (R 3.3.0)
##  Rsamtools              1.23.8   2016-04-10 Bioconductor  
##  RSQLite                1.0.0    2014-10-25 CRAN (R 3.3.0)
##  rtracklayer            1.31.10  2016-04-07 Bioconductor  
##  S4Vectors            * 0.9.51   2016-04-17 Bioconductor  
##  scales                 0.4.0    2016-02-26 CRAN (R 3.3.0)
##  stringi                1.0-1    2015-10-22 CRAN (R 3.3.0)
##  stringr                1.0.0    2015-04-30 CRAN (R 3.3.0)
##  SummarizedExperiment * 1.1.24   2016-04-11 Bioconductor  
##  survival               2.39-2   2016-04-16 CRAN (R 3.3.0)
##  VariantAnnotation      1.17.24  2016-04-12 Bioconductor  
##  withr                  1.0.1    2016-02-04 CRAN (R 3.3.0)
##  XML                    3.98-1.4 2016-03-01 CRAN (R 3.3.0)
##  xtable                 1.8-2    2016-02-05 CRAN (R 3.3.0)
##  XVector                0.11.8   2016-04-06 Bioconductor  
##  yaml                   2.1.13   2014-06-12 CRAN (R 3.3.0)
##  zlibbioc               1.17.1   2016-03-19 Bioconductor