Skip to content

Commit 72a6a61

Browse files
committed
split source file into multiple parrs
1 parent 20431f7 commit 72a6a61

8 files changed

Lines changed: 180 additions & 181 deletions

File tree

R/application/reflection.R

Lines changed: 0 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -45,47 +45,3 @@ const __build_app = function(f) {
4545
}
4646
}
4747

48-
#' parse the workfile expression
49-
#'
50-
const __workfiles = function(files_uri) {
51-
if (length(files_uri) == 0) {
52-
NULL;
53-
} else {
54-
__workfiles_data(files_uri);
55-
}
56-
}
57-
58-
const __workfiles_data = function(files_uri) {
59-
let uri = lapply(files_uri, si -> __workfile_uri_parser(si));
60-
let app = as.character(uri@app);
61-
let file = as.character(uri@file);
62-
let app_groups = data.frame(app, file)
63-
|> as.list(byrow = TRUE)
64-
|> groupBy("app")
65-
|> lapply(app -> app@file)
66-
;
67-
68-
app_groups;
69-
}
70-
71-
#' parse the workfile expression
72-
#'
73-
#' @param uri a character vector that contains the workfile
74-
#' reference expression.
75-
#'
76-
#' @return a tuple list object that contains the necessary
77-
#' parameter value for call ``workfile`` function for gets
78-
#' the reference file path to the required data files.
79-
#'
80-
const __workfile_uri_parser = function(uri) {
81-
# example as:
82-
# app_name://file/path/to/file.txt
83-
let tuple = tagvalue(uri, '://', as.list = TRUE);
84-
let ref = list(
85-
app = names(tuple),
86-
file = unlist(tuple)
87-
);
88-
89-
# app, file
90-
return(ref);
91-
}

R/application/uri_parser.R

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
#' parse the workfile expression
2+
#'
3+
const __workfiles = function(files_uri) {
4+
if (length(files_uri) == 0) {
5+
NULL;
6+
} else {
7+
__workfiles_data(files_uri);
8+
}
9+
}
10+
11+
const __workfiles_data = function(files_uri) {
12+
let uri = lapply(files_uri, si -> __workfile_uri_parser(si));
13+
let app = as.character(uri@app);
14+
let file = as.character(uri@file);
15+
let app_groups = data.frame(app, file)
16+
|> as.list(byrow = TRUE)
17+
|> groupBy("app")
18+
|> lapply(app -> app@file)
19+
;
20+
21+
app_groups;
22+
}
23+
24+
#' parse the workfile expression
25+
#'
26+
#' @param uri a character vector that contains the workfile
27+
#' reference expression.
28+
#'
29+
#' @return a tuple list object that contains the necessary
30+
#' parameter value for call ``workfile`` function for gets
31+
#' the reference file path to the required data files.
32+
#'
33+
const __workfile_uri_parser = function(uri) {
34+
# example as:
35+
# app_name://file/path/to/file.txt
36+
let tuple = tagvalue(uri, '://', as.list = TRUE);
37+
let ref = list(
38+
app = names(tuple),
39+
file = unlist(tuple)
40+
);
41+
42+
# app, file
43+
return(ref);
44+
}

R/context/context.R

Lines changed: 0 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -44,43 +44,3 @@ const init_context = function(outputdir = "./", ssid = NULL) {
4444
invisible(NULL);
4545
}
4646

47-
#' create an in-memory context object just used for run debug
48-
#'
49-
#' @param ssid the session id for multiple user environment, default NULL means global user environment
50-
#' @param mounts should be a callable function for mounts the
51-
#' application modules into the workflow registry.
52-
#'
53-
const create_memory_context = function(mounts = NULL,ssid = NULL) {
54-
set(globalenv(), paste( [__global_ctx,ssid], sep ="-"), list(
55-
root = NULL, # set all workspace to empty
56-
analysis = NULL,
57-
temp_dir = NULL,
58-
t0 = now(),
59-
workflow = list(),
60-
pipeline = [],
61-
symbols = list()
62-
));
63-
64-
if (!is.null(mounts)) {
65-
mounts();
66-
}
67-
}
68-
69-
const __global_ctx = "&[workflow_render]";
70-
71-
#' get current workflow environment context
72-
#'
73-
#' @param ssid the session id for multiple user environment, default NULL means global user environment
74-
#'
75-
#' @return the context object which is generated via the
76-
#' ``init_context`` function.
77-
#'
78-
const .get_context = function(ssid = NULL) {
79-
const workflow_render as string = paste([__global_ctx, ssid], sep = "-");
80-
81-
if (exists(workflow_render, globalenv())) {
82-
get(workflow_render, globalenv());
83-
} else {
84-
.Internal::stop("You must initialize the analysis context at first!");
85-
}
86-
}

