Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -1629,50 +1629,45 @@ def plot_trial_country_map(df):
|
|
1629 |
|
1630 |
## Root Country Node
|
1631 |
icicle_df = pd.DataFrame(columns=['ids', 'labels', 'parents', 'hover_text'])
|
1632 |
-
icicle_df =
|
1633 |
'ids': ["Country"],
|
1634 |
'labels': ["Country"],
|
1635 |
'parents': [""],
|
1636 |
'hover_text': ["Country"]
|
1637 |
-
}), ignore_index=True)
|
1638 |
|
1639 |
-
icicle_df =
|
1640 |
'ids': df['Country'].unique(),
|
1641 |
'labels': df['Country'].unique(),
|
1642 |
'parents': ["Country"] * len(df['Country'].unique()),
|
1643 |
'hover_text': [f"({len(df[df['Country'] == country]['NCTId'].unique())} Trials)" for country in df['Country'].unique()]
|
1644 |
-
}), ignore_index=True)
|
1645 |
|
1646 |
### Country and Conditions
|
1647 |
|
1648 |
for country in df['Country'].unique():
|
1649 |
temp_df = df[df['Country'] == country]
|
1650 |
conditions = temp_df['Condition'].unique()
|
1651 |
-
icicle_df =
|
1652 |
'ids': [f"{country}__{condition}" for condition in conditions],
|
1653 |
'labels': conditions,
|
1654 |
'parents': [country] * len(conditions),
|
1655 |
'hover_text': [f"({len(temp_df[temp_df['Condition'] == condition]['NCTId'].unique())} Trials)" for condition in conditions]
|
1656 |
-
}), ignore_index=True)
|
1657 |
|
1658 |
### Country with Conditions and Trials NCTId and OrgStudId
|
1659 |
|
1660 |
for country_condition in icicle_df['ids'][icicle_df['parents'].isin(df['Country'].unique())]:
|
1661 |
country, condition = country_condition.split('__')
|
1662 |
temp_df = df[(df['Country'] == country) & (df['Condition'] == condition)]
|
1663 |
-
#trials = temp_df[['NCTId', 'OrgStudyId']].apply(lambda x: f"{x['NCTId']}<br>{x['OrgStudyId']}", axis=1).unique()
|
1664 |
trials = temp_df['NCTId'].unique()
|
1665 |
-
# Update the trials line to include both NCTId and OrgStudyId
|
1666 |
-
#trials = [temp_df[['NCTId', 'OrgStudyId']].apply(lambda x: f"{x['NCTId']}<br>{x['OrgStudyId']}", axis=1).unique() for trial in trials]
|
1667 |
-
|
1668 |
-
#trials = [f"<br>{(temp_df[temp_df['NCTId'] == trial]['OrgStudyId'].iloc[0])}" for trial in trials]
|
1669 |
trial_labels = [f"<br>{insert_line_break(temp_df[temp_df['NCTId'] == trial]['BriefTitle'].iloc[0])}" for trial in trials]
|
1670 |
-
icicle_df =
|
1671 |
'ids': [f"{country_condition}__{trial}" for trial in trials],
|
1672 |
'labels': trials,
|
1673 |
'parents': [country_condition] * len(trials),
|
1674 |
'hover_text': trial_labels
|
1675 |
-
}), ignore_index=True)
|
1676 |
|
1677 |
fig = go.Figure(go.Icicle(
|
1678 |
ids=icicle_df.ids,
|
@@ -1690,13 +1685,10 @@ def plot_trial_country_map(df):
|
|
1690 |
|
1691 |
return fig
|
1692 |
|
1693 |
-
####################
|
1694 |
-
|
1695 |
-
################################################################ SITES #####################################################
|
1696 |
-
|
1697 |
-
|
1698 |
|
|
|
1699 |
|
|
|
1700 |
|
1701 |
################################################################ TRIAL SITES ###########################################
|
1702 |
def plot_trial_sites(df):
|
@@ -1716,51 +1708,47 @@ def plot_trial_sites(df):
|
|
1716 |
|
1717 |
## Root Site Node
|
1718 |
icicle_df = pd.DataFrame(columns=['ids', 'labels', 'parents', 'hover_text'])
|
1719 |
-
icicle_df =
|
1720 |
'ids': ["Sites"],
|
1721 |
'labels': ["Sites"],
|
1722 |
'parents': [""],
|
1723 |
'hover_text': ["Sites"]
|
1724 |
-
}), ignore_index=True)
|
1725 |
|
1726 |
-
icicle_df =
|
1727 |
'ids': df['City'].unique(),
|
1728 |
'labels': df['City'].unique(),
|
1729 |
'parents': ["Sites"] * len(df['City'].unique()),
|
1730 |
'hover_text': [f"({len(df[df['City'] == city]['NCTId'].unique())} Trials)" for city in df['City'].unique()]
|
1731 |
-
}), ignore_index=True)
|
1732 |
|
1733 |
### City and Site
|
1734 |
|
1735 |
for city in df['City'].unique():
|
1736 |
temp_df = df[df['City'] == city]
|
1737 |
sites = temp_df['Site'].unique()
|
1738 |
-
icicle_df =
|
1739 |
'ids': [f"{city}__{site}" for site in sites],
|
1740 |
'labels': sites,
|
1741 |
'parents': [city] * len(sites),
|
1742 |
'hover_text': [f"({len(temp_df[temp_df['Site'] == site]['NCTId'].unique())} Trials)" for site in sites]
|
1743 |
-
}), ignore_index=True)
|
1744 |
|
1745 |
### Site and Trials (NCTId, OrgStudyId, BriefTitle)
|
1746 |
|
1747 |
for city_site in icicle_df['ids'][icicle_df['parents'].isin(df['City'].unique())]:
|
1748 |
city, site = city_site.split('__')
|
1749 |
temp_df = df[(df['City'] == city) & (df['Site'] == site)]
|
1750 |
-
#trials = temp_df[['NCTId', 'OrgStudyId', 'BriefTitle']].apply(lambda x: f"{x['NCTId']}<br>{x['OrgStudyId']}<br>{insert_line_break(x['BriefTitle'])}", axis=1).unique()
|
1751 |
trials = temp_df[['NCTId', 'OrgStudyId']].apply(lambda x: f"{x['NCTId']}<br>{x['OrgStudyId']}", axis=1).unique()
|
1752 |
-
# ncts = temp_df['NCTId'].unique()
|
1753 |
|
1754 |
for trial in trials:
|
1755 |
nctid = trial.split('<br>')[0]
|
1756 |
-
icicle_df =
|
1757 |
'ids': [f"{city_site}__{nctid}"],
|
1758 |
'labels': [trial],
|
1759 |
-
# 'labels': [ncts],
|
1760 |
'parents': [city_site],
|
1761 |
-
#'hover_text': [trial]
|
1762 |
'hover_text': [""]
|
1763 |
-
}), ignore_index=True)
|
1764 |
|
1765 |
fig = go.Figure(go.Icicle(
|
1766 |
ids=icicle_df.ids,
|
@@ -1777,7 +1765,6 @@ def plot_trial_sites(df):
|
|
1777 |
return fig
|
1778 |
|
1779 |
|
1780 |
-
|
1781 |
#############################################################################################################################################
|
1782 |
def plot_trial_site_map(df):
|
1783 |
def insert_line_break(text, max_length=30):
|
|
|
1629 |
|
1630 |
## Root Country Node
|
1631 |
icicle_df = pd.DataFrame(columns=['ids', 'labels', 'parents', 'hover_text'])
|
1632 |
+
icicle_df = pd.concat([icicle_df, pd.DataFrame({
|
1633 |
'ids': ["Country"],
|
1634 |
'labels': ["Country"],
|
1635 |
'parents': [""],
|
1636 |
'hover_text': ["Country"]
|
1637 |
+
})], ignore_index=True)
|
1638 |
|
1639 |
+
icicle_df = pd.concat([icicle_df, pd.DataFrame({
|
1640 |
'ids': df['Country'].unique(),
|
1641 |
'labels': df['Country'].unique(),
|
1642 |
'parents': ["Country"] * len(df['Country'].unique()),
|
1643 |
'hover_text': [f"({len(df[df['Country'] == country]['NCTId'].unique())} Trials)" for country in df['Country'].unique()]
|
1644 |
+
})], ignore_index=True)
|
1645 |
|
1646 |
### Country and Conditions
|
1647 |
|
1648 |
for country in df['Country'].unique():
|
1649 |
temp_df = df[df['Country'] == country]
|
1650 |
conditions = temp_df['Condition'].unique()
|
1651 |
+
icicle_df = pd.concat([icicle_df, pd.DataFrame({
|
1652 |
'ids': [f"{country}__{condition}" for condition in conditions],
|
1653 |
'labels': conditions,
|
1654 |
'parents': [country] * len(conditions),
|
1655 |
'hover_text': [f"({len(temp_df[temp_df['Condition'] == condition]['NCTId'].unique())} Trials)" for condition in conditions]
|
1656 |
+
})], ignore_index=True)
|
1657 |
|
1658 |
### Country with Conditions and Trials NCTId and OrgStudId
|
1659 |
|
1660 |
for country_condition in icicle_df['ids'][icicle_df['parents'].isin(df['Country'].unique())]:
|
1661 |
country, condition = country_condition.split('__')
|
1662 |
temp_df = df[(df['Country'] == country) & (df['Condition'] == condition)]
|
|
|
1663 |
trials = temp_df['NCTId'].unique()
|
|
|
|
|
|
|
|
|
1664 |
trial_labels = [f"<br>{insert_line_break(temp_df[temp_df['NCTId'] == trial]['BriefTitle'].iloc[0])}" for trial in trials]
|
1665 |
+
icicle_df = pd.concat([icicle_df, pd.DataFrame({
|
1666 |
'ids': [f"{country_condition}__{trial}" for trial in trials],
|
1667 |
'labels': trials,
|
1668 |
'parents': [country_condition] * len(trials),
|
1669 |
'hover_text': trial_labels
|
1670 |
+
})], ignore_index=True)
|
1671 |
|
1672 |
fig = go.Figure(go.Icicle(
|
1673 |
ids=icicle_df.ids,
|
|
|
1685 |
|
1686 |
return fig
|
1687 |
|
|
|
|
|
|
|
|
|
|
|
1688 |
|
1689 |
+
####################
|
1690 |
|
1691 |
+
################################################################ SITES ####################################################
|
1692 |
|
1693 |
################################################################ TRIAL SITES ###########################################
|
1694 |
def plot_trial_sites(df):
|
|
|
1708 |
|
1709 |
## Root Site Node
|
1710 |
icicle_df = pd.DataFrame(columns=['ids', 'labels', 'parents', 'hover_text'])
|
1711 |
+
icicle_df = pd.concat([icicle_df, pd.DataFrame({
|
1712 |
'ids': ["Sites"],
|
1713 |
'labels': ["Sites"],
|
1714 |
'parents': [""],
|
1715 |
'hover_text': ["Sites"]
|
1716 |
+
})], ignore_index=True)
|
1717 |
|
1718 |
+
icicle_df = pd.concat([icicle_df, pd.DataFrame({
|
1719 |
'ids': df['City'].unique(),
|
1720 |
'labels': df['City'].unique(),
|
1721 |
'parents': ["Sites"] * len(df['City'].unique()),
|
1722 |
'hover_text': [f"({len(df[df['City'] == city]['NCTId'].unique())} Trials)" for city in df['City'].unique()]
|
1723 |
+
})], ignore_index=True)
|
1724 |
|
1725 |
### City and Site
|
1726 |
|
1727 |
for city in df['City'].unique():
|
1728 |
temp_df = df[df['City'] == city]
|
1729 |
sites = temp_df['Site'].unique()
|
1730 |
+
icicle_df = pd.concat([icicle_df, pd.DataFrame({
|
1731 |
'ids': [f"{city}__{site}" for site in sites],
|
1732 |
'labels': sites,
|
1733 |
'parents': [city] * len(sites),
|
1734 |
'hover_text': [f"({len(temp_df[temp_df['Site'] == site]['NCTId'].unique())} Trials)" for site in sites]
|
1735 |
+
})], ignore_index=True)
|
1736 |
|
1737 |
### Site and Trials (NCTId, OrgStudyId, BriefTitle)
|
1738 |
|
1739 |
for city_site in icicle_df['ids'][icicle_df['parents'].isin(df['City'].unique())]:
|
1740 |
city, site = city_site.split('__')
|
1741 |
temp_df = df[(df['City'] == city) & (df['Site'] == site)]
|
|
|
1742 |
trials = temp_df[['NCTId', 'OrgStudyId']].apply(lambda x: f"{x['NCTId']}<br>{x['OrgStudyId']}", axis=1).unique()
|
|
|
1743 |
|
1744 |
for trial in trials:
|
1745 |
nctid = trial.split('<br>')[0]
|
1746 |
+
icicle_df = pd.concat([icicle_df, pd.DataFrame({
|
1747 |
'ids': [f"{city_site}__{nctid}"],
|
1748 |
'labels': [trial],
|
|
|
1749 |
'parents': [city_site],
|
|
|
1750 |
'hover_text': [""]
|
1751 |
+
})], ignore_index=True)
|
1752 |
|
1753 |
fig = go.Figure(go.Icicle(
|
1754 |
ids=icicle_df.ids,
|
|
|
1765 |
return fig
|
1766 |
|
1767 |
|
|
|
1768 |
#############################################################################################################################################
|
1769 |
def plot_trial_site_map(df):
|
1770 |
def insert_line_break(text, max_length=30):
|