PTreeGenerator  1.0
Simple phylogenetic tree generation from multiple sequence alignment.
 All Classes Namespaces Files Functions Variables
combination_utils.py
Go to the documentation of this file.
1 ## @package combination_utils
2 # Contains functions that generate
3 # different kinds of combinations
4 # from an iterable.
5 #
6 
7 ##
8 # A generator of unique combinations of size n
9 # from the given list of items.
10 #
11 # @param items an iterable to be processed
12 # @param n size of each of the unique combinations generated
13 # @return returns all possible unique combinations as a list of lists
15  if not n:
16  yield []
17  else:
18  for i in xrange(len(items)):
19  for comb in uniqueCombinationsGenerator(items[i+1:], n-1):
20  yield [items[i]] + comb
21 
22 ##
23 # A generator of all non-unique combinations
24 # (permutations) of size n from the given list of items.
25 #
26 # @param items an iterable to be processed
27 # @param n size of each of the combinations generated
28 # @return returns all possible unique combinations as a list of lists
29 def combinationsGenerator(items, n):
30  if not n:
31  yield []
32  else:
33  for i in xrange(len(items)):
34  for comb in combinationsGenerator(items[:i]+items[i+1:],n-1):
35  yield [items[i]] + comb