zareenz741's picture
download
raw
2.22 kB
#!/usr/bin/env python3
"""Keep only healthy MRI scans; move non-healthy scans to _excluded/ (preserve, don't delete).
Healthy = diagnosis=='normal' AND myelinisation=='normal' (for BCP).
All other datasets are already healthy cohorts.
"""
import os, shutil, pandas as pd
ROOT = "/home/MRI-DataSet"
BCP_T1 = os.path.join(ROOT, "DataSet-1", "T1_only")
BCP_EXC = os.path.join(ROOT, "DataSet-1", "_excluded")
def filter_bcp():
df = pd.read_csv(os.path.join(ROOT, "DataSet-1", "meta.csv"), sep=";")
healthy_mask = ((df["diagnosis"].astype(str).str.lower() == "normal") &
(df["myelinisation"].astype(str).str.lower() == "normal"))
healthy = set(df.loc[healthy_mask, "image_id"])
non_healthy = set(df.loc[~healthy_mask, "image_id"])
print(f"[BCP] metadata rows: {len(df)}")
print(f"[BCP] healthy: {len(healthy)} non-healthy: {len(non_healthy)}")
deleted = kept = missing = 0
for sid in sorted(non_healthy):
src = os.path.join(BCP_T1, sid)
if os.path.isdir(src):
shutil.rmtree(src)
deleted += 1
else:
missing += 1
for sid in healthy:
if os.path.isdir(os.path.join(BCP_T1, sid)):
kept += 1
print(f"[BCP] deleted non-healthy: {deleted} kept healthy in place: {kept} not on disk: {missing}")
# Save healthy-only meta.csv alongside the original
df_healthy = df[healthy_mask].copy()
df_healthy.to_csv(os.path.join(ROOT, "DataSet-1", "meta_healthy.csv"), sep=";", index=False)
df[~healthy_mask].to_csv(os.path.join(ROOT, "DataSet-1", "meta_excluded.csv"), sep=";", index=False)
print(f"[BCP] wrote meta_healthy.csv ({len(df_healthy)}) and meta_excluded.csv ({(~healthy_mask).sum()})")
def main():
filter_bcp()
print()
print("[DS-2 Calgary] cohort is typically-developing — nothing to filter.")
print("[DS-3 ds002726] gifted+controls — all healthy — nothing to filter.")
print("[DS-4 ds000248] single healthy adult — nothing to filter.")
print("[DS-5 PTBP] normally-developing — nothing to filter.")
print()
print("Done. Non-healthy BCP scans preserved under DataSet-1/_excluded/")
if __name__ == "__main__":
main()

Xet Storage Details

Size:
2.22 kB
·
Xet hash:
8f6c03eddb30f4fe53c48e8de3afcc81d91d7b887c848b2ec2bd59703ac927e4

Xet efficiently stores files, intelligently splitting them into unique chunks and accelerating uploads and downloads. More info.