-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcalculate_coexpression_matrix.py
43 lines (34 loc) · 1.05 KB
/
calculate_coexpression_matrix.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
#!/usr/bin/env python
### Imports ###
from pathlib import Path
from lib import load_file
### Functions ###
def calculate_coexpression_matrix(
expression: Path,
output: Path,
) -> None:
"""
Calculates the coexpression matrix from the given gene expression.
Parameters
----------
expression : Path
Path to a file containing the gene expression
output : Path
Path where the coexpression matrix will be saved
"""
df = load_file(expression)
coexpr_df = df.T.corr()
coexpr_df.reset_index().to_feather(output)
### Main body ###
if __name__ == '__main__':
from argparse import ArgumentParser
parser = ArgumentParser()
parser.add_argument('-e', '--expression', dest='expression',
help='file to load the gene expression from', metavar='FILE')
parser.add_argument('-o', '--output', dest='output',
help='file to save the coexpression matrix into', metavar='FEATHER')
args = parser.parse_args()
calculate_coexpression_matrix(
args.expression,
args.output,
)