def test_wrpy():
    """Test writing GOATOOLS GOEA results to a Python module as a list of nts."""
    # Run GOATOOLS Gene Ontology Enrichment Analysis
    nature_data = get_goea_results()
    # Convert GOATOOLS GOEA results into a list of namedtuples
    goea_results = [nt for nt in nature_data['goea_results'] if nt.p_fdr_bh < 0.05]
    nts_goea = get_goea_nts_prt(goea_results)
    _run(nts_goea, next(iter(nts_goea))._fields)
def _wr_3fmt_wrtbl(tsv_nts, goea_results, wr_params, log):
    """Using functions in the wr_tbl pkg, demonstrate printing a subset of namedtuple fields."""
    goea_nts = get_goea_nts_prt(goea_results)
    # List of all fields, printable or not, in namedtuple (nt):
    log.write("\nnamedtuple FIELDS: {F}\n".format(F=" ".join(goea_nts[0]._fields)))
    # Print to Excel Spreadsheet
    title = "Print subset of namedtuple fields"
    wr_xlsx("nbt3102_subset_nt.xlsx", goea_nts, title=title, **wr_params)
    # Print to tab-separated file
    wr_tsv(tsv_nts, goea_nts, **wr_params)
def test_wrpy():
    """Test writing GOATOOLS GOEA results to a Python module as a list of nts."""
    # Run GOATOOLS Gene Ontology Enrichment Analysis
    nature_data = get_goea_results()
    # Convert GOATOOLS GOEA results into a list of namedtuples
    goea_results = [
        nt for nt in nature_data['goea_results'] if nt.p_fdr_bh < 0.05
    ]
    nts_goea = get_goea_nts_prt(goea_results)
    _run(nts_goea, next(iter(nts_goea))._fields)
Beispiel #4
0
def _wr_3fmt_wrtbl(tsv_nts, goea_results, wr_params, log):
    """Using functions in the wr_tbl pkg, demonstrate printing a subset of namedtuple fields."""
    goea_nts = get_goea_nts_prt(goea_results)
    # List of all fields, printable or not, in namedtuple (nt):
    log.write(
        "\nnamedtuple FIELDS: {F}\n".format(F=" ".join(goea_nts[0]._fields)))
    # Print to Excel Spreadsheet
    title = "Print subset of namedtuple fields"
    wr_xlsx("nbt3102_subset_nt.xlsx", goea_nts, title=title, **wr_params)
    # Print to tab-separated file
    wr_tsv(tsv_nts, goea_nts, **wr_params)
def test_combine_nt_lists():
    """Test combining lists whose elements are namedtuples or class objects."""
    ntobj = cx.namedtuple("Nt", "idx")
    goea_results = get_goea_results()
    # Zip a list of namedtuples and another list of namedtuples
    goea_nts = get_goea_nts_prt(goea_results)
    lst2_nts = [ntobj._make([i]) for i in range(len(goea_nts))]
    # Combine lists into a single list whose elements are a namedtuple
    flds = lst2_nts[0]._fields + goea_nts[0]._fields
    lst_all = combine_nt_lists([lst2_nts, goea_nts], flds)
    assert lst_all[0]._fields == lst2_nts[0]._fields + goea_nts[0]._fields
    # Combine list contains a subset of namedtuple fields
    hdrs = ['idx', 'NS', 'level', 'depth', 'GO',
            'study_count', 'study_n', 'pop_count', 'pop_n', 'p_fdr_bh', 'name']
    lst_sub = combine_nt_lists([lst2_nts, goea_nts], hdrs)
    assert list(lst_sub[0]._fields) == hdrs, "{F} {H}".format(F=lst_sub[0]._fields, H=hdrs)
def test_combine_nt_lists():
    """Test combining lists whose elements are namedtuples or class objects."""
    ntobj = cx.namedtuple("Nt", "idx")
    goea_results = get_goea_results()
    # Zip a list of namedtuples and another list of namedtuples
    goea_nts = get_goea_nts_prt(goea_results)
    lst2_nts = [ntobj._make([i]) for i in range(len(goea_nts))]
    # Combine lists into a single list whose elements are a namedtuple
    flds = lst2_nts[0]._fields + goea_nts[0]._fields
    lst_all = combine_nt_lists([lst2_nts, goea_nts], flds)
    assert lst_all[0]._fields == lst2_nts[0]._fields + goea_nts[0]._fields
    # Combine list contains a subset of namedtuple fields
    hdrs = ['idx', 'NS', 'level', 'depth', 'GO',
            'study_count', 'study_n', 'pop_count', 'pop_n', 'p_fdr_bh', 'name']
    lst_sub = combine_nt_lists([lst2_nts, goea_nts], hdrs)
    assert list(lst_sub[0]._fields) == hdrs, "{F} {H}".format(F=lst_sub[0]._fields, H=hdrs)
Beispiel #7
0
def test_wrpy():
    """Test writing GOATOOLS GOEA results to a Python module as a list of nts."""
    # 1. Run GOATOOLS Gene Ontology Enrichment Analysis
    nature_data = get_goea_results()
    # 2. Convert GOATOOLS GOEA results into a list of namedtuples
    goea_results = nature_data['goea_results']
    nts_goea = get_goea_nts_prt(goea_results)

    # 3. Save GOATOOLS GOEA into a Python module
    #    3a. Python module name
    module_name = "nbt3102_goea"
    fout_py = get_fout_py(module_name)
    #    3b. Save GOATOOLS GOEA into a Python module
    wr_py_nts(fout_py, nts_goea, varname="nts")
    # 4. Check results
    nts_py = importlib.import_module(module_name).nts
    assert len(nts_goea) == len(nts_py)

    # Alternatively, save module through goea object
    module_name = "nbt3102_goea_alt"
    fout_py = get_fout_py(module_name)
    nature_data['goeaobj'].wr_py_goea_results(fout_py, goea_results)
    nts_py = importlib.import_module(module_name).goea_results
    assert len(nts_goea) == len(nts_py)
def test_wrpy():
    """Test writing GOATOOLS GOEA results to a Python module as a list of nts."""
    # 1. Run GOATOOLS Gene Ontology Enrichment Analysis
    nature_data = get_goea_results()
    # 2. Convert GOATOOLS GOEA results into a list of namedtuples
    goea_results = nature_data['goea_results']
    nts_goea = get_goea_nts_prt(goea_results)

    # 3. Save GOATOOLS GOEA into a Python module
    #    3a. Python module name
    module_name = "nbt3102_goea"
    fout_py = get_fout_py(module_name)
    #    3b. Save GOATOOLS GOEA into a Python module
    wr_py_nts(fout_py, nts_goea, varname="nts")
    # 4. Check results
    nts_py = importlib.import_module(module_name).nts
    assert len(nts_goea) == len(nts_py)

    # Alternatively, save module through goea object
    module_name = "nbt3102_goea_alt"
    fout_py = get_fout_py(module_name)
    nature_data['goeaobj'].wr_py_goea_results(fout_py, goea_results)
    nts_py = importlib.import_module(module_name).goea_results
    assert len(nts_goea) == len(nts_py)