Browse code

added FULL() parameters, fixed multiple collect

Simone authored on 11/04/2021 18:14:20
Showing 3 changed files

... ...
@@ -26,7 +26,11 @@
26 26
 #' @param region_attributes vector of strings that extracts only region
27 27
 #' attributes  specified; if NULL no regions attribute is taken and the output
28 28
 #' is only GRanges made up by the region coordinate attributes
29
-#' (seqnames, start, end, strand)
29
+#' (seqnames, start, end, strand);
30
+#' It is also possible to assign the \code{\link{FULL}} with or without 
31
+#' its input parameter; in case was without the `except` parameter, 
32
+#' all the region attributes are taken, otherwise all the region attributes 
33
+#' are taken except the input attribute defined by except.
30 34
 #' @param suffix name for each metadata column of GRanges. By default it is the
31 35
 #' value of the metadata attribute named "antibody_target". This string is
32 36
 #' taken from sample metadata file or from metadata() associated.
... ...
@@ -61,19 +65,14 @@
61 65
 #' sorted_grl <- sort(grl)
62 66
 #' filter_and_extract(sorted_grl, region_attributes = c("pvalue", "peak"))
63 67
 #' 
64
-#' ## It is also possible to define the region attributes, using the FULL() 
65
-#' ## function parameter, in order to includes every region 
66
-#' ## attributes present into the schema file
68
+#' ## This statement imports a GMQL dataset as GRangesList and filters it
69
+#' ## including all the region attributes
67 70
 #' 
68 71
 #' sorted_grl_full <- sort(grl)
69
-#' filter_and_extract(sorted_grl, region_attributes = FULL())
72
+#' filter_and_extract(sorted_grl_full, region_attributes = FULL())
70 73
 #' 
71
-#' grl <- import_gmql(test_path, TRUE)
72
-#' sorted_grl <- sort(grl)
73
-#' filter_and_extract(sorted_grl, region_attributes = FULL())
74
-#' 
75
-#' ## Also, we can inlcude a list of region attribute inside the FULL() 
76
-#' ## function to exlucde that regions
74
+#' ## This statement imports a GMQL dataset as GRangesList and filters it
75
+#' ## including all the region attributes except "jaccard" and "score"
77 76
 #' 
78 77
 #' sorted_grl_full_except <- sort(grl)
79 78
 #' filter_and_extract(
... ...
@@ -75,13 +75,21 @@ execute <- function() {
75 75
   
76 76
   remote <- WrappeR$is_remote_processing()
77 77
   if(remote) {
78
-    lapply(data_list,function(x){
78
+    lapply(data_list,function(x) {
79 79
       if(!is.null(x[[1]]) && !is.na(x[[1]]))
80
-        upload_dataset(url,x[[2]],x[[1]],x[[3]])})
80
+        upload_dataset(url,x[[2]],x[[1]],x[[3]]) 
81
+    })
81 82
   } else {
82
-    lapply(data_list,function(x){
83
-      if(!is.null(x[[2]]) && !is.na(x[[2]]))
84
-        download_dataset(url,x[[2]],x[[1]])})
83
+    lapply(data_list,function(x) {
84
+      if(!is.null(x[[2]]) && !is.na(x[[2]])) {
85
+        path <- x[[1]]
86
+        # create downloads folder where putting all the downloading dataset
87
+        if(!dir.exists(path))
88
+          dir.create(path)
89
+        
90
+        download_dataset(url,x[[2]], path) 
91
+      }
92
+    })
85 93
   }
86 94
 }
87 95
 
... ...
@@ -150,7 +158,7 @@ gmql_materialize <- function(input_data, name, dir_out) {
150 158
   
151 159
   if(!remote_proc) {
152 160
     dir_out <- sub("/*[/]$","",dir_out)
153
-    res_dir_out <- file.path(dir_out,name)
161
+    res_dir_out <- file.path(dir_out, name)
154 162
     if(!dir.exists(res_dir_out))
155 163
       dir.create(res_dir_out)
156 164
   }
... ...
@@ -68,11 +68,11 @@ login_gmql <- function(url, username = NULL, password = NULL) {
68 68
     req <- httr::GET(URL,httr::add_headers(h))
69 69
   } else {
70 70
     req <- httr::GET(url)
71
-    real_URL <- req$url
71
+    real_URL <- sub("/*[/]$","",req$url)
72 72
     h <- c('Accept'="Application/json",'Content-Type'='Application/json')
73 73
     URL <- paste0(real_URL,"/login")
74 74
     body <- list('username' = username,'password' = password)
75
-    req <- httr::POST(URL,httr::add_headers(h),body = body,encode = "json")
75
+    req <- httr::POST(URL, httr::add_headers(h), body = body, encode = "json")
76 76
   }
77 77
   
78 78
   content <- httr::content(req)
... ...
@@ -87,9 +87,9 @@ login_gmql <- function(url, username = NULL, password = NULL) {
87 87
       "username" = username,
88 88
       "password" = password
89 89
     )
90
-    
91
-    assign("GMQL_credentials",GMQL_remote,.GlobalEnv)
92
-    print(paste("your Token is",GMQL_remote$authToken))
90
+  
91
+    assign("GMQL_credentials", GMQL_remote, .GlobalEnv)
92
+    print(paste("your Token is", GMQL_remote$authToken))
93 93
   }
94 94
 }
95 95
 
