From 1a3945dc13d6507b74f3029b0f42919520f50cb8 Mon Sep 17 00:00:00 2001 From: Spiros Maggioros Date: Wed, 27 Nov 2024 21:22:46 +0200 Subject: [PATCH 1/2] Made function running step appear --- src/workflows/w_sMRI/w_mlscores.py | 76 +++++++++++++++--------------- 1 file changed, 39 insertions(+), 37 deletions(-) diff --git a/src/workflows/w_sMRI/w_mlscores.py b/src/workflows/w_sMRI/w_mlscores.py index e4c70a56..2a45c1f9 100644 --- a/src/workflows/w_sMRI/w_mlscores.py +++ b/src/workflows/w_sMRI/w_mlscores.py @@ -56,9 +56,9 @@ def calc_subject_centiles(df_in: str, df_cent: str, df_dict: str): # Rename centiles roi names rdict = dict(zip(df_dict['Name'], df_dict['Code'])) df_cent['VarName'] = df_cent['VarName'].replace(rdict) - + cent = df_cent.columns[2:].str.replace("centile_", "").astype(int).values - + # Get age bin df_in['Age'] = df_in.Age.round(0) df_in.loc[df_in['Age']>df_cent.Age.max(), 'Age'] = df_cent.Age.max() @@ -66,7 +66,7 @@ def calc_subject_centiles(df_in: str, df_cent: str, df_dict: str): # Find ROIs sel_vars = df_in.columns[df_in.columns.isin(df_cent.VarName.unique())].tolist() - + # For each subject find the centile value of each roi cent_subj_all = np.zeros([df_in.shape[0], len(sel_vars)]) for i, tmp_ind in enumerate(df_in.index): @@ -92,7 +92,7 @@ def calc_subject_centiles(df_in: str, df_cent: str, df_dict: str): # Estimate subj centile cent_subj_all[i,j] = cent[ind1] + slope * (sval - vals_cent[ind1]) - + # Create and save output data df_out = pd.DataFrame(columns=sel_vars, data=cent_subj_all) df_out = pd.concat([df_in[['MRID']], df_out], axis=1) @@ -112,7 +112,7 @@ def run_workflow( max_age=95 suff_combat='_HARM' spare_types=['AD', 'Age'] - icv_ref_val=1430000 + icv_ref_val=1430000 cent_csv=os.path.join( bdir, 'resources', 'centiles', 'istag_centiles_CN_ICV_Corrected.csv' ) @@ -182,7 +182,7 @@ def step_centiles(): # Read input f_in=os.path.join(out_wdir, f"{dset_name}_combat.csv") df_in=pd.read_csv(f_in, dtype={"MRID": str}) - + # Normalize ROIs df_icvcorr=df_in.copy() var_muse=df_icvcorr.columns[df_icvcorr.columns.str.contains('MUSE')] @@ -208,7 +208,7 @@ def step_spare(): # Apply spare df_spare=df_in[['MRID']] - for spare_type in spare_types: + for spare_type in spare_types: spare_mdl=os.path.join(spare_dir, f'{spare_pref}{spare_type}{suff}') f_spare_out=os.path.join(out_wdir, f'{dset_name}_combat_spare_{spare_type}.csv') os.system(f"spare_score -a test -i {f_in} -m {spare_mdl} -o {f_spare_out}") @@ -227,20 +227,20 @@ def step_sgan(): # Read input f_in=os.path.join(out_wdir, f"{dset_name}_rois_init.csv") df_in=pd.read_csv(f_in, dtype={"MRID": str}) - + # Select input sel_covars=['MRID', 'Age', 'Sex', 'DLICV'] sel_vars=sel_covars + list_muse_single df_sel=df_in[sel_vars] f_sgan_in=os.path.join(out_wdir, f"{dset_name}_sgan_in.csv") df_sel.to_csv(f_sgan_in, index=False) - + # Run prediction f_sgan_out=os.path.join(out_wdir, f"{dset_name}_sgan_init.csv") - cmd = f'PredCRD -i {f_sgan_in} -o {f_sgan_out}' + cmd = f'PredCRD -i {f_sgan_in} -o {f_sgan_out}' print(f'About to run {cmd}') os.system(cmd) - + # Edit columns df_sgan=pd.read_csv(f_sgan_out) df_sgan.columns=['MRID'] + df_sgan.add_prefix('SurrealGAN_').columns[1:].tolist() @@ -257,26 +257,26 @@ def step_sgan(): # Read roi lists df_tmp=pd.read_csv(csv_muse_single) list_muse_single=df_tmp.Code.tolist() - + # Read data df = pd.read_csv(in_csv, dtype={"MRID": str}) df.columns = df.columns.astype(str) - + # Rename ROIs df_roidict = pd.read_csv(csv_muse_all) df_roidict.Index = df_roidict.Index.astype(str) vdict = df_roidict.set_index('Index')['Code'].to_dict() df=df.rename(columns=vdict) - + # Keep DLICV in a separate df df_icv=df[['MRID', 'MUSE_702']] df_icv.columns=['MRID', 'DLICV'] df=df.drop(columns=['MUSE_702']) - + # Add DLICV to demog df_demog = pd.read_csv(in_demog, dtype={"MRID": str}) df_demog = df_demog.merge(df_icv, on='MRID') - + # Add covars df_raw=df.merge(df_demog, on=key_var) f_raw=os.path.join(out_wdir, f"{dset_name}_rois_init.csv") @@ -289,13 +289,15 @@ def step_sgan(): 'SPARE index calculation', 'SurrealGAN index calculation' ] - - for i, sel_func in stqdm( - enumerate(list_func), - desc=f"Running step ...", + + idx = 0 + for sel_func in stqdm( + list_func, + desc=f"Running {list_fnames[idx]}", total=len(list_func), ): sel_func() + idx += 1 # Combine results @@ -313,15 +315,15 @@ def step_sgan(): f_spare=os.path.join(out_wdir, f"{dset_name}_combat_spare-all.csv") df_spare=pd.read_csv(f_spare, dtype={"MRID": str}) df_out=df_out.merge(df_spare, on='MRID') - + f_sgan=os.path.join(out_wdir, f"{dset_name}_sgan.csv") df_sgan=pd.read_csv(f_sgan, dtype={"MRID": str}) df_out=df_out.merge(df_sgan, on='MRID') - + # Write out file f_results = os.path.join(out_dir, f"{dset_name}_DLMUSE+MLScores.csv") df_out.to_csv(f_results, index=False) - + def run_workflow_noharmonization( dset_name, @@ -359,7 +361,7 @@ def step_centiles(): # Read input f_in=os.path.join(out_wdir, f"{dset_name}_rois_init.csv") df_in=pd.read_csv(f_in, dtype={"MRID": str}) - + # Normalize ROIs df_icvcorr=df_in.copy() var_muse=df_icvcorr.columns[df_icvcorr.columns.str.contains('MUSE')] @@ -385,7 +387,7 @@ def step_spare(): # Apply spare df_spare=df_in[['MRID']] - for spare_type in spare_types: + for spare_type in spare_types: spare_mdl=os.path.join(spare_dir, f'{spare_pref}{spare_type}{spare_suff}') f_spare_out=os.path.join(out_wdir, f'{dset_name}_spare_{spare_type}.csv') os.system(f"spare_score -a test -i {f_in} -m {spare_mdl} -o {f_spare_out}") @@ -404,20 +406,20 @@ def step_sgan(): # Read input f_in=os.path.join(out_wdir, f"{dset_name}_rois_init.csv") df_in=pd.read_csv(f_in, dtype={"MRID": str}) - + # Select input sel_covars=['MRID', 'Age', 'Sex', 'DLICV'] sel_vars=sel_covars + list_muse_single df_sel=df_in[sel_vars] f_sgan_in=os.path.join(out_wdir, f"{dset_name}_sgan_in.csv") df_sel.to_csv(f_sgan_in, index=False) - + # Run prediction f_sgan_out=os.path.join(out_wdir, f"{dset_name}_sgan_init.csv") - cmd = f'PredCRD -i {f_sgan_in} -o {f_sgan_out}' + cmd = f'PredCRD -i {f_sgan_in} -o {f_sgan_out}' print(f'About to run {cmd}') os.system(cmd) - + # Edit columns df_sgan=pd.read_csv(f_sgan_out) df_sgan.columns=['MRID'] + df_sgan.add_prefix('SurrealGAN_').columns[1:].tolist() @@ -434,26 +436,26 @@ def step_sgan(): # Read roi lists df_tmp=pd.read_csv(csv_muse_single) list_muse_single=df_tmp.Code.tolist() - + # Read data df = pd.read_csv(in_csv, dtype={"MRID": str}) df.columns = df.columns.astype(str) - + # Rename ROIs df_roidict = pd.read_csv(csv_muse_all) df_roidict.Index = df_roidict.Index.astype(str) vdict = df_roidict.set_index('Index')['Code'].to_dict() df=df.rename(columns=vdict) - + # Keep DLICV in a separate df df_icv=df[['MRID', 'MUSE_702']] df_icv.columns=['MRID', 'DLICV'] df=df.drop(columns=['MUSE_702']) - + # Add DLICV to demog df_demog = pd.read_csv(in_demog, dtype={"MRID": str}) df_demog = df_demog.merge(df_icv, on='MRID') - + # Add covars df_raw=df.merge(df_demog, on=key_var) f_raw=os.path.join(out_wdir, f"{dset_name}_rois_init.csv") @@ -465,7 +467,7 @@ def step_sgan(): 'SPARE index calculation', 'SurrealGAN index calculation' ] - + for i, sel_func in stqdm( enumerate(list_func), desc=f"Running step ...", @@ -489,11 +491,11 @@ def step_sgan(): f_spare=os.path.join(out_wdir, f"{dset_name}_spare-all.csv") df_spare=pd.read_csv(f_spare, dtype={"MRID": str}) df_out=df_out.merge(df_spare, on='MRID') - + f_sgan=os.path.join(out_wdir, f"{dset_name}_sgan.csv") df_sgan=pd.read_csv(f_sgan, dtype={"MRID": str}) df_out=df_out.merge(df_sgan, on='MRID') - + # Write out file f_results = os.path.join(out_dir, f"{dset_name}_DLMUSE+MLScores.csv") df_out.to_csv(f_results, index=False) From ed4a366c1ef4204a2dcd044e636a8d558de4c508 Mon Sep 17 00:00:00 2001 From: Spiros Maggioros Date: Wed, 27 Nov 2024 21:28:40 +0200 Subject: [PATCH 2/2] Fixed readme installation instructions --- README.md | 21 ++++----------------- 1 file changed, 4 insertions(+), 17 deletions(-) diff --git a/README.md b/README.md index c358c8ee..4ee52613 100644 --- a/README.md +++ b/README.md @@ -17,23 +17,10 @@ NiChart is a comprehensive framework designed to revolutionize neuroimaging rese For recommended system configuration, please refer to: [nnUNet hardware requirements](https://github.com/MIC-DKFZ/nnUNet/blob/master/documentation/installation_instructions.md#hardware-requirements). ## Installation Instructions - -1. Mamba installation - [Mamba Installation Guide (Official)](https://mamba.readthedocs.io/en/latest/installation/mamba-installation.html) - - Example (Linux x86): - ```bash - wget https://github.com/conda-forge/miniforge/releases/latest/download/Mambaforge-Linux-x86_64.sh - - bash Mambaforge-Linux-x86_64.sh - mamba create -c conda-forge -c bioconda -n NCP_env python=3.12 snakemake - mamba activate NCP_env - ``` -2. Manual installation - ```bash - git clone https://github.com/CBICA/NiChart_Project.git - pip install -r requirements.txt - ``` + ```bash + git clone https://github.com/CBICA/NiChart_Project.git + pip install -r requirements.txt + ``` ## Run NiChart Locally (GUI) ```bash