# HG changeset patch # User mingchen0919 # Date 1521491391 14400 # Node ID 4bc7752bfd7257d56493d3cc160c9c2dbc4730dc # Parent 5accedb3133e2fc6afed5e5bfee9ee6672aa45bb resources summary + search diff -r 5accedb3133e -r 4bc7752bfd72 get_content_types.csv --- a/get_content_types.csv Mon Mar 19 00:43:50 2018 -0400 +++ b/get_content_types.csv Mon Mar 19 16:29:51 2018 -0400 @@ -3,3 +3,4 @@ d,1,character,report.files_path,data, s,1,character,sink_message,data, u,1,character,web_services_root_url, +r,1,character,search_results, diff -r 5accedb3133e -r 4bc7752bfd72 get_content_types.xml --- a/get_content_types.xml Mon Mar 19 00:43:50 2018 -0400 +++ b/get_content_types.xml Mon Mar 19 16:29:51 2018 -0400 @@ -1,11 +1,19 @@ - - Tripal database explorer: get content types + + - - pandocr-getoptr-rmarkdownr-jsonliter-dtr-curl - - - + pandoc + r-getopt + r-rmarkdown + r-jsonlite + r-dt + r-curl + + + + + - - - - - + + + + + + + + ]]> + diff -r 5accedb3133e -r 4bc7752bfd72 search_contents.Rmd --- a/search_contents.Rmd Mon Mar 19 00:43:50 2018 -0400 +++ b/search_contents.Rmd Mon Mar 19 16:29:51 2018 -0400 @@ -1,30 +1,57 @@ --- -title: 'HTML report title' +title: 'Tripal database explorer: search results' output: html_document: - number_sections: true - toc: true theme: cosmo highlight: tango - code_folding: hide --- ```{r setup, include=FALSE, warning=FALSE, message=FALSE} knitr::opts_chunk$set( - echo = TRUE, + echo = FALSE, error = TRUE ) ``` -# Code for computational analysis - -```{r 'step 1'} - -``` - -```{r 'ste[ 2'} - +```{r} +# get member ids after implementing search filtering +content_type_url = opt$X_u +path = "organism,genus=Fagus&name=ABall;contains" +path = sub('\\|', '&', opt$X_s) +search_url = paste0(content_type_url, '?', path) +search_members = fromJSON(search_url) +# search_url_rebuild = paste0(search_url, '&limit=', search_members$totalItems) +total_records = as.integer(opt$X_l) +if (total_records == 0) { + total_records = search_members$totalItems +} +search_url_rebuild = paste0(search_url, '&limit=', total_records) +re_search_members = fromJSON(search_url_rebuild) ``` +```{r} +# get requested field values from search results +request_paths = sub(',', '\\.', strsplit(opt$X_e, '\\|')[[1]]) +res = data.frame() +for (id in re_search_members$member$`@id`) { + member = as.data.frame(fromJSON(id)) + res = rbind(res, member[, request_paths]) +} +colnames(res) = request_paths +``` + +```{r} +if (nrow(res) < 1) { + cat('No records found.') +} else { + DT::datatable(res) +} +``` + +```{r} +# save results to file +write.table(res, file = opt$X_r, quote = FALSE, col.names = FALSE) +``` + diff -r 5accedb3133e -r 4bc7752bfd72 search_contents.csv --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/search_contents.csv Mon Mar 19 16:29:51 2018 -0400 @@ -0,0 +1,9 @@ +short flag,argument mask,data type,variable name,galaxy input type,description +o,1,character,report,data, +d,1,character,report.files_path,data, +u,1,character,content_type_url,data, +s,1,character,search_paths, +e,1,character,extract_paths, +l,1,character,records_number, +r,1,character,search_results, + diff -r 5accedb3133e -r 4bc7752bfd72 search_contents.sh --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/search_contents.sh Mon Mar 19 16:29:51 2018 -0400 @@ -0,0 +1,26 @@ +export TOOL_DIR='${__tool_directory__}' && + +Rscript '${__tool_directory__}/'search_contents_render.R + + -o '$report' + -d '$report.files_path' + -u '$content_type_url' + + #set $sep = '' + #set $search_paths = '' + #for $search_path in $search_section.search_field_repeat: + #set $search_paths += $sep + str($search_path.field_path) + ';' + str($search_path.search_operator) + #set $sep = '|' + #end for + -s '$search_paths' + + #set $sep = '' + #set $extract_paths = '' + #for $extract_path in $extract_section.extract_field_repeat: + #set $extract_paths += $sep + str($extract_path.field_path) + #set $sep = '|' + #end for + -e '$extract_paths' + + -l '$records_number' + -r '$search_results' diff -r 5accedb3133e -r 4bc7752bfd72 search_contents.xml --- a/search_contents.xml Mon Mar 19 00:43:50 2018 -0400 +++ b/search_contents.xml Mon Mar 19 16:29:51 2018 -0400 @@ -1,30 +1,71 @@ - - - some description + + - - pandocr-getoptr-rmarkdownr-jsonliter-dtr-curl - - - + pandoc + r-getopt + r-rmarkdown + r-jsonlite + r-dt + r-curl + + + + + - -
- - - + -l '$records_number' + -r '$search_results' +]]>
+ + +
+ + + + + + + +
+
+ + + +
+ +
+ + + + + ]]> +
diff -r 5accedb3133e -r 4bc7752bfd72 search_contents_render.R --- a/search_contents_render.R Mon Mar 19 00:43:50 2018 -0400 +++ b/search_contents_render.R Mon Mar 19 16:29:51 2018 -0400 @@ -10,6 +10,7 @@ library(getopt) library(rmarkdown) +library(jsonlite) #------------------------------------------------ @@ -17,13 +18,13 @@ # load helper function source(paste0(Sys.getenv('TOOL_DIR'), '/helper.R')) # import getopt specification matrix from a csv file -spec_csv = paste0(Sys.getenv('TOOL_DIR'), '/getopt_specification.csv') -opt = getopt(getopt_specification_matrix(spec_csv)) +opt = getopt(getopt_specification_matrix('/search_contents.csv')) opt$X_t = Sys.getenv('TOOL_DIR') +print(opt) #---------------------------------------------------- -#-----------using passed arguments in R +#-----------using passed arguments in R # to define system environment variables--- do.call(Sys.setenv, opt[-1]) #---------------------------------------------------- @@ -34,7 +35,7 @@ OUTPUT_DIR = opt$X_d TOOL_DIR = opt$X_t OUTPUT_REPORT = opt$X_o -RMD_NAME = '' +RMD_NAME = 'search_contents.Rmd' # create the output associated directory to store all outputs dir.create(OUTPUT_DIR, recursive = TRUE) @@ -48,4 +49,4 @@ ##--------end of code rendering .Rmd templates---------------- sink() -##=========== End of sinking output============================= \ No newline at end of file +##=========== End of sinking output=============================