Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
def run(data, gmt, cls, permutation_type='phenotype', method='signal_to_noise', permution_num=1000):
prefix = gp.__name__ + "."
for importer, modname, ispkg in pkgutil.iter_modules(gp.__path__, prefix):
if modname == "gseapy.gsea":
module = __import__(modname, fromlist="dummy")
vs = gp.__version__.split(".")
if int(vs[0]) == 0 and int(vs[1]) < 9:
module.ranking_metric = GSEA._ranking_metric
else:
module.ranking_metric = GSEA._ranking_metric2
gp.algorithm.ranking_metric = GSEA._ranking_metric
res = gp.gsea(data, gmt, cls, permutation_type=permutation_type, permutation_num=permution_num,
outdir=os.path.join(os.path.dirname(os.path.realpath(__file__)), 'images'), method=method)
return GSEA(res.res2d, data, gmt, cls)
def run_gsea(gene_exp: str, gene_set: str, phenotype_class: str, permutations: int = 500, output_dir: str = GSEA):
"""Run GSEA on a given dataset with a given gene set.
:param gene_exp: file with gene expression data
:param gene_set: gmt files containing pathway gene sets
:param phenotype_class: cls file containing information on class labels
:param permutations: number of permutations
:param output_dir: output directory
:return:
"""
return gseapy.gsea(
data=gene_exp,
gene_sets=gene_set,
cls=phenotype_class, # cls=class_vector
max_size=3000,
# set permutation_type to phenotype if samples >=15
permutation_type='phenotype',
permutation_num=permutations, # reduce number to speed up test
outdir=output_dir, # do not write output to disk
no_plot=True, # Skip plotting
processes=4,
format='png',
)