comparison generate-foo.sh @ 10:bc7bd4710c4e draft

"planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/openms commit 55a2aeba8bfd8a6910630721de9857dcdfe05d3c"
author galaxyp
date Tue, 13 Oct 2020 19:52:20 +0000
parents
children 01f5e95b5961
comparison
equal deleted inserted replaced
9:861833218c65 10:bc7bd4710c4e
1 #!/usr/bin/env bash
2
3 # parse test definitions from OpenMS sources for a tool with a given id
4 function get_tests2 {
5 id=$1
6 >&2 echo "generate tests for $id"
7 echo '<xml name="autotest_'"$id"'">'
8
9 # get the tests from the CMakeLists.txt
10 # 1st remove some tests
11 # - OpenSwathMzMLFileCacher with -convert_back argumen https://github.com/OpenMS/OpenMS/issues/4399
12 # - IDRipper PATH gets empty causing problems. TODO But overall the option needs to be handled differentlt
13 # - several tools with duplicated input (leads to conflict when linking)
14 # - TOFCalibration inputs we extension (also in prepare_test_data) https://github.com/OpenMS/OpenMS/pull/4525
15 # - MaRaCluster with -consensus_out (parameter blacklister: https://github.com/OpenMS/OpenMS/issues/4456)
16 # - FileMerger with mixed dta dta2d input (ftype can not be specified in the test, dta can not be sniffed)
17 # - some input files are originally in a subdir (degenerated cases/), but not in test-data
18 # - SeedListGenerator: https://github.com/OpenMS/OpenMS/issues/4404
19 # - OpenSwathAnalyzer 9/10: cachedMzML (not supported yet)
20 # - FeatureFinderIdentification name clash of two tests https://github.com/OpenMS/OpenMS/pull/5002
21 # - TODO SiriusAdapter https://github.com/OpenMS/OpenMS/pull/5010
22 CMAKE=$(cat $OPENMSGIT/src/tests/topp/CMakeLists.txt $OPENMSGIT/src/tests/topp/THIRDPARTY/third_party_tests.cmake |
23 sed 's@${DATA_DIR_SHARE}/@@g' |
24 grep -v 'OpenSwathMzMLFileCacher .*-convert_back' |
25 sed 's/${TMP_RIP_PATH}/""/' |
26 grep -v "MaRaClusterAdapter.*-consensus_out"|
27 grep -v "FileMerger_1_input1.dta2d.*FileMerger_1_input2.dta " |
28 sed 's@degenerate_cases/@@g' |
29 grep -v 'TOPP_SeedListGenerator_3"' |
30 egrep -v 'TOPP_OpenSwathAnalyzer_test_3"|TOPP_OpenSwathAnalyzer_test_4"' |
31 egrep -v '"TOPP_FeatureFinderIdentification_4"' |
32 sed 's/\("TOPP_SiriusAdapter_4".*\)-sirius:database all\(.*\)/\1-sirius:database pubchem\2/')
33
34
35 # grep -v 'FileFilter.*-spectra:select_polarity ""' |
36 # grep -v 'MassTraceExtractor_2.ini ' |
37 # grep -v "FileMerger_6_input2.mzML.*FileMerger_6_input2.mzML" |
38 # grep -v "IDMerger_1_input1.idXML.*IDMerger_1_input1.idXML" |
39 # grep -v "degenerated_empty.idXML.*degenerated_empty.idXML" |
40 # grep -v "FeatureLinkerUnlabeledKD_1_output.consensusXML.*FeatureLinkerUnlabeledKD_1_output.consensusXML" |
41 # grep -v "FeatureLinkerUnlabeledQT_1_output.consensusXML.*FeatureLinkerUnlabeledQT_1_output.consensusXML" |
42
43 # 1st part is a dirty hack to join lines containing a single function call, e.g.
44 # addtest(....
45 # ....)
46 echo "$CMAKE" | sed 's/#.*//; s/^\s*//; s/\s*$//' | grep -v "^#" | grep -v "^$" | awk '{printf("%s@NEWLINE@", $0)}' | sed 's/)@NEWLINE@/)\n/g' | sed 's/@NEWLINE@/ /g' |
47 grep -iE "add_test\(\"(TOPP|UTILS)_.*/$id " | egrep -v "_prepare\"|_convert|WRITEINI|WRITECTD|INVALIDVALUE" | while read -r line
48 do
49 line=$(echo "$line" | sed 's/add_test("\([^"]\+\)"/\1/; s/)$//; s/\${TOPP_BIN_PATH}\///g;s/\${DATA_DIR_TOPP}\///g; s#THIRDPARTY/##g')
50 # >&2 echo $line
51 test_id=$(echo "$line" | cut -d" " -f 1)
52 tool_id=$(echo "$line" | cut -d" " -f 2)
53 if [[ $test_id =~ _out_?[0-9]? ]]; then
54 >&2 echo " skip $test_id $line"
55 continue
56 fi
57 if [[ ${id,,} != ${tool_id,,} ]]; then
58 >&2 echo " skip $test_id ($id != $tool_id) $line"
59 continue
60 fi
61
62 #remove tests with set_tests_properties(....PROPERTIES WILL_FAIL 1)
63 if grep -lq "$test_id"'\".* PROPERTIES WILL_FAIL 1' $OPENMSGIT/src/tests/topp/CMakeLists.txt $OPENMSGIT/src/tests/topp/THIRDPARTY/third_party_tests.cmake; then
64 >&2 echo " skip failing "$test_id
65 continue
66 fi
67 tes=" <test>\n"
68 line=$(fix_tmp_files "$line")
69 line=$(unique_files "$line")
70 # >&2 echo $line
71 #if there is an ini file then we use this to generate the test
72 #otherwise the ctd file is used
73 #other command line parameters are inserted later into this xml
74 if grep -lq "\-ini" <<<"$line"; then
75 ini=$(echo $line | sed 's/.*-ini \([^ ]\+\).*/\1/')
76 ini="test-data/$ini"
77 else
78 ini="ctd/$tool_id.ctd"
79 fi
80 cli=$(echo $line |cut -d" " -f3- | sed 's/-ini [^ ]\+//')
81
82 ctdtmp=$(mktemp)
83 #echo python3 fill_ctd_clargs.py --ctd $ini $cli
84 # using eval: otherwise for some reason quoted values are not used properly ('A B' -> ["'A", "B'"])
85 # >&2 echo "python3 fill_ctd_clargs.py --ctd $ini $cli"
86 eval "python3 fill_ctd_clargs.py --ctd $ini $cli" > "$ctdtmp"
87 # echo $ctdtmp
88 # >&2 cat $ctdtmp
89 testtmp=$(mktemp)
90 python3 $CTDCONVERTER/convert.py galaxy -i $ctdtmp -o $testtmp -s tools_blacklist.txt -f "$FILETYPES" -m macros.xml -t tool.conf -p hardcoded_params.json --tool-version $VERSION --test-only --test-unsniffable csv tsv txt dta dta2d edta mrm splib > /dev/null
91 cat $testtmp | grep -v '<output.*file=""' # | grep -v 'CHEMISTRY/'
92 rm $ctdtmp $testtmp
93
94 #> /dev/null
95
96 #rm $testtmp
97 done
98 echo '</xml>'
99 }
100
101 #some tests use the same file twice which does not work in planemo tests
102 #hence we create symlinks for each file used twice
103 function unique_files {
104 line=$@
105 for arg in $@
106 do
107 if [[ ! -f "test-data/$arg" ]]; then
108 continue
109 fi
110 cnt=$(grep -c $arg <<< $(echo "$line" | tr ' ' '\n'))
111 while [[ $cnt -gt 1 ]]; do
112 new_arg=$(echo $arg | sed "s/\(.*\)\./\1_$cnt./")
113 ln -fs $arg test-data/$new_arg
114 line=$(echo $line | sed "s/\($arg.*\)$arg/\1$new_arg/")
115 cnt=$(grep -c $arg <<< $(echo "$line" | tr ' ' '\n'))
116 done
117 done
118
119 echo $line
120 }
121
122 # options of out_type selects need to be fixed to Galaxy data types
123 function fix_out_type {
124 grep "^$1" "$2" | awk '{print $2}'
125 }
126
127 #OpenMS tests output to tmp files and compare with FuzzyDiff to the expected file.
128 #problem: the extension of the tmp files is unusable for test generation.
129 #unfortunately the extensions used in the DIFF lines are not always usable for the CLI
130 #(e.g. for prepare_test_data, e.g. CLI expects csv but test file is txt)
131 #this function replaces the tmp file by the expected file.
132 function fix_tmp_files {
133 # >&2 echo "FIX $line"
134 ret=""
135 for a in $@; do
136 if [[ ! $a =~ .tmp$ ]]; then
137 ret="$ret $a"
138 continue
139 fi
140 # >&2 echo " a "$a
141 g=$(cat $OPENMSGIT/src/tests/topp/CMakeLists.txt $OPENMSGIT/src/tests/topp/THIRDPARTY/third_party_tests.cmake | awk '{printf("%s@NEWLINE@", $0)}' | sed 's/)@NEWLINE@/)\n/g' | sed 's/@NEWLINE@/ /g' | grep '\${DIFF}.*'"$a")
142 # >&2 echo " g "$g
143 in1=$(sed 's/.*-in1 \([^ ]\+\).*/\1/' <<<$g)
144 # >&2 echo " in1 "$in1
145 if [[ "$a" != "$in1" ]]; then
146 ret="$ret $a"
147 continue
148 fi
149 in2=$(sed 's/.*-in2 \([^ ]\+\).*/\1/' <<<$g)
150 in2=$(basename $in2 | sed 's/)$//')
151 # >&2 echo " in2 "$in2
152 if [[ -f "test-data/$in2" ]]; then
153 ln -fs "$in1" "test-data/$in2"
154 ret="$ret $in2"
155 else
156 ret="$ret $a"
157 fi
158 done
159 # >&2 echo "--> $ret"
160 echo "$ret"
161 }
162
163 function link_tmp_files {
164 # note this also considers commented lines (starting with a #)
165 # because of tests where the diff command is commented and we
166 # still want to use the extension of these files
167 cat $OPENMSGIT/src/tests/topp/CMakeLists.txt $OPENMSGIT/src/tests/topp/THIRDPARTY/third_party_tests.cmake | sed 's/^\s*//; s/\s*$//' | grep -v "^$" | awk '{printf("%s@NEWLINE@", $0)}' | sed 's/)@NEWLINE@/)\n/g' | sed 's/@NEWLINE@/ /g' | grep "\${DIFF}" | while read -r line
168 do
169 in1=$(sed 's/.*-in1 \([^ ]\+\).*/\1/' <<<$line)
170 in1=$(basename $in1 | sed 's/)$//')
171 in2=$(sed 's/.*-in2 \([^ ]\+\).*/\1/' <<<$line)
172 in2=$(basename $in2 | sed 's/)$//')
173 if [[ "$in1" == "$in2" ]]; then
174 >&2 echo "not linking equal $in1 $in2"
175 continue
176 fi
177 ln -f -s $in1 test-data/$in2
178 done
179 for i in test-data/*.tmp
180 do
181 if [ ! -e test-data/$(basename $i .tmp) ]; then
182 ln -s $(basename $i) test-data/$(basename $i .tmp)
183 #ln -s $(basename $i) test-data/$(basename $i .tmp)
184 else
185 ln -fs $(basename $i) test-data/$(basename $i .tmp)
186 fi
187 done
188 }
189
190
191
192 # parse data preparation calls from OpenMS sources for a tool with a given id
193 function prepare_test_data {
194 # id=$1
195 # | egrep -i "$id\_.*[0-9]+(_prepare\"|_convert)?"
196
197 # TODO SiriusAdapter https://github.com/OpenMS/OpenMS/pull/5010
198 cat $OPENMSGIT/src/tests/topp/CMakeLists.txt $OPENMSGIT/src/tests/topp/THIRDPARTY/third_party_tests.cmake | sed 's/#.*$//'| sed 's/^\s*//; s/\s*$//' | grep -v "^$" | awk '{printf("%s@NEWLINE@", $0)}' | sed 's/)@NEWLINE@/)\n/g' | sed 's/@NEWLINE@/ /g' |
199 sed 's/degenerate_cases\///' |
200 egrep -v "WRITEINI|WRITECTD|INVALIDVALUE|DIFF" |
201 grep add_test |
202 egrep "TOPP|UTILS" |
203 sed 's@${DATA_DIR_SHARE}/@@g;'|
204 sed 's@${TMP_RIP_PATH}@dummy2.tmp@g'|
205 sed 's@TOFCalibration_ref_masses @TOFCalibration_ref_masses.txt @g; s@TOFCalibration_const @TOFCalibration_const.csv @'|
206 sed 's/\("TOPP_SiriusAdapter_4".*\)-sirius:database all\(.*\)/\1-sirius:database pubchem\2/' |
207 while read line
208 do
209 test_id=$(echo "$line" | sed 's/add_test(//; s/"//g; s/)[^)]*$//; s/\${TOPP_BIN_PATH}\///g;s/\${DATA_DIR_TOPP}\///g; s#THIRDPARTY/##g' | cut -d" " -f1)
210
211 if grep -lq "$test_id"'\".* PROPERTIES WILL_FAIL 1' $OPENMSGIT/src/tests/topp/CMakeLists.txt $OPENMSGIT/src/tests/topp/THIRDPARTY/third_party_tests.cmake; then
212 >&2 echo " skip failing "$test_id
213 continue
214 fi
215
216 line=$(echo "$line" | sed 's/add_test("//; s/)[^)]*$//; s/\${TOPP_BIN_PATH}\///g;s/\${DATA_DIR_TOPP}\///g; s#THIRDPARTY/##g' | cut -d" " -f2-)
217 # line="$(fix_tmp_files $line)"
218 echo 'echo executing "'$test_id'"'
219 echo "$line > $test_id.stdout 2> $test_id.stderr"
220 echo "if [[ \"\$?\" -ne \"0\" ]]; then >&2 echo '$test_id failed'; >&2 echo -e \"stderr:\n\$(cat $test_id.stderr | sed 's/^/ /')\"; echo -e \"stdout:\n\$(cat $test_id.stdout)\";fi"
221 done
222 }