Skip to content
Snippets Groups Projects
Commit a487e35e authored by Reto Gerber's avatar Reto Gerber
Browse files

Saved changes to: metrics-collect.Rproj src/dataset_utils.sh

parent 45f2c9ed
No related branches found
No related tags found
No related merge requests found
......@@ -10,4 +10,4 @@ NumSpacesForTab: 2
Encoding: UTF-8
RnwWeave: Sweave
LaTeX: pdfLaTeX
\ No newline at end of file
LaTeX: pdfLaTeX
#!/usr/bin/env bash
# author: Oksana Riba Grognuz
function list_datasets_matching_string () {
USAGE="\nUsage:\n${FUNCNAME[*]} <string>\n\n\
List dataset identifiers for all datasets \n\
with any fields matching <string>.\n"
if [ $# -eq 0 ]
then
echo -e $USAGE; return
fi
local query=$1
curl -s "https://renkulab.io/knowledge-graph/datasets?query=$query" | jq -r '.[] | .identifier'
}
function datasets_properties_by_id () {
USAGE="\nUsage:\n${FUNCNAME[*]} <dataset_id> <field>\n\n\
Return dataset <field> value for a <dataset_id>.\n\
If field is not specified, then retrieve name.\n"
if [ $# -eq 0 ]
then
echo -e $USAGE; return
fi
local dataset_id=$1
local field=${2:-name}
curl -s "https://renkulab.io/knowledge-graph/datasets/$dataset_id" | jq -r '.'\"$field\"''
}
function query_datasets_by_string () {
USAGE="\nUsage:\n${FUNCNAME[*]} <string> <field>\n\n\
Retrieve dataset <field> values for all datasets \n\
with any fields matching <string>.\n\
Specify <field> as: name, title, description, identifier\n\
If <field> is not specified, then retrieve identifier.\n"
if [ $# -eq 0 ]
then
echo -e $USAGE; return
fi
local keyword=$1
local field=${2:-identifier}
for dataset_id in `list_datasets_matching_string "$keyword"`
do
datasets_properties_by_id $dataset_id $field
done
}
function match_datasets_keywords () {
USAGE="\nUsage:\n${FUNCNAME[*]} <dataset_id> <keyword> <field>\n\n\
Return dataset <field> value if there is an exact\n\
case insensitive match of <dataset_id> keywords to <keyword>.\n\
If field is not specified, then retrieve identifier.\n"
if [ $# -eq 0 ]
then
echo -e $USAGE; return
fi
local dataset_id=$1
local keyword=`echo $2 | awk '{print tolower($0)}'`
local field=${3:-identifier}
curl -s "https://renkulab.io/knowledge-graph/datasets/$dataset_id" \
| jq -r 'select(.keywords[] | ascii_downcase == ('\"$keyword\"')) | .'\"$field\"''
}
function query_datasets_by_keyword () {
USAGE="\nUsage:\n${FUNCNAME[*]} <keyword> <field>\n\n\
Return dataset <field> value for all datasets with an exact\n\
case insensitive match of dataset keywords to <keyword>.\n\
If field is not specified, then retrieve identifier.\n"
if [ $# -eq 0 ]
then
echo -e $USAGE; return
fi
local keyword=$1
local field=${2:-identifier}
for dataset_id in `list_datasets_matching_string "$keyword"`
do
match_datasets_keywords $dataset_id "$keyword" $field
done
}
function import_datasets_by_keyword () {
USAGE="\nUsage:\n${FUNCNAME[*]} <keyword>\n\n\
Import all datasets annotated with <keyword>.\n\
Update, if datasets were already imported.\n"
if [ $# -eq 0 ]
then
echo -e $USAGE; return
fi
local keyword=$1
for dataset_id in `query_datasets_by_keyword $keyword identifier`
do
local data_name=`datasets_properties_by_id $dataset_id name`
local data_path="${WORK_DIR}/data/${data_name}"
local data_url=`datasets_properties_by_id $dataset_id url`
if [ -d "${data_path}" ]
then
renku dataset update $data_name
else
renku dataset import -y $data_url
fi
done
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment