def deseqParseResults(control_name, treatment_name, fdr, vsd=False):
    '''parse deseq output.

    retrieve deseq results from object 'res' in R namespace.

    The 'res' object is a dataframe with the following columns (from the
    DESeq manual):

    id: The ID of the observable, taken from the row names of the
          counts slots.

    baseMean: The base mean (i.e., mean of the counts divided by the size
          factors) for the counts for both conditions

    baseMeanA: The base mean (i.e., mean of the counts divided by the size
          factors) for the counts for condition A

    baseMeanB: The base mean for condition B

    foldChange: The ratio meanB/meanA

    log2FoldChange: The log2 of the fold change

    pval: The p value for rejecting the null hypothesis 'meanA==meanB'

    padj: The adjusted p values (adjusted with 'p.adjust( pval,
          method="BH")')

    vsd_log2FoldChange: The log2 fold change after variance stabilization.
          This data field is not part of DESeq proper, but has been added
          in this module in the runDESeq() method.

    Here, 'conditionA' is 'control' and 'conditionB' is 'treatment'
    such that a foldChange of 2 means that treatment is twice
    upregulated compared to control.

    Returns a list of results.

    If vsd is True, the log fold change will be computed from the variance
    stabilized data.

    '''

    results = []
    isna = R["is.na"]

    # Get column names from output and edit
    names = list(R['res'].names)
    m = dict([(x, x) for x in names])
    m.update(dict(
        pval="pvalue",
        baseMeanA="value1",
        baseMeanB="value2",
        id="interval_id",
        log2FoldChange="lfold"))

    rtype = collections.namedtuple("rtype", names)
    counts = E.Counter()

    for data in zip(*R['res']):
        counts.input += 1

        d = rtype._make(data)

        # set significant flag
        if d.padj <= fdr:
            signif = 1
            counts.significant += 1
            if d.log2FoldChange > 0:
                counts.significant_over += 1
            else:
                counts.significant_under += 1
        else:
            signif = 0
            counts.insignificant += 1

        if 0 > d.log2FoldChange:
            counts.all_over += 1
        else:
            counts.all_under += 1

        # set lfold change to 0 if both are not expressed
        if d.baseMeanA == 0.0 and d.baseMeanB == 0.0:
            d = d._replace(foldChange=0, log2FoldChange=0)

        if d.pval != R('''NA'''):
            status = "OK"
        else:
            status = "FAIL"

        counts[status] += 1

        counts.output += 1

        # check if our assumptions about the direction of fold change
        # are correct
        assert (d.foldChange > 1) == (d.baseMeanB > d.baseMeanA)

        # note that fold change is computed as second group (B) divided by
        # first (A)
        results.append(GeneExpressionResult._make((
            d.id,
            treatment_name,
            d.baseMeanB,
            0,
            control_name,
            d.baseMeanA,
            0,
            d.pval,
            d.padj,
            d.log2FoldChange,
            d.foldChange,
            d.transformed_log2FoldChange,
            str(signif),
            status)))

    return results, counts
dataset/ETHPy150Open CGATOxford/cgat/CGAT/Expression.py/deseqParseResults/swapped operands of `>`