def multigroup(pvals, groups, exact=True, keep_all=True, alpha=0.05):
 pvals = pd.Series(pvals)
 if (not (set(pvals.unique()) <= set([False, True]))):
  raise ValueError('the series should be binary')
 if (hasattr(pvals.index, 'is_unique') and (not pvals.index.is_unique)):
  raise ValueError('series with duplicated index is not accepted')
 results = {'pvals': {}, 'increase': {}, '_in_sign': {}, '_in_non': {}, '_out_sign': {}, '_out_non': {}}
 for (group_name, group_list) in iteritems(groups):
  res = _test_group(pvals, group_name, group_list, exact)
  results['pvals'][group_name] = res[0]
  results['increase'][group_name] = res[1]
  results['_in_sign'][group_name] = res[2][0]
  results['_in_non'][group_name] = res[2][1]
  results['_out_sign'][group_name] = res[2][2]
  results['_out_non'][group_name] = res[2][3]
 result_df = sort_values(pd.DataFrame(results), 'pvals')
 if (not keep_all):
  result_df = result_df[result_df.increase]
 smt = stats.multipletests
 corrected = smt(result_df['pvals'], method='fdr_bh', alpha=alpha)[1]
 result_df['adj_pvals'] = corrected
 return result_df

def multigroup ( pvals , groups , exact = True , keep_all = True , alpha = 0.05 ) : pvals = pd . Series ( pvals ) if ( not ( set ( pvals . unique ( ) ) <= set ( [ False , True ] ) ) ) : raise ValueError ( 'the series should be binary' ) if ( hasattr ( pvals . index , 'is_unique' ) and ( not pvals . index . is_unique ) ) : raise ValueError ( 'series with duplicated index is not accepted' ) results = { 'pvals' : { } , 'increase' : { } , '_in_sign' : { } , '_in_non' : { } , '_out_sign' : { } , '_out_non' : { } } for ( group_name , group_list ) in iteritems ( groups ) : res = _test_group ( pvals , group_name , group_list , exact ) results [ 'pvals' ] [ group_name ] = res [ 0 ] results [ 'increase' ] [ group_name ] = res [ 1 ] results [ '_in_sign' ] [ group_name ] = res [ 2 ] [ 0 ] results [ '_in_non' ] [ group_name ] = res [ 2 ] [ 1 ] results [ '_out_sign' ] [ group_name ] = res [ 2 ] [ 2 ] results [ '_out_non' ] [ group_name ] = res [ 2 ] [ 3 ] result_df = sort_values ( pd . DataFrame ( results ) , 'pvals' ) if ( not keep_all ) : result_df = result_df [ result_df . increase ] smt = stats . multipletests corrected = smt ( result_df [ 'pvals' ] , method = 'fdr_bh' , alpha = alpha ) [ 1 ] result_df [ 'adj_pvals' ] = corrected return result_df
test if the given groups are different from the total partition .