Spaces:
Sleeping
Sleeping
fangjiang commited on
Commit ·
1151941
1
Parent(s): f2af4e1
initial update
Browse files
app.py
CHANGED
|
@@ -388,7 +388,6 @@ with gr.Blocks() as demo:
|
|
| 388 |
'<li>upload a Marker File listing the channels to identify the antibodies.</li>'
|
| 389 |
'</ul></div>')
|
| 390 |
|
| 391 |
-
gr.Markdown('<hr>')
|
| 392 |
gr.Markdown('<div class="h-2">Select Input Case:</div>')
|
| 393 |
|
| 394 |
choices = gr.Radio(["Case 1", "Case 2"], value="Case 1", label="Choose Input Case", elem_classes='input-choices')
|
|
@@ -423,12 +422,11 @@ with gr.Blocks() as demo:
|
|
| 423 |
choices.change(fn=toggle_file_input, inputs=choices, outputs=[img_path, marker_path])
|
| 424 |
|
| 425 |
# img_viz = gr.Plot(label="Visualization of individual channels")
|
| 426 |
-
|
| 427 |
gr.Markdown('<div class="h-1">Step 2. Modify existing channels</div>')
|
| 428 |
gr.Markdown('<div class="h-2">(Required) Define channels designed to visualize nuclei. </div>')
|
| 429 |
gr.Markdown('<div class="h-2">(Optional) Remove unwanted channel after visualizing the individual channels. </div>')
|
| 430 |
gr.Markdown('<div class="h-2">(Optional) Define channels degisned to visualize membranes.</div>')
|
| 431 |
-
gr.Markdown('<hr>')
|
| 432 |
|
| 433 |
with gr.Row(equal_height=True): # third row selects nuclei channels
|
| 434 |
with gr.Column(scale=2):
|
|
@@ -454,9 +452,8 @@ with gr.Blocks() as demo:
|
|
| 454 |
# modifies the channels per user input
|
| 455 |
define_btn.click(fn=modify_channels, inputs=[cytof_original_state, selected_unwanted_channel, selected_nuclei, selected_membrane], outputs=[channel_feedback, cytof_state])
|
| 456 |
|
| 457 |
-
|
| 458 |
gr.Markdown('<div class="h-1">Step 3. Perform cell segmentation based on the defined nuclei and membrane channels</div>')
|
| 459 |
-
gr.Markdown('<hr>')
|
| 460 |
|
| 461 |
with gr.Row(): # This row defines cell radius and performs segmentation
|
| 462 |
with gr.Column(scale=2):
|
|
@@ -468,10 +465,9 @@ with gr.Blocks() as demo:
|
|
| 468 |
seg_viz = gr.Plot(label="Hover over graph to zoom, pan, save, etc.")
|
| 469 |
seg_btn.click(fn=cell_seg, inputs=[cytof_state, cell_radius], outputs=[seg_viz, cytof_state])
|
| 470 |
|
| 471 |
-
|
| 472 |
gr.Markdown('<div class="h-1">Step 4. Extract cell features</div>')
|
| 473 |
gr.Markdown('<div class="h-2">Note: This step will take significantly longer than the previous ones. A 300MB IMC file takes about 7 minutes to compute.</div>')
|
| 474 |
-
gr.Markdown('<hr>')
|
| 475 |
|
| 476 |
cohort_state = gr.State(CytofCohort())
|
| 477 |
with gr.Row(): # feature extraction related functinos
|
|
@@ -485,9 +481,8 @@ with gr.Blocks() as demo:
|
|
| 485 |
extract_btn.click(fn=feature_extraction, inputs=[cytof_state, cohort_state, norm_percentile],
|
| 486 |
outputs=[cytof_state, cohort_state, feat_df])
|
| 487 |
|
| 488 |
-
|
| 489 |
gr.Markdown('<div class="h-1">Step 5. Downstream analysis</div>')
|
| 490 |
-
gr.Markdown('<hr>')
|
| 491 |
|
| 492 |
gr.Markdown('<div class="h-2">(1) Co-expression Analysis</div>')
|
| 493 |
with gr.Row(): # show co-expression and spatial analysis
|
|
@@ -522,12 +517,11 @@ with gr.Blocks() as demo:
|
|
| 522 |
co_exp_btn.click(fn=co_expression, inputs=[cytof_state, norm_percentile], outputs=[co_exp_viz, cytof_state])
|
| 523 |
# spatial_btn logic is in step6. This is populate the marker positive dropdown options
|
| 524 |
|
| 525 |
-
|
| 526 |
gr.Markdown('<div class="h-1">Step 6. Visualize positive markers</div>')
|
| 527 |
gr.Markdown('<div class="h-2">Select two markers for side-by-side comparison to visualize their positive states in cells. This serves two purposes. </div>')
|
| 528 |
gr.Markdown('<div class="h-2">(1) Validate the co-expression analysis results. High expression level should mean a similar number of positive markers within the two slides, whereas low expression level mean a large difference of in the number of positive markers. </div>')
|
| 529 |
gr.Markdown('<div class="h-2">(2) Validate teh spatial interaction analysis results. High interaction means the two positive markers are in close proximity of each other (proximity is previously defined in `clustering threshold`), and vice versa.</div>')
|
| 530 |
-
gr.Markdown('<hr>')
|
| 531 |
|
| 532 |
with gr.Row(): # two marker positive visualization - dropdown options
|
| 533 |
with gr.Column(scale=2):
|
|
@@ -545,11 +539,10 @@ with gr.Blocks() as demo:
|
|
| 545 |
)
|
| 546 |
pos_viz_btn.click(fn=viz_pos_marker_pair, inputs=[cytof_state, selected_marker1, selected_marker2, norm_percentile], outputs=[marker_pos_viz])
|
| 547 |
|
| 548 |
-
|
| 549 |
gr.Markdown('<div class="h-1">Step 7. Phenogrpah Clustering</div>')
|
| 550 |
gr.Markdown('<div class="h-2">Cells can be clustered into sub-groups based on the extracted single-cell data.</div>')
|
| 551 |
gr.Markdown('<div class="h-2">Time reference: a 300MB IMC file takes about 2 minutes to compute.</div>')
|
| 552 |
-
gr.Markdown('<hr>')
|
| 553 |
|
| 554 |
with gr.Row(): # add two plots to visualize phenograph results
|
| 555 |
with gr.Column(scale=2):
|
|
@@ -566,9 +559,8 @@ with gr.Blocks() as demo:
|
|
| 566 |
cluster_interaction = gr.Plot(label="Spatial interaction of clusters")
|
| 567 |
cluster_interact_btn.click(cluster_interaction_fn, inputs=[cytof_state, cohort_state], outputs=[cluster_interaction, cytof_state, cohort_state])
|
| 568 |
|
| 569 |
-
|
| 570 |
gr.Markdown('<div class="h-2">In additional, you could visualizing the cluster assignments against the positive markers to oberve any patterns:</div>')
|
| 571 |
-
gr.Markdown('<hr>')
|
| 572 |
with gr.Row():
|
| 573 |
with gr.Column(scale=2):
|
| 574 |
selected_cluster_marker = gr.Dropdown(label='Select one marker', info='Select a marker to visualize', interactive=True)
|
|
|
|
| 388 |
'<li>upload a Marker File listing the channels to identify the antibodies.</li>'
|
| 389 |
'</ul></div>')
|
| 390 |
|
|
|
|
| 391 |
gr.Markdown('<div class="h-2">Select Input Case:</div>')
|
| 392 |
|
| 393 |
choices = gr.Radio(["Case 1", "Case 2"], value="Case 1", label="Choose Input Case", elem_classes='input-choices')
|
|
|
|
| 422 |
choices.change(fn=toggle_file_input, inputs=choices, outputs=[img_path, marker_path])
|
| 423 |
|
| 424 |
# img_viz = gr.Plot(label="Visualization of individual channels")
|
| 425 |
+
gr.Markdown('<br>')
|
| 426 |
gr.Markdown('<div class="h-1">Step 2. Modify existing channels</div>')
|
| 427 |
gr.Markdown('<div class="h-2">(Required) Define channels designed to visualize nuclei. </div>')
|
| 428 |
gr.Markdown('<div class="h-2">(Optional) Remove unwanted channel after visualizing the individual channels. </div>')
|
| 429 |
gr.Markdown('<div class="h-2">(Optional) Define channels degisned to visualize membranes.</div>')
|
|
|
|
| 430 |
|
| 431 |
with gr.Row(equal_height=True): # third row selects nuclei channels
|
| 432 |
with gr.Column(scale=2):
|
|
|
|
| 452 |
# modifies the channels per user input
|
| 453 |
define_btn.click(fn=modify_channels, inputs=[cytof_original_state, selected_unwanted_channel, selected_nuclei, selected_membrane], outputs=[channel_feedback, cytof_state])
|
| 454 |
|
| 455 |
+
gr.Markdown('<br>')
|
| 456 |
gr.Markdown('<div class="h-1">Step 3. Perform cell segmentation based on the defined nuclei and membrane channels</div>')
|
|
|
|
| 457 |
|
| 458 |
with gr.Row(): # This row defines cell radius and performs segmentation
|
| 459 |
with gr.Column(scale=2):
|
|
|
|
| 465 |
seg_viz = gr.Plot(label="Hover over graph to zoom, pan, save, etc.")
|
| 466 |
seg_btn.click(fn=cell_seg, inputs=[cytof_state, cell_radius], outputs=[seg_viz, cytof_state])
|
| 467 |
|
| 468 |
+
gr.Markdown('<br>')
|
| 469 |
gr.Markdown('<div class="h-1">Step 4. Extract cell features</div>')
|
| 470 |
gr.Markdown('<div class="h-2">Note: This step will take significantly longer than the previous ones. A 300MB IMC file takes about 7 minutes to compute.</div>')
|
|
|
|
| 471 |
|
| 472 |
cohort_state = gr.State(CytofCohort())
|
| 473 |
with gr.Row(): # feature extraction related functinos
|
|
|
|
| 481 |
extract_btn.click(fn=feature_extraction, inputs=[cytof_state, cohort_state, norm_percentile],
|
| 482 |
outputs=[cytof_state, cohort_state, feat_df])
|
| 483 |
|
| 484 |
+
gr.Markdown('<br>')
|
| 485 |
gr.Markdown('<div class="h-1">Step 5. Downstream analysis</div>')
|
|
|
|
| 486 |
|
| 487 |
gr.Markdown('<div class="h-2">(1) Co-expression Analysis</div>')
|
| 488 |
with gr.Row(): # show co-expression and spatial analysis
|
|
|
|
| 517 |
co_exp_btn.click(fn=co_expression, inputs=[cytof_state, norm_percentile], outputs=[co_exp_viz, cytof_state])
|
| 518 |
# spatial_btn logic is in step6. This is populate the marker positive dropdown options
|
| 519 |
|
| 520 |
+
gr.Markdown('<br>')
|
| 521 |
gr.Markdown('<div class="h-1">Step 6. Visualize positive markers</div>')
|
| 522 |
gr.Markdown('<div class="h-2">Select two markers for side-by-side comparison to visualize their positive states in cells. This serves two purposes. </div>')
|
| 523 |
gr.Markdown('<div class="h-2">(1) Validate the co-expression analysis results. High expression level should mean a similar number of positive markers within the two slides, whereas low expression level mean a large difference of in the number of positive markers. </div>')
|
| 524 |
gr.Markdown('<div class="h-2">(2) Validate teh spatial interaction analysis results. High interaction means the two positive markers are in close proximity of each other (proximity is previously defined in `clustering threshold`), and vice versa.</div>')
|
|
|
|
| 525 |
|
| 526 |
with gr.Row(): # two marker positive visualization - dropdown options
|
| 527 |
with gr.Column(scale=2):
|
|
|
|
| 539 |
)
|
| 540 |
pos_viz_btn.click(fn=viz_pos_marker_pair, inputs=[cytof_state, selected_marker1, selected_marker2, norm_percentile], outputs=[marker_pos_viz])
|
| 541 |
|
| 542 |
+
gr.Markdown('<br>')
|
| 543 |
gr.Markdown('<div class="h-1">Step 7. Phenogrpah Clustering</div>')
|
| 544 |
gr.Markdown('<div class="h-2">Cells can be clustered into sub-groups based on the extracted single-cell data.</div>')
|
| 545 |
gr.Markdown('<div class="h-2">Time reference: a 300MB IMC file takes about 2 minutes to compute.</div>')
|
|
|
|
| 546 |
|
| 547 |
with gr.Row(): # add two plots to visualize phenograph results
|
| 548 |
with gr.Column(scale=2):
|
|
|
|
| 559 |
cluster_interaction = gr.Plot(label="Spatial interaction of clusters")
|
| 560 |
cluster_interact_btn.click(cluster_interaction_fn, inputs=[cytof_state, cohort_state], outputs=[cluster_interaction, cytof_state, cohort_state])
|
| 561 |
|
| 562 |
+
gr.Markdown('<br>')
|
| 563 |
gr.Markdown('<div class="h-2">In additional, you could visualizing the cluster assignments against the positive markers to oberve any patterns:</div>')
|
|
|
|
| 564 |
with gr.Row():
|
| 565 |
with gr.Column(scale=2):
|
| 566 |
selected_cluster_marker = gr.Dropdown(label='Select one marker', info='Select a marker to visualize', interactive=True)
|