Browse code

update documentation

Simone authored on 24/03/2021 19:24:37
Showing5 changed files

... ...
@@ -58,7 +58,7 @@ init_gmql <- function(
58 58
   # mettere attesa da input keyboard, controllare se token giĆ  esiste 
59 59
   # da sessione precedente
60 60
   if(!is.null(url) && !exists("GMQL_credentials", envir = .GlobalEnv))
61
-    login_gmql(url,username,password)
61
+    login_gmql(url, username, password)
62 62
   
63 63
   WrappeR <- J("it/polimi/genomics/r/Wrapper")
64 64
   WrappeR$initGMQL(out_format,remote_processing)
... ...
@@ -51,7 +51,12 @@ execute <- function() {
51 51
       if(identical(outformat, "gtf"))
52 52
         isGTF <- TRUE
53 53
       
54
-      url <- WrappeR$get_url()
54
+      credential <- get("GMQL_credentials", envir = .GlobalEnv)
55
+      url <- credential$remote_url
56
+      
57
+      if(is.null(url))
58
+        stop("url from GMQL_credentials is missing")
59
+      
55 60
       .download_or_upload(datasets)
56 61
       res <- serialize_query(url,isGTF,val)
57 62
     }
... ...
@@ -61,7 +66,13 @@ execute <- function() {
61 66
 .download_or_upload <- function(datasets) {
62 67
   WrappeR <- J("it/polimi/genomics/r/Wrapper")
63 68
   data_list <- apply(datasets, 1, as.list)
64
-  url <- WrappeR$get_url()
69
+  
70
+  credential <- get("GMQL_credentials", envir = .GlobalEnv)
71
+  url <- credential$remote_url
72
+  
73
+  if(is.null(url))
74
+    stop("url from GMQL_credentials is missing")
75
+  
65 76
   remote <- WrappeR$is_remote_processing()
66 77
   if(remote) {
67 78
     lapply(data_list,function(x){
... ...
@@ -74,9 +85,9 @@ execute <- function() {
74 85
   }
75 86
 }
76 87
 
77
-collect.GMQLDataset <- function(x, dir_out = getwd(), name = "ds1") {
88
+collect.GMQLDataset <- function(x,  name = "ds1", dir_out = getwd()) {
78 89
   ptr_data <- value(x)
79
-  gmql_materialize(ptr_data, dir_out, name)
90
+  gmql_materialize(ptr_data, name, dir_out)
80 91
 }
81 92
 
82 93
 
... ...
@@ -37,6 +37,21 @@
37 37
 #' \item{"application" = "RGMQL"}
38 38
 #' }
39 39
 #'
40
+#' NOTE: 
41
+#' The folder layout must obey the following rules and adopt 
42
+#' the following layout:
43
+#' The dataset folder can have any name, but must contains the 
44
+#' sub-folders named: "files".
45
+#' The sub-folder "files" contains the dataset files and 
46
+#' the schema xml file.
47
+#' The schema files adopt the following the naming conventions:
48
+#' 
49
+#' - "schema.xml"
50
+#' - "test.schema"
51
+#' 
52
+#' The names must be in LOWERCASE. Any other schema file 
53
+#' will not be conisdered, if both are present, "test.schema" will be used. 
54
+#'
40 55
 #' @examples
41 56
 #' 
42 57
 #' ## This statement initializes and runs the GMQL server for local execution 
... ...
@@ -61,6 +76,7 @@
61 76
 #' login_gmql(remote_url)
62 77
 #' data1 = read_gmql("public.Example_Dataset_1", is_local = FALSE)
63 78
 #' 
79
+#' 
64 80
 #' @name read_gmql
65 81
 #' @rdname read-function
66 82
 #' @export
... ...
@@ -82,22 +98,24 @@ read_gmql <- function(
82 98
     if(basename(dataset) !="files")
83 99
       dataset <- file.path(dataset,"files")
84 100
     
85
-    schema_XML <- .retrieve_schema(dataset)
101
+    schema_XML <- .retrieve_schema(dataset, T)
86 102
     
87 103
     schema_matrix <- .jnull("java/lang/String")
88 104
     url <- .jnull("java/lang/String")
89 105
     coords_sys <- .jnull("java/lang/String")
90 106
     type <- .jnull("java/lang/String")
91 107
   } else {
92
-    url <- WrappeR$get_url()
93
-    if(is.null(url))
94
-      stop("You have to log on using login function")
95 108
     
96 109
     if(!exists("GMQL_credentials", envir = .GlobalEnv))
97 110
       stop("You have to log on using login function")
98 111
     
112
+    credential <- get("GMQL_credentials", envir = .GlobalEnv)
113
+    url <- credential$remote_url
114
+    if(is.null(url))
115
+      stop("You have to log on using login function")
116
+    
99 117
     if(identical(parser_name,"CUSTOMPARSER")) {
100
-      list <- show_schema(url,dataset)
118
+      list <- show_schema(url, dataset)
101 119
       coords_sys <- list$coordinate_system
102 120
       type <- list$type
103 121
       schema_names <- vapply(
... ...
@@ -60,8 +60,9 @@ login_gmql <- function(url, username = NULL, password = NULL) {
60 60
   if(!is.null(username) || !is.null(password))
61 61
     as_guest <- FALSE
62 62
   
63
+  url <- sub("/*[/]$","",url)
64
+  
63 65
   if(as_guest) {
64
-    url <- sub("/*[/]$","",url)
65 66
     h <- c('Accept' = "Application/json")
66 67
     URL <- paste0(url,"/guest")
67 68
     req <- httr::GET(URL,httr::add_headers(h))
... ...
@@ -69,7 +70,7 @@ login_gmql <- function(url, username = NULL, password = NULL) {
69 70
     req <- httr::GET(url)
70 71
     real_URL <- req$url
71 72
     h <- c('Accept'="Application/json",'Content-Type'='Application/json')
72
-    URL <- paste0(real_URL,"login")
73
+    URL <- paste0(real_URL,"/login")
73 74
     body <- list('username' = username,'password' = password)
74 75
     req <- httr::POST(URL,httr::add_headers(h),body = body,encode = "json")
75 76
   }
... ...
@@ -79,7 +80,6 @@ login_gmql <- function(url, username = NULL, password = NULL) {
79 80
   if(req$status_code != 200)
80 81
     stop(content$errorString)
81 82
   else {
82
-    WrappeR <- J("it/polimi/genomics/r/Wrapper")
83 83
     url <- paste0(url,"/")
84 84
     GMQL_remote <- list(
85 85
       "remote_url" = url, 
... ...
@@ -88,7 +88,6 @@ login_gmql <- function(url, username = NULL, password = NULL) {
88 88
       "password" = password
89 89
     )
90 90
     
91
-    WrappeR$save_tokenAndUrl(GMQL_remote$authToken,url)
92 91
     assign("GMQL_credentials",GMQL_remote,.GlobalEnv)
93 92
     print(paste("your Token is",GMQL_remote$authToken))
94 93
   }
... ...
@@ -124,8 +123,7 @@ login_gmql <- function(url, username = NULL, password = NULL) {
124 123
 #' @rdname logout_gmql
125 124
 #' @export
126 125
 #'
127
-logout_gmql <- function(url)
128
-{
126
+logout_gmql <- function(url) {
129 127
   authToken = GMQL_credentials$authToken
130 128
   url <- sub("/*[/]$","",url)
131 129
   
... ...
@@ -136,11 +134,8 @@ logout_gmql <- function(url)
136 134
   
137 135
   if(req$status_code !=200)
138 136
     stop(content$error)
139
-  else
140
-  {
137
+  else {
141 138
     #delete token from environment
142
-    WrappeR <- J("it/polimi/genomics/r/Wrapper")
143
-    WrappeR$delete_token()
144 139
     if(exists("authToken", where = GMQL_credentials))
145 140
       rm(GMQL_credentials, envir = .GlobalEnv)
146 141
     
... ...
@@ -220,16 +215,14 @@ register_gmql <- function(
220 215
   if(req$status_code != 200) {
221 216
     stop(content)
222 217
   } else {
223
-    WrappeR <- J("it/polimi/genomics/r/Wrapper")
224 218
     GMQL_remote <- list(
225 219
       "remote_url" = url, 
226 220
       "authToken" = content$authToken,
227 221
       "username" = username,
228 222
       "password" = psw
229 223
     )
230
-    WrappeR$save_tokenAndUrl(GMQL_remote$authToken,url)
231
-    assign("GMQL_credentials",GMQL_remote,.GlobalEnv)
232
-    print(paste("your Token is",GMQL_remote$authToken))
224
+    assign("GMQL_credentials", GMQL_remote,.GlobalEnv)
225
+    print(paste("your Token is", GMQL_remote$authToken))
233 226
   }
234 227
 }
235 228
 
... ...
@@ -903,7 +896,22 @@ show_schema <- function(url, datasetName) {
903 896
 #' @details
904 897
 #' If no error occurs, it prints "Upload Complete", otherwise a specific error 
905 898
 #' is printed
906
-#'
899
+#' 
900
+#' NOTE: 
901
+#' The folder layout must obey the following rules and adopt 
902
+#' the following layout:
903
+#' The dataset folder can have any name, but must contains the 
904
+#' sub-folders named: "files".
905
+#' The sub-folder "files" contains the dataset files and 
906
+#' the schema xml file.
907
+#' The schema files adopt the following the naming conventions:
908
+#' 
909
+#' - "schema.xml"
910
+#' - "test.schema"
911
+#' 
912
+#' The names must be in LOWERCASE. Any other schema file 
913
+#' will not be conisdered, if both are present, "test.schema" will be used. 
914
+#' 
907 915
 #' @examples
908 916
 #'
909 917
 #' \dontrun{
... ...
@@ -935,16 +943,17 @@ upload_dataset <- function(
935 943
   schemaName = NULL
936 944
 ) {
937 945
   
938
-  folderPath <- sub("/*[/]$","",dataset)
946
+  folderPath <- sub("/*[/]$","",folderPath)
939 947
   if(basename(folderPath) !="files")
940 948
     folderPath <- file.path(folderPath,"files")
941 949
   
942
-  files <- list.files(folderPath, full.names = TRUE)
950
+  files <- list.files(folderPath, pattern = "*(.gtf|.gdm)", full.names = TRUE)
943 951
   if (!length(files)) {
944 952
     stop("no files present")
945 953
   }
946 954
   
947 955
   count = .counter(0)
956
+  
948 957
   list_files <- lapply(files, function(x) {
949 958
     file <- httr::upload_file(x)
950 959
   })
... ...
@@ -962,7 +971,7 @@ upload_dataset <- function(
962 971
   
963 972
   schema_name <- tolower(schemaName)
964 973
   
965
-  if (is.null(schemaName)) {
974
+  if (is.null(schemaName) || identical(schema_name, "customparser")) {
966 975
     schema <- .retrieve_schema(folderPath)
967 976
     
968 977
     list_files <- list(
... ...
@@ -972,37 +981,24 @@ upload_dataset <- function(
972 981
     list_files <- unlist(list_files, recursive = FALSE)
973 982
     URL <- paste0(real_URL, "datasets/", datasetName, "/uploadSample")
974 983
   } else {
975
-    schema_name <- tolower(schemaName)
976
-    if (identical(schema_name, "customparser")) {
977
-      schema <- .retrieve_schema(folderPath)
978
-      
979
-      list_files <- list(
980
-        list("schema" = httr::upload_file(schema)),
981
-        list_files
982
-      )
983
-      list_files <- unlist(list_files, recursive = FALSE)
984
-      
985
-      URL <- paste0(real_URL, "datasets/", datasetName, "/uploadSample")
986
-    }else {
987
-      schemaList <- c(
988
-        "narrowpeak",
989
-        "vcf",
990
-        "broadpeak",
991
-        "bed",
992
-        "bedgraph"
993
-      )
994
-      if (!schema_name %in% schemaList) {
995
-        stop("schema not admissable")
996
-      }
997
-      
998
-      URL <- paste0(
999
-        real_URL,
1000
-        "datasets/",
1001
-        datasetName,
1002
-        "/uploadSample?schemaName=",
1003
-        schema_name
1004
-      )
984
+    schemaList <- c(
985
+      "narrowpeak",
986
+      "vcf",
987
+      "broadpeak",
988
+      "bed",
989
+      "bedgraph"
990
+    )
991
+    if (!schema_name %in% schemaList) {
992
+      stop("schema not admissable")
1005 993
     }
994
+    
995
+    URL <- paste0(
996
+      real_URL,
997
+      "datasets/",
998
+      datasetName,
999
+      "/uploadSample?schemaName=",
1000
+      schema_name
1001
+    )
1006 1002
   }
1007 1003
   
1008 1004
   req <- httr::POST(URL, body = list_files , httr::add_headers(h))
... ...
@@ -1328,8 +1324,7 @@ serialize_query <- function(url,output_gtf,base64) {
1328 1324
 }
1329 1325
 
1330 1326
 
1331
-
1332
-.retrieve_schema <- function(folderPath) {
1327
+.retrieve_schema <- function(folderPath, duringReading = F) {
1333 1328
   schema_SCHEMA <- list.files(
1334 1329
     folderPath, pattern = "test.schema$", full.names = TRUE
1335 1330
   )
... ...
@@ -1344,7 +1339,11 @@ serialize_query <- function(url,output_gtf,base64) {
1344 1339
   schema <- if(!length(schema_SCHEMA)) 
1345 1340
     xml_schema 
1346 1341
   else
1347
-    schema_SCHEMA
1342
+    if(!duringReading) {
1343
+      schema_SCHEMA
1344
+    } else {
1345
+      folderPath
1346
+    }
1348 1347
   
1349 1348
   schema
1350 1349
 }
... ...
@@ -6,15 +6,15 @@
6 6
 \alias{collect-method}
7 7
 \title{Method collect}
8 8
 \usage{
9
-\S4method{collect}{GMQLDataset}(x, dir_out = getwd(), name = "ds1")
9
+\S4method{collect}{GMQLDataset}(x, name = "ds1", dir_out = getwd())
10 10
 }
11 11
 \arguments{
12 12
 \item{x}{GMQLDataset class object}
13 13
 
14
+\item{name}{name of the result dataset. By default it is the string "ds1"}
15
+
14 16
 \item{dir_out}{destination folder path. By default it is the current 
15 17
 working directory of the R process}
16
-
17
-\item{name}{name of the result dataset. By default it is the string "ds1"}
18 18
 }
19 19
 \value{
20 20
 None