Why are there empty lists in my results? (e.g. when using Biomoby)
An empty list usually means that for a given input, no results were found. For instance, if you have a service that looks up genes producing a certain protein, and you feed it with a list of 8 different protein identifiers, you might get back a list of lists of proteins. There would then normally be one list corresponding to each of the inputs, in order. If any of the inputs didn't match in the database, the inner list will be empty.
In a complex workflow, these empty lists will not disappear by themselves, because they represent "no results". So if you pass the result of the previously mentioned service into another service again, if Taverna iterates over the inputs, the service will not actually be called when it encounters the empty list, but a corresponding empty list will be added to the output.
This picture is of course complicated by that some services actually read whole lists of inputs (for instance for sorting them or similar).
To get rid of the empty lists, you can apply a beanshell like this:
removeEmpty(Collection collection) {
ArrayList filteredList = new ArrayList();
for (Object elem : collection) {
if (elem instanceof Collection) {
Collection elemCollection = elem;
if (! elemCollection.isEmpty()) {
filteredList.add(removeEmpty(elemCollection));
}
} else {
filteredList.add(elem);
}
}
return filteredList;
}
ArrayList output = removeEmpty(list);
Remember to specify the correct depth of the input list to the beanshell
processor for this to work, in this case the input "list" can be changed
from "a Plain Text" to "2-deep list of Plain Text" (matching the depth
of the input) and should be able to
transform:
{
{
{}
{
Hello
}
}
{}
}
into
{
{
{
Hello
}
}
}
Note that this beanshell shim probably won't be able to handle removal
of lists that become empty because they only contained empty lists.
We have noted this as a bug,
TAV-119, and will
hopefully include this as a local Java widget shim in a later Taverna
release.