This workflow implements a strategy for this problem:
> I would like to perform an iteration including a dot product between
> a list and a list of lists; example:
> Input:
>
> [1] (1)
> [A,B,C] (2)
> [[a,b],[c,d],[e,f]] (3)
>
> Desired output:
>
> [1Aa, 1Ab, 1Bc, 1Bd, 1Ce, 1Cf]
In this implementation a java beanshell is used to clone the items in list 2 as many times per item as there are items in the sublists of list 3. The iteration strategy for Clone is set top dot product.
Thus a count on list 2 produces: [2,2,2]
Clone with input: [2,2,2] . [A,B,C] produces [[A,A],[B,B],[C,C]] (note the dot product) (4)
Then concatenation of (1)*((4).(3)) produces: [[1Aa,1Ab],[1Bc,1Bd],[1Ce,1Cf]]
import java.util.*;
List newlist = new ArrayList();
for (int i=0; i<3; i++) {
newlist.add((String) (Character.toString((char) ('A'+(char) i))+"."));
}
capitallist=newlist;
capitallist
1.
import java.util.*;
List newListOfLists = new ArrayList();
int k=0;
for (int j=0; j<3; j++) {
List newlist = new ArrayList();
for (int i=0; i<2; i++) {
newlist.add((String) (Character.toString((char) ('a' + k))));
k++;
}
newListOfLists.add((List) newlist);
}
outlist=newListOfLists;
outlist
file:/D:/Marco/adaptivedisclosure.org/public_html/BioAID/Preliminary/Workflows/UtilityWorkflows/CountListElements.xml
file:/D:/Marco/adaptivedisclosure.org/public_html/BioAID/Preliminary/Workflows/UtilityWorkflows/CountListElements.xml
org.embl.ebi.escience.scuflworkers.java.StringConcat
org.embl.ebi.escience.scuflworkers.java.StringConcat
Utility workflow that clones an item copy_number times. You can use this to work around standard iteration strategies, e.g. in combination with the CountListItems workflow.
Workflow examples: TestIterationStrategy_withClones. For an alternative approach see TestIterationStrategy_withNesting.
Example I/O:
input: A
copy_number: 3
result: [A,A,A]
input: [A,B,C]
copy_number: 3
result: [[A,A,A][B,B,B][C,C,C]]
input: [A,B,C]
copy_number: [3,2]
result: [[[A,A,A],[A,A]][[B,B,B],[B,B]],[[C,C,C],[C,C]]]
input: [A,B,C]
copy_number: [3,2,1]
iteration strategy: dot product
result: [[A,A,A],[B,B],[C]]
import java.util.*;
List newlist = new ArrayList();
for (int i=0; i<((int) Integer.parseInt(copy_number.toString())); i++) {
newlist.add(input);
}
clones=newlist;
copy_number
input
clones