Mercurial > repos > mingchen0919 > tripal_db_explorer
changeset 6:4bc7752bfd72 draft
resources summary + search
| author | mingchen0919 |
|---|---|
| date | Mon, 19 Mar 2018 16:29:51 -0400 |
| parents | 5accedb3133e |
| children | 7fd14296e7e0 |
| files | get_content_types.csv get_content_types.xml search_contents.Rmd search_contents.csv search_contents.sh search_contents.xml search_contents_render.R |
| diffstat | 7 files changed, 178 insertions(+), 57 deletions(-) [+] |
line wrap: on
line diff
--- 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,
--- 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 @@ -<tool id="get_content_types" name="Get content types" version="1.0.0"> - <description>Tripal database explorer: get content types
 +<tool id="get_content_types" name="tripal_db_explorer: resources summary" version="1.0.0"> + <description> </description> - <requirements> - <requirement type="package" version="1.15.0.6-0">pandoc</requirement><requirement type="package" version="1.20.0">r-getopt</requirement><requirement type="package" version="1.6">r-rmarkdown</requirement><requirement type="package" version="1.5">r-jsonlite</requirement><requirement type="package" version="0.2">r-dt</requirement><requirement type="package" version="3.1">r-curl</requirement></requirements> - <stdio> - <regex match="XXX" source="stderr" level="warning" description="Check the warnings_and_errors.txt file for more details."/></stdio> - <command><![CDATA[export TOOL_DIR='${__tool_directory__}' && + <requirements> + <requirement type="package" version="1.15.0.6-0">pandoc</requirement> + <requirement type="package" version="1.20.0">r-getopt</requirement> + <requirement type="package" version="1.6">r-rmarkdown</requirement> + <requirement type="package" version="1.5">r-jsonlite</requirement> + <requirement type="package" version="0.2">r-dt</requirement> + <requirement type="package" version="3.1">r-curl</requirement> + </requirements> + <stdio> + <regex match="XXX" source="stderr" level="warning" + description="Check the warnings_and_errors.txt file for more details."/> + </stdio> + <command><![CDATA[export TOOL_DIR='${__tool_directory__}' && Rscript '${__tool_directory__}/'get_content_types_render.R @@ -14,11 +22,15 @@ -s '$sink_message' -u '$web_services_root_url' ]]></command> - <inputs> - <param type="text" name="web_services_root_url" label="Web services root URL" optional="False"/></inputs> - <outputs> - <data name="report" format="html" label="${tool.name} report" hidden="false"/><data name="sink_message" format="txt" label="${tool.name} log" from_work_dir="warnings_and_errors.txt" hidden="false"/></outputs> - <citations> + <inputs> + <param type="text" name="web_services_root_url" label="Web services root URL" optional="False"/> + </inputs> + <outputs> + <data name="report" format="html" label="${tool.name} report" hidden="false"/> + <data name="sink_message" format="txt" label="${tool.name} log" from_work_dir="warnings_and_errors.txt" + hidden="false"/> + </outputs> + <citations> <citation type="bibtex"><![CDATA[ @article{allaire2016rmarkdown, title={rmarkdown: Dynamic Documents for R, 2016}, @@ -28,7 +40,8 @@ volume={6}, year={2016} } - ]]></citation><citation type="bibtex"><![CDATA[ + ]]></citation> + <citation type="bibtex"><![CDATA[ @book{xie2015dynamic, title={Dynamic Documents with R and knitr}, author={Xie, Yihui}, @@ -36,5 +49,6 @@ year={2015}, publisher={CRC Press} } - ]]></citation></citations> + ]]></citation> + </citations> </tool>
