Turn your functions into composable apps¶
This is super easy – just use the appify decorator! This generates a user_function wrapper class that takes a reference to your function and the input, output and data types. The resulting app can then become part of a composed function.
You need four things.
funcA function to decorate … duh!
input_typesA type, or collection of type that your function can handle. This setting dictates what other apps have an output that is a compatable input for your function.
output_typesA type, or collection of type that your function produces. This setting dictates what other apps can have yours as input.
data_typesThe data class names, as strings, that your function can handle. Not required, but useful.
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()
Now we define a user_function instance that takes and ret
The repr() of your user_function instance indicates the wrapped function and the module it’s in.
We create an app instance for a specific value of index
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 SERIALISABLE_TYPE indicates the data has the ability to be converted to json.
A user app with a different output type¶
In this example, we make an function that returns DistanceMatrix of an alignment.
Note
We omitted the data_types argument just for demonstration purposes.