R/context/memory_access.R

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
#' create an in-memory context object just used for run debug
2+
#'
3+
#' @param ssid the session id for multiple user environment, default NULL means global user environment
4+
#' @param mounts should be a callable function for mounts the
5+
#' application modules into the workflow registry.
6+
#'
7+
const create_memory_context = function(mounts = NULL,ssid = NULL) {
8+
set(globalenv(), paste( [__global_ctx,ssid], sep ="-"), list(
9+
root = NULL, # set all workspace to empty
10+
analysis = NULL,
11+
temp_dir = NULL,
12+
t0 = now(),
13+
workflow = list(),
14+
pipeline = [],
15+
symbols = list()
16+
));
17+
18+
if (!is.null(mounts)) {
19+
mounts();
20+
}
21+
}
22+
23+
const __global_ctx = "&[workflow_render]";
24+
25+
#' get current workflow environment context
26+
#'
27+
#' @param ssid the session id for multiple user environment, default NULL means global user environment
28+
#'
29+
#' @return the context object which is generated via the
30+
#' ``init_context`` function.
31+
#'
32+
const .get_context = function(ssid = NULL) {
33+
const workflow_render as string = paste([__global_ctx, ssid], sep = "-");
34+
35+
if (exists(workflow_render, globalenv())) {
36+
get(workflow_render, globalenv());
37+
} else {
38+
.Internal::stop("You must initialize the analysis context at first!");
39+
}
40+
}

R/context/workspace.R

Lines changed: 0 additions & 97 deletions
This file was deleted.

R/context/workspace/workdir.R

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
#' Get workspace root directory
2+
#'
3+
#' @param ssid the session id for multiple user environment, default NULL means global user environment
4+
#' @details actually this function will returns the ``output`` dir
5+
#' path which is set via the ``init_context`` function
6+
#'
7+
const workdir_root = function(ssid = NULL) {
8+
.get_context(ssid)$root;
9+
}
10+
11+
#' get directory folder path for the analysis output result
12+
#'
13+
#' @param ssid the session id for multiple user environment, default NULL means global user environment
14+
#' @details a character vector of the analysis result output directory.
15+
#'
16+
const result_dir = function(ssid = NULL) {
17+
.get_context(ssid)$analysis;
18+
}
19+
20+
const workspace_temproot = function(ssid = NULL) {
21+
const context = .get_context(ssid);
22+
const temp_root = context$temp_dir;
23+
24+
temp_root;
25+
}

R/context/workspace/workfile.R

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
#' Construct of the file path inside an app workspace
2+
#'
3+
#' @param app this app parameter value could be in 3 kinds
4+
#' of data type:
5+
#'
6+
#' 1. app tuple list object, which is created via the ``app`` function.
7+
#' 2. the app name character vector
8+
#' 3. the workfile path expression, should be in format like: ``app://relpath/to/file.ext``
9+
#' @param ssid the session id for multiple user environment, default NULL means global user environment
10+
#'
11+
#' @return the data file path of the required reference file inside this workflow
12+
#'
13+
#' @details the workfile path expression is in format string of: ``app://filepath``,
14+
#' example as ``getMzSet://mzset.txt``, where we could parse the reference information
15+
#' from this character string: app name is ``getMzSet``, and the relpath data is
16+
#' ``mzset.txt``. so, such configuation could be equals to the function invoke
17+
#' of the workfile function: ``workfile("getMzSet", "/mzset.txt");``.
18+
#'
19+
const workfile = function(app, relpath = NULL, ssid = NULL, verbose = FALSE) {
20+
if (is.empty(relpath)) {
21+
if (is.character(app)) {
22+
relpath <- __workfile_uri_parser(app);
23+
24+
# gets the internal workfile reference
25+
# its physical file path
26+
file.path(WorkflowRender::workspace(relpath$app, ssid, verbose = verbose), relpath$file);
27+
} else {
28+
throw_err("the given expression value should be an internal workfile path reference!");
29+
}
30+
} else {
31+
file.path(WorkflowRender::workspace(app, ssid, verbose = verbose), relpath);
32+
}
33+
}

R/context/workspace/workspace.R

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
2+
#' get app workspace location
3+
#'
4+
#' @param app the app list object or just the app name its
5+
#' character text value.
6+
#' @param ssid the session id for multiple user environment, default NULL means global user environment
7+
#'
8+
#' @return a character vector of the workspace directory path
9+
#' of the specific analysis application.
10+
#'
11+
#' @details the verbose option could be config from the
12+
#' commandline option: ``--verbose``
13+
#'
14+
const workspace = function(app, ssid = NULL, verbose = FALSE) {
15+
const verboseOpt = as.logical(getOption("verbose", default = verbose));
16+
const context = .get_context(ssid);
17+
const temp_root = context$temp_dir;
18+
const app_name = get_app_name(app);
19+
const workdir = normalizePath(`${temp_root}/workflow_tmp/${app_name}/`);
20+
const program = context$pipeline;
21+
22+
if (verboseOpt) {
23+
print("view of the given app object for get its workspace dir:");
24+
print("get app_name:");
25+
str(app_name);
26+
print("get pipeline workflow components:");
27+
str(program);
28+
print("combine the workdir path:");
29+
print(workdir);
30+
};
31+
32+
if (!(app_name in program)) {
33+
echo_warning(`The app(${app_name}) has not been registered in the analysis context yet.`, app);
34+
};
35+
36+
workdir;
37+
}
38+

0 commit comments

Comments
 (0)