<jupyter_start><jupyter_text>Load data<jupyter_code>adni.load(show_output=False)<jupyter_output><empty_output><jupyter_text>Display MetaData<jupyter_code>meta_df = adni.meta_to_df()
sprint.pd_cols(meta_df)<jupyter_output><empty_output><jupyter_text>Display ImageFiles<jupyter_code>files_df = adni.files_to_df()
sprint.pd_cols(files_df)
adni_df = adni.to_df()
sprint.pd_cols(adni_df)<jupyter_output><empty_output><jupyter_text>Analysis  Overview<jupyter_code>fig, axes = splot.meta_settings(rows=3)

splot.histplot(
    adni_df, 
    x='subject.researchGroup', 
    hue='subject.subjectSex',
    ax=axes[0,0],
    plot_kws={'stat':'frequency'},
    legend_kws={'title':'ResearchGroup'},
    setting_kws={'title':'ResearchGroup distribution','xlabel':'Disorder'}
)

splot.histplot(
    adni_df, 
    x='subject.subjectIdentifier', 
    ax=axes[0,1],
    plot_kws={'stat':'frequency'},
    legend_kws={'title':'ResearchGroup'},
    setting_kws={'title':'SubjectIdentifier distribution','xlabel':'subjectIdentifier','rotation':90}
)

splot.histplot(
    adni_df, 
    x='subject.subjectSex', 
    ax=axes[1,0],
    plot_kws={'stat':'frequency'},
    legend_kws={'title':'ResearchGroup'},
    setting_kws={'title':'SubjectSex distribution','xlabel':'subjectSex'}
)

splot.histplot(
    adni_df, 
    x='subject.study.subjectAge',
    hue='subject.subjectSex',
    discrete=False,
    ax=axes[1,1],
    plot_kws={'element':'poly','fill':False},
    legend_kws={'title':'ResearchGroup'},
    setting_kws={'title':'SubjectAge distribution'}
)

splot.histplot(
    adni_df, 
    x='subject.study.series.dateAcquired',
    hue='subject.researchGroup',
    discrete=False,
    ax=axes[2,0],
    plot_kws={},
    legend_kws={'title':'ResearchGroup'},
    setting_kws={'title':'SubjectAge distribution'}
)

splot.histplot(
    adni_df, 
    x='subject.study.weightKg',
    hue='subject.subjectSex',
    discrete=False,
    ax=axes[2,1],
    plot_kws={'element':'poly','fill':False},
    legend_kws={'title':'subjectSex'},
    setting_kws={'title':'weightKg distribution'}
)


plt.show()<jupyter_output><empty_output><jupyter_text>Data sizes<jupyter_code>fig, axes = splot.meta_settings(rows=2,figsize=(15,10))

splot.histplot(
    adni_df, 
    discrete=False,
    x='subject.study.imagingProtocol.protocolTerm.protocol.Number_of_Slices', 
    hue='subject.researchGroup', 
    multiple='stack',
    ax=axes[0,0],
    plot_kws={'stat':'frequency'},
    legend_kws={'title':'ResearchGroup'},
    setting_kws={'title':'Number of Slices','xlabel':'Slices','ylabel':'Frequency'}
)
splot.histplot(
    adni_df, 
    discrete=False,
    x='subject.study.imagingProtocol.protocolTerm.protocol.Number_of_Columns', 
    hue='subject.researchGroup', 
    multiple='stack',
    ax=axes[0,1],
    plot_kws={'stat':'frequency'},
    legend_kws={'title':'ResearchGroup'},
    setting_kws={'title':'Number of Columns','xlabel':'Slices','ylabel':'Frequency'}
)
splot.histplot(
    adni_df, 
    discrete=False,
    x='subject.study.imagingProtocol.protocolTerm.protocol.Number_of_Rows', 
    hue='subject.researchGroup', 
    multiple='stack',
    ax=axes[1,0],
    plot_kws={'stat':'frequency'},
    legend_kws={'title':'ResearchGroup'},
    setting_kws={'title':'Number of Rows','xlabel':'Slices','ylabel':'Frequency'}
)
plt.show()<jupyter_output><empty_output><jupyter_text>Scoring<jupyter_code>fig, axes = splot.meta_settings(rows=3)

splot.histplot(
    adni_df, 
    discrete=True,
    x='subject.visit.assessment.component.assessmentScore.FAQTOTAL', 
    hue='subject.researchGroup', 
    multiple='stack',
    ax=axes[0,0],
    plot_kws={'stat':'frequency'},
    legend_kws={'title':'ResearchGroup'},
    setting_kws={'title':'Functional Activities Questionnaires (FAQTOTAL)','xlabel':'Score','ylabel':'Frequency'}
)

splot.histplot(
    adni_df, 
    discrete=True,
    x='subject.visit.assessment.component.assessmentScore.NPISCORE', 
    hue='subject.researchGroup', 
    multiple='stack',
    ax=axes[0,1],
    legend_kws={'title':'ResearchGroup'},
    setting_kws={'title':'assessmentScore_NPISCORE','xlabel':'Score','ylabel':'Frequency'}
)

