GalaxyGetOpt Quickstart

Use of GalaxyGetOpt is incredibly simple. This is partially a result of it being rather unpythonic as I came from a Perl world.

#!/usr/bin/env python
"""
Docstring goes here
"""
from galaxygetopt.ggo import GalaxyGetOpt as GGO


def main():
    c = GGO(
        options=[
            ['int', 'An integer parameter', {'required': True, 'validate':
                                            'Int', 'default': 10}],
            ['float', 'A float', {'required': True, 'validate': 'Float',
                                'default': 1e-4}],
            ['string', 'A string value', {'required': True, 'multiple': True,
                                        'default': ['Hello', 'World'],
                                        'validate': 'String'}],
            [],
            ['Advanced'],
            ['option', 'A selection type parameter', {'required': False,
                                                    'validate': 'Option',
                                                    'options': {'a': 'Alpha',
                                                                'b': 'Bravo'}
                                                    }],
            ['file', 'An input file', {'required': True, 'validate':
                                    'File/Input'}],
            ['tag', 'Genomic Tag', {'required': True, 'validate':
                                    'Genomic/Tag'}]
        ],
        outputs=[
            [
                'test_output',
                'Main output file of this utility',
                {
                    'validate': 'File/Output',
                    'required': True,
                    'default': 'ggo_out.complex',
                    'data_format': 'text/tabular',
                    'default_format': 'TSV_U',
                }
            ]
        ],
        defaults={
            'appid': 'ggo.testscript.complex',
            'appname': 'GGO Complex Test Script',
            'appdesc': 'tests functinoality of ggo',
            'appvers': '1.0.0',
        },
        tests=[
            {
                'test_name': 'Default',
                'params': {'tag': 'CDS'},
                'outputs': {
                    'test_output': ['ggo_out.complex.Sheet1.tsv', 'galaxygetopt/tests/test_file.tsv'],
                }
            }
        ],
        doc=__doc__
    )
    my_params = c.params()

This GGO invocation was originally incredibly simple, starting with only options. Over time, the need for storing data like application name and version was added, as was the code for outputs. Outputs represent a file that will be written that is of interest to the user. Included in galaxygetopt are several output handlers: output formatters that take a specific internal data structure and produce output formatted to whatever the user wants. In our Perl version of this module, we provide output handlers for

  • Spreadsheets: XLS, ODS
  • Flat tabular files: CSV, CSV (Unquoted), TSV, TSV (Unquoted)
  • Raw structures: YAML, JSON

This can be seen in the definition of an output structure (data) and the call to galaxygetopt.outputfiles.CRR which writes the data to disk

from galaxygetopt.outputfiles import OutputFiles
of = OutputFiles(name='test_output', GGO=c)
data = {
    'Sheet1': {
        'header': ['Key', 'Value'],
        'data': []
    }
}
tbl_data = []
for key in my_params:
    tbl_data.append([key, my_params[key]])
data['Sheet1']['data'] = tbl_data

of.CRR(data=data)

Previous topic

Welcome to GalaxyGetOpt’s documentation!

Next topic

Creating Parameters

This Page