New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add new CLI script to compute normalized metric ratios (MSCC, etc.) for compressed levels #4003
Merged
joshuacwnewton
merged 224 commits into
master
from
sb/3733-bring-metrics-to-pam50-add_mscc
Jul 11, 2023
Merged
Add new CLI script to compute normalized metric ratios (MSCC, etc.) for compressed levels #4003
joshuacwnewton
merged 224 commits into
master
from
sb/3733-bring-metrics-to-pam50-add_mscc
Jul 11, 2023
Conversation
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
8 tasks
This commit also simplifies get_slice_thickness and loading of PAM50. Now, PAM50 is loaded only once (previously was loaded for every level)
Distinguishing between the PAM50 z_range and the centerline z_range will help to make further refactors clearer.
This dict is necessary to properly compute the non-normalized `diameter_AP_ratio` quantity.
The first computed ratio (`{metric}_ratio`) should be consistent, regardless of whether `normalize_hc` is specified.
Before, this quantity would overlap with the `diameter_AP_ratio` key. Now, it is its own separate quantity.
This now matches the pattern suggested by Jan. :) Co-authored-by: Jan Valosek <39456460+valosekj@users.noreply.github.com>
This now better matches the order of the steps inside the loop, too.
joshuacwnewton
changed the title
Morphometric normalization
Add new CLI script to compute normalized metric ratios (MSCC, etc.) for compressed levels
Jun 29, 2023
sct_compute_compression
This was referenced Jun 30, 2023
This now ACTUALLY matches the pattern suggested by Jan. :) Co-authored-by: Jan Valosek <39456460+valosekj@users.noreply.github.com>
valosekj
approved these changes
Jul 11, 2023
joshuacwnewton
approved these changes
Jul 11, 2023
Thank you so much @sandrinebedard and @valosekj for this massive effort! |
@joshuacwnewton thank you for your detailed review and help! 💯 |
1 task
valosekj
added a commit
to sct-pipeline/dcm-metric-normalization
that referenced
this pull request
Aug 16, 2023
valosekj
added a commit
to sct-pipeline/dcm-metric-normalization
that referenced
this pull request
Aug 24, 2023
valosekj
added a commit
to sct-pipeline/dcm-metric-normalization
that referenced
this pull request
Mar 26, 2024
* initial commit database * get the max compression * add mjoa correlation graphs and mean±std * add logistic reg * add ratio for categorical data and add r coeff on mscc graphs * add ratio norm vs no norm graphs * Update requirements.txt * Rename metrics to METRICS and metrics_norm to METRICS_NORM to indicate that they are global variables * Improve insertion of text with corr coef and pval * Add function docstrings * Improve output figure filenames * Fix typos and small formatting issues * add kfold cross-validation * fix name * compute z scores * add ratio of levels groupby therapeutic decision * change for repeated k fold and add composite z scores * add VIF * add logistic for composite z score * Move code for the prediction of therapeutic_decision into a separate function * Add functions to predict mJOA after 6m and 12m * Expand regression functions to allow to compute either logistic or linear regression * Add function to compare mJOA change between subjects with therapeutic_decision == 0 and subjects with therapeutic_decision == 1 * OS compatibility formatting fixes * Add TODO * Remove code which have been moved under predict_theurapeutic_decision function * Fix variable name * Remove plot.show * Create sns.regplot between sex and weight * Improve script description, help and args help * add 95% CI for ROC curves * Remove 'id' since it is probably not necessary? * Add missing space * Add TODO - read table with electrophysiology, anatomical and motion data * Small fixes * read electrophysiological data * load electrophysiological data * Make 'electro_file' non-required arg * Read also ASIA/GRASSP subscores * Update predict_theurapeutic_decision function docstring * Print Candidate predictors * Remove spaces * Print where ROC curves are saved * Read also mJOA subscores - motor_dysfunction_UE_bl - motor_dysfunction_LE_bl - sensory_dysfunction_LE_bl - sphincter_dysfunction_bl * Print only 2 Candidate predictors perline * Plot and save correlation matrix for mJOA, mJOA subscores, and ASIA/GRASSP * Create read_clinical_file function to read clinical file * Move correlation plotting into a separate function * Simplify columns renaming in read_clinical_file function * Add plt.close() * Update input args description; make '-electro-file' required again * Add read_electrophysiology_and_anatomical_file function to read electrophysiology and anatomical data * Read separately anatomical_df and electrophysiology_df dataframes * Rename df_combined to df_morphometrics to improve code readability * Plot and save correlation matrix for anatomical (aSCOR and aMSCC) and morphometric metrics * Small code improvments * Drop columns with more than 25% nan values for correlation analysis * Add per level correlations for anatomical (aSCOR and aMSCC) and morphometric metrics * Read also motion data * Plot and save correlation matrix for motion data * Update docstring and prints * Keep two levels for aSCOR and aMSCC correlations * Create regplot for anatomical (aSCOR and aMSCC) and morphometric metrics * Add loop across metrics to create_regplot_anatomical_and_morphometric_metrics function * add function to merge df for reg * Improve figure titles * Drop 6m and 12m anatomical metrics. Because we have only baseline values for our morphometric metrics * Drop 6m and 12m anatomical metrics. Because we have only baseline values for our morphometric metrics * Insert text box with correlation coefficient to regplots * Put number of subjects into title of all correlations plots. Drop subjects with nan for clinical scores corr matrix. * Add textbox with correlation coefficient and p-value * Merge all dataframes for prediction * fix change mjoa for total mjoa and lenght of y * add motion data to dataframe * Update function for plotting of correlation matrix and pairplot for anatomical (aSCOR and aMSCC) and morphometric metrics * Rename electrophysiology_and_anatomical_df to df_all * Read also electrophysiology data; rename function to read_electrophysiology_anatomical_and_motion_file * Set index to participant_id' right in read_electrophysiology_anatomical_and_motion_file function * Move nan dropping into the relevant functions * Remove create_regplot_anatomical_and_morphometric_metrics function -- it is no longer relevant and was replaced by compute_correlations_anatomical_and_morphometric_metrics * Docstring update * Move nan dropping for weight and height to the relevant function * Improve comments, remove unused code * Use final_df for compute_correlations_motion_and_morphometric_metrics function * Introduce generate_correlation_matrix function to simplify the code * Introduce generate_pairplot function to simplify the code * Generate pairplot also for motion and clinical data * Add print to generate_pairplot function * Fix formatting * Implement read_metric_file() function to read CSV file with computed metrics * Compare read_metric_file() with read_MSCC() * Remove debug code printing repeated indices * Finalize read_metric_file() function to keep only levels with max compression * Add comments * Add TODO that name dict_exclude_subj is confusing -- it's not a dict, it's a list * Fix typo * Update merge_anatomical_morphological_final_for_pred() function to be compatible with read_metric_file() * Remove read_MSCC() function and relevant ifolder input arg * Update '-input-file' input arg * Rename metric names to be compatible with updated names - for details see spinalcordtoolbox/spinalcordtoolbox#4003 (comment) * update names * update names saved now * add a todo to update * fix columns drop with new naming * Move SmartFormatter class to utils.py * Move SmartFormatter class to utils.py * Remove unused csv2dataFrame function * Move read_metric_file and fetch_participant_id functions to utils.py * Move read_participants_file function to utils.py * Move read_clinical_file function to utils.py * Move read_electrophysiology_anatomical_and_motion_file function to utils.py * Remove unused print * Move format_pvalue function to utils.py * Move compute_spearmans function to utils.py * Create utils folder. Move utils.py into the util folder. Create utils/read_files.py. Move relevant functions from utils.py to utils/read_files.py * Move plotting functions under utils/generate_figures.py. Add logger as input arg to the plotting functions. * Move fit_reg function to utils.py * Remove unused import * Remove spaces and empty lines * Move plot_correlation_for_clinical_scores function under generate_figures.py * Move compute_correlations_motion_and_morphometric_metrics function under generate_figures.py and rename it to plot_correlations_motion_and_morphometric_metrics * Pass logger to plot_correlation_for_clinical_scores * Move compute_correlations_anatomical_and_morphometric_metrics function to generate_figures.py and rename it to plot_correlations_anatomical_and_morphometric_metrics * Remove unused imports * Move merge_anatomical_morphological_final_for_pred function to read_files.py * Fix import from utils.py * add logger as arg * Split read_electrophysiology_anatomical_and_motion_file function into read_electrophysiology_file, read_anatomical_file, and read_motion_file functions to make the scripts compatible with XLSX files under phenotype folder * rmeove 2 variables to create model * add grid and comments * Allow to read motion_data_maximum_stenosis.xlsx with motion data from the maximum stenosis level * fix stepwise backward * last fixes --------- Co-authored-by: sandrinebedard <sandrine.bedard@polymtl.ca>
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Checklist
GitHub
PR contents
Description
This issue is related to #3733. It computes normalized metrics ratio (MSCC and others) using a reference dataset of healthy subject in the PAM50 anatomical space. It calls
sct_process_segmentation
to generate the spinal cord morphometrics perslice in the native space and in the PAM50 anatomical dimensions (if-normalize
1) to compute the metric ratio.It relies on 3 inputs:
How to test
Prepare the development environment by running:
Download the reference dataset of healthy controls to
$SCT_DIR/data/
by running:Generate the 3 necessary input files from this subject file: sub-twh018_T2w.nii.gz
sub-twh018_T2w_compression_labels.nii.gz
)Run the following example commands:
Compute ratio of (diameter ap):
Compute ratio of area (CSA):
Test specifying sex and age range
Test without normalization
What is left
Linked issues
Fixes #3733.