splot.histplot(
    adni_df, 
    discrete=True,
    x='subject.visit.assessment.component.assessmentScore.CDGLOBAL', 
    hue='subject.researchGroup', 
    multiple='stack',
    ax=axes[1,0],
    legend_kws={'title':'ResearchGroup'},
    setting_kws={'title':'Clinical Dementia Rating Scale (CDGLOBAL)','xlabel':'Score','ylabel':'Frequency'}
)

splot.histplot(
    adni_df, 
    discrete=True,
    x='subject.visit.assessment.component.assessmentScore.GDTOTAL', 
    hue='subject.researchGroup', 
    multiple='stack',
    ax=axes[1,1],
    legend_kws={'title':'ResearchGroup'},
    setting_kws={'title':'assessmentScore.GDTOTAL','xlabel':'Score','ylabel':'Frequency'}
)

splot.histplot(
    adni_df, 
    discrete=True,
    x='subject.visit.assessment.component.assessmentScore.MMSCORE', 
    hue='subject.researchGroup', 
    multiple='stack',
    ax=axes[2,0],
    legend_kws={'title':'ResearchGroup'},
    setting_kws={'title':'Mini-Mental State Examination (MMSCORE)','xlabel':'Score','ylabel':'Frequency'}
)

splot.histplot(
    adni_df, 
    x='subject.visit.assessment.component.assessmentScore.MMSCORE',
    hue='subject.researchGroup',
    discrete=False,
    ax=axes[2,1],
    plot_kws={'element':'poly','fill':False},
    legend_kws={'title':'ResearchGroup'},
    setting_kws={'title':'MMSE Score per Condition'}
)

plt.show()<jupyter_output><empty_output><jupyter_text>Visualise brain slices  Create Image generator<jupyter_code>SKIP_LAYERS = 10
LIMIT_LAYERS = 70
image_AD_generator = adni.load_images(
    files=adni.load_files(adni.path.category+'AD/', adni.filename_category, use_processed=True)
)
image_CN_generator = adni.load_images(
    files=adni.load_files(adni.path.category+'CN/', adni.filename_category, use_processed=True)
)
image_MCI_generator = adni.load_images(
    files=adni.load_files(adni.path.category+'MCI/', adni.filename_category, use_processed=True)
)
### Testing functions
from nilearn.plotting import view_img, plot_glass_brain, plot_anat, plot_epi
test_image = next(image_CN_generator)
test_image.shape
while True:
    test_image = next(image_AD_generator)
    plot_anat(test_image, draw_cross=False, display_mode='z',cut_coords=20,annotate=False)
    plt.show()
    break
images_AD_array = adni.to_array(list(image_AD_generator))
images_CN_array = adni.to_array(list(image_CN_generator))
images_MCI_array = adni.to_array(list(image_MCI_generator))
images_AD = next(images_AD_array)
images_CN = next(images_CN_array)
images_MCI = next(images_CN_array)<jupyter_output><empty_output><jupyter_text>Coronal plane (From top)<jupyter_code>image_AD_slices = [images_AD[layer,:,:] for layer in range(0,images_AD.shape[0],SKIP_LAYERS)]
dplay.display_advanced_plot(image_AD_slices)
plt.suptitle("Coronal plane - AD")  

image_CN_slices = [images_CN[layer,:,:] for layer in range(0,images_CN.shape[0],SKIP_LAYERS)]
dplay.display_advanced_plot(image_CN_slices)
plt.suptitle("Coronal plane - CN")  
image_MCI_slices = [images_MCI[layer,:,:] for layer in range(0,images_MCI.shape[0],SKIP_LAYERS)]
dplay.display_advanced_plot(image_MCI_slices)
plt.suptitle("Coronal plane - MCI")<jupyter_output><empty_output><jupyter_text>Sagittal plane (From front)<jupyter_code>image_slices = [images_AD[:,layer,:] for layer in range(0,images_AD.shape[1], SKIP_LAYERS)]
dplay.display_advanced_plot(image_slices)
plt.suptitle("Sagittal plane")<jupyter_output><empty_output><jupyter_text>Horisontal plane (from side)<jupyter_code>image_slices = [images_AD[:,:,layer] for layer in range(0,images_AD.shape[2], SKIP_LAYERS)]
dplay.display_advanced_plot(image_slices)
plt.suptitle("Horisonal plane")<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.1596238082968307, 'fraction_numerical': 0.007085802628188611, 'mean_word_length': 6.464423076923077, 'pattern_counts': {'":': 0, '<': 41, '<?xml version=': 0, '>': 41, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '10', 'dir': 'jupyter-structured-clean-dedup', 'id': '667567', 'license': 'Apache-2.0', 'n_tokens_mistral': 2990, 'n_tokens_neox': 2827, 'n_words': 293, 'path': 'notebooks/00 - visualisation.ipynb', 'repo_name': 'FredrikM97/Medical-ROI', 'size': '7762'}