diff --git a/extensions/chaeo/batch_jobs/20231023_Porto_EtOHfixed.py b/extensions/chaeo/batch_jobs/20231023_Porto_EtOHfixed.py new file mode 100644 index 0000000000000000000000000000000000000000..45ee113035f0511b8e32d9753063160e2db29538 --- /dev/null +++ b/extensions/chaeo/batch_jobs/20231023_Porto_EtOHfixed.py @@ -0,0 +1,54 @@ +from pathlib import Path + +from model_server.util import autonumber_new_directory, get_matching_files, loop_workflow +from extensions.chaeo.ecotaxa import write_ecotaxa_tsv +from extensions.chaeo.workflows import export_patches_from_multichannel_zstack +from extensions.ilastik.models import IlastikPixelClassifierModel + + +if __name__ == '__main__': + root = Path('c:/Users/rhodes/projects/proj0012-trec-handoff/owncloud-sync/TREC-HD/Images/') + where_czi = (root / 'TREC_STOP_26_Porto/231023_automic/20231023-175838_EtOHfixed/LowZoom').__str__() + where_output = autonumber_new_directory( + 'c:/Users/rhodes/projects/proj0011-plankton-seg/exp0020/output', + 'batch-output' + ) + + px_ilp = Path('c:/Users/rhodes/projects/proj0011-plankton-seg/exp0017/pxAF405_dim8bit.ilp').__str__() + + params = { + 'pxmap_threshold': 0.25, + 'pxmap_foreground_channel': 0, + 'segmentation_channel': 0, + 'zmask_zindex': None, + 'patches_channel': 2, + 'zmask_type': 'boxes', + 'zmask_filters': {'area': (1e3, 1e8)}, + 'zmask_expand_box_by': (128, 3), + 'export_pixel_probabilities': True, + 'export_2d_patches_for_training': True, + 'draw_bounding_box_on_2d_patch': True, + 'export_2d_patches_for_annotation': True, + 'export_3d_patches': False, + 'export_annotated_zstack': True, + 'export_patch_masks': True, + 'zmask_clip': 0.01, + 'rgb_overlay_channels': (1, None, None), + 'rgb_overlay_weights': (0.2, 1.0, 1.0) + } + + input_files = get_matching_files(where_czi, 'czi', coord_filter={}) + + loop_workflow( + input_files, + where_output, + export_patches_from_multichannel_zstack, + [IlastikPixelClassifierModel(params={'project_file': Path(px_ilp)})], + params, + catch_and_continue=False, + ) + + csv_path = (Path(where_output) / 'workflow_data.csv').__str__() + write_ecotaxa_tsv(csv_path, where_output, sample_id='20231023-porto', scope_id='EMBL-MS-Zeiss-LSM900') + + print('Finished') \ No newline at end of file diff --git a/extensions/chaeo/ecotaxa.py b/extensions/chaeo/ecotaxa.py new file mode 100644 index 0000000000000000000000000000000000000000..770b5b74798d65bd7f7a7cb3bc133ef781982db3 --- /dev/null +++ b/extensions/chaeo/ecotaxa.py @@ -0,0 +1,40 @@ +from pathlib import Path + +import pandas as pd + +def write_ecotaxa_tsv(patches_csv_path: str, where: str, sample_id: str, scope_id: str): + # import patch output table + df_patches = pd.read_csv(patches_csv_path) + df_patches['img_file_name'] = df_patches['patch_filename'].apply(lambda x: '2d_patches_annotation/' + x) + + # make second column index level to comply w/ EcoTaxa schema + df_patches.columns = pd.MultiIndex.from_frame( + pd.DataFrame([ + df_patches.columns, + df_patches.dtypes.apply( + lambda x: '[f]' if x in ['float64'] else '[t]' + ) + ]).T, + names=['variable', 'data type'] + ) + + # add new columns for ecotaxa + df_patches.loc[:, ('acq_instrument', '[t]')] = 'Other microscope' + df_patches.loc[:, ('acq_instrument_microscope', '[t]')] = scope_id + df_patches.loc[:, ('sample_id', '[t]')] = sample_id + + df_patches.loc[:, ('acq_id', '[t]')] = df_patches.loc[:, ('input_file', '[t]')] + df_patches.loc[:, ('object_id', '[t]')] = df_patches.loc[:, ('patch_id', '[t]')] + df_patches.loc[:, ('process_id', '[t]')] = df_patches.loc[:, ('patch_id', '[t]')] + + cols_to_transfer = [ + 'img_file_name', + 'object_id', + 'acq_id', + 'acq_instrument', + 'acq_instrument_microscope', + 'sample_id', + 'process_id' + ] + df_export = df_patches.loc[:, pd.IndexSlice[cols_to_transfer, :]] + df_export.to_csv(Path(where) / 'ecotaxa.tsv', sep='\t', index=False) \ No newline at end of file diff --git a/extensions/chaeo/workflows.py b/extensions/chaeo/workflows.py index b6cc877c8a2183001f83b41b26c6af0417d8b8c7..8da67916e7e3a1dc408d8e15cd950afa48743151 100644 --- a/extensions/chaeo/workflows.py +++ b/extensions/chaeo/workflows.py @@ -63,7 +63,7 @@ def get_zmask_meta( stack.get_one_channel_data(segmentation_channel), mask_type=zmask_type, filters=zmask_filters, - **kwargs, + expand_box_by=kwargs['zmask_expand_box_by'], ) ti.click('generate_zmasks')