Skip to content

gsea

Run single-omic GSEA with a gmt and a rank list in form of list[tuple[str, float]].

Parameters

  • gmt_path - String of the path to the gmt file of interest
  • rank_list - list[tuple[str, float]] the rank list of interest.

Returns

Returns a list containing the GSEA results for every set.

Panics

Panics if the GMT or the rank list is malformed or not at specified path.

Example

import webgestaltpy

def create_rank_list(file_path: str) -> list[tuple[str, float]]:
    """Function that converts rnk file to format for gsea().

    This is for demo purposes. gsea_from_files would be more convenient in this case.
    However, for when the scores are calculated in a Python script, gsea() allows you to directly
    use the results without having to save to a file first.

    """

    res = []
    with open(file_path, "r") as r:
        lines = r.readlines()
    for line in lines:
        if "\t" in line:
            vals = line.split("\t")
            res.append((vals[0], float(vals[1])))
    return res

res = webgestaltpy.gsea("kegg.gmt", create_rank_list("test.rnk"))

print(res[0:2]) ## print first two results

Output

Your results may vary depending on random permutations

[
  {
    'set': 'has00010',
    'p': 0.353,
    'fdr': 1.0,
    'es': 0.40653028852961814,
    'nes': 1.07659486501464,
    'leading_edge': 24
  },
  {
    'set': 'has00020',
    'p': 0,
    'fdr': 0.028834551777982824,
    'es': 0.6216527702210619,
    'nes': 1.5721004858071521,
    'leading_edge': 20
  }
]