Calcium_Model/statistiline_filter.py

85 lines
2.2 KiB
Python
Raw Normal View History

import h5py
import os
import pandas as pd
h5_file = 'ltcc_current.h5'
sobiv_eid_list = []
ttx_eid_list = []
teised_eid_list = []
with h5py.File(h5_file, 'r') as h5_file:
for eid in h5_file.keys():
if 'tag' in h5_file[eid].attrs:
tag_val = h5_file[eid].attrs['tag']
if isinstance(tag_val, bytes):
tag_val = tag_val.decode('utf-8')
puhas_eid = eid.replace(" ", "_").replace(":", "-")
fit_result_eid = "fit_results_" + puhas_eid
if tag_val == 'iso':
sobiv_eid_list.append(fit_result_eid)
elif tag_val == 'ttx':
ttx_eid_list.append(fit_result_eid)
else:
teised_eid_list.append(fit_result_eid)
file = 'ltcc_current.h5'
with h5py.File(file, 'r') as h5_file:
for eid in h5_file.keys():
puhastatud_eid = eid.replace(" ", "_").replace(":", "-")
atribuudid = h5_file[eid].attrs
sex = atribuudid.get('sex')
spid = atribuudid.get('spid')
csv_file_name = f"fit_results_{puhastatud_eid}.csv"
if os.path.exists(csv_file_name):
df = pd.read_csv(csv_file_name)
df['sex'] = sex
df['spid'] = spid.replace("Mouse AGAT", "")
df['eid'] = eid
df.to_csv(csv_file_name, index=False)
for fail in os.listdir():
if fail.endswith('.csv'):
eksperiment_id = fail.replace(".csv", "")
if eksperiment_id in sobiv_eid_list:
df = pd.read_csv(fail)
df['tag'] = 'iso'
df.to_csv(fail, index=False)
elif eksperiment_id in ttx_eid_list:
df = pd.read_csv(fail)
df['tag'] = 'ttx'
df.to_csv(fail, index=False)
else:
df = pd.read_csv(fail)
df['tag'] = 'teised'
df.to_csv(fail, index=False)
comb_df = pd.DataFrame()
for filename in os.listdir():
if filename.endswith('.csv'):
df = pd.read_csv(filename)
if 'tag' in df.columns and df['tag'].isin(['iso', 'ttx']).all():
comb_df = pd.concat([comb_df, df], ignore_index=True)
print(comb_df)