def loadTagData(tags_filename, design_filename):
    '''load tag data for deseq/edger analysis.

    *Infile* is a tab-separated file with counts.

    *design_file* is a tab-separated file with the
    experimental design with a minimum of four columns::

      track   include group   pair
      CW-CD14-R1      0       CD14    1
      CW-CD14-R2      0       CD14    1
      CW-CD14-R3      1       CD14    1
      CW-CD4-R1       1       CD4     1
      FM-CD14-R1      1       CD14    2
      FM-CD4-R2       0       CD4     2
      FM-CD4-R3       0       CD4     2
      FM-CD4-R4       0       CD4     2

    track
        name of track - should correspond to column header in *infile*
    include
        flag to indicate whether or not to include this data
    group
        group indicator - experimental group
    pair
        pair that sample belongs to (for paired tests)

    Additional columns in design file are taken to contain levels for
    additional factors and may be included for tests that allow multi-factor
    model designs.

    This method creates various R objects:

    countsTable : data frame with counts.
    groups : vector with groups
    pairs  : vector with pairs
    factors : df of additional factors for more complex model designs

    '''

    # Load counts table
    E.info(tags_filename % "loading tag data from %s")

    R('''counts_table = read.table('%(tags_filename)s',
    header=TRUE,
    row.names=1,
    stringsAsFactors=TRUE,
    comment.char='#')''' % locals())

    E.info("read data: %i observations for %i samples" %
           tuple(R('''dim(counts_table)''')))
    E.debug("sample names: %s" % R('''colnames(counts_table)'''))

    # Load comparisons from file
    R('''pheno = read.delim(
    '%(design_filename)s',
    header=TRUE,
    stringsAsFactors=TRUE,
    comment.char='#')''' % locals())

    # Make sample names R-like - substitute - for .
    R('''pheno[,1] = gsub('-', '.', pheno[,1]) ''')
    E.debug("design names: %s" % R('''pheno[,1]'''))

    # Ensure pheno rows match count columns
    pheno = R(
        '''pheno2 = pheno[match(colnames(counts_table),pheno[,1]),,drop=FALSE]''')
    missing = R('''colnames(counts_table)[is.na(pheno2)][1]''')
    if missing:
        E.warn("missing samples from design file are ignored: %s" %
               missing)

    # Subset data & set conditions
    R('''includedSamples <- !(is.na(pheno2$include) | pheno2$include == '0') ''')
    E.debug("included samples: %s" %
            R('''colnames(counts_table)[includedSamples]'''))
    R('''countsTable <- counts_table[ , includedSamples ]''')
    R('''groups <- factor(pheno2$group[ includedSamples ])''')
    R('''conds <- pheno2$group[ includedSamples ]''')
    R('''pairs <- factor(pheno2$pair[ includedSamples ])''')

    # JJ if additional columns present, pass to 'factors'
    R('''if (length(names(pheno2)) > 4) {
           factors <- data.frame(pheno2[includedSamples,5:length(names(pheno2))])
         } else {
           factors <- NA
         }''')

    E.info("filtered data: %i observations for %i samples" %
           tuple(R('''dim(countsTable)''')))
dataset/ETHPy150Open CGATOxford/cgat/CGAT/Expression.py/loadTagData/swapped operands of `%`