Spaces:
Running
Running
Update app.py
Browse files
app.py
CHANGED
@@ -1449,45 +1449,39 @@ def plot_condition_treemap_nct (df):
|
|
1449 |
# Create a dictionary to map NCTId to BriefTitle
|
1450 |
nctid_to_orgstudyid = df.set_index('NCTId')['OrgStudyId'].to_dict()
|
1451 |
|
1452 |
-
|
1453 |
icicle_df = pd.DataFrame(columns=['ids', 'labels', 'parents'])
|
1454 |
|
1455 |
# Add the "Trials" root node
|
1456 |
-
icicle_df =
|
1457 |
'ids': ["Trials"],
|
1458 |
'labels': ["Trials"],
|
1459 |
'parents': [""]
|
1460 |
-
}), ignore_index=True)
|
1461 |
|
1462 |
# Add the Condition level
|
1463 |
-
icicle_df =
|
1464 |
'ids': df['Condition'].unique(),
|
1465 |
'labels': df['Condition'].unique(),
|
1466 |
'parents': ["Trials"] * len(df['Condition'].unique())
|
1467 |
-
}), ignore_index=True)
|
1468 |
|
1469 |
# Add the Phase level
|
1470 |
for condition in df['Condition'].unique():
|
1471 |
temp_df = df[df['Condition'] == condition]
|
1472 |
phases = temp_df['Phase'].unique()
|
1473 |
-
icicle_df =
|
1474 |
'ids': [f"{condition}-{phase}" for phase in phases],
|
1475 |
'labels': phases,
|
1476 |
'parents': [condition] * len(phases)
|
1477 |
-
}), ignore_index=True)
|
1478 |
|
1479 |
# Add the NCTId level
|
1480 |
for _, row in df.iterrows():
|
1481 |
-
icicle_df =
|
1482 |
'ids': [row['NCTId']],
|
1483 |
-
# 'labels': [row['NCTId']],
|
1484 |
'labels': [f"{row['NCTId']} ({nctid_to_orgstudyid[row['NCTId']]}) ({nctid_to_brieftitle[row['NCTId']]})"],
|
1485 |
-
# 'labels': [nctid_to_brieftitle[row['NCTId']]],
|
1486 |
'parents': [f"{row['Condition']}-{row['Phase']}"]
|
1487 |
-
}), ignore_index=True)
|
1488 |
-
|
1489 |
-
# trial_labels = [f"{trial}<br>{insert_line_break(temp_df[temp_df['NCTId'] == trial]['BriefTitle'].iloc[0])}" for trial in trials]
|
1490 |
-
|
1491 |
|
1492 |
fig = go.Figure(go.Icicle(
|
1493 |
ids=icicle_df.ids,
|
@@ -1495,13 +1489,10 @@ def plot_condition_treemap_nct (df):
|
|
1495 |
parents=icicle_df.parents,
|
1496 |
root_color="lightgrey",
|
1497 |
textfont=dict(size=34, family="Arial"),
|
1498 |
-
#hovertemplate="<b>%{label}</b><br><br>NCTId: %{id}<br>OrgStudyId: %{customdata[0]}<br>BriefTitle: %{customdata[1]}<extra></extra>",
|
1499 |
hovertemplate="<b>NCTId: %{id}<br>OrgStudyId: %{customdata[0]}<br>BriefTitle: %{customdata[1]}<extra></extra>",
|
1500 |
customdata=list(zip(icicle_df.ids.map(nctid_to_orgstudyid).fillna(''), icicle_df.ids.map(nctid_to_brieftitle).fillna('')))
|
1501 |
))
|
1502 |
|
1503 |
-
|
1504 |
-
|
1505 |
fig.update_layout(autosize=True, height=1000)
|
1506 |
|
1507 |
return fig
|
|
|
1449 |
# Create a dictionary to map NCTId to BriefTitle
|
1450 |
nctid_to_orgstudyid = df.set_index('NCTId')['OrgStudyId'].to_dict()
|
1451 |
|
|
|
1452 |
icicle_df = pd.DataFrame(columns=['ids', 'labels', 'parents'])
|
1453 |
|
1454 |
# Add the "Trials" root node
|
1455 |
+
icicle_df = pd.concat([icicle_df, pd.DataFrame({
|
1456 |
'ids': ["Trials"],
|
1457 |
'labels': ["Trials"],
|
1458 |
'parents': [""]
|
1459 |
+
})], ignore_index=True)
|
1460 |
|
1461 |
# Add the Condition level
|
1462 |
+
icicle_df = pd.concat([icicle_df, pd.DataFrame({
|
1463 |
'ids': df['Condition'].unique(),
|
1464 |
'labels': df['Condition'].unique(),
|
1465 |
'parents': ["Trials"] * len(df['Condition'].unique())
|
1466 |
+
})], ignore_index=True)
|
1467 |
|
1468 |
# Add the Phase level
|
1469 |
for condition in df['Condition'].unique():
|
1470 |
temp_df = df[df['Condition'] == condition]
|
1471 |
phases = temp_df['Phase'].unique()
|
1472 |
+
icicle_df = pd.concat([icicle_df, pd.DataFrame({
|
1473 |
'ids': [f"{condition}-{phase}" for phase in phases],
|
1474 |
'labels': phases,
|
1475 |
'parents': [condition] * len(phases)
|
1476 |
+
})], ignore_index=True)
|
1477 |
|
1478 |
# Add the NCTId level
|
1479 |
for _, row in df.iterrows():
|
1480 |
+
icicle_df = pd.concat([icicle_df, pd.DataFrame({
|
1481 |
'ids': [row['NCTId']],
|
|
|
1482 |
'labels': [f"{row['NCTId']} ({nctid_to_orgstudyid[row['NCTId']]}) ({nctid_to_brieftitle[row['NCTId']]})"],
|
|
|
1483 |
'parents': [f"{row['Condition']}-{row['Phase']}"]
|
1484 |
+
})], ignore_index=True)
|
|
|
|
|
|
|
1485 |
|
1486 |
fig = go.Figure(go.Icicle(
|
1487 |
ids=icicle_df.ids,
|
|
|
1489 |
parents=icicle_df.parents,
|
1490 |
root_color="lightgrey",
|
1491 |
textfont=dict(size=34, family="Arial"),
|
|
|
1492 |
hovertemplate="<b>NCTId: %{id}<br>OrgStudyId: %{customdata[0]}<br>BriefTitle: %{customdata[1]}<extra></extra>",
|
1493 |
customdata=list(zip(icicle_df.ids.map(nctid_to_orgstudyid).fillna(''), icicle_df.ids.map(nctid_to_brieftitle).fillna('')))
|
1494 |
))
|
1495 |
|
|
|
|
|
1496 |
fig.update_layout(autosize=True, height=1000)
|
1497 |
|
1498 |
return fig
|