nodes: 0, module; 1, function_definition; 2, function_name:fromgroups; 3, parameters; 4, block; 5, identifier:args; 6, expression_statement; 7, import_from_statement; 8, expression_statement; 9, expression_statement; 10, if_statement; 11, expression_statement; 12, expression_statement; 13, expression_statement; 14, expression_statement; 15, expression_statement; 16, for_statement; 17, comment:"""
      %prog fromgroups groupsfile a.bed b.bed ...
  
      Flatten the gene familes into pairs, the groupsfile is a file with each line
      containing the members, separated by comma. The commands also require
      several bed files in order to sort the pairs into different piles (e.g.
      pairs of species in comparison.
      """; 18, dotted_name; 19, dotted_name; 20, assignment; 21, assignment; 22, comparison_operator:len(args) < 2; 23, block; 24, assignment; 25, assignment; 26, assignment; 27, assignment; 28, assignment; 29, pattern_list; 30, call; 31, block; 32, identifier:jcvi; 33, identifier:formats; 34, identifier:bed; 35, identifier:Bed; 36, identifier:p; 37, call; 38, pattern_list; 39, call; 40, call; 41, integer:2; 42, expression_statement; 43, identifier:groupsfile; 44, subscript; 45, identifier:bedfiles; 46, subscript; 47, identifier:beds; 48, list_comprehension; 49, identifier:fp; 50, call; 51, identifier:groups; 52, list_comprehension; 53, identifier:b1; 54, identifier:b2; 55, identifier:product; 56, argument_list; 57, expression_statement; 58, identifier:OptionParser; 59, argument_list; 60, identifier:opts; 61, identifier:args; 62, attribute; 63, argument_list; 64, identifier:len; 65, argument_list; 66, call; 67, identifier:args; 68, integer:0; 69, identifier:args; 70, slice; 71, call; 72, for_in_clause; 73, identifier:open; 74, argument_list; 75, call; 76, for_in_clause; 77, identifier:beds; 78, keyword_argument; 79, call; 80, attribute; 81, identifier:p; 82, identifier:parse_args; 83, identifier:args; 84, identifier:args; 85, attribute; 86, argument_list; 87, integer:1; 88, identifier:Bed; 89, argument_list; 90, identifier:x; 91, identifier:bedfiles; 92, identifier:groupsfile; 93, attribute; 94, argument_list; 95, identifier:row; 96, identifier:fp; 97, identifier:repeat; 98, integer:2; 99, identifier:extract_pairs; 100, argument_list; 101, identifier:fromgroups; 102, identifier:__doc__; 103, identifier:sys; 104, identifier:exit; 105, not_operator; 106, identifier:x; 107, call; 108, identifier:split; 109, string:","; 110, identifier:b1; 111, identifier:b2; 112, identifier:groups; 113, call; 114, attribute; 115, argument_list; 116, attribute; 117, argument_list; 118, identifier:row; 119, identifier:strip; 120, identifier:p; 121, identifier:print_help
code: def fromgroups(args):
      """
      %prog fromgroups groupsfile a.bed b.bed ...
  
      Flatten the gene familes into pairs, the groupsfile is a file with each line
      containing the members, separated by comma. The commands also require
      several bed files in order to sort the pairs into different piles (e.g.
      pairs of species in comparison.
      """
      from jcvi.formats.bed import Bed
  
      p = OptionParser(fromgroups.__doc__)
      opts, args = p.parse_args(args)
  
      if len(args) < 2:
          sys.exit(not p.print_help())
  
      groupsfile = args[0]
      bedfiles = args[1:]
      beds = [Bed(x) for x in bedfiles]
      fp = open(groupsfile)
      groups = [row.strip().split(",") for row in fp]
      for b1, b2 in product(beds, repeat=2):
          extract_pairs(b1, b2, groups)