def runTTest(outfile,
             outfile_prefix,
             fdr=0.1,
             ref_group=None,
             ref_regex=None):
    '''apply a ttest on the data.

    For the T-test it is best to use FPKM values as
    this method does not perform any library normalization.
    '''
    groups, pairs, has_replicates, has_pairs = groupTagData(ref_group,
                                                            ref_regex)

    results = []
    for combination in itertools.combinations(groups, 2):
        control, treatment = combination
        r = R('''r = apply(countsTable, 1,
        function(x) { t.test(
        x[groups == '%(treatment)s'],
        x[groups == '%(control)s']) } )
        ''' % locals())

        for test_id, ttest in zip(r.names, r):
            # TS, swapped order below as assignment was incorrect
            treatment_mean, control_mean = tuple(ttest.rx2('estimate'))
            fold_change = treatment_mean / control_mean
            pvalue = tuple(ttest.rx2('p.value'))[0]
            significant = (0, 1)[pvalue < fdr]
            results.append(GeneExpressionResult._make((test_id,
                                                       treatment,
                                                       treatment_mean,
                                                       0,
                                                       control,
                                                       control_mean,
                                                       0,
                                                       pvalue,
                                                       pvalue,
                                                       numpy.log2(fold_change),
                                                       fold_change,
                                                       numpy.log2(fold_change),
                                                       significant,
                                                       "OK")))

    writeExpressionResults(outfile, results)


#####################################################################
# Pandas-based functions and matplotlib-based plotting functions ####
#####################################################################
dataset/ETHPy150Open CGATOxford/cgat/CGAT/Expression.py/runTTest/original