'sept 2009: cannot use whitespace to split - make a more complex structure here
and adjust the methods that rely on this structure
return interesting phenotype column names for an rexpression eset or affybatch
to use in array subsetting and so on. Returns a data structure for a
dynamic Galaxy select parameter.
A column with only 1 value doesn\'t change, so is not interesting for
analysis. A column with a different value in every row is equivalent to a unique
identifier so is also not interesting for anova or limma analysis - both these
are removed after the concordance (count of unique terms) is constructed for each
column. Then a complication - each remaining pair of columns is tested for
redundancy - if two columns are always paired, then only one is needed :)'

def get_phecols(self, phenolist=[], maxConc=20):

    for (nrows, row) in enumerate(phenolist):
        if (len(row.strip()) == 0):
            break
        row = row.strip().split(' DCTB ')
        if (nrows == 0):
            head = row
            totcols = len(row)
            concordance = [{} for x in head]
        else:
            for (col, code) in enumerate(row):
                if (col >= totcols):
                    gal_Log.warning(('###    get_phecols    error    in    pheno    file    -    row    %d    col    %d    (%s)    longer    than    header    %s' % (nrows, col, row, head)))
                else:
                    concordance[col].setdefault(code, 0)
                    concordance[col][code] += 1
    useCols = []
    useConc = []
    nrows = len(phenolist)
    nrows -= 1
    for (c, conc) in enumerate(concordance):
        if ((len(conc) > 1) and (len(conc) < min(nrows, maxConc))):
            useConc.append(conc)
            useCols.append(c)
    nuse = len(useCols)
    delme = []
    p = phenolist[1:]
    plist = [x.strip().split(' DCTB ') for x in p]
    phe = [[x[i] for i in useCols] for x in plist if (len(x) >= totcols)]
    for i in range(0, (nuse - 1)):
        for j in range((i + 1), nuse):
            kdict = {}
            for row in phe:
                k = ('%s%s' % (row[i], row[j]))
                kdict[k] = k
            if (len(kdict.keys()) == len(concordance[useCols[j]])):
                delme.append(j)
    delme = list(set(delme))
    listCol = []
    delme.sort()
    delme.reverse()
    for i in delme:
        del useConc[i]
        del useCols[i]
    for (i, conc) in enumerate(useConc):
        ccounts = sorted(((conc.get(code, 0), code) for code in conc.keys()))
        cc = [(x[1], x[0]) for x in ccounts]
        codeDetails = (head[useCols[i]], cc)
        listCol.append(codeDetails)
    if (len(listCol) > 0):
        res = listCol
    else:
        res = [('no    usable    phenotype    columns    found', [('?', 0)])]
    return res
