Skip to content

Commit

Permalink
add diagnosis action; fix bugs
Browse files Browse the repository at this point in the history
  • Loading branch information
Nanguage committed Jun 29, 2024
1 parent 0aefeba commit c48dac9
Show file tree
Hide file tree
Showing 4 changed files with 64 additions and 16 deletions.
Binary file added public/images/dual fusion example2.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added public/images/dual fusion example3.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
51 changes: 47 additions & 4 deletions public/plugins/chatbot-extension-diagnosis.imjoy.html
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
<script lang="javascript">
const chatbot_url = "https://bioimage.io/chat/"
const ufish_url = "https://ufish-team.github.io/"
//const ufish_url = "http://localhost:5173/"
//const ufish_url = "http://localhost:5174/"
const utils_url = ufish_url + "/plugins/chatbot-utils.imjoy.html"
const dna_utils_url = ufish_url + "/plugins/dna-ufish-utils.imjoy.html"
const displayer_url = ufish_url + "/plugins/img-display.imjoy.html"
Expand Down Expand Up @@ -64,7 +64,7 @@
w: 25, h: 6
});
}
client.setExampleImageUrl(ufish_url + "images/test_fish_img2.jpg")
await client.setExampleImageUrl(ufish_url + "images/trisomy_example.png")
return client
}

Expand Down Expand Up @@ -281,8 +281,8 @@
properties: {
"condition": {
type: "string",
description: "Condition to count, e.g., table['ch0+ch1']>2",
default: "table['ch0+ch1']>2",
description: "Condition to count, e.g., table['ch0+ch1']>=2. ch0,ch1,ch2 are RGB channels. 'ch0+ch1' means the yellow channel signals.",
default: "table['ch0+ch1']>=2",
}
}
}
Expand Down Expand Up @@ -314,6 +314,49 @@
}
})

const diagnosisPrompt = `
Diagnosis disease using DNA-FISH data.
Need to run the analysisDnaFish first, then run this extension.
Common DNA-FISH probe and disease examples:
- Trisomy probe: 3 signals in one cell
+ Example disease: Myelodysplastic syndrome (MDS)
+ Abnormal cell: red signal >= 3
+ Criteria: abnormal ratio >= 0.05
- Fusion probe: 2 fusions in one cell
+ Example disease: PML-RARA acute leukemia
+ Abnormal cell: yellow signal >= 2
+ Criteria: abnormal ratio >= 0.05
- Separation probe: 1 fusion and 1 separation in one cell
+ Example disease: KMT2A gene acute leukemia
+ Abnormal cell: yellow signal == 1, red signal == 1, green signal == 1
+ Criteria: abnormal ratio >= 0.05
`

await register({
_rintf: true,
name: "DnaFishDiseaseDiagnosis",
description: diagnosisPrompt,
get_schema: async () => {
return {
type: "object",
title: "DnaFishDiseaseDiagnosis",
description: diagnosisPrompt,
properties: {
"countCondition": {
type: "string",
description: "Condition to count, e.g., table['ch0+ch1']>=2. ch0,ch1,ch2 are RGB channels. 'ch0+ch1' means the yellow channel signals.",
default: "table['ch0+ch1']>=2",
}
}
}
},
execute: async (config) => {
const dna_utils = await this.getDnaUtils()
const ratio = await dna_utils.count_cell_ratio(config.countCondition)
return ratio
}
})

api.log('initialized')
}

Expand Down
29 changes: 17 additions & 12 deletions public/plugins/dna-ufish-utils.imjoy.html
Original file line number Diff line number Diff line change
Expand Up @@ -237,8 +237,9 @@
masks = [masks[i] for i in selected_index]
signals = [signals[i] for i in selected_index]
num_plots = len(rois)
rows = int(np.ceil(num_plots / 5))
cols = min(3, num_plots)
cols_per_row = 3
rows = int(np.ceil(num_plots / cols_per_row))
cols = min(cols_per_row, num_plots)
unit = 1.6
fig, axs = plt.subplots(
rows, cols,
Expand Down Expand Up @@ -482,7 +483,6 @@
name: "ufish",
w: 25, h: 6
})
await client.setExampleImageUrl(ufish_url + "images/trisomy_example.jpg")
await client.setOnnxModelUrl(ufish_url + "model/v1.0.1-DNAFISH_model.onnx")
await client.waitReady()
return client
Expand Down Expand Up @@ -546,18 +546,23 @@
return self.result_summary()

async def count_cell_ratio(self, condition_str):
num1 = await self.count_cell_number(condition_str)
total = await self.count_cell_number("")
ratio = num1 / total
return f"{num1}/{total}={ratio:.2f}"

async def count_cell_number(self, condition_str):
if self.res is None:
return None
raise ValueError("No results found.")
table = self.res["table"]
cell_num = table.shape[0]
if cell_num == 0:
return None
try:
if len(table) == 0:
raise ValueError("No cells found.")
if condition_str == "":
return table.shape[0]
else:
condition = eval(condition_str)
ratio = table[condition].shape[0] / cell_num
except Exception as e:
return str(e)
return ratio
cell_num = table[condition].shape[0]
return cell_num

async def count_mean_signals(self):
if self.res is None:
Expand Down

0 comments on commit c48dac9

Please sign in to comment.