Source code

Download source archive ↓

make-catalog.py

1#!/usr/bin/env python3
2"""Generate the source-only operator definitions; no credentials are read."""
3import json
4import yaml
5from pathlib import Path
6HERE=Path(__file__).resolve().parent
7columns={'type':'string','default':'c1','maxLength':4096,'description':'One-based columns, for example c1,c3 or c2-c4. At most 1024 selected columns.'}
8delimiter={'type':'string','enum':['tab','comma','dash','underscore','pipe','dot','whitespace'],'default':'tab'}
9characters=['tab','space','whitespace','dot','comma','dash','underscore','pipe','colon']
10specs={
11'change_case':('ChangeCase','Change selected columns to upper or lower case and emit tab-separated text.',{'columns':columns,'delimiter':delimiter,'casing':{'type':'string','enum':['upper','lower'],'default':'upper'}},{'columns':'c1','delimiter':'tab','casing':'upper'},'M3 18 8 6l5 12M5 14h6m5-3h5l-5 7h5'),
12'condense_characters':('CondenseCharacters','Replace runs of a selected delimiter with one character, preserving the other text.',{'character':{'type':'string','enum':characters,'default':'tab'}},{'character':'tab'},'M3 6h18M3 18h18m-15-6h12m-9-3-3 3 3 3m6-6 3 3-3 3'),
13'convert_delimiters':('ConvertDelimiters','Trim each text line and convert runs of a selected delimiter to tabs.',{'character':{'type':'string','enum':characters,'default':'tab'}},{'character':'whitespace'},'M3 7h7m4 0h7M3 17h7m4 0h7M7 10l5 4 5-4'),
14'cut_columns':('CutColumns','Select and reorder text columns, supporting ranges and repeated columns; fill missing values with a dot.',{'columns':columns,'delimiter':delimiter},{'columns':'c1,c4,c2-c3','delimiter':'tab'},'M3 4h18v16H3zM8 4v16m8-16v16M3 9h18'),
15'merge_columns':('MergeColumns','Append a column formed by concatenating the selected tab-separated fields; preserve comment and empty lines.',{'columns':columns},{'columns':'c4,c1,c6'},'M4 4v7l8 5 8-5V4M12 16v5M1 7h6m10 0h6'),
16'add_column':('AddColumn','Append a fixed value or sequential identifier to every line of tabular text.',{'value':{'type':'string','default':'1','maxLength':4096},'iterate':{'type':'boolean','default':False}},{'value':'1','iterate':False},'M3 4h12v16H3zM8 4v16m10-11v6m-3-3h6')}
17def integer(default=0,maximum=1000000000):return {'type':'integer','minimum':0,'maximum':maximum,'default':default}
18keep=integer(0,4096)
19specs.update({
20 'fasta_length':('FastaLength','Count sequence characters per FASTA entry and emit title/identifier and length as TSV.',{'keep_first':keep,'id_only':{'type':'boolean','default':False}},{'keep_first':0,'id_only':True},'M4 3h16v18H4zM8 7h8M8 12h4m-4 5h8'),
21 'fasta_filter_length':('FastaFilterLength','Keep FASTA entries whose sequence lengths fall within the inclusive configured interval.',{'min_length':integer(),'max_length':integer()},{'min_length':10,'max_length':0},'M3 4h18l-7 8v7l-4 2v-9z'),
22 'fasta_to_tabular':('FastaToTabular','Convert FASTA entries into title columns followed by their concatenated sequence.',{'keep_first':keep,'description_columns':{'type':'integer','minimum':1,'maximum':32,'default':1}},{'keep_first':0,'description_columns':2},'M3 4h18v16H3zM3 10h18m-12 0v10m6-10v10'),
23 'remove_beginning':('RemoveBeginning','Discard the first N text lines and stream the remaining lines unchanged.',{'lines':integer(10,1000000)},{'lines':2},'M4 5h16M4 10h16M4 15h16M4 20h16M2 2l20 10'),
24 'head':('Head','Return the first N text lines, preserving their line endings and draining the input.',{'lines':integer(10,1000000)},{'lines':2},'M4 5h16M4 10h16m-16 5h10m-10 5h6M18 13v8m-3-5 3-3 3 3'),
25 'tail':('Tail','Return the last N text lines with a bounded rolling buffer, preserving original line endings.',{'lines':integer(10,10000)},{'lines':2},'M4 5h6M4 10h10M4 15h16M4 20h16M18 3v8m-3-3 3 3 3-3')})
26FIELD_INFO={
27 'columns':('One-based field selectors.','Use c1,c3 or c2-c4; at most 1024 expanded columns. This is delimiter-based text, not quote-aware CSV.'),
28 'delimiter':('Input field delimiter.','Choose one of the listed delimiter names. The output is tab-separated.'),
29 'casing':('Case conversion applied to the selected fields.','upper converts to uppercase; lower converts to lowercase, using locale-independent Unicode rules.'),
30 'character':('Delimiter character to process.','Choose a listed delimiter name. whitespace means any whitespace; tab matches only tab characters.'),
31 'value':('Fixed value or starting sequence label.','Use a nonnegative integer for numeric iteration or text for labels. Tabs and line breaks are forbidden.'),
32 'iterate':('Whether the appended field increments for each row.','false repeats value; true emits increasing numbers or labels such as sample-0.'),
33 'keep_first':('Maximum retained title/identifier characters.','Zero keeps the complete title or identifier; positive values truncate it to that many Unicode characters.'),
34 'id_only':('Whether to discard the description following a FASTA identifier.','true retains the first title word; false retains the complete title before optional truncation.'),
35 'min_length':('Minimum accepted sequence length.','Inclusive lower bound, in sequence characters. FASTA headers and line endings do not count.'),
36 'max_length':('Maximum accepted sequence length.','Inclusive upper bound; zero removes the upper threshold. A retained FASTA record is still limited to 8 MiB characters.'),
37 'description_columns':('Number of columns extracted from the FASTA title.','One keeps the whole title. Larger values split the first words; the last title column retains the remaining description.'),
38 'lines':('Number of lines to select or discard.','Use a nonnegative integer. Tail is limited to 10000 lines and an 8 MiB-character rolling buffer.')}
39
40result={}
41for name,(cls,description,properties,params,path) in specs.items():
42 result[name]={'name':'galaxy_'+name,'version':'1.0','description':description,'entrypoint':'xstream.galaxy.'+cls,'icon':{'path':path,'color':'#5265ad'},'parameters':{'type':'object','properties':properties,'required':[],'additionalProperties':False},'params':params}
43for name,item in result.items():
44 pdocs={}
45 for key,schema in item['parameters']['properties'].items():
46  desc,help=FIELD_INFO[key];schema['description']=desc
47  pdocs[key]={'description':desc,'help':help,'example':item['params'][key] if key in item['params'] else schema['default']}
48 source='sequences.fasta' if name.startswith('fasta_') else 'input.txt' if name=='convert_delimiters' else 'table.tsv'
49 params=dict(item['params'])
50 if name=='convert_delimiters':params['character']='comma';pdocs['character']['example']='comma'
51 job={'name':item['description'],'steps':[{'id':'read','operator':'read_item@1.0','inputs':{},'params':{'uri':'context:/galaxy/'+source,'view':'bytes'}},{'id':'process','operator':item['name']+'@'+item['version'],'inputs':{'source':'read'},'params':params}],'outputs':{'result':'process'}}
52 item['documentation']={'inputs':{'source':'UTF-8 FASTA bytes with > headers and one or more sequence lines.' if name.startswith('fasta_') else 'UTF-8 text bytes. Column tools use the selected delimiter, without CSV quote interpretation.'},'outputs':{'result':item['description']},'parameters':pdocs,'example_job':yaml.safe_dump(job,sort_keys=False,allow_unicode=True)}
53(HERE/'catalog.json').write_text(json.dumps(result,indent=2)+'\n')