Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
galaxyproject
GitHub Repository: galaxyproject/training-material
Path: blob/main/_plugins/util.rb
1677 views
1
require 'yaml'
2
3
# This module specifically avoids having any dependencies. If you have a method
4
# that needs to be used in many places, even those without initialisation, it
5
# should go here.
6
7
ALLOWED_SHORT_IDS = [
8
'addValue',
9
'aggregate_scores_in_intervals2',
10
'axt_to_concat_fasta',
11
'axt_to_fasta',
12
'axt_to_lav_1',
13
'barchart_gnuplot',
14
'bed2gff1',
15
'bed_to_bigBed',
16
'bfast_wrapper',
17
'bgchem_fragment_merger',
18
'bg_protein_properties',
19
'bigwigtowig',
20
'biomart',
21
'biomart_test',
22
'biopython_base_distribution',
23
'blockbuster',
24
'bwtool-lift',
25
'cat1',
26
'cbi_rice_mart',
27
'ChangeCase',
28
'codon_count',
29
'comp1',
30
'concatenate_icenet_data',
31
'Convert characters1',
32
'Count1',
33
'create_API_requests_for_icenet_data',
34
'createInterval',
35
'csv_to_tabular',
36
'Cut1',
37
'diced_database',
38
'ds_seek_test',
39
'ebi_sra_main',
40
'eupathdb',
41
'export_remote',
42
'Extract_features1',
43
'Filter1',
44
'flymine',
45
'fragmenter',
46
'gbk_to_orf',
47
'genbank_to_gff',
48
'gene2exon1',
49
'GeneBed_Maf_Fasta2',
50
'gff2bed1',
51
'gff_filter_by_attribute',
52
'gff_filter_by_feature_count',
53
'gff_to_sequence',
54
'gramenemart',
55
'Grep1',
56
'Grouping1',
57
'gtf2bedgraph',
58
'gtf_filter_by_attribute_values_list',
59
'hbvar',
60
'hgv_beam',
61
'hgv_david',
62
'hgv_gpass',
63
'hgv_ldtools',
64
'hgv_linkToGProfile',
65
'hgv_lps',
66
'hgv_pass',
67
'icenet_forecast',
68
'intermine',
69
'Interval2Maf1',
70
'Interval2Maf_pairwise1',
71
'Interval_Maf_Merged_Fasta2',
72
'join1',
73
'lav_to_bed1',
74
'lftp',
75
'liftOver1',
76
'lped2fpedconvert',
77
'lped2pbedconvert',
78
'maf_by_block_number1',
79
'MAF_filter',
80
'maf_limit_size1',
81
'MAF_Limit_To_Species1',
82
'MAF_Reverse_Complement_1',
83
'MAF_split_blocks_by_species1',
84
'maf_stats1',
85
'MAF_Thread_For_Species1',
86
'MAF_To_BED1',
87
'MAF_To_Fasta1',
88
'MAF_To_Interval1',
89
'master2pgSnp',
90
'metabolicmine',
91
'microbial_import1',
92
'modENCODEfly',
93
'modENCODEworm',
94
'modmine',
95
'mosaik_wrapper',
96
'mousemine',
97
'ncbi_datasets_source',
98
'netcdf2zarr',
99
'omicsdi',
100
'param_value_from_file',
101
'Paste1',
102
'pbed2ldindepconvert',
103
'pbed2lpedconvert',
104
'pcgr',
105
'PerM',
106
'preprocess_icenet_data',
107
'proteomics_search_interprophet_1',
108
'proteomics_search_peptide_prophet_1',
109
'proteomics_search_protein_prophet_1',
110
'proteomics_search_tandem_1',
111
'proteomics_search_tandem_2',
112
'pyiron_meta',
113
'qual_stats_boxplot',
114
'random_lines1',
115
'ratmine',
116
'Remove beginning1',
117
'rnalfoldz',
118
'secure_hash_message_digest',
119
'sequence_convert',
120
'Sff_extractor',
121
'Show beginning1',
122
'Show tail1',
123
'snpSift_geneSets',
124
'solid2fastq',
125
'solid_qual_boxplot',
126
'solid_qual_stats',
127
'sort1',
128
'sra_source',
129
'srma_wrapper',
130
'Summary_Statistics1',
131
'tabular_to_csv',
132
'tabular_to_dbnsfp',
133
'terrabyte_ogc_api_processes',
134
'tombo_detect_modifications',
135
'tombo_plot_genome_locations',
136
'tombo_plot_most_significant',
137
'tombo_resquiggle',
138
'tombo_text_output',
139
'translate_nucleotides',
140
'trimmer',
141
'ucsc_bigbedtobed',
142
#'ucsc_table_direct1', # This does not work, surprisingly.
143
'ucsc_table_direct_archaea1',
144
'upload1',
145
'vcf_to_maf_customtrack1',
146
#'velvetg', # velvet has a toolshed alternative, discourage using built-in version
147
#'velveth', # velvet has a toolshed alternative, discourage using built-in version
148
'visualize_icenet_forecast',
149
'wc_gnu',
150
'wiggle2simple1',
151
'wig_to_bigWig',
152
'wormbase',
153
'yeastmine',
154
'zebrafishmine'
155
].freeze
156
157
ALLOWED_LOWER_SHORT_IDS = ALLOWED_SHORT_IDS.map(&:downcase)
158
159
def safe_load_yaml(file)
160
YAML.load_file(file)
161
rescue StandardError
162
YAML.load_file(file, permitted_classes: [Date])
163
end
164
165
def collapse_event_date_pretty(event)
166
s = event['date_start']
167
e = if event['date_end'].nil?
168
s
169
else
170
event['date_end']
171
end
172
# want dates like "Mar 22-25, 2024" or "Mar 22-May 1, 2024"
173
dash = ' – ' # thin space, en dash, thin space
174
if s.year == e.year
175
if s.month == e.month
176
if s.day == e.day
177
"#{s.strftime('%B')} #{s.day}, #{s.year}"
178
else
179
"#{s.strftime('%B')} #{s.day}#{dash}#{e.day}, #{s.year}"
180
end
181
else
182
"#{s.strftime('%B')} #{s.day}#{dash}#{e.strftime('%B')} #{e.day}, #{s.year}"
183
end
184
else
185
"#{s.strftime('%B')} #{s.day}, #{s.year}#{dash}#{e.strftime('%B')} #{e.day}, #{e.year}"
186
end
187
end
188
189
def safe_site_config(site, key, default)
190
if !site.config.nil? && site.config.key?(key)
191
site.config[key]
192
else
193
default
194
end
195
end
196
197
198
def url_prefix(site)
199
if !site.config.nil? && site.config.key?('url')
200
"#{site.config['url']}#{site.config['baseurl']}"
201
else
202
'http://localhost:4000/training-material/'
203
end
204
end
205
206
def markdownify(site, text)
207
site.find_converter_instance(
208
Jekyll::Converters::Markdown
209
).convert(text.to_s)
210
end
211
212
def unsafe_slugify(text)
213
text.gsub(%r{["'\\/;:,.!@#$%^&*()]}, '').gsub(/\s/, '-').gsub(/-+/, '-')
214
end
215
216
def fix_version(version)
217
version
218
.gsub('_beta+galaxy', '+galaxy')
219
.gsub(/^([0-9]+)_([0-9]+)_([0-9]+)\+galaxy(.+)/, '\1.\2.\3galaxy\4')
220
.gsub(/^([0-9]+)\+galaxy(.+)/, '\1.0.0galaxy\2')
221
.gsub(/^([0-9.]+)_([0-9]+)/, '\1galaxy\2')
222
.gsub(/_rc(.*)galaxy/, 'rc\1galaxy')
223
.gsub('+', '')
224
.gsub(/^v/, '')
225
end
226
227
def acceptable_tool?(tool_id)
228
if ! tool_id.is_a?(String)
229
return false
230
end
231
232
# Public TS links are fine
233
if tool_id.start_with?('toolshed.g2.bx.psu.edu')
234
return true
235
end
236
237
# These are always allowed (mostly built-ins)
238
if ALLOWED_LOWER_SHORT_IDS.include?(tool_id.downcase) || tool_id =~ /^__.*__$/
239
return true
240
end
241
242
if tool_id.start_with?('interactive_tool_')
243
return true
244
end
245
246
if tool_id.start_with?('CONVERTER_')
247
return true
248
end
249
250
# Templated tool IDs are hopefully fine!
251
if tool_id.start_with?('{{')
252
return true
253
end
254
255
# Just the tutorial
256
if tool_id.start_with?('Toolshed ID')
257
return true
258
end
259
260
# Unacceptable
261
return false
262
end
263
264
265
def tool_id_extractor(wf, path: [])
266
res = []
267
wf['steps'].each do |step_id, step|
268
if step.key?('subworkflow')
269
res += tool_id_extractor(step['subworkflow'], path: path + [step_id])
270
elsif step.key?('tool_id') && ! step['tool_id'].nil?
271
res.push(["#{path.join('/')}/#{step_id}", step['tool_id']])
272
end
273
end
274
res
275
end
276
277
def objectify(attrs, url, path)
278
obj = attrs.clone
279
obj['__path'] = path
280
obj['__url'] = url
281
282
def obj.data
283
self
284
end
285
286
def obj.path
287
self['__path']
288
end
289
290
def obj.url
291
self['__url']
292
end
293
294
def obj.content
295
self.fetch('content', 'NO CONTENT AVAILABLE')
296
end
297
298
def obj.title
299
self['title']
300
end
301
302
obj
303
end
304
305
if __FILE__ == $PROGRAM_NAME
306
require 'test/unit'
307
# Testing for the class
308
class Gtn::Test::IntersectionTest < Test::Unit::TestCase
309
def test_bad_versions
310
# toolshed.g2.bx.psu.edu/repos/wolma/mimodd_main/mimodd_info/0.1.8_1
311
assert_equal(fix_version("0.1.8_1"), "0.1.8galaxy1")
312
313
# toolshed.g2.bx.psu.edu/repos/iuc/snap_training/snap_training/2013_11_29+galaxy1
314
assert_equal(fix_version("2013_11_29+galaxy1"), "2013.11.29galaxy1")
315
316
# toolshed.g2.bx.psu.edu/repos/devteam/vcffilter/vcffilter2/1.0.0_rc1+galaxy3
317
assert_equal(fix_version("1.0.0_rc1+galaxy3"), "1.0.0rc1galaxy3")
318
319
#
320
assert_equal(fix_version("3+galaxy0"), "3.0.0galaxy0")
321
end
322
end
323
end
324
325