-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcalculate_degrees.py
54 lines (43 loc) · 1.48 KB
/
calculate_degrees.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
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
#!/usr/bin/env python
### Imports ###
from pathlib import Path
from lib import load_file
### Functions ###
def calculate_degrees(
lioness_feather: Path,
ind_feather: Path,
outd_feather: Path,
) -> None:
"""
Generates indegree and outdegree files from LIONESS networks saved
in feather format.
Parameters
----------
lioness_feather : Path
Path to the input feather file with the LIONESS networks
ind_feather : Path
Path to the output feather file with the calculated indegrees
outd_feather : Path
Path to the output feather file with the calculated outdegrees
"""
df = load_file(lioness_feather)
ind_df = df.groupby('gene').sum()
ind_df.reset_index().to_feather(ind_feather)
outd_df = df.groupby('tf').sum()
outd_df.reset_index().to_feather(outd_feather)
### Main body ###
if __name__ == '__main__':
from argparse import ArgumentParser
parser = ArgumentParser()
parser.add_argument('-l', '--lioness', dest='lioness_feather',
help='file to load the LIONESS networks from', metavar='FEATHER')
parser.add_argument('-i', '--indegree', dest='ind_feather',
help='file to save the indegrees into', metavar='FEATHER')
parser.add_argument('-o', '--outdegree', dest='outd_feather',
help='file to save the indegrees into', metavar='FEATHER')
args = parser.parse_args()
calculate_degrees(
args.lioness_feather,
args.ind_feather,
args.outd_feather,
)