Skip to content

Commit

Permalink
Construct UMAP from Enrichr Gene Set
Browse files Browse the repository at this point in the history
  • Loading branch information
u8sand committed Sep 9, 2024
1 parent 9a93a82 commit 2fdfd2b
Show file tree
Hide file tree
Showing 2 changed files with 60 additions and 1 deletion.
38 changes: 38 additions & 0 deletions components/service/enrichr/__init__.py
Original file line number Diff line number Diff line change
@@ -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())
23 changes: 22 additions & 1 deletion components/service/enrichr/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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'

Expand Down Expand Up @@ -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(),
]
)

Expand Down

0 comments on commit 2fdfd2b

Please sign in to comment.