Browse code

fixed remote

Simone authored on 19/03/2021 17:30:11
Showing8 changed files

1 1
old mode 100644
2 2
new mode 100755
... ...
@@ -8,8 +8,7 @@
8 8
 #' @noRd
9 9
 #' @return instance of GMQL dataset
10 10
 #' 
11
-setClass("GMQLDataset",
12
-            representation(value = "character"))
11
+setClass("GMQLDataset", representation(value = "character"))
13 12
 
14 13
 #' GMQLDataset alloc Function
15 14
 #' 
... ...
@@ -22,19 +21,16 @@ setClass("GMQLDataset",
22 21
 #' @rdname GMQLDataset-class
23 22
 #' @noRd
24 23
 GMQLDataset <- function(value) {
25
-    dataset <- new("GMQLDataset",value = value)
26
-    return(dataset)
24
+  dataset <- new("GMQLDataset",value = value)
25
+  return(dataset)
27 26
 }
28 27
 
29
-setMethod("show", "GMQLDataset",
30
-            function(object)
31
-            {
32
-                cat("GMQL Dataset \n")
33
-                cat(" value :",paste(object@value))
34
-            })
28
+setMethod("show", "GMQLDataset", function(object) {
29
+  cat("GMQL Dataset \n")
30
+  cat(" value :",paste(object@value))
31
+})
35 32
 
36 33
 setGeneric("value", function(.dataset) standardGeneric("value"))
37 34
 
38 35
 setMethod("value", "GMQLDataset", function(.dataset) .dataset@value)
39 36
 
40
-
41 37
old mode 100644
42 38
new mode 100755
... ...
@@ -18,7 +18,6 @@ setGeneric("cover", function(.data, ...) standardGeneric("cover"))
18 18
 #' 
19 19
 setGeneric("map", function(x, y, ...) standardGeneric("map"))
20 20
 
21
-
22 21
 #' Method take
23 22
 #' 
24 23
 #' Wrapper to TAKE operation
... ...
@@ -29,7 +28,6 @@ setGeneric("map", function(x, y, ...) standardGeneric("map"))
29 28
 #' 
30 29
 setGeneric("take", function(.data, ...) standardGeneric("take"))
31 30
 
32
-
33 31
 #' Method extend
34 32
 #' 
35 33
 #' Wrapper to GMQL EXTEND operator 
36 34
old mode 100644
37 35
new mode 100755
... ...
@@ -32,23 +32,23 @@
32 32
 #' @rdname condition_eval_func
33 33
 #' @export
34 34
 conds <- function(default = c(""), full = c(""), exact = c("")) {
35
-    df <- .condition("DEF",default)
36
-    fn <- .condition("FULL",full)
37
-    ex <- .condition("EXACT",exact)
38
-    list("condition" = list("def" = df, "full" = fn, "exact" = ex))
35
+  df <- .condition("DEF",default)
36
+  fn <- .condition("FULL",full)
37
+  ex <- .condition("EXACT",exact)
38
+  list("condition" = list("def" = df, "full" = fn, "exact" = ex))
39 39
 }
40 40
 
41 41
 .condition <- function(cond, array) {
42
-    array = array[!array %in% ""]
43
-    array = array[!duplicated(array)]
44
-    
45
-    if(!length(array))
46
-        join_condition_matrix <- NULL
47
-    else {
48
-        join_condition_matrix <- t(vapply(array, function(x) {
49
-            new_value = c(cond, x)
50
-            matrix <- matrix(new_value)
51
-        },character(2)))
52
-    }
53
-    join_condition_matrix
42
+  array = array[!array %in% ""]
43
+  array = array[!duplicated(array)]
44
+  
45
+  if(!length(array))
46
+    join_condition_matrix <- NULL
47
+  else {
48
+    join_condition_matrix <- t(vapply(array, function(x) {
49
+      new_value = c(cond, x)
50
+      matrix <- matrix(new_value)
51
+    },character(2)))
52
+  }
53
+  join_condition_matrix
54 54
 }
55 55
old mode 100644
56 56
new mode 100755
... ...
@@ -122,90 +122,87 @@
122 122
 #' @aliases cover,GMQLDataset-method
123 123
 #' @aliases cover-method
124 124
 #' @export
125
-setMethod("cover", "GMQLDataset",
126
-            function(.data, min_acc, max_acc, groupBy = conds(), 
127
-                    variation = "cover", ...)
128
-            {
129
-                val <- value(.data)
130
-                s_min <- substitute(min_acc)
131
-                s_min <- .trasform_cover(deparse(s_min))                
132
-                s_max <- substitute(max_acc)
133
-                s_max <- .trasform_cover(deparse(s_max))
134
-                
135
-                q_max <- .check_cover_param(s_max,FALSE)
136
-                q_min <- .check_cover_param(s_min,TRUE)
137
-                
138
-                flag = toupper(variation)
139
-                aggregates = list(...)
140
-                gmql_cover(val, q_min, q_max, groupBy, aggregates, flag)
141
-            })
142
-
143
-gmql_cover <- function(input_data, min_acc, max_acc, groupBy,aggregates,flag)
125
+setMethod("cover", "GMQLDataset", function(
126
+  .data, min_acc, max_acc, groupBy = conds(), variation = "cover", ...)
144 127
 {
145
-    if(!is.null(groupBy))
146
-    {
147
-        if("condition" %in% names(groupBy))
148
-        {
149
-            cond <- .join_condition(groupBy)
150
-            if(is.null(cond))
151
-                join_matrix <- .jnull("java/lang/String")
152
-            else
153
-                join_matrix <- .jarray(cond, dispatch = TRUE)
154
-        }
155
-        else
156
-            stop("use function conds()")
157
-    }
158
-    else
159
-        join_matrix <- .jnull("java/lang/String")
128
+  val <- value(.data)
129
+  s_min <- substitute(min_acc)
130
+  s_min <- .trasform_cover(deparse(s_min))                
131
+  s_max <- substitute(max_acc)
132
+  s_max <- .trasform_cover(deparse(s_max))
133
+  
134
+  q_max <- .check_cover_param(s_max,FALSE)
135
+  q_min <- .check_cover_param(s_min,TRUE)
136
+  
137
+  flag = toupper(variation)
138
+  aggregates = list(...)
139
+  gmql_cover(val, q_min, q_max, groupBy, aggregates, flag)
140
+})
160 141
 
161
-    if(!is.null(aggregates) && length(aggregates))
162
-    {
163
-        aggr <- .aggregates(aggregates,"AGGREGATES")
164
-        metadata_matrix <- .jarray(aggr, dispatch = TRUE)
142
+gmql_cover <- function(
143
+  input_data, 
144
+  min_acc, 
145
+  max_acc, 
146
+  groupBy,
147
+  aggregates,
148
+  flag
149
+) {
150
+  if(!is.null(groupBy)) {
151
+    if("condition" %in% names(groupBy)) {
152
+      cond <- .join_condition(groupBy)
153
+      if(is.null(cond))
154
+        join_matrix <- .jnull("java/lang/String")
155
+      else
156
+        join_matrix <- .jarray(cond, dispatch = TRUE)
165 157
     }
166 158
     else
167
-        metadata_matrix <- .jnull("java/lang/String")
168
-    
169
-    WrappeR <- J("it/polimi/genomics/r/Wrapper")
170
-    response <- switch(flag,
171
-        "COVER" = WrappeR$cover(min_acc, max_acc, join_matrix,
172
-                                    metadata_matrix, input_data),
173
-        "FLAT" = WrappeR$flat(min_acc, max_acc, join_matrix,
174
-                                    metadata_matrix, input_data),
175
-        "SUMMIT" = WrappeR$summit(min_acc,max_acc, join_matrix,
176
-                                    metadata_matrix, input_data),
177
-        "HISTOGRAM" = WrappeR$histogram(min_acc, max_acc, join_matrix, 
178
-                                    metadata_matrix, input_data))
179
-    if(is.null(response))
180
-        stop("no admissible variation: cover, flat, summit, histogram")
181
-    
182
-    error <- strtoi(response[1])
183
-    val <- response[2]
184
-    if(error)
185
-        stop(val)
186
-    else
187
-        GMQLDataset(val)
159
+      stop("use function conds()")
160
+  } else
161
+    join_matrix <- .jnull("java/lang/String")
162
+  
163
+  if(!is.null(aggregates) && length(aggregates)) {
164
+    aggr <- .aggregates(aggregates,"AGGREGATES")
165
+    metadata_matrix <- .jarray(aggr, dispatch = TRUE)
166
+  } else
167
+    metadata_matrix <- .jnull("java/lang/String")
168
+  
169
+  WrappeR <- J("it/polimi/genomics/r/Wrapper")
170
+  response <- switch(
171
+    flag,
172
+    "COVER" = WrappeR$cover(
173
+      min_acc, max_acc, join_matrix, metadata_matrix, input_data),
174
+    "FLAT" = WrappeR$flat(
175
+      min_acc, max_acc, join_matrix,metadata_matrix, input_data),
176
+    "SUMMIT" = WrappeR$summit(
177
+      min_acc,max_acc, join_matrix, metadata_matrix, input_data),
178
+    "HISTOGRAM" = WrappeR$histogram(
179
+      min_acc, max_acc, join_matrix, metadata_matrix, input_data)
180
+  )
181
+  if(is.null(response))
182
+    stop("no admissible variation: cover, flat, summit, histogram")
183
+  
184
+  error <- strtoi(response[1])
185
+  val <- response[2]
186
+  if(error)
187
+    stop(val)
188
+  else
189
+    GMQLDataset(val)
188 190
 }
189 191
 
190
-.check_cover_param <- function(param, is_min)
191
-{
192
-    if(length(param) > 1)
193
-        stop("length > 1")
194
-
195
-    if(is.character(param))
196
-    {
197
-        if(is_min && identical(param,"ANY"))
198
-            stop("min cannot assume ANY as value")
199
-        
200
-        return(param)
201
-    }
202
-    else
203
-        stop("invalid input data")
192
+.check_cover_param <- function(param, is_min) {
193
+  if(length(param) > 1)
194
+    stop("length > 1")
195
+  
196
+  if(is.character(param)) {
197
+    if(is_min && identical(param,"ANY"))
198
+      stop("min cannot assume ANY as value")
204 199
     
200
+    return(param)
201
+  } else
202
+    stop("invalid input data")
205 203
 }
206 204
 
207
-.trasform_cover <- function(predicate)
208
-{
205
+.trasform_cover <- function(predicate) {
209 206
     predicate <- gsub("\\(\\)","",predicate)
210 207
 }
211 208
 
212 209
old mode 100644
213 210
new mode 100755
... ...
@@ -61,36 +61,34 @@
61 61
 #' @aliases setdiff,GMQLDataset,GMQLDataset-method
62 62
 #' @aliases setdiff-method
63 63
 #' @export
64
-setMethod("setdiff", c("GMQLDataset","GMQLDataset"),
65
-            function(x, y, joinBy = conds(), is_exact = FALSE)
66
-            {
67
-                ptr_data_x = value(x)
68
-                ptr_data_y = value(y)
69
-                gmql_difference(ptr_data_x, ptr_data_y, is_exact, joinBy)
70
-            })
64
+setMethod("setdiff", c("GMQLDataset","GMQLDataset"), 
65
+  function(x, y, joinBy = conds(), is_exact = FALSE) {
66
+    ptr_data_x = value(x)
67
+    ptr_data_y = value(y)
68
+    gmql_difference(ptr_data_x, ptr_data_y, is_exact, joinBy)
69
+  })
71 70
 
72
-gmql_difference <- function(left_data, right_data, is_exact, joinBy)
73
-{
74
-    if(!is.null(joinBy))
75
-    {
76
-        cond <- .join_condition(joinBy)
77
-        if(is.null(cond))
78
-            join_matrix <- .jnull("java/lang/String")
79
-        else
80
-            join_matrix <- .jarray(cond, dispatch = TRUE)
81
-    }
71
+gmql_difference <- function(left_data, right_data, is_exact, joinBy) {
72
+  if(!is.null(joinBy)) {
73
+    cond <- .join_condition(joinBy)
74
+    if(is.null(cond))
75
+      join_matrix <- .jnull("java/lang/String")
82 76
     else
83
-        join_matrix <- .jnull("java/lang/String")
84
-    
85
-    WrappeR <- J("it/polimi/genomics/r/Wrapper")
86
-    response <- WrappeR$difference(join_matrix, left_data, right_data, 
87
-                                        is_exact)
88
-    error <- strtoi(response[1])
89
-    val <- response[2]
90
-    if(error)
91
-        stop(val)
92
-    else
93
-        GMQLDataset(val)
77
+      join_matrix <- .jarray(cond, dispatch = TRUE)
78
+  }
79
+  else
80
+    join_matrix <- .jnull("java/lang/String")
81
+  
82
+  WrappeR <- J("it/polimi/genomics/r/Wrapper")
83
+  response <- WrappeR$difference(
84
+    join_matrix, left_data, right_data, is_exact
85
+  )
86
+  error <- strtoi(response[1])
87
+  val <- response[2]
88
+  if(error)
89
+    stop(val)
90
+  else
91
+    GMQLDataset(val)
94 92
 }
95 93
 
96 94
 
97 95
old mode 100644
98 96
new mode 100755
... ...
@@ -35,8 +35,10 @@ execute <- function()
35 35
 {
36 36
     WrappeR <- J("it/polimi/genomics/r/Wrapper")
37 37
     remote_proc <- WrappeR$is_remote_processing()
38
+    datasets <- .jevalArray(WrappeR$get_dataset_list(),simplify = TRUE)
39
+    
38 40
     if(!remote_proc)
39
-        .download_or_upload()
41
+        .download_or_upload(datasets)
40 42
     
41 43
     response <- WrappeR$execute()
42 44
     error <- strtoi(response[1])
... ...
@@ -51,15 +53,14 @@ execute <- function()
51 53
                 isGTF <- TRUE
52 54
             
53 55
             url <- WrappeR$get_url()
54
-            .download_or_upload()
56
+            .download_or_upload(datasets)
55 57
             res <- serialize_query(url,isGTF,val)
56 58
         }
57 59
     }
58 60
 }
59 61
 
60
-.download_or_upload <- function() {
62
+.download_or_upload <- function(datasets) {
61 63
     WrappeR <- J("it/polimi/genomics/r/Wrapper")
62
-    datasets <- .jevalArray(WrappeR$get_dataset_list(),simplify = TRUE)
63 64
     data_list <- apply(datasets, 1, as.list)
64 65
     url <- WrappeR$get_url()
65 66
     remote <- WrappeR$is_remote_processing()
66 67
old mode 100644
67 68
new mode 100755
... ...
@@ -66,82 +66,93 @@
66 66
 #' @rdname read-function
67 67
 #' @export
68 68
 #'
69
-read_gmql <- function(dataset, parser = "CustomParser", is_local = TRUE, 
70
-                            is_GMQL = TRUE)
71
-{
72
-    .check_input(dataset)
73
-    .check_logical(is_local)
74
-    .check_logical(is_GMQL)
75
-    WrappeR <- J("it/polimi/genomics/r/Wrapper")
76
-    parser_name <- .check_parser(parser)
77
-    if(is_local)
78
-    {
79
-        if(!dir.exists(dataset))
80
-            stop("folder does not exist")
81
-        
82
-        dataset <- sub("/*[/]$","",dataset)
83
-        if(basename(dataset) !="files")
84
-            dataset <- file.path(dataset,"files")
85
-        
86
-        schema_SCHEMA <- list.files(dataset, pattern = "*.schema$",
87
-                                        full.names = TRUE)
88
-        
89
-        xml_schema <- list.files(dataset, pattern = "*.xml$",
90
-                                        full.names = TRUE)
91
-        xml_schema = xml_schema[!basename(xml_schema) %in% c("web_profile.xml")]
92
-        
93
-        if(!length(schema_SCHEMA) && !length(xml_schema))
94
-            stop("schema not present")
95
-        
96
-        if(!length(schema_SCHEMA))
97
-            schema_XML <- xml_schema
98
-        else
99
-            schema_XML <- dataset
100
-        
101
-        schema_matrix <- .jnull("java/lang/String")
102
-        url <- .jnull("java/lang/String")
103
-        coords_sys <- .jnull("java/lang/String")
104
-        type <- .jnull("java/lang/String")
105
-    }
69
+read_gmql <- function(
70
+  dataset, 
71
+  parser = "CustomParser", 
72
+  is_local = TRUE, 
73
+  is_GMQL = TRUE
74
+) {
75
+  .check_input(dataset)
76
+  .check_logical(is_local)
77
+  .check_logical(is_GMQL)
78
+  WrappeR <- J("it/polimi/genomics/r/Wrapper")
79
+  parser_name <- .check_parser(parser)
80
+  if(is_local) {
81
+    if(!dir.exists(dataset))
82
+      stop("folder does not exist")
83
+    
84
+    dataset <- sub("/*[/]$","",dataset)
85
+    if(basename(dataset) !="files")
86
+      dataset <- file.path(dataset,"files")
87
+    
88
+    schema_SCHEMA <- list.files(
89
+      dataset, pattern = "*.schema$", full.names = TRUE
90
+    )
91
+    
92
+    xml_schema <- list.files(
93
+      dataset, pattern = "*.xml$", full.names = TRUE
94
+    )
95
+    xml_schema = xml_schema[!basename(xml_schema) %in% c("web_profile.xml")]
96
+    
97
+    if(!length(schema_SCHEMA) && !length(xml_schema))
98
+      stop("schema not present")
99
+    
100
+    if(!length(schema_SCHEMA))
101
+      schema_XML <- xml_schema
106 102
     else
107
-    {
108
-        url <- WrappeR$get_url()
109
-        if(is.null(url))
110
-            stop("You have to log on using login function")
111
-        
112
-        if(!exists("GMQL_credentials", envir = .GlobalEnv))
113
-            stop("You have to log on using login function")
114
-        
115
-        if(identical(parser_name,"CUSTOMPARSER"))
116
-        {
117
-            list <- show_schema(url,dataset)
118
-            coords_sys <- list$coordinate_system
119
-            type <- list$type
120
-            schema_names <- vapply(list$fields, function(x){x$name},
121
-                                        character(1))
122
-            schema_type <- vapply(list$fields, function(x){x$type},
123
-                                        character(1))
124
-            schema_matrix <- cbind(schema_names,schema_type)
125
-
126
-            if(is.null(schema_matrix) || !length(schema_matrix))
127
-                schema_matrix <- .jnull("java/lang/String")
128
-            else
129
-                schema_matrix <- .jarray(schema_matrix, dispatch = TRUE)
130
-        }
131
-        else
132
-            schema_matrix <- .jnull("java/lang/String")
133
-        
134
-        schema_XML <- .jnull("java/lang/String")
103
+      schema_XML <- dataset
104
+    
105
+    schema_matrix <- .jnull("java/lang/String")
106
+    url <- .jnull("java/lang/String")
107
+    coords_sys <- .jnull("java/lang/String")
108
+    type <- .jnull("java/lang/String")
109
+  } else {
110
+    url <- WrappeR$get_url()
111
+    if(is.null(url))
112
+      stop("You have to log on using login function")
113
+    
114
+    if(!exists("GMQL_credentials", envir = .GlobalEnv))
115
+      stop("You have to log on using login function")
116
+    
117
+    if(identical(parser_name,"CUSTOMPARSER")) {
118
+      list <- show_schema(url,dataset)
119
+      coords_sys <- list$coordinate_system
120
+      type <- list$type
121
+      schema_names <- vapply(
122
+        list$fields, function(x){x$name},character(1)
123
+      )
124
+      schema_type <- vapply(
125
+        list$fields, function(x){x$type},character(1)
126
+      )
127
+      schema_matrix <- cbind(schema_names,schema_type)
128
+      
129
+      if(is.null(schema_matrix) || !length(schema_matrix))
130
+        schema_matrix <- .jnull("java/lang/String")
131
+      else
132
+        schema_matrix <- .jarray(schema_matrix, dispatch = TRUE)
135 133
     }
136
-
137
-    response <- WrappeR$readDataset(dataset, parser_name, is_local, is_GMQL, 
138
-                    schema_matrix, schema_XML, coords_sys, type)
139
-    error <- strtoi(response[1])
140
-    data <- response[2]
141
-    if(error)
142
-        stop(data)
143 134
     else
144
-        GMQLDataset(data)
135
+      schema_matrix <- .jnull("java/lang/String")
136
+    
137
+    schema_XML <- .jnull("java/lang/String")
138
+  }
139
+  
140
+  response <- WrappeR$readDataset(
141
+    dataset, 
142
+    parser_name, 
143
+    is_local, 
144
+    is_GMQL, 
145
+    schema_matrix,
146
+    schema_XML,
147
+    coords_sys, 
148
+    type
149
+  )
150
+  error <- strtoi(response[1])
151
+  data <- response[2]
152
+  if(error)
153
+    stop(data)
154
+  else
155
+    GMQLDataset(data)
145 156
 }
146 157
 
147 158
 
... ...
@@ -154,81 +165,89 @@ read_gmql <- function(dataset, parser = "CustomParser", is_local = TRUE,
154 165
 #' @rdname read-function
155 166
 #' @export
156 167
 #'
157
-read_GRangesList <- function(samples)
158
-{
159
-    if(!is(samples,"GRangesList"))
160
-        stop("only GrangesList")
161
-    
162
-    meta <- S4Vectors::metadata(samples)
163
-    if(is.null(meta) || !length(meta)) 
164
-    {
165
-        #repeat meta for each sample in samples list
166
-        len <- length(samples)
167
-        warning("No metadata.\nWe provide two metadata for you:
168
-                \n1.provider = PoliMi\n2.application = RGMQL\n")
169
-        index_meta <- rep(seq_len(len),each = len)
170
-        rep_meta <- rep(c("provider","PoliMi", "application", "RGMQL"),
171
-                            times = len)
172
-        meta_matrix <- matrix(rep_meta,ncol = 2,byrow = TRUE)
173
-        meta_matrix <- cbind(index_meta,meta_matrix)
174
-    }
175
-    else 
176
-    {
177
-        unlist_meta <- unlist(meta)
178
-        names_meta <- names(unlist_meta)
179
-        group_names <- gsub(".*_([0-9]*)\\..*","\\1", names_meta)
180
-        names(unlist_meta) <- NULL
181
-        meta_matrix <- cbind(group_names,names_meta,unlist_meta)
182
-    }
183
-    
184
-    df <- data.frame(samples)
185
-    df <- df[-2] #delete group_name
186
-    len_df <- dim(df)[1] # number of rows
187
-
188
-    col_types <- vapply(df,class,character(1))
189
-    col_names <- names(col_types)
190
-    #re order the schema?
191
-    if("phase" %in% col_names) # if GTF, change
192
-    {
193
-        col_names <- plyr::revalue(col_names,c(type = "feature", 
194
-                                    phase = "frame", seqnames = "seqname"))
195
-        schema_matrix <- cbind(toupper(col_types),col_names)
196
-        schema_matrix<- schema_matrix[setdiff(rownames(schema_matrix),
197
-                                        c("group","width")),]
198
-    }
199
-    else
200
-    {
201
-        col_names <- plyr::revalue(col_names,c(start = "left", 
202
-                                        end = "right", seqnames = "chr"))
203
-        schema_matrix <- cbind(col_names,toupper(col_types))
204
-        df$start = df$start - 1
205
-        schema_matrix<- schema_matrix[setdiff(rownames(schema_matrix),
206
-                                        c("group","width")),]
207
-    }
208
-    region_matrix <- as.matrix(vapply(df, as.character,character(len_df)))
209
-    region_matrix[is.na(region_matrix)] <- "NA"
210
-    region_matrix <- region_matrix[,setdiff(colnames(region_matrix),"width")]
211
-    rownames(schema_matrix) <- NULL
212
-    colnames(schema_matrix) <- NULL
213
-    
214
-    schema_matrix <- .jarray(schema_matrix,dispatch = TRUE)
215
-    meta_matrix <- .jarray(meta_matrix,dispatch = TRUE)
216
-    region_matrix <- .jarray(region_matrix,dispatch = TRUE)
217
-    
218
-    WrappeR <- J("it/polimi/genomics/r/Wrapper")
219
-    response <- WrappeR$read(meta_matrix,region_matrix,schema_matrix,
220
-                                "default", "TAB")
221
-    GMQLDataset(response)
168
+read_GRangesList <- function(samples) {
169
+  if(!is(samples,"GRangesList"))
170
+    stop("only GrangesList")
171
+  
172
+  meta <- S4Vectors::metadata(samples)
173
+  if(is.null(meta) || !length(meta)) {
174
+    #repeat meta for each sample in samples list
175
+    len <- length(samples)
176
+    warning(
177
+    "No metadata.\nWe provide two metadata for you:
178
+    \n1.provider = PoliMi\n2.application = RGMQL\n"
179
+    )
180
+    index_meta <- rep(seq_len(len),each = len)
181
+    rep_meta <- rep(
182
+      c("provider","PoliMi", "application", "RGMQL"),
183
+      times = len
184
+    )
185
+    meta_matrix <- matrix(rep_meta,ncol = 2,byrow = TRUE)
186
+    meta_matrix <- cbind(index_meta,meta_matrix)
187
+  }else {
188
+    unlist_meta <- unlist(meta)
189
+    names_meta <- names(unlist_meta)
190
+    group_names <- gsub(".*_([0-9]*)\\..*","\\1", names_meta)
191
+    names(unlist_meta) <- NULL
192
+    meta_matrix <- cbind(group_names,names_meta,unlist_meta)
193
+  }
194
+  
195
+  df <- data.frame(samples)
196
+  df <- df[-2] #delete group_name
197
+  len_df <- dim(df)[1] # number of rows
198
+  
199
+  col_types <- vapply(df,class,character(1))
200
+  col_names <- names(col_types)
201
+  #re order the schema?
202
+  # if GTF, change
203
+  if("phase" %in% col_names) {
204
+    col_names <- plyr::revalue(
205
+      col_names,c(type = "feature", phase = "frame", seqnames = "seqname")
206
+    )
207
+    schema_matrix <- cbind(toupper(col_types),col_names)
208
+    schema_matrix<- schema_matrix[
209
+      setdiff(rownames(schema_matrix), c("group","width")),]
210
+  } else {
211
+    col_names <- plyr::revalue(
212
+      col_names,
213
+      c(start = "left", end = "right", seqnames = "chr"))
214
+    schema_matrix <- cbind(col_names,toupper(col_types))
215
+    df$start = df$start - 1
216
+    schema_matrix<- schema_matrix[
217
+      setdiff(rownames(schema_matrix),c("group","width")),]
218
+  }
219
+  region_matrix <- as.matrix(vapply(df, as.character,character(len_df)))
220
+  region_matrix[is.na(region_matrix)] <- "NA"
221
+  region_matrix <- region_matrix[,setdiff(colnames(region_matrix),"width")]
222
+  rownames(schema_matrix) <- NULL
223
+  colnames(schema_matrix) <- NULL
224
+  
225
+  schema_matrix <- .jarray(schema_matrix,dispatch = TRUE)
226
+  meta_matrix <- .jarray(meta_matrix,dispatch = TRUE)
227
+  region_matrix <- .jarray(region_matrix,dispatch = TRUE)
228
+  
229
+  WrappeR <- J("it/polimi/genomics/r/Wrapper")
230
+  response <- WrappeR$read(
231
+    meta_matrix,
232
+    region_matrix,
233
+    schema_matrix,
234
+    "default", "TAB"
235
+  )
236
+  
237
+  GMQLDataset(response)
222 238
 }
223 239
 
224
-
225
-.check_parser <- function(parser)
226
-{
227
-    parser <- toupper(parser)
228
-    if(!parser %in% c("BEDPARSER","BROADPEAKPARSER", "NARROWPEAKPARSER",
229
-                        "CUSTOMPARSER"))
230
-        stop("parser not defined")
231
-    
232
-    parser
240
+.check_parser <- function(parser) {
241
+  parser <- toupper(parser)
242
+  parsers <- c(
243
+    "BEDPARSER",
244
+    "BROADPEAKPARSER",
245
+    "NARROWPEAKPARSER",
246
+    "CUSTOMPARSER")
247
+  
248
+  if(!parser %in% parsers)
249
+    stop("parser not defined")
250
+  
251
+  parser
233 252
 }
234 253
 
235 254
old mode 100644
236 255
new mode 100755
... ...
@@ -1,17 +1,14 @@
1
-if(getRversion() >= "2.15.1")
2
-{
3
-    utils::globalVariables("GMQL_credentials")
4
-    utils::globalVariables("remote_url")
1
+if(getRversion() >= "2.15.1") {
2
+  utils::globalVariables("GMQL_credentials")
3
+  utils::globalVariables("remote_url")
5 4
 }
6 5
 
7
-if(getRversion() >= "3.1.0")
8
-{
9
-    utils::suppressForeignCheck("GMQL_credentials")
10
-    utils::suppressForeignCheck("remote_url")
6
+if(getRversion() >= "3.1.0") {
7
+  utils::suppressForeignCheck("GMQL_credentials")
8
+  utils::suppressForeignCheck("remote_url")
11 9
 }
12 10
 
13 11
 
14
-
15 12
 #############################
16 13
 #     WEB AUTHENTICATION   #
17 14
 ############################
... ...
@@ -52,10 +49,8 @@ if(getRversion() >= "3.1.0")
52 49
 #' @rdname login_gmql
53 50
 #' @export
54 51
 #' 
55
-login_gmql <- function(url, username = NULL, password = NULL)
56
-{
57
-    if(!.is_login_expired(url))
58
-    {
52
+login_gmql <- function(url, username = NULL, password = NULL) {
53
+    if(!.is_login_expired(url)) {
59 54
         print("Login still valid")
60 55
         return(invisible(NULL))
61 56
     }
... ...
@@ -65,8 +60,7 @@ login_gmql <- function(url, username = NULL, password = NULL)
65 60
     if(!is.null(username) || !is.null(password))
66 61
         as_guest <- FALSE
67 62
     
68
-    if(as_guest)
69
-    {
63
+    if(as_guest) {
70 64
         url <- sub("/*[/]$","",url)
71 65
         h <- c('Accept' = "Application/json")
72 66
         URL <- paste0(url,"/guest")
... ...
@@ -836,8 +830,7 @@ show_samples_list <- function(url,datasetName)
836 830
 #' @rdname show_schema
837 831
 #' @export
838 832
 #'
839
-show_schema <- function(url,datasetName)
840
-{
833
+show_schema <- function(url,datasetName) {
841 834
     url <- sub("/*[/]$","",url)
842 835
     URL <- paste0(url,"/datasets/",datasetName,"/schema")
843 836
     authToken = GMQL_credentials$authToken
... ...
@@ -977,7 +970,7 @@ upload_dataset <- function(url, datasetName, folderPath, schemaName = NULL,
977 970
     req <- httr::POST(URL, body = list_files ,httr::add_headers(h))
978 971
     content <- httr::content(req)
979 972
     if(req$status_code !=200)
980
-        print(content)
973
+        stop(content)
981 974
     else
982 975
         print("upload Complete")
983 976
 }
... ...
@@ -1082,7 +1075,7 @@ download_dataset <- function(url, datasetName, path = getwd())
1082 1075
     
1083 1076
     content <- httr::content(req)
1084 1077
     if(req$status_code !=200)
1085
-        print(content)
1078
+        stop(content)
1086 1079
     else
1087 1080
     {
1088 1081
         zip_path <- file.path(path,paste0(datasetName,".zip"))