Skip to content
Snippets Groups Projects
Commit 12c42c6d authored by LouisGendron's avatar LouisGendron
Browse files

Added annotation & metadata download, and single file download.

parent 8954dfc2
No related branches found
No related tags found
No related merge requests found
......@@ -27,7 +27,7 @@ IRICData <- setClass(
prototype = list(
user="",
pwd="",
url="https://thepond.bioinfo.iric.ca"
url=""
),
# Make a function that can test to see if the data is consistent.
......@@ -65,6 +65,30 @@ setMethod(
#' ### Accessors
#' ###
#Download file from file_url
setGeneric(
name="DL_file",
def=function(object, session, file_url, path_out){
standardGeneric("DL_file")
}
)
setMethod(
f="DL_file",
signature="IRICData",
definition=function(object, session, file_url, path_out) {
# create directory output
dir.create(path_out, showWarnings = FALSE)
resp = rvest::jump_to(session,file_url)
file_name = unlist(resp$response$headers[grep("content-disposition", names((resp$response$headers)))])
file_name = unlist(strsplit(file_name, "UTF-8''"))[2]
file_out = file.path(path_out, file_name)
cat(paste('Downloading',file_name,'\n'))
writeBin(resp$response$content, file_out)
}
)
#Download an entire dataset
setGeneric(
name="DL_dataset",
def=function(object, session, id_dataset, path_out){
......@@ -76,24 +100,19 @@ setMethod(
signature="IRICData",
definition=function(object, session, id_dataset, path_out) {
# create directory output
dir.create(path_out, showWarnings = FALSE)
#dir.create(path_out, showWarnings = FALSE)
#Get all files of a dataset
resp = rvest::jump_to(session, paste(object@url,"/secure/dataset/", id_dataset, "/file-list", sep=""))
files_to_DL = unlist(strsplit(rawToChar(resp$response$content), "\n"))
#DL all file in path_out
for (file_url in files_to_DL) {
resp = rvest::jump_to(session,file_url)
file_name = unlist(resp$response$headers[grep("content-disposition", names((resp$response$headers)))])
file_name = unlist(strsplit(file_name, "UTF-8''"))[2]
file_out = file.path(path_out, file_name)
writeBin(resp$response$content, file_out)
DL_file(object, session, file_url, path_out)
}
}
)
#Fetch file metadata as JSON
setGeneric(
name='get_file_metadata',
......@@ -111,6 +130,7 @@ setMethod(
}
)
#Fetch file annotation as JSON
setGeneric(
name='get_file_annotation',
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment