<jupyter_start><jupyter_text>Assessing pathways and drug targets in Cyclic Multiplexed-Immunofluorescence (cmIF) image biomarkersResource: https://www.ncbi.nlm.nih.gov/pubmed/315021681. After mapping proteins to gene names, we wrangle the matrix into a dictionary where each image section would hold the biomarkers as its values.<jupyter_code>path = "data/marker_matrix_gene.csv"

df = pandas.read_csv(path, index_col=0)
df = df.apply(lambda x : x.str.split(","), axis=0)
row_dict = df.T.to_dict('records')

def imggenes2dict(row_dict):
    dd = defaultdict(list)
    dict_items = map(methodcaller('items'), row_dict)
    
    for k, v in chain.from_iterable(dict_items):
        dd[k].extend(v)
    
    img_dict = dict(dd)
    return(img_dict)

img_dict = imggenes2dict(row_dict)<jupyter_output><empty_output><jupyter_text>2. Now we can pass the biomarkers to fetch all possible reactome pathways available for each image segment.<jupyter_code>result = [analysis.identifiers(ids=",".join(d)) for d in img_dict.values()]
tokens = [r['summary']['token'] for r in result]


def get_pathways(t):
    token_result = analysis.token(token=t, species='Homo sapiens', page_size='-1', page='-1', sort_by='ENTITIES_FDR', 
                                  order='ASC', resource='TOTAL', p_value='1', include_disease=True, 
                                  min_entities=None, max_entities=None)
    l = [p['name'] for p in token_result['pathways']]
    l.sort() 
    return(l)

pathways = [get_pathways(t) for t in tokens]<jupyter_output><empty_output><jupyter_text>3. Given the biomarkers, we can also fetch all available drug targets from Drug Central.<jupyter_code>result_drug_targets = [utils.genelist_drug_target(ids=",".join(d), source="drugcentral") for d in img_dict.values()]<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.12354570637119114, 'fraction_numerical': 0.009972299168975069, 'mean_word_length': 4.591331269349845, 'pattern_counts': {'":': 0, '<': 13, '<?xml version=': 0, '>': 13, 'https://': 1, 'lorem ipsum': 0, 'www.': 1, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 2, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '3', 'dir': 'jupyter-structured-clean-dedup', 'id': '327574', 'license': 'Apache-2.0', 'n_tokens_mistral': 639, 'n_tokens_neox': 593, 'n_words': 142, 'path': 'demo/img2path.ipynb', 'repo_name': 'reactome/reactome2py', 'size': '1805'}