import json
import sys
import matplotlib.pyplot as plt
def update_k_v(dic, k, v):
dic[k] = dic.get(k, 0) + v
if __name__ == "__main__":
assert (len(sys.argv) == 3), "please provide an input json file name and a cell_type"
json_file = sys.argv[1]
cell_type = sys.argv[2]
data = json.load(open(json_file))
for comp_map in data.values():
for cell_type in comp_map:
comp_map[cell_type] = {int(k): v for k, v in comp_map[cell_type].items()}
main_data = data["main"]
total_data = {}
for comp_name in data:
if cell_type in data[comp_name]:
freq_map = data[comp_name][cell_type]
new_data = {}
if comp_name in main_data:
comp_map = main_data[comp_name]
for (in_component_shared, in_component_num_cells) in freq_map.items():
for (component_shared, component_num_cells) in comp_map.items():
new_shared = in_component_shared * component_shared
new_num_cells = in_component_num_cells * component_num_cells
new_data[new_shared] = new_data.get(
new_shared, 0) + new_num_cells
else:
new_data = freq_map
for (k, v) in new_data.items():
total_data[k] = total_data.get(k, 0) + v
cumulative_val = 0.0
y_axis = []
x_axis = list(range(1, max(int(x) for x in total_data.keys()) + 1))
for i in x_axis:
pdf_val = total_data[i] if i in total_data else 0.0
cumulative_val += pdf_val
y_axis.append(cumulative_val)
y_axis = [v/cumulative_val for v in y_axis]
plt.bar(x_axis, y_axis, width=1, align="edge")
plt.show()