Queries the DAVID database for an enrichment analysis and plots CellPlots as
    well as SymPlots (see plots).
    Check https://david.ncifcrf.gov/content.jsp?file=DAVID_API.html for database == "type" tag and categories ==  "annot" tag.

    :param database: a string for the database to query, e.g. 'WORMBASE_GENE_ID'
    :param categories: a comma separated string with databases
    :param user: a user ID registered at DAVID for querying
    :param df_ids: a dataframe where the first column contains the identifiers
        to be queried and the second column the respective log2fc for each identifier.
    :param output: /path/to/output/prefix
    :param df_ids_bg: a dataframe where the first column contains the identifiers
        to be used as background. None for whole set.
    :param name: a string with the name for the query set
    :param name_bg: a string with the name for the background set
    :param p: Maximum p value for enrichment of a term
    :param n: Minimum number of genes within a term

    :returns: Nothing

def DAVIDplot(database, categories, user, df_ids, output, df_ids_bg = None, name = '', \
    name_bg = '', verbose = False, p = 0.1, n = 2):
    """
    Queries the DAVID database for an enrichment analysis and plots CellPlots as
    well as SymPlots (see plots).
    Check https://david.ncifcrf.gov/content.jsp?file=DAVID_API.html for database == "type" tag and categories ==  "annot" tag.

    :param database: a string for the database to query, e.g. 'WORMBASE_GENE_ID'
    :param categories: a comma separated string with databases
    :param user: a user ID registered at DAVID for querying
    :param df_ids: a dataframe where the first column contains the identifiers
        to be queried and the second column the respective log2fc for each identifier.
    :param output: /path/to/output/prefix
    :param df_ids_bg: a dataframe where the first column contains the identifiers
        to be used as background. None for whole set.
    :param name: a string with the name for the query set
    :param name_bg: a string with the name for the background set
    :param p: Maximum p value for enrichment of a term
    :param n: Minimum number of genes within a term

    :returns: Nothing
    """

    idsc1=df_ids.columns.tolist()[0]
    idsc2=df_ids.columns.tolist()[1]

    ids=df_ids[idsc1].tolist()
    if type(df_ids_bg)==type(pd.DataFrame()):
        ids_bg=df_ids_bg[df_ids_bg.columns.tolist()[0]]
    else:
        ids_bg=None
    
    print(categories)
    
    david=DAVIDenrich(database, categories, user, ids, ids_bg = ids_bg, \
    name = name, name_bg = name_bg, verbose = verbose, p = p, n = n)

    print(list(set(david["categoryName"].tolist())))
    if type(david)!=type(pd.DataFrame()):
        print("For this dataset no enrichments could be returned.")
        sys.stdout.flush()
    else:
        david[idsc2]=david["geneIds"].apply(lambda x: \
                          DAVIDgetGeneAttribute(x,\
                          df_ids,\
                          refCol=idsc1,\
                          fieldTOretrieve=idsc2))
        david[idsc2]=david[idsc2].apply(lambda x: x.replace(", ", ","))
        EXC=pd.ExcelWriter(output+".xlsx")
        for category in list(set(david["categoryName"].tolist())):
            david_=david[david["categoryName"]==category]
            print(category)
            david_.to_excel(EXC,category)

            tmp=david_[:20]
            tmp["Enrichment"]=tmp["foldEnrichment"]
            tmp["Term"]=tmp['termName']
            tmp["Annotated"]=tmp["listHits"]
            cellplot=CellPlot(tmp, output_file=output+"."+category, gene_expression=idsc2, \
            figure_title=category+"\n"+output.split("/")[-1], pvalCol="ease", \
            lowerLimit=None, upperLimit=None, colorBarType='bwr')

            symplot=SymPlot(tmp, output_file=output+"."+category, \
            figure_title=category+"\n"+output.split("/")[-1], \
            pvalCol="ease")
        EXC.save()