-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgalaxy2shiny2galaxy.sh
100 lines (54 loc) · 2.41 KB
/
galaxy2shiny2galaxy.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
#!/bin/sh
# galaxy2shiny2galaxy scatterplot example
#
# Author: Hans-Rudolf Hotz
#
#
#
# Version: 1.0.0 17-Apr-2018
#
#
#
##############################################################################
TABLE="$1"
IDENTIFIER="$2"
COLUMNS="$3"
OUTPUTFILE1="$4"
OUTPUTFILE2="$5"
# for this dummy example, we just cut out the selected colums and generate a new table
#######################################################################################
cut -f $IDENTIFIER,$COLUMNS < $TABLE > $OUTPUTFILE1
# in a real tool, this command would for example calculate a count table from
# BAM files or generate the top table in a differential gene expression analysis.
# now, we create a new shiny app to look at this table
######################################################
# set up the stage for shiny
###REPLACE### SHINYHOME="/PATH/TO/shiny-server/apps/"
###REPLACE### SHINYAPPTEMPLATES="GALAXYROOT/tools/galaxy2shiny2galaxy/app_templates"
###REPLACE### SHINYLINK="BASE URL for SHINY SERVER"
###REPLACE### APITOOLS="GALAXYROOT/tools/galaxy2shiny2galaxy/helper_scripts"
# get the job id (12345) from the working directory (/PATH/TO/GALAXY/database/jobs_directory/012/12345/working)
# the job id will be used to generate a unique URL for the new shiny app
pwd=$(pwd)
IFS='/' array=($pwd)
JOBID="${array[-2]}"
# make a new directory on the shiny server for the new app and sym-link the table
mkdir "$SHINYHOME"$JOBID
ln -s "$OUTPUTFILE1" "$SHINYHOME"$JOBID"/table"
# copy the shiny code
# (I recommend copy the code from templates, instead of a symlink)
cp -p "$SHINYAPPTEMPLATES"/"ui.R" "$SHINYHOME"$JOBID
cp -p "$SHINYAPPTEMPLATES"/"server.R" "$SHINYHOME"$JOBID
mkdir "$SHINYHOME"$JOBID"/www"
cp -p "$SHINYAPPTEMPLATES"/"styles.css" "$SHINYHOME"$JOBID"/www"
# store the encoded history id
# (the encoded history id is required by the Galaxy API to store plots and tables back into the Galaxy history)
# first, get the dataset id from the outputpath
IFS='/' read -ra ARRAY <<< "$OUTPUTFILE1"
DATAFILE="${ARRAY[-1]}"
DATASET=$(echo $DATAFILE | tr -dc '0-9')
# second, get the history id from the dataset id and encode it
HISTORYID=$(sh "$APITOOLS/dataset2history_id.wrapper.sh" $DATASET)
sh "$APITOOLS/encode_history_id.sh" $HISTORYID > "$SHINYHOME"$JOBID"/encoded.history.id"
# generate the simple html page
echo "access the shiny server here <a href=\"$SHINYLINK$JOBID\">$JOBID</a>" > "$OUTPUTFILE2"