<jupyter_start><jupyter_text>Analysis of cognitive atlas terms in openneuro metadataUsing data generated by find_cogat_matches.py, saved to ../data/openneuro/cogatlas_matches.json<jupyter_code>import pandas as pd
import json
from collections import defaultdict
import matplotlib.pyplot as plt
from wordcloud import WordCloud

with open('../data/openneuro/cogatlas_matches.json') as f:
    cogatlas_matches = json.load(f)
# get matches for each class of terms

def split_matches_by_type(allmatches):
    match_dict = {}
    for ds, matches in allmatches.items():
        for match in matches:
            matchtype, term = match[1], match[0]
            if matchtype not in match_dict:
                match_dict[matchtype] = defaultdict(lambda: [])
            match_dict[matchtype][ds].append(term)
    return(match_dict)

matches_by_type = split_matches_by_type(cogatlas_matches)
# summarize concept terms

def get_terms_df(term_dict):
    # return long df with terms for each dataset
    allterms = []
    for k, terms in term_dict.items():
        # note: remove repetitions of a term within a dataset
        for term in list(set(terms)):
            allterms.append([k, term])
    
    return(pd.DataFrame(allterms, columns=['ds', 'terms']))

concept_df = get_terms_df(matches_by_type['concept'])
concept_df.head()
concept_df.terms.value_counts()<jupyter_output><empty_output><jupyter_text>word cloud for concepts<jupyter_code># drop these terms because they are generally not being used as cognitive concepts in this context
stopterms = ['fixation', 'activation']
concept_text = ' '.join([i.replace(' ', '_') for i in concept_df.terms if i not in stopterms])

wc = WordCloud(background_color="white",
               repeat=False, relative_scaling=.5,
              width=800, height=600)
wc.generate(concept_text)

plt.axis("off")
plt.imshow(wc, interpolation="bilinear")
plt.tight_layout()
plt.savefig('../figures/wordcloud_concept.png')

plt.show()<jupyter_output><empty_output><jupyter_text>word cloud for tasks<jupyter_code>task_df = get_terms_df(matches_by_type['task'])

stopterms = ['criteria task']
def cleanup_text(t):
    bespoke_replacements = {' ': '_',
                            '-': '_',
                            '_task': '',
                            '_test': '',
                            '_fmri_paradigm': ''}
    for orig, repl in bespoke_replacements.items():
        t = t.replace(orig, repl)
    return(t)

task_text = ' '.join([cleanup_text(i) for i in task_df.terms if i not in stopterms])

wc = WordCloud(background_color="white",
               repeat=False, relative_scaling=0,
              width=800, height=600)
wc.generate(task_text)


plt.axis("off")
plt.imshow(wc, interpolation="bilinear")
plt.tight_layout()
plt.savefig('../figures/wordcloud_task.png')

plt.show()<jupyter_output><empty_output><jupyter_text>word cloud for disorders<jupyter_code>disorder_df = get_terms_df(matches_by_type['disorder'])

stopterms = []
disorder_text = ' '.join([i.replace(' ', '_').replace('-', '_') for i in disorder_df.terms if i not in stopterms])

wc = WordCloud(background_color="white",
               repeat=False, relative_scaling=0,
              width=800, height=400)
wc.generate(disorder_text)

plt.savefig('../figures/wordcloud_disorder.png')

plt.axis("off")
plt.imshow(wc, interpolation="bilinear")
plt.show()<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.12374483165977555, 'fraction_numerical': 0.006792675723567632, 'mean_word_length': 3.7838983050847457, 'pattern_counts': {'":': 0, '<': 17, '<?xml version=': 0, '>': 17, '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': '4', 'dir': 'jupyter-structured-clean-dedup', 'id': '488540', 'license': 'MIT', 'n_tokens_mistral': 1148, 'n_tokens_neox': 1072, 'n_words': 234, 'path': 'metadata_analyses/CogAtlasTerms.ipynb', 'repo_name': 'oesteban/OpenNeuro_analyses', 'size': '3386'}