Allow cheetah tool templates to reason polymorphically about datatypes.

#457 Merged at 08e25f0
Repository
galaxy-central-fork-1
Branch
default
Repository
galaxy-central
Branch
default
Author
  1. John Chilton
Reviewers
Description

Adds a $input.is_of_type( 'ext' ) method to dataset wrappers.

Peter brought this issue up on galaxy-dev here http://dev.list.galaxyproject.org/Determining-datatype-inheritance-in-tool-XML-Cheetah-td4665348.html. There are some hacks if you are willing to import the datatype or use $app but both of these are exposing details and frankly internals of Galaxy that we should not want to expose to tools or tool authors.

Bad ways and new good way:

    #import galaxy.datatypes.sequence
    ; echo "${isinstance($input1.datatype, galaxy.datatypes.sequence.Fastq )}"
    ; echo "$input1.datatype.matches_any([galaxy.datatypes.sequence.Fastq])"
    ; echo "$input1.datatype.matches_any([ $__app__.datatypes_registry.get_datatype_by_extension( 'fastq' )])"
    ; echo "$input1.is_of_type( 'fastq' )"

Comments (5)

  1. Peter Cock

    I like the idea of a method on the dataset like this.

    I presume .is_of_type(...) would return True for exact matches and sub-class matches (e.g. when dataset is fastqsanger, $input1.is_of_type( 'fastq' ) would return True).

  2. Peter Cock

    Thoughts:

    How about an optional argument for exact matching versus subclass matching?

    Bonus points to follow the API style of Python string's .startwith(...) where in addition to a single prefix you can give a tuple, for instance .startswith(("Hello", "Hi")) e.g. $input1.is_of_type(('fastq', 'fasta'))

    If you don't add optional arguments, then this might be nicer - variable number of arguments: $input1.is_of_type('fastq', 'fasta')

    Note this can be done already with $input1.is_of_type('fastq') or $input1.is_of_type('fasta')

    1. John Chilton author

      For exact matching I think I would just prefer people did $input.ext == 'fastq'. I wouldn't mind making $input1.is_of_type('fastq', 'fasta') work - but it makes my concern that the method name is not quite right grow. Hmmm... I'll update the pull request.