Browse code

fix take and read

Simone authored on 09/02/2021 09:07:32
Showing23 changed files

... ...
@@ -23,7 +23,7 @@ License: Artistic-2.0
23 23
 URL: http://www.bioinformatics.deib.polimi.it/genomic_computing/GMQL/
24 24
 Encoding: UTF-8
25 25
 LazyData: true
26
-RoxygenNote: 6.1.1
26
+RoxygenNote: 7.1.1
27 27
 Imports:
28 28
     httr,
29 29
     rJava,
... ...
@@ -1,6 +1,5 @@
1 1
 
2
-.counter <- function(zero = 0)
3
-{
2
+.counter <- function(zero = 0) {
4 3
     i <- zero
5 4
     function() {
6 5
         i <<- i + 1
... ...
@@ -8,16 +7,14 @@
8 7
     }
9 8
 }
10 9
 
11
-.add_metadata <- function(files)
12
-{
10
+.add_metadata <- function(files) {
13 11
     x <- scan(files, what="", sep="\n")
14 12
     y <- strsplit(x, "\t")
15 13
     names(y) <- vapply(y, `[[`,character(1), 1)
16 14
     listMeta <- lapply(y, `[`, -1)
17 15
 }
18 16
 
19
-.schema_header <- function(datasetName)
20
-{
17
+.schema_header <- function(datasetName) {
21 18
     schema_name <- list.files(datasetName, pattern = "*.schema$",
22 19
                                 full.names = TRUE)
23 20
     
... ...
@@ -36,8 +33,7 @@
36 33
     vector_field <- unlist(list_field)
37 34
 }
38 35
 
39
-.schema_type_coordinate <- function(datasetName)
40
-{
36
+.schema_type_coordinate <- function(datasetName) {
41 37
     schema_name <- list.files(datasetName, pattern = "*.schema$",
42 38
                               full.names = TRUE)
43 39
     
... ...
@@ -58,8 +54,7 @@
58 54
 }
59 55
 
60 56
 # aggregates factory
61
-.aggregates <- function(meta_data,class)
62
-{
57
+.aggregates <- function(meta_data,class) {
63 58
     if(!is.list(meta_data))
64 59
         stop("meta_data: invalid input")
65 60
     
... ...
@@ -88,8 +83,7 @@
88 83
 
89 84
 
90 85
 # meta join condition
91
-.join_condition <- function(cond)
92
-{
86
+.join_condition <- function(cond) {
93 87
     cond_matrix <- NULL
94 88
     def <- cond$condition$def
95 89
     if(!is.null(def))
... ...
@@ -105,8 +99,7 @@
105 99
     cond_matrix
106 100
 }
107 101
 
108
-.check_input <- function(value)
109
-{
102
+.check_input <- function(value) {
110 103
     if(!is.character(value))
111 104
         stop("no valid data")
112 105
     
... ...
@@ -114,8 +107,7 @@
114 107
         stop("no multiple string")
115 108
 }
116 109
 
117
-.check_logical <- function(value)
118
-{
110
+.check_logical <- function(value) {
119 111
     if(!is.logical(value))
120 112
         stop("no valid data")
121 113
     
... ...
@@ -123,18 +115,15 @@
123 115
         stop("no multiple string")
124 116
 }
125 117
 
126
-.is_login_expired <- function(url)
127
-{
128
-    if(exists("GMQL_credentials", envir = .GlobalEnv))
129
-    {
130
-        if(exists("authToken", where = GMQL_credentials))
131
-        {
118
+.is_login_expired <- function(url) {
119
+    if(exists("GMQL_credentials", envir = .GlobalEnv)) {
120
+        if(exists("authToken", where = GMQL_credentials)) {
132 121
             authToken <- GMQL_credentials$authToken
133 122
             url <- sub("/*[/]$","",url)
134 123
             h <- c('Accept' = 'Application/json', 'X-Auth-Token' = authToken)
135 124
             URL <- paste0(url,"/user")
136 125
             req <- httr::GET(URL,httr::add_headers(h))
137
-            if(req$status_code !=200)
126
+            if(req$status_code != 200)
138 127
                 return(TRUE)
139 128
             else
140 129
                 return(FALSE)
... ...
@@ -142,5 +131,3 @@
142 131
     }
143 132
     return(TRUE)
144 133
 }
145
-
146
-
... ...
@@ -31,23 +31,20 @@
31 31
 #' @aliases condition_evaluation
32 32
 #' @rdname condition_eval_func
33 33
 #' @export
34
-conds <- function(default = c(""), full = c(""), exact = c(""))
35
-{
34
+conds <- function(default = c(""), full = c(""), exact = c("")) {
36 35
     df <- .condition("DEF",default)
37 36
     fn <- .condition("FULL",full)
38 37
     ex <- .condition("EXACT",exact)
39 38
     list("condition" = list("def" = df, "full" = fn, "exact" = ex))
40 39
 }
41 40
 
42
-.condition <- function(cond, array)
43
-{
41
+.condition <- function(cond, array) {
44 42
     array = array[!array %in% ""]
45 43
     array = array[!duplicated(array)]
46 44
     
47 45
     if(!length(array))
48 46
         join_condition_matrix <- NULL
49
-    else
50
-    {
47
+    else {
51 48
         join_condition_matrix <- t(vapply(array, function(x) {
52 49
             new_value = c(cond, x)
53 50
             matrix <- matrix(new_value)
... ...
@@ -55,5 +52,3 @@ conds <- function(default = c(""), full = c(""), exact = c(""))
55 52
     }
56 53
     join_condition_matrix
57 54
 }
58
-
59
-
... ...
@@ -43,10 +43,8 @@ execute <- function()
43 43
     val <- response[2]
44 44
     if(error)
45 45
         stop(val)
46
-    else
47
-    {
48
-        if(remote_proc)
49
-        {
46
+    else {
47
+        if(remote_proc) {
50 48
             isGTF <- FALSE
51 49
             outformat <- WrappeR$outputMaterialize()
52 50
             if(identical(outformat, "gtf"))
... ...
@@ -59,29 +57,24 @@ execute <- function()
59 57
     }
60 58
 }
61 59
 
62
-.download_or_upload <- function()
63
-{
60
+.download_or_upload <- function() {
64 61
     WrappeR <- J("it/polimi/genomics/r/Wrapper")
65 62
     datasets <- .jevalArray(WrappeR$get_dataset_list(),simplify = TRUE)
66 63
     data_list <- apply(datasets, 1, as.list)
67 64
     url <- WrappeR$get_url()
68 65
     remote <- WrappeR$is_remote_processing()
69
-    if(remote)
70
-    {
66
+    if(remote) {
71 67
         lapply(data_list,function(x){
72 68
             if(!is.null(x[[1]]) && !is.na(x[[1]]))
73 69
                 upload_dataset(url,x[[2]],x[[1]],x[[3]],FALSE)})
74
-    }
75
-    else
76
-    {
70
+    } else {
77 71
         lapply(data_list,function(x){
78 72
             if(!is.null(x[[2]]) && !is.na(x[[2]]))
79 73
                 download_dataset(url,x[[2]],x[[1]])})
80 74
     }
81 75
 }
82 76
 
83
-collect.GMQLDataset <- function(x, dir_out = getwd(), name = "ds1")
84
-{
77
+collect.GMQLDataset <- function(x, dir_out = getwd(), name = "ds1") {
85 78
     ptr_data <- value(x)
86 79
     gmql_materialize(ptr_data, dir_out, name)
87 80
 }
... ...
@@ -137,12 +130,10 @@ collect.GMQLDataset <- function(x, dir_out = getwd(), name = "ds1")
137 130
 #' @export
138 131
 setMethod("collect", "GMQLDataset",collect.GMQLDataset)
139 132
 
140
-gmql_materialize <- function(input_data, dir_out, name)
141
-{
133
+gmql_materialize <- function(input_data, dir_out, name) {
142 134
     WrappeR <- J("it/polimi/genomics/r/Wrapper")
143 135
     remote_proc <- WrappeR$is_remote_processing()
144
-    if(!remote_proc)
145
-    {
136
+    if(!remote_proc) {
146 137
         dir_out <- sub("/*[/]$","",dir_out)
147 138
         res_dir_out <- file.path(dir_out,name)
148 139
         if(!dir.exists(res_dir_out))
... ...
@@ -226,8 +217,7 @@ setMethod("take", "GMQLDataset",
226 217
                 gmql_take(ptr_data, rows)
227 218
             })
228 219
 
229
-gmql_take <- function(input_data, rows)
230
-{
220
+gmql_take <- function(input_data, rows) {
231 221
     rows <- as.integer(rows[1])
232 222
     if(rows<0)
233 223
         stop("rows cannot be negative")
... ...
@@ -259,9 +249,11 @@ gmql_take <- function(input_data, rows)
259 249
     sampleList <- lapply(list, function(x){
260 250
         x <- x[-1]
261 251
         names(x) <- seq_name
262
-        start_numeric = as.numeric(levels(x$start))[x$start]
252
+    #    start_numeric = as.numeric(levels(x$start))[x$start]
253
+        start_numeric = as.numeric(x$start)
263 254
         start_numeric = start_numeric + 1
264
-        levels(x$start)[x$start] = start_numeric
255
+        x$start =  start_numeric
256
+        #levels(x$start)[x$start] = start_numeric
265 257
         g <- GenomicRanges::makeGRangesFromDataFrame(x,
266 258
                                     keep.extra.columns = TRUE,
267 259
                                     start.field = "start",
... ...
@@ -277,8 +269,7 @@ gmql_take <- function(input_data, rows)
277 269
     return(gRange_list)
278 270
 }
279 271
 
280
-.metadata_from_frame_to_list <- function(metadata_frame)
281
-{
272
+.metadata_from_frame_to_list <- function(metadata_frame) {
282 273
     meta_frame <- as.data.frame(metadata_frame)
283 274
     list <- split(meta_frame, meta_frame[1])
284 275
     name_value_list <- lapply(list, function(x){x <- x[-1]})
... ...
@@ -96,7 +96,7 @@ read_gmql <- function(dataset, parser = "CustomParser", is_local = TRUE,
96 96
         if(!length(schema_SCHEMA))
97 97
             schema_XML <- xml_schema
98 98
         else
99
-            schema_XML <- schema_SCHEMA
99
+            schema_XML <- dataset
100 100
         
101 101
         schema_matrix <- .jnull("java/lang/String")
102 102
         url <- .jnull("java/lang/String")
103 103
similarity index 100%
104 104
rename from inst/example/DATASET/files/dataset.schema
105 105
rename to inst/example/DATASET/files/test.schema
... ...
@@ -1,9 +1,9 @@
1 1
 % Generated by roxygen2: do not edit by hand
2 2
 % Please edit documentation in R/gmql_merge.R
3
-\docType{methods}
4 3
 \name{aggregate}
5 4
 \alias{aggregate}
6 5
 \alias{aggregate,GMQLDataset-method}
6
+\alias{aggregate-method}
7 7
 \title{Method aggregate}
8 8
 \usage{
9 9
 \S4method{aggregate}{GMQLDataset}(x, groupBy = conds())
... ...
@@ -1,14 +1,20 @@
1 1
 % Generated by roxygen2: do not edit by hand
2 2
 % Please edit documentation in R/gmql_order.R
3
-\docType{methods}
4 3
 \name{arrange}
5 4
 \alias{arrange}
6 5
 \alias{arrange,GMQLDataset-method}
6
+\alias{arrange-method}
7 7
 \title{Method arrange}
8 8
 \usage{
9
-\S4method{arrange}{GMQLDataset}(.data, metadata_ordering = NULL,
10
-  regions_ordering = NULL, fetch_opt = "", num_fetch = 0L,
11
-  reg_fetch_opt = "", reg_num_fetch = 0L)
9
+\S4method{arrange}{GMQLDataset}(
10
+  .data,
11
+  metadata_ordering = NULL,
12
+  regions_ordering = NULL,
13
+  fetch_opt = "",
14
+  num_fetch = 0L,
15
+  reg_fetch_opt = "",
16
+  reg_num_fetch = 0L
17
+)
12 18
 }
13 19
 \arguments{
14 20
 \item{.data}{GMQLDataset class object}
... ...
@@ -1,9 +1,9 @@
1 1
 % Generated by roxygen2: do not edit by hand
2 2
 % Please edit documentation in R/gmql_materialize.R
3
-\docType{methods}
4 3
 \name{collect}
5 4
 \alias{collect}
6 5
 \alias{collect,GMQLDataset-method}
6
+\alias{collect-method}
7 7
 \title{Method collect}
8 8
 \usage{
9 9
 \S4method{collect}{GMQLDataset}(x, dir_out = getwd(), name = "ds1")
... ...
@@ -1,15 +1,14 @@
1 1
 % Generated by roxygen2: do not edit by hand
2 2
 % Please edit documentation in R/AllGenerics.R, R/gmql_cover.R
3
-\docType{methods}
4 3
 \name{cover}
5 4
 \alias{cover}
6 5
 \alias{cover,GMQLDataset-method}
6
+\alias{cover-method}
7 7
 \title{Method cover}
8 8
 \usage{
9 9
 cover(.data, ...)
10 10
 
11
-\S4method{cover}{GMQLDataset}(.data, min_acc, max_acc, groupBy = conds(),
12
-  variation = "cover", ...)
11
+\S4method{cover}{GMQLDataset}(.data, min_acc, max_acc, groupBy = conds(), variation = "cover", ...)
13 12
 }
14 13
 \arguments{
15 14
 \item{.data}{GMQLDataset class object}
... ...
@@ -1,6 +1,5 @@
1 1
 % Generated by roxygen2: do not edit by hand
2 2
 % Please edit documentation in R/AllGenerics.R, R/gmql_extend.R
3
-\docType{methods}
4 3
 \name{extend}
5 4
 \alias{extend}
6 5
 \alias{extend,GMQLDataset-method}
... ...
@@ -1,13 +1,12 @@
1 1
 % Generated by roxygen2: do not edit by hand
2 2
 % Please edit documentation in R/gmql_select.R
3
-\docType{methods}
4 3
 \name{filter}
5 4
 \alias{filter}
6 5
 \alias{filter,GMQLDataset-method}
6
+\alias{filter-method}
7 7
 \title{Method filter}
8 8
 \usage{
9
-\S4method{filter}{GMQLDataset}(.data, m_predicate = NULL,
10
-  r_predicate = NULL, semijoin = NULL)
9
+\S4method{filter}{GMQLDataset}(.data, m_predicate = NULL, r_predicate = NULL, semijoin = NULL)
11 10
 }
12 11
 \arguments{
13 12
 \item{.data}{GMQLDataset class object}
... ...
@@ -4,8 +4,13 @@
4 4
 \alias{filter_and_extract}
5 5
 \title{Filter and extract function}
6 6
 \usage{
7
-filter_and_extract(data, metadata = NULL, metadata_prefix = NULL,
8
-  region_attributes = NULL, suffix = "antibody_target")
7
+filter_and_extract(
8
+  data,
9
+  metadata = NULL,
10
+  metadata_prefix = NULL,
11
+  region_attributes = NULL,
12
+  suffix = "antibody_target"
13
+)
9 14
 }
10 15
 \arguments{
11 16
 \item{data}{string GMQL dataset folder path or GRangesList
... ...
@@ -1,14 +1,18 @@
1 1
 % Generated by roxygen2: do not edit by hand
2 2
 % Please edit documentation in R/gmql_group.R
3
-\docType{methods}
4 3
 \name{group_by}
5 4
 \alias{group_by}
6 5
 \alias{group_by,GMQLDataset-method}
6
+\alias{group_by-method}
7 7
 \title{Method group_by}
8 8
 \usage{
9
-\S4method{group_by}{GMQLDataset}(.data, groupBy_meta = conds(),
10
-  groupBy_regions = c(""), region_aggregates = NULL,
11
-  meta_aggregates = NULL)
9
+\S4method{group_by}{GMQLDataset}(
10
+  .data,
11
+  groupBy_meta = conds(),
12
+  groupBy_regions = c(""),
13
+  region_aggregates = NULL,
14
+  meta_aggregates = NULL
15
+)
12 16
 }
13 17
 \arguments{
14 18
 \item{.data}{GMQLDataset object}
... ...
@@ -4,8 +4,13 @@
4 4
 \alias{init_gmql}
5 5
 \title{Init GMQL server}
6 6
 \usage{
7
-init_gmql(output_format = "GTF", remote_processing = FALSE,
8
-  url = NULL, username = NULL, password = NULL)
7
+init_gmql(
8
+  output_format = "GTF",
9
+  remote_processing = FALSE,
10
+  url = NULL,
11
+  username = NULL,
12
+  password = NULL
13
+)
9 14
 }
10 15
 \arguments{
11 16
 \item{output_format}{string that identifies the output format of all sample 
... ...
@@ -1,6 +1,5 @@
1 1
 % Generated by roxygen2: do not edit by hand
2 2
 % Please edit documentation in R/AllGenerics.R, R/gmql_map.R
3
-\docType{methods}
4 3
 \name{map}
5 4
 \alias{map}
6 5
 \alias{map,GMQLDataset-method}
... ...
@@ -9,8 +8,7 @@
9 8
 \usage{
10 9
 map(x, y, ...)
11 10
 
12
-\S4method{map}{GMQLDataset}(x, y, ..., joinBy = conds(),
13
-  count_name = "")
11
+\S4method{map}{GMQLDataset}(x, y, ..., joinBy = conds(), count_name = "")
14 12
 }
15 13
 \arguments{
16 14
 \item{x}{GMQLDataset class object}
... ...
@@ -1,14 +1,19 @@
1 1
 % Generated by roxygen2: do not edit by hand
2 2
 % Please edit documentation in R/gmql_join.R
3
-\docType{methods}
4 3
 \name{merge}
5 4
 \alias{merge}
6 5
 \alias{merge,GMQLDataset,GMQLDataset-method}
6
+\alias{merge-method}
7 7
 \title{Method merge}
8 8
 \usage{
9
-\S4method{merge}{GMQLDataset,GMQLDataset}(x, y,
10
-  genometric_predicate = NULL, region_output = "CAT",
11
-  joinBy = conds(), reg_attr = c(""))
9
+\S4method{merge}{GMQLDataset,GMQLDataset}(
10
+  x,
11
+  y,
12
+  genometric_predicate = NULL,
13
+  region_output = "CAT",
14
+  joinBy = conds(),
15
+  reg_attr = c("")
16
+)
12 17
 }
13 18
 \arguments{
14 19
 \item{x}{GMQLDataset class object}
... ...
@@ -5,8 +5,7 @@
5 5
 \alias{read_GRangesList}
6 6
 \title{Function read}
7 7
 \usage{
8
-read_gmql(dataset, parser = "CustomParser", is_local = TRUE,
9
-  is_GMQL = TRUE)
8
+read_gmql(dataset, parser = "CustomParser", is_local = TRUE, is_GMQL = TRUE)
10 9
 
11 10
 read_GRangesList(samples)
12 11
 }
... ...
@@ -41,7 +40,7 @@ remote processing.
41 40
 }
42 41
 \details{
43 42
 Normally, a GMQL dataset contains an XML schema file that contains
44
-name of region attributes. (e.g chr, start, stop, strand)
43
+name of region attributes. (e.g chr, start, stop, strand)"
45 44
 The CustomParser reads this XML schema; 
46 45
 if you already know what kind of schema your files have, use one of the 
47 46
 parsers defined, without reading any XML schema.
... ...
@@ -1,14 +1,20 @@
1 1
 % Generated by roxygen2: do not edit by hand
2 2
 % Please edit documentation in R/gmql_project.R
3
-\docType{methods}
4 3
 \name{select}
5 4
 \alias{select}
6 5
 \alias{select,GMQLDataset-method}
6
+\alias{select-method}
7 7
 \title{Method select}
8 8
 \usage{
9
-\S4method{select}{GMQLDataset}(.data, metadata = NULL,
10
-  metadata_update = NULL, all_but_meta = FALSE, regions = NULL,
11
-  regions_update = NULL, all_but_reg = FALSE)
9
+\S4method{select}{GMQLDataset}(
10
+  .data,
11
+  metadata = NULL,
12
+  metadata_update = NULL,
13
+  all_but_meta = FALSE,
14
+  regions = NULL,
15
+  regions_update = NULL,
16
+  all_but_reg = FALSE
17
+)
12 18
 }
13 19
 \arguments{
14 20
 \item{.data}{GMQLDataset class object}
... ...
@@ -1,13 +1,12 @@
1 1
 % Generated by roxygen2: do not edit by hand
2 2
 % Please edit documentation in R/gmql_difference.R
3
-\docType{methods}
4 3
 \name{setdiff}
5 4
 \alias{setdiff}
6 5
 \alias{setdiff,GMQLDataset,GMQLDataset-method}
6
+\alias{setdiff-method}
7 7
 \title{Method setdiff}
8 8
 \usage{
9
-\S4method{setdiff}{GMQLDataset,GMQLDataset}(x, y, joinBy = conds(),
10
-  is_exact = FALSE)
9
+\S4method{setdiff}{GMQLDataset,GMQLDataset}(x, y, joinBy = conds(), is_exact = FALSE)
11 10
 }
12 11
 \arguments{
13 12
 \item{x}{GMQLDataset class object}
... ...
@@ -1,6 +1,5 @@
1 1
 % Generated by roxygen2: do not edit by hand
2 2
 % Please edit documentation in R/AllGenerics.R, R/gmql_materialize.R
3
-\docType{methods}
4 3
 \name{take}
5 4
 \alias{take}
6 5
 \alias{take,GMQLDataset-method}
... ...
@@ -1,9 +1,9 @@
1 1
 % Generated by roxygen2: do not edit by hand
2 2
 % Please edit documentation in R/gmql_union.R
3
-\docType{methods}
4 3
 \name{union}
5 4
 \alias{union}
6 5
 \alias{union,GMQLDataset,GMQLDataset-method}
6
+\alias{union-method}
7 7
 \title{Method union}
8 8
 \usage{
9 9
 \S4method{union}{GMQLDataset,GMQLDataset}(x, y)
... ...
@@ -4,8 +4,7 @@
4 4
 \alias{upload_dataset}
5 5
 \title{Upload dataset}
6 6
 \usage{
7
-upload_dataset(url, datasetName, folderPath, schemaName = NULL,
8
-  isGMQL = TRUE)
7
+upload_dataset(url, datasetName, folderPath, schemaName = NULL, isGMQL = TRUE)
9 8
 }
10 9
 \arguments{
11 10
 \item{url}{string url of server: It must contain the server address