-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathplot_coexpression_error_by_sparsity.py
59 lines (48 loc) · 1.68 KB
/
plot_coexpression_error_by_sparsity.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
55
56
57
58
59
#!/usr/bin/env python
### Imports ###
import pandas as pd
import numpy as np
from pathlib import Path
from typing import Iterable
from lib import plot_boxplots
### Functions ###
def plot_coexpression_error_by_sparsity(
input_files: Iterable[Path],
sparsity_levels: Iterable[float],
output: Path,
) -> None:
"""
Plots the statistics for the coexpression error from the
provided files as a boxplot.
Parameters
----------
input_files : Iterable[Path]
Iterable of Paths to files containing the data
sparsity_levels : Iterable[float]
Iterable of sparsity levels corresponding to the files
output : Path
Path to the file where the plot will be saved
"""
df = pd.DataFrame()
for sparsity,file in zip(sparsity_levels, input_files):
df[sparsity] = np.load(file)
df[sparsity] = df[sparsity].fillna(df[sparsity].mean())
fig,_ = plot_boxplots(df, corr_name=None, ylim=(0, 2))
fig.savefig(output, dpi=300, bbox_inches='tight')
### Main body ###
if __name__ == '__main__':
from argparse import ArgumentParser
parser = ArgumentParser()
parser.add_argument('-i', '--input', dest='input_files', nargs='+',
help='files to plot the data from', metavar='FILE')
parser.add_argument('-sl', '--sparsity_levels', dest='s_levels', nargs='+',
help='levels of sparsity corresponding to the files', metavar='FLOAT',
type=float)
parser.add_argument('-o', '--output', dest='output',
help='file to save the plot to', metavar='FILE')
args = parser.parse_args()
plot_coexpression_error_by_sparsity(
args.input_files,
args.s_levels,
args.output,
)