Spaces:
Sleeping
Sleeping
Upload 5 files
Browse files- STRINGdb_data.tsv +14 -0
- app.py +206 -0
- banner.png +0 -0
- colocalisation_results.csv +0 -0
- requirements.txt +6 -0
STRINGdb_data.tsv
ADDED
|
@@ -0,0 +1,14 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
node1 node2 node1_string_id node2_string_id neighborhood_on_chromosome gene_fusion phylogenetic_cooccurrence homology coexpression experimentally_determined_interaction database_annotated automated_textmining combined_score
|
| 2 |
+
CRHR1 MAPT 9606.ENSP00000381333 9606.ENSP00000340820 0 0 0 0 0.172 0 0 0.717 0.755
|
| 3 |
+
EPHA2 ITGB3 9606.ENSP00000351209 9606.ENSP00000452786 0 0 0 0 0.056 0.300 0 0.366 0.544
|
| 4 |
+
EPHA2 PTPN11 9606.ENSP00000351209 9606.ENSP00000489597 0 0 0 0 0.083 0.455 0 0.773 0.877
|
| 5 |
+
ITGB3 RAF1 9606.ENSP00000452786 9606.ENSP00000401888 0 0 0 0 0 0.052 0.500 0.086 0.529
|
| 6 |
+
ITGB3 PTPN11 9606.ENSP00000452786 9606.ENSP00000489597 0 0 0 0 0.106 0.328 0 0.492 0.668
|
| 7 |
+
MAPT NPEPPS 9606.ENSP00000340820 9606.ENSP00000320324 0 0 0 0 0.056 0.319 0 0.480 0.636
|
| 8 |
+
MAPT PTPN11 9606.ENSP00000340820 9606.ENSP00000489597 0 0 0 0 0 0.303 0 0.513 0.646
|
| 9 |
+
MYL2 RPL6 9606.ENSP00000228841 9606.ENSP00000403172 0 0 0 0 0.067 0 0 0.568 0.580
|
| 10 |
+
MYL2 TNNT3 9606.ENSP00000228841 9606.ENSP00000370975 0 0 0 0 0.510 0.127 0.500 0.500 0.879
|
| 11 |
+
MYL2 MYL4 9606.ENSP00000228841 9606.ENSP00000347055 0 0 0 0.673 0.168 0.311 0.900 0.584 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|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import streamlit as st
|
| 2 |
+
import re
|
| 3 |
+
import pandas as pd
|
| 4 |
+
import networkx as nx
|
| 5 |
+
import numpy as np
|
| 6 |
+
import matplotlib.pyplot as plt
|
| 7 |
+
from matplotlib import cm
|
| 8 |
+
|
| 9 |
+
st.image("banner.png", use_column_width=True)
|
| 10 |
+
st.markdown(
|
| 11 |
+
"<h1 style='text-align: center;'>CMR and Heart Failure Colocalisation Viewer</h1>",
|
| 12 |
+
unsafe_allow_html=True
|
| 13 |
+
)
|
| 14 |
+
|
| 15 |
+
# Description text
|
| 16 |
+
st.markdown(
|
| 17 |
+
"""
|
| 18 |
+
This interactive app allows you to explore colocalising genes between cardiovascular magnetic resonance image (CMR) traits and heart failure (HF) that have interacting drugs.
|
| 19 |
+
You can input multiple HGNC gene names or disease terms to filter the dataset or enter a single gene for more detailed information.
|
| 20 |
+
Additionally, you can visualize a protein interaction network for specific genes using STRINGdb data.
|
| 21 |
+
""",
|
| 22 |
+
unsafe_allow_html=True
|
| 23 |
+
)
|
| 24 |
+
|
| 25 |
+
# Load and prepare colocalisation results
|
| 26 |
+
annotations = pd.read_csv("colocalisation_results.csv")
|
| 27 |
+
annotations.fillna(0, inplace=True)
|
| 28 |
+
annotations = annotations.set_index("Gene")
|
| 29 |
+
|
| 30 |
+
# Define a function to collect genes from input
|
| 31 |
+
collect_genes = lambda x: [str(i) for i in re.split(",|,\s+|\s+", x) if i != ""]
|
| 32 |
+
input_gene_list = st.text_input("Input a list of multiple HGNC genes (enter comma separated):")
|
| 33 |
+
gene_list = collect_genes(input_gene_list)
|
| 34 |
+
|
| 35 |
+
# Function to convert DataFrame to CSV for download
|
| 36 |
+
@st.cache_data
|
| 37 |
+
def convert_df(df):
|
| 38 |
+
return df.to_csv(index=False).encode('utf-8')
|
| 39 |
+
|
| 40 |
+
# Filter based on gene list
|
| 41 |
+
st.markdown("### View colocalisation results for selected genes or the entire dataset.")
|
| 42 |
+
|
| 43 |
+
if len(gene_list) > 1:
|
| 44 |
+
# Filter for input gene list
|
| 45 |
+
df = annotations[annotations.index.isin(gene_list)]
|
| 46 |
+
df['Gene'] = df.index
|
| 47 |
+
df.reset_index(drop=True, inplace=True)
|
| 48 |
+
|
| 49 |
+
# Reorder columns to have "Gene" as the first column
|
| 50 |
+
df = df[['Gene'] + [col for col in df.columns if col != 'Gene']]
|
| 51 |
+
|
| 52 |
+
# Display the filtered results
|
| 53 |
+
st.dataframe(df)
|
| 54 |
+
output = df[['Gene']]
|
| 55 |
+
csv = convert_df(output)
|
| 56 |
+
# st.download_button("Download Filtered Colocalisation Results", csv, "filtered_colocalisation_results.csv", "text/csv", key='download-csv')
|
| 57 |
+
|
| 58 |
+
# Add a new search box for filtering by disease name
|
| 59 |
+
input_disease = st.text_input("Input a disease name to search in drug terms (partial match allowed):")
|
| 60 |
+
|
| 61 |
+
if input_disease:
|
| 62 |
+
# Search for partial matches in the "terms_drug" column
|
| 63 |
+
df_disease_filtered = annotations[annotations['terms_drug'].str.contains(input_disease, case=False, na=False)]
|
| 64 |
+
|
| 65 |
+
if not df_disease_filtered.empty:
|
| 66 |
+
st.markdown(f"### Colocalisation results for disease: {input_disease}")
|
| 67 |
+
df_disease_filtered['Gene'] = df_disease_filtered.index
|
| 68 |
+
df_disease_filtered.reset_index(drop=True, inplace=True)
|
| 69 |
+
|
| 70 |
+
# Reorder columns to have "Gene" as the first column
|
| 71 |
+
df_disease_filtered = df_disease_filtered[['Gene'] + [col for col in df_disease_filtered.columns if col != 'Gene']]
|
| 72 |
+
|
| 73 |
+
# Display filtered dataframe
|
| 74 |
+
st.dataframe(df_disease_filtered)
|
| 75 |
+
|
| 76 |
+
# Convert filtered dataframe to CSV for download
|
| 77 |
+
csv_disease_filtered = convert_df(df_disease_filtered)
|
| 78 |
+
# st.download_button("Download Filtered Colocalisation Results", csv_disease_filtered, "filtered_colocalisation_disease_results.csv", "text/csv", key='download-disease-csv')
|
| 79 |
+
else:
|
| 80 |
+
st.write(f"No results found for disease: {input_disease}")
|
| 81 |
+
|
| 82 |
+
# Display individual gene details if a single gene is input
|
| 83 |
+
input_gene = st.text_input("Input an individual HGNC gene:")
|
| 84 |
+
if input_gene:
|
| 85 |
+
df2 = annotations[annotations.index == input_gene]
|
| 86 |
+
if not df2.empty:
|
| 87 |
+
df2['Gene'] = df2.index
|
| 88 |
+
df2.reset_index(drop=True, inplace=True)
|
| 89 |
+
|
| 90 |
+
# Reorder columns to have "Gene" as the first column
|
| 91 |
+
df2 = df2[['Gene'] + [col for col in df2.columns if col != 'Gene']]
|
| 92 |
+
|
| 93 |
+
st.dataframe(df2)
|
| 94 |
+
|
| 95 |
+
# Provide a link to the gene's DrugnomeAI page
|
| 96 |
+
url = f"https://astrazeneca-cgr-publications.github.io/DrugnomeAI/geneview.html?gene={input_gene}"
|
| 97 |
+
markdown_link = f"[{input_gene} druggability in DrugnomeAI]({url})"
|
| 98 |
+
st.markdown(markdown_link, unsafe_allow_html=True)
|
| 99 |
+
else:
|
| 100 |
+
st.write("Gene not found in the dataset.")
|
| 101 |
+
|
| 102 |
+
# Display the entire dataset with download option
|
| 103 |
+
st.markdown("### All Colocalisation Results Interacting with Drugs")
|
| 104 |
+
df_total_output = annotations.copy()
|
| 105 |
+
df_total_output['Gene'] = df_total_output.index
|
| 106 |
+
df_total_output.reset_index(drop=True, inplace=True)
|
| 107 |
+
|
| 108 |
+
# Reorder columns to have "Gene" as the first column
|
| 109 |
+
df_total_output = df_total_output[['Gene'] + [col for col in df_total_output.columns if col != 'Gene']]
|
| 110 |
+
|
| 111 |
+
st.dataframe(df_total_output)
|
| 112 |
+
csv = convert_df(df_total_output)
|
| 113 |
+
# st.download_button("Download Complete Colocalisation Results", csv, "complete_colocalisation_results.csv", "text/csv", key='download-all-csv')
|
| 114 |
+
|
| 115 |
+
# Protein interaction network visualization using STRINGDB_data.tsv
|
| 116 |
+
st.markdown(
|
| 117 |
+
"<h1 style='text-align: center;'>Protein Interaction Networks of Colocalising Drug Targets</h1>",
|
| 118 |
+
unsafe_allow_html=True
|
| 119 |
+
)
|
| 120 |
+
|
| 121 |
+
# Description text
|
| 122 |
+
# Description text
|
| 123 |
+
st.markdown(
|
| 124 |
+
"""
|
| 125 |
+
- The color of each node represents its degree (number of direct connections it has with other nodes).
|
| 126 |
+
- The size of each node represents its betweenness centrality.
|
| 127 |
+
- Larger nodes play a more central role in the network, facilitating communication between other proteins.
|
| 128 |
+
- Node edges/connections are colour-coded by confidence of PPI (lighter colors (brighter) represent stronger interactions).
|
| 129 |
+
- Genes that interact with cardiovascular drugs are highlighted with a bold black outline.
|
| 130 |
+
""",
|
| 131 |
+
unsafe_allow_html=True
|
| 132 |
+
)
|
| 133 |
+
|
| 134 |
+
|
| 135 |
+
# Load STRINGDB dataset
|
| 136 |
+
ppi_data = pd.read_csv("STRINGdb_data.tsv", sep='\t')
|
| 137 |
+
|
| 138 |
+
# Create a graph from the STRINGDB PPI data
|
| 139 |
+
G = nx.Graph()
|
| 140 |
+
|
| 141 |
+
# Add edges to the graph based on PPI data
|
| 142 |
+
for index, row in ppi_data.iterrows():
|
| 143 |
+
G.add_edge(row['node1'], row['node2'], weight=row['combined_score'])
|
| 144 |
+
|
| 145 |
+
# Function to rescale values to a given range
|
| 146 |
+
def rescale(l, newmin, newmax):
|
| 147 |
+
arr = list(l)
|
| 148 |
+
return [(x - min(arr)) / (max(arr) - min(arr)) * (newmax - newmin) + newmin for x in arr]
|
| 149 |
+
|
| 150 |
+
# Use the plasma colormap
|
| 151 |
+
graph_colormap = plt.get_cmap('plasma', 12)
|
| 152 |
+
|
| 153 |
+
# Node color varies with Degree
|
| 154 |
+
c = rescale([G.degree(v) for v in G], 0.0, 0.9)
|
| 155 |
+
c = [graph_colormap(i) for i in c]
|
| 156 |
+
|
| 157 |
+
# Node size varies with betweeness centrality - map to range [1500, 7000]
|
| 158 |
+
bc = nx.betweenness_centrality(G)
|
| 159 |
+
s = rescale([v for v in bc.values()], 1500, 7000)
|
| 160 |
+
|
| 161 |
+
# Edge width shows 1 - weight (to convert cost back to strength of interaction)
|
| 162 |
+
ew = rescale([float(G[u][v]['weight']) for u, v in G.edges], 0.1, 4)
|
| 163 |
+
ec = rescale([float(G[u][v]['weight']) for u, v in G.edges], 0.1, 1)
|
| 164 |
+
ec = [graph_colormap(i) for i in ec]
|
| 165 |
+
|
| 166 |
+
# Adjust spring_layout parameters to bring the networks closer together
|
| 167 |
+
pos = nx.spring_layout(G, k=0.5)
|
| 168 |
+
|
| 169 |
+
# Prepare to highlight genes with "Cardiovascular_Drug" as "Yes"
|
| 170 |
+
highlighted_nodes = annotations[annotations['Cardiovascular_Drug'] == 'Yes'].index
|
| 171 |
+
|
| 172 |
+
# Draw the network plot
|
| 173 |
+
plt.figure(figsize=(19, 9), facecolor='white')
|
| 174 |
+
|
| 175 |
+
# Draw the nodes with black outline for highlighted ones
|
| 176 |
+
nx.draw_networkx_nodes(G, pos, node_color=c, node_size=s, edgecolors=['black' if node in highlighted_nodes else 'none' for node in G], linewidths=2)
|
| 177 |
+
|
| 178 |
+
# Draw the edges
|
| 179 |
+
nx.draw_networkx_edges(G, pos, edge_color=ec, width=ew)
|
| 180 |
+
|
| 181 |
+
# Draw node labels with customized font color based on degree
|
| 182 |
+
# Draw node labels with customized font color based on degree
|
| 183 |
+
for node, (x, y) in pos.items():
|
| 184 |
+
# Determine font color
|
| 185 |
+
font_color = 'white' if G.degree(node) < np.median([G.degree(n) for n in G]) else 'black'
|
| 186 |
+
|
| 187 |
+
# Dynamically adjust font size for nodes with white text (smaller font size to fit inside node)
|
| 188 |
+
if font_color == 'white':
|
| 189 |
+
font_size = min(s[list(G.nodes).index(node)] * 0.01, 10) # Adjust the multiplier and limit font size
|
| 190 |
+
else:
|
| 191 |
+
font_size = 12 # Default size for black font
|
| 192 |
+
|
| 193 |
+
plt.text(x, y, node, fontsize=font_size, fontweight='bold', ha='center', va='center', color=font_color)
|
| 194 |
+
|
| 195 |
+
|
| 196 |
+
|
| 197 |
+
# Add a colorbar to represent the node degree color scale
|
| 198 |
+
sm = plt.cm.ScalarMappable(cmap=graph_colormap, norm=plt.Normalize(vmin=0, vmax=1))
|
| 199 |
+
sm.set_array([])
|
| 200 |
+
cbar = plt.colorbar(sm)
|
| 201 |
+
cbar.set_label('Node Degree (Higher = More Connected)', fontsize=12)
|
| 202 |
+
|
| 203 |
+
plt.axis('off')
|
| 204 |
+
|
| 205 |
+
# Display the network plot in the Streamlit app directly
|
| 206 |
+
st.pyplot(plt)
|
banner.png
ADDED
|
colocalisation_results.csv
ADDED
|
The diff for this file is too large to render.
See raw diff
|
|
|
requirements.txt
ADDED
|
@@ -0,0 +1,6 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
numpy==1.23.4
|
| 2 |
+
altair==5.1.2
|
| 3 |
+
pandas==2.0.3
|
| 4 |
+
plotly==5.20.0
|
| 5 |
+
matplotlib==3.4.3
|
| 6 |
+
networkx
|