--- 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) +``` +
--- /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, +
--- /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'
--- 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 @@ -<tool id="search_contents" name="Search contents" version="1.0.0"> - <description> - some description +<tool id="search_contents" name="tripal_db_explorer: search" version="1.0.0"> + <description> </description> - <requirements> - <requirement type="package" version="1.15.0.6-0">pandoc</requirement><requirement type="package" version="1.20.0">r-getopt</requirement><requirement type="package" version="1.6">r-rmarkdown</requirement><requirement type="package" version="1.5">r-jsonlite</requirement><requirement type="package" version="0.2">r-dt</requirement><requirement type="package" version="3.1">r-curl</requirement></requirements> - <stdio> - <regex match="XXX" source="stderr" level="warning" description="Check the warnings_and_errors.txt file for more details."/></stdio> - <command><![CDATA[ - export TOOL_DIRECTORY='${__tool_directory__}' && + <requirements> + <requirement type="package" version="1.15.0.6-0">pandoc</requirement> + <requirement type="package" version="1.20.0">r-getopt</requirement> + <requirement type="package" version="1.6">r-rmarkdown</requirement> + <requirement type="package" version="1.5">r-jsonlite</requirement> + <requirement type="package" version="0.2">r-dt</requirement> + <requirement type="package" version="3.1">r-curl</requirement> + </requirements> + <stdio> + <regex match="XXX" source="stderr" level="warning" + description="Check the warnings_and_errors.txt file for more details."/> + </stdio> + <command><![CDATA[export TOOL_DIR='${__tool_directory__}' && - Rscript '${__tool_directory__}/rmarkdown_report_render.R' +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' - -e $echo - -o $report - -d $report.files_path - -s $sink_message - -t '${__tool_directory__}' - + #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' - - ]]></command> - <inputs> - <param type="text" name="web_services_root_url" label="Web services root URL" optional="False"/><section name="search_fields" title="Fields being searched" expanded="True"><repeat name="search_field_repeat" title="search fields" min="1" max="20" default="1"><param type="text" name="field_path_search" optional="False"/></repeat></section><section name="extract_fields" title="Fields being extracted"><repeat name="extract_field_repeat" title="Fields being extracted" min="1" max="20" default="1"><param type="text" name="field_path_extract" optional="False"/></repeat></section></inputs> - <outputs> - <data name="report" format="html" label="${tool.name} report" hidden="false"/><data format="txt" name="sink_message" label="Warnings and Errors" from_work_dir="warnings_and_errors.txt"/></outputs> - <citations> + -l '$records_number' + -r '$search_results' +]]></command> + <inputs> + <param type="text" name="content_type_url" label="Content type URL" optional="False"/> + <section name="search_section" title="Search: fields" expanded="True"> + <repeat name="search_field_repeat" title="Field paths" min="1" max="20" default="1"> + <param type="text" name="field_path" optional="False"/> + <param type="select" name="search_operator" optional="False"> + <option value="eq" selected="false">equal (string value)</option> + <option value="contains" selected="true">contains (string value)</option> + </param> + </repeat> + </section> + <section name="extract_section" title="Extract: fields" expanded="True"> + <repeat name="extract_field_repeat" title="Field paths" min="1" max="20" default="1"> + <param type="text" name="field_path" optional="False"/> + </repeat> + </section> + <param type="integer" name="records_number" label="Records number" + help="The maximum number of records to be extracted" optional="False" value="25" min="0"/> + </inputs> + <outputs> + <data name="report" format="html" label="${tool.name} report" hidden="false"/> + <data name="sink_message" format="txt" label="${tool.name} log" from_work_dir="warnings_and_errors.txt" + hidden="false"/> + <data name="search_results" format="txt" label="${tool.name} results" hidden="false"/> + </outputs> + <citations> <citation type="bibtex"><![CDATA[ @article{allaire2016rmarkdown, title={rmarkdown: Dynamic Documents for R, 2016}, @@ -34,7 +75,8 @@ volume={6}, year={2016} } - ]]></citation><citation type="bibtex"><![CDATA[ + ]]></citation> + <citation type="bibtex"><![CDATA[ @book{xie2015dynamic, title={Dynamic Documents with R and knitr}, author={Xie, Yihui}, @@ -42,5 +84,6 @@ year={2015}, publisher={CRC Press} } - ]]></citation></citations> + ]]></citation> + </citations> </tool>
--- 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=============================
