2024-07-11 10:08:48 +03:00
|
|
|
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']
|
|
|
|
|
2024-07-11 11:15:30 +03:00
|
|
|
if isinstance(tag_val, bytes):
|
|
|
|
tag_val = tag_val.decode('utf-8')
|
2024-07-11 10:08:48 +03:00
|
|
|
|
|
|
|
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(":", "-")
|
2024-07-11 11:15:30 +03:00
|
|
|
|
2024-07-11 10:08:48 +03:00
|
|
|
atribuudid = h5_file[eid].attrs
|
|
|
|
sex = atribuudid.get('sex')
|
|
|
|
spid = atribuudid.get('spid')
|
2024-07-11 11:15:30 +03:00
|
|
|
|
2024-07-11 10:08:48 +03:00
|
|
|
csv_file_name = f"fit_results_{puhastatud_eid}.csv"
|
2024-07-11 11:15:30 +03:00
|
|
|
|
2024-07-11 10:08:48 +03:00
|
|
|
if os.path.exists(csv_file_name):
|
|
|
|
df = pd.read_csv(csv_file_name)
|
2024-07-11 11:15:30 +03:00
|
|
|
|
2024-07-11 10:08:48 +03:00
|
|
|
df['sex'] = sex
|
2024-07-11 11:15:30 +03:00
|
|
|
df['spid'] = spid.replace("Mouse AGAT", "")
|
2024-07-11 10:08:48 +03:00
|
|
|
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:
|
2024-07-11 11:15:30 +03:00
|
|
|
|
2024-07-11 10:08:48 +03:00
|
|
|
df = pd.read_csv(fail)
|
|
|
|
df['tag'] = 'iso'
|
|
|
|
df.to_csv(fail, index=False)
|
|
|
|
|
|
|
|
elif eksperiment_id in ttx_eid_list:
|
2024-07-11 11:15:30 +03:00
|
|
|
|
2024-07-11 10:08:48 +03:00
|
|
|
df = pd.read_csv(fail)
|
|
|
|
df['tag'] = 'ttx'
|
|
|
|
df.to_csv(fail, index=False)
|
|
|
|
|
|
|
|
else:
|
2024-07-11 11:15:30 +03:00
|
|
|
|
2024-07-11 10:08:48 +03:00
|
|
|
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():
|
2024-07-11 11:15:30 +03:00
|
|
|
|
2024-07-11 10:08:48 +03:00
|
|
|
comb_df = pd.concat([comb_df, df], ignore_index=True)
|
|
|
|
|
|
|
|
print(comb_df)
|