From 2fdfd2b90d57ef99070545d8f9008f85f9d87776 Mon Sep 17 00:00:00 2001 From: Daniel Clarke Date: Mon, 9 Sep 2024 16:44:38 -0400 Subject: [PATCH] Construct UMAP from Enrichr Gene Set --- components/service/enrichr/__init__.py | 38 ++++++++++++++++++++++++++ components/service/enrichr/index.tsx | 23 +++++++++++++++- 2 files changed, 60 insertions(+), 1 deletion(-) create mode 100644 components/service/enrichr/__init__.py diff --git a/components/service/enrichr/__init__.py b/components/service/enrichr/__init__.py new file mode 100644 index 00000000..7fc76e71 --- /dev/null +++ b/components/service/enrichr/__init__.py @@ -0,0 +1,38 @@ +import io +import json +import requests +import pandas as pd +import plotly.graph_objects as go +from urllib.parse import quote + +def resolveGenesetLibraryUMAP(enrichrset): + ''' Use the preprocessed Enrichr-Viz-Appyter coordinates to display UMAPs for the gene set libraries + ''' + req = requests.get(f"https://raw.githubusercontent.com/MaayanLab/Enrichr-Viz-Appyter/master/Enrichr-Processed-Library-Storage/Clustered_Scatterplots/{quote(enrichrset['background'])}.csv") + req.raise_for_status() + df = pd.read_csv(io.BytesIO(req.content)) + d_in = df[df['term'].isin(enrichrset['terms'])] + d_out = df[~df['term'].isin(enrichrset['terms'])] + fig = go.Figure(data=[ + go.Scattergl( + name='Relevant Sets', + x=d_in['x'], + y=d_in['y'], + mode='markers', + marker=dict( + color='black', + ), + hovertext=d_in['term'], + ) + ]+[ + go.Scattergl( + name=cluster, + x=d['x'], + y=d['y'], + mode='markers', + opacity=0.1, + hovertext=d['term'], + ) + for cluster, d in d_out.groupby('cluster') + ]) + return json.loads(fig.to_json()) diff --git a/components/service/enrichr/index.tsx b/components/service/enrichr/index.tsx index dec2f8a0..a1696bc8 100644 --- a/components/service/enrichr/index.tsx +++ b/components/service/enrichr/index.tsx @@ -50,6 +50,8 @@ import { Table, Cell, Column } from '@/app/components/Table' import type { ValuesOf } from '@/utils/types' import { downloadBlob } from '@/utils/download' import pluralize from 'pluralize' +import python from '@/utils/python' +import { PlotlyPlot } from '@/components/viz/plotly' const enrichr_url = 'https://maayanlab.cloud/Enrichr' @@ -143,7 +145,26 @@ export const EnrichrSetTToSetT = [ legend: `The significantly enriched gene sets filtered from the gene set library from Enrichr\\ref{doi:10.1002/cpz1.90} stored in the gene matrix transpose (GMT) format\\ref{Gene Matrix Transpose file format, https://software.broadinstitute.org/cancer/software/gsea/wiki/index.php/Data_formats#GMT:_Gene_Matrix_Transposed_file_format_.28.2A.gmt.29}.`, })) .build(), - + MetaNode(`EnrichrSetTToUMAP[${T.name}]`) + .meta({ + label: `${EnrichrSetT.meta.label} as UMAP`, + icon: [enrichr_icon], + description: `Load Enrichr set as UMAP`, + }) + .inputs({ enrichrset: EnrichrSetT }) + .output(PlotlyPlot) + .resolve(async (props) => await python( + 'components.service.enrichr.resolveGenesetLibraryUMAP', + { kargs: [props.inputs.enrichrset] }, + message => props.notify({ type: 'info', message }), + )) + .story(props => ({ + abstract: `Relevant terms are displayed on a gene set library UMAP\\ref{doi:10.48550/arXiv.1802.03426}${props.inputs?.enrichrset?.background ? ` for ${props.inputs.enrichrset.background}` : ''}.`, + introduction: `Profiling samples from patients, tissues, and cells with genomics, transcriptomics, epigenomics, proteomics, and metabolomics ultimately produces lists of genes and proteins that need to be further analyzed and integrated in the context of known biology. Enrichr is a gene set search engine that enables the querying of hundreds of thousands of annotated gene sets\\ref{doi:10.1002/cpz1.90}.`, + methods: `The significantly enriched gene sets from the Enrichr\\ref{doi:10.1002/cpz1.90} results in ${props.input_refs?.enrichrset} are highlighted in a UMAP\\ref{doi:10.48550/arXiv.1802.03426} of the original gene set library to produce ${props.output_ref}.`, + legend: `The relevant gene sets highlighted in a UMAP\\ref{doi:10.48550/arXiv.1802.03426} of the gene set library from Enrichr\\ref{doi:10.1002/cpz1.90}.`, + })) + .build(), ] )