-
Notifications
You must be signed in to change notification settings - Fork 0
/
prepare_for_gsea.py
36 lines (27 loc) · 1.09 KB
/
prepare_for_gsea.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
import json
import numpy as np
import pandas as pd
from netprop.models import PropagationResultModel
from scipy import stats
from pathlib import Path
def make_gct(df: pd.DataFrame, path: str):
with open(path, 'w') as handler:
handler.write(f"# 1.3\n"
f"{len(df)}\t{len(df.columns)}\n"
f"NAME\tDescription\tpropagation_diff\n")
for i in range(len(df)):
handler.write(f"{df.iloc[i].names}\tNA\t{df.iloc[i].propagation_diff}\n")
def make_cls(sample_name: str, path:str):
with open(path, 'w') as handler:
handler.write(f"1 1 1\n"
f"# {sample_name}\n"
f"{sample_name}")
def make_gmx(gene_set_name: str, gene_set: list[str], path):
with open(path, 'w') as handler:
handler.write(f"{gene_set_name}\n"
f"na\n")
handler.write("\n".join(gene_set))
def make_gmt(gene_set_name: str, gene_set: list[str], path):
with open(path, 'w') as handler:
header = f"{gene_set_name}\tna\t"
handler.write(header + "\t".join(gene_set))