comparison generate-foo.sh @ 11:910f1fdf039a draft

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