... ...
@@ -124,11 +124,12 @@ login_gmql <- function(url, username = NULL, password = NULL) {
124 124
 #' @export
125 125
 #'
126 126
 logout_gmql <- function(url) {
127
-  authToken = GMQL_credentials$authToken
128 127
   url <- sub("/*[/]$","",url)
129
-  
130 128
   URL <- paste0(url,"/logout")
129
+  
130
+  authToken = GMQL_credentials$authToken
131 131
   h <- c('X-Auth-Token' = authToken)
132
+  
132 133
   req <- httr::GET(URL, httr::add_headers(h))
133 134
   content <- httr::content(req)
134 135
   
... ...
@@ -192,9 +193,9 @@ register_gmql <- function(
192 193
   last_name
193 194
 ) {
194 195
   req <- httr::GET(url)
195
-  real_URL <- req$url
196
+  url <- sub("/*[/]$","",req$url)
196 197
   
197
-  URL <- paste0(real_URL,"register")
198
+  URL <- paste0(url,"/register")
198 199
   h <- c('Accept' = "Application/json")
199 200
   reg_body <- list(
200 201
     "firstName" = first_name, 
... ...
@@ -221,7 +222,7 @@ register_gmql <- function(
221 222
       "username" = username,
222 223
       "password" = psw
223 224
     )
224
-    assign("GMQL_credentials", GMQL_remote,.GlobalEnv)
225
+    assign("GMQL_credentials", GMQL_remote, .GlobalEnv)
225 226
     print(paste("your Token is", GMQL_remote$authToken))
226 227
   }
227 228
 }
... ...
@@ -323,8 +324,8 @@ show_queries_list <- function(url) {
323 324
 #'
324 325
 save_query <- function(url, queryName, queryTxt) {
325 326
   req <- httr::GET(url)
326
-  real_URL <- req$url
327
-  URL <- paste0(real_URL,"query/",queryName,"/save")
327
+  url <- sub("/*[/]$","",req$url)
328
+  URL <- paste0(url,"/query/",queryName,"/save")
328 329
   authToken = GMQL_credentials$authToken
329 330
   h <- c(
330 331
     'Accept' = 'text/plain',
... ...
@@ -420,8 +421,8 @@ run_query <- function(url, queryName, query, output_gtf = TRUE) {
420 421
     out <- "TAB"
421 422
   
422 423
   req <- httr::GET(url)
423
-  real_URL <- req$url
424
-  URL <- paste0(real_URL,"queries/run/",queryName,"/",out)
424
+  url <- sub("/*[/]$","",req$url)
425
+  URL <- paste0(url,"/queries/run/",queryName,"/",out)
425 426
   authToken = GMQL_credentials$authToken
426 427
   h <- c(
427 428
     'Accept' = "Application/json",
... ...
@@ -507,8 +508,8 @@ compile_query <- function(url, query) {
507 508
     'X-Auth-Token' = authToken
508 509
   )
509 510
   req <- httr::GET(url)
510
-  real_URL <- req$url
511
-  URL <- paste0(real_URL, "queries/compile")
511
+  url <- sub("/*[/]$","",req$url)
512
+  URL <- paste0(url, "/queries/compile")
512 513
   req <- httr::POST(
513 514
     URL, 
514 515
     body = query ,
... ...
@@ -964,8 +965,8 @@ upload_dataset <- function(
964 965
   
965 966
   names(list_files) <- list_files_names
966 967
   req <- httr::GET(url)
967
-  real_URL <- req$url
968
-  URL <- paste0(real_URL, "datasets/", datasetName, "/uploadSample")
968
+  real_URL <- sub("/*[/]$","",req$url)
969
+  URL <- paste0(real_URL, "/datasets/", datasetName, "/uploadSample")
969 970
   authToken = GMQL_credentials$authToken
970 971
   h <- c('X-Auth-Token' = authToken, 'Accept:' = 'Application/json')
971 972
   
... ...
@@ -979,7 +980,7 @@ upload_dataset <- function(
979 980
       list_files
980 981
     )
981 982
     list_files <- unlist(list_files, recursive = FALSE)
982
-    URL <- paste0(real_URL, "datasets/", datasetName, "/uploadSample")
983
+    URL <- paste0(real_URL, "/datasets/", datasetName, "/uploadSample")
983 984
   } else {
984 985
     schemaList <- c(
985 986
       "narrowpeak",
... ...
@@ -994,7 +995,7 @@ upload_dataset <- function(
994 995
     
995 996
     URL <- paste0(
996 997
       real_URL,
997
-      "datasets/",
998
+      "/datasets/",
998 999
       datasetName,
999 1000
       "/uploadSample?schemaName=",
1000 1001
       schema_name
... ...
@@ -1044,8 +1045,8 @@ upload_dataset <- function(
1044 1045
 #'
1045 1046
 delete_dataset <- function(url, datasetName) {
1046 1047
   req <- httr::GET(url)
1047
-  real_URL <- req$url
1048
-  URL <- paste0(real_URL, "datasets/", datasetName)
1048
+  real_URL <- sub("/*[/]$","",req$url)
1049
+  URL <- paste0(real_URL, "/datasets/", datasetName)
1049 1050
   authToken = GMQL_credentials$authToken
1050 1051
   h <- c('X-Auth-Token' = authToken, 'Accept:' = 'application/json')
1051 1052
   req <- httr::DELETE(URL, httr::add_headers(h))
... ...
@@ -1305,9 +1306,9 @@ serialize_query <- function(url,output_gtf,base64) {
1305 1306
   }
1306 1307
   url <- sub("/*[/]$","",url)
1307 1308
   req <- httr::GET(url)
1308
-  real_URL <- req$url
1309
+  real_URL <- sub("/*[/]$","",req$url)
1309 1310
   authToken = GMQL_credentials$authToken
1310
-  URL <- paste0(real_URL,"queries/dag/",out)
1311
+  URL <- paste0(real_URL,"/queries/dag/",out)
1311 1312
   h <- c(
1312 1313
     'Accept' = "Application/json",
1313 1314
     'Content-Type' = 'text/plain',