Turn your functions into composable apps

Just use the define_app decorator! This generates a wrapper class that has a reference to your function and can then become part of a composed function.

You need two things:

  1. your function

  2. Type hints on the function first argument and the function return type.

A simple example

Let’s make an app that returns the elements of an alignment up to a specified index, with the index being a keyword argument. We now define a decorated function up_to and import the type hints and the decorator.

We create an app instance for a specific value of index

The repr() of the instance indicates the wrapped function and the module it’s in.

You use first4() like all composable apps, e.g.

Renaming sequences

This time we wrap a method call on a SequenceCollection (and the alignment sub-classes) for renaming sequences. We also illustrate here that to support both aligned and unaligned data types as input/output, we have to include these in the construction of the custom function.

Note

The SerialisableType indicates the data has the ability to be converted to json.

A user app with a different output type

In this example, we make a function that returns a DistanceMatrix from an alignment.