Created
November 4, 2019 13:31
-
-
Save oeway/b1f3e5201f97c77dc602a67cb9f2f8de to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<docs lang="markdown"> | |
[TODO: write documentation for this plugin.] | |
</docs> | |
<config lang="json"> | |
{ | |
"name": "ImportHPAImagesJS", | |
"type": "web-worker", | |
"version": "0.1.0", | |
"description": "[TODO: describe this plugin with one sentence.]", | |
"tags": [], | |
"ui": "", | |
"cover": "", | |
"inputs": null, | |
"outputs": null, | |
"flags": [], | |
"icon": "extension", | |
"api_version": "0.1.6", | |
"env": "", | |
"permissions": [], | |
"requirements": [], | |
"dependencies": [] | |
} | |
</config> | |
<script lang="javascript"> | |
const images_train = [ | |
'https://images.proteinatlas.org/48363/780_E12_2', | |
'https://images.proteinatlas.org/41082/733_D4_2', | |
'https://images.proteinatlas.org/3733/992_A2_1', | |
'https://images.proteinatlas.org/41082/721_D4_1', | |
'https://images.proteinatlas.org/50418/816_E1_1', | |
'https://images.proteinatlas.org/50418/777_E1_2', | |
'https://images.proteinatlas.org/3733/1432_H3_1', | |
'https://images.proteinatlas.org/58509/1039_A5_1', | |
'https://images.proteinatlas.org/41082/684_C4_2', | |
'https://images.proteinatlas.org/44227/747_G1_2', | |
'https://images.proteinatlas.org/14060/105_G9_1', | |
'https://images.proteinatlas.org/48363/788_E12_1', | |
'https://images.proteinatlas.org/44227/713_G1_1', | |
'https://images.proteinatlas.org/3733/992_A2_2', | |
'https://images.proteinatlas.org/58509/1037_A5_3', | |
'https://images.proteinatlas.org/50418/790_E1_2', | |
'https://images.proteinatlas.org/14060/107_G9_2', | |
'https://images.proteinatlas.org/44227/714_G1_2', | |
'https://images.proteinatlas.org/44227/si31_G10_7', | |
'https://images.proteinatlas.org/14060/107_G9_1' | |
] | |
const images_test = [ | |
'https://images.proteinatlas.org/41082/860_D8_1', | |
'https://images.proteinatlas.org/44227/713_G1_3', | |
'https://images.proteinatlas.org/44227/si31_G12_11', | |
'https://images.proteinatlas.org/41082/684_C4_1' | |
] | |
const more_images = [ | |
'https://images.proteinatlas.org/16562/132_D2_1', | |
'https://images.proteinatlas.org/19589/175_B12_1', | |
'https://images.proteinatlas.org/50306/789_D9_1', | |
'https://images.proteinatlas.org/50306/789_D9_2', | |
'https://images.proteinatlas.org/63553/1226_A7_3', | |
'https://images.proteinatlas.org/16562/132_D2_2', | |
'https://images.proteinatlas.org/41219/557_E9_2', | |
'https://images.proteinatlas.org/41219/493_E9_2', | |
'https://images.proteinatlas.org/63553/1226_A7_5', | |
'https://images.proteinatlas.org/19589/175_B12_2', | |
'https://images.proteinatlas.org/41219/557_E9_1', | |
'https://images.proteinatlas.org/41227/485_D12_3', | |
'https://images.proteinatlas.org/19589/174_B12_2', | |
'https://images.proteinatlas.org/19589/174_B12_1', | |
'https://images.proteinatlas.org/41227/485_D12_2', | |
'https://images.proteinatlas.org/16562/164_D2_1', | |
'https://images.proteinatlas.org/63553/1139_C2_1', | |
'https://images.proteinatlas.org/16562/131_D2_1', | |
'https://images.proteinatlas.org/41219/493_E9_1', | |
'https://images.proteinatlas.org/41227/494_D12_1', | |
'https://images.proteinatlas.org/41227/488_D12_1', | |
'https://images.proteinatlas.org/16562/164_D2_2', | |
'https://images.proteinatlas.org/63553/1132_C2_2', | |
'https://images.proteinatlas.org/41227/488_D12_2', | |
'https://images.proteinatlas.org/63553/1132_C2_1', | |
'https://images.proteinatlas.org/41227/494_D12_3', | |
'https://images.proteinatlas.org/63553/1139_C2_2', | |
'https://images.proteinatlas.org/41219/502_E9_2', | |
'https://images.proteinatlas.org/19589/176_B12_1', | |
'https://images.proteinatlas.org/16562/131_D2_2' | |
] | |
new_images = [ | |
'https://images.proteinatlas.org/40758/557_C6_1_blue_red_green.jpg', | |
'https://images.proteinatlas.org/40758/557_C6_2_blue_red_green.jpg', | |
'https://images.proteinatlas.org/41824/862_B4_1_blue_red_green.jpg', | |
'https://images.proteinatlas.org/41824/862_B4_2_blue_red_green.jpg', | |
'https://images.proteinatlas.org/64645/1873_H8_2_blue_red_green.jpg', | |
'https://images.proteinatlas.org/64645/1873_H8_5_blue_red_green.jpg', | |
'https://images.proteinatlas.org/41824/867_A2_1_blue_red_green.jpg', | |
'https://images.proteinatlas.org/41824/867_A2_2_blue_red_green.jpg', | |
'https://images.proteinatlas.org/40758/493_C6_1_blue_red_green.jpg', | |
'https://images.proteinatlas.org/40758/493_C6_2_blue_red_green.jpg', | |
'https://images.proteinatlas.org/41824/859_B4_1_blue_red_green.jpg', | |
'https://images.proteinatlas.org/41824/859_B4_3_blue_red_green.jpg', | |
'https://images.proteinatlas.org/64645/1199_C12_5_blue_red_green.jpg', | |
'https://images.proteinatlas.org/64645/1199_C12_6_blue_red_green.jpg', | |
'https://images.proteinatlas.org/40758/502_C6_3_blue_red_green.jpg' | |
] | |
function filter_images(new_images){ | |
const seged_images = more_images.concat(images_test).concat(images_train) | |
for(let i=0;i<new_images.length;i++){ | |
new_images[i] = new_images[i].split('_').slice(0,3).join('_') | |
} | |
new_images = seged_images.concat(new_images) | |
return new_images | |
} | |
function format_path(path){ | |
const arr = path.split('/'); | |
return arr.slice(arr.length-2).join('_') | |
} | |
function link_name(path){ | |
//"""find the link and path to images""" | |
links_names = {} | |
links_names['name'] = format_path(path) | |
links_names['data'] = {'All': {}, 'Microtubules': {}, 'Antibody': {}, 'Nucleus': {}, 'ER': {}} | |
links_names['data']['All']['url'] = path + '_blue_red_green_yellow.jpg' | |
links_names['data']['All']['file_name'] = format_path(links_names['data']['All']['url']) | |
links_names['data']['Microtubules']['url'] = path + '_red.jpg' | |
links_names['data']['Microtubules']['file_name'] = format_path(links_names['data']['Microtubules']['url']) | |
links_names['data']['Antibody']['url'] = path + '_green.jpg' | |
links_names['data']['Antibody']['file_name'] = format_path(links_names['data']['Antibody']['url']) | |
links_names['data']['Nucleus']['url'] = path + '_blue.jpg' | |
links_names['data']['Nucleus']['file_name'] = format_path(links_names['data']['Nucleus']['url']) | |
links_names['data']['ER']['url'] = path + '_yellow.jpg' | |
links_names['data']['ER']['file_name'] = format_path(links_names['data']['ER']['url']) | |
links_names['group'] = 'train' | |
return links_names | |
} | |
function samples_generate(images_train){ | |
return images_train.map(item=>link_name(item)) | |
} | |
const True = true; | |
const default_dataset = { | |
'api_version': '0.1.6', | |
'version': 5, | |
'name': 'hap-segmentation', | |
'root_folder': '/home/hap-segmentation', | |
'samples': samples_generate(filter_images(new_images)), | |
'annotation_types':{ | |
"cell":{ | |
"label":"cell", | |
"color":"#3f51b5", | |
"line_width":4, | |
"type":"Polygon", | |
"freehand":True, | |
"checked":True | |
}, | |
"nuclei":{ | |
"label":"nuclei", | |
"color":"#ff9800", | |
"line_width":4, | |
"type":"Polygon", | |
"freehand":True, | |
"checked":True | |
} | |
}, | |
'channel_config': { | |
"All": { | |
'filter': '_blue_red_green_yellow.jpg', | |
'name': 'All' | |
}, | |
"Microtubules": { | |
'filter': '_red.jpg', | |
'name': 'Microtubules' | |
}, | |
"Antibody": { | |
'filter': '_green.jpg', | |
'name': 'Antibody' | |
}, | |
"Nucleus": { | |
'filter': '_blue.jpg', | |
'name': 'Nucleus' | |
}, | |
"ER": { | |
'filter': '_yellow.jpg', | |
'name': 'ER' | |
} | |
} | |
} | |
console.log('====================>', default_dataset) | |
class ImJoyPlugin{ | |
setup(){ | |
api.log('initialized') | |
} | |
loadData(win){ | |
win.importSampleComplete(default_dataset, True) | |
} | |
async run(ctx){ | |
const window = await api.createWindow({'name': 'Annotator', 'type': 'ImageAnnotator', 'data': {}}) | |
await this.loadData(window) | |
} | |
} | |
api.export(new ImJoyPlugin()) | |
</script> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment