|
| 1 | +"""private |
| 2 | +""" |
| 3 | +import argparse |
| 4 | + |
| 5 | +from .label_components import label_components_single |
| 6 | +from .cochlea_mapping import tonotopic_mapping_single |
| 7 | +from flamingo_tools.measurements import object_measures_single |
| 8 | + |
| 9 | + |
| 10 | +def label_components(): |
| 11 | + parser = argparse.ArgumentParser( |
| 12 | + description="Script to label segmentation using a segmentation table and graph connected components.") |
| 13 | + |
| 14 | + parser.add_argument("-i", "--input", type=str, required=True, help="Input path to segmentation table.") |
| 15 | + parser.add_argument("-o", "--output", type=str, required=True, |
| 16 | + help="Output path. Either directory (for --json) or specific file otherwise.") |
| 17 | + parser.add_argument("--force", action="store_true", help="Forcefully overwrite output.") |
| 18 | + |
| 19 | + # options for post-processing |
| 20 | + parser.add_argument("--cell_type", type=str, default="sgn", |
| 21 | + help="Cell type of segmentation. Either 'sgn' or 'ihc'.") |
| 22 | + parser.add_argument("--min_size", type=int, default=1000, |
| 23 | + help="Minimal number of pixels for filtering small instances.") |
| 24 | + parser.add_argument("--min_component_length", type=int, default=50, |
| 25 | + help="Minimal length for filtering out connected components.") |
| 26 | + parser.add_argument("--max_edge_distance", type=float, default=30, |
| 27 | + help="Maximal distance in micrometer between points to create edges for connected components.") |
| 28 | + parser.add_argument("-c", "--components", type=str, nargs="+", default=[1], help="List of connected components.") |
| 29 | + |
| 30 | + # options for S3 bucket |
| 31 | + parser.add_argument("--s3", action="store_true", help="Flag for using S3 bucket.") |
| 32 | + parser.add_argument("--s3_credentials", type=str, default=None, |
| 33 | + help="Input file containing S3 credentials. " |
| 34 | + "Optional if AWS_ACCESS_KEY_ID and AWS_SECRET_ACCESS_KEY were exported.") |
| 35 | + parser.add_argument("--s3_bucket_name", type=str, default=None, |
| 36 | + help="S3 bucket name. Optional if BUCKET_NAME was exported.") |
| 37 | + parser.add_argument("--s3_service_endpoint", type=str, default=None, |
| 38 | + help="S3 service endpoint. Optional if SERVICE_ENDPOINT was exported.") |
| 39 | + |
| 40 | + args = parser.parse_args() |
| 41 | + |
| 42 | + label_components_single( |
| 43 | + table_path=args.input, |
| 44 | + output_path=args.output, |
| 45 | + cell_type=args.cell_type, |
| 46 | + component_list=args.components, |
| 47 | + max_edge_distance=args.max_edge_distance, |
| 48 | + min_component_length=args.min_component_length, |
| 49 | + min_size=args.min_size, |
| 50 | + force_overwrite=args.force, |
| 51 | + s3=args.s3, |
| 52 | + s3_credentials=args.s3_credentials, |
| 53 | + s3_bucket_name=args.s3_bucket_name, |
| 54 | + s3_service_endpoint=args.s3_service_endpoint, |
| 55 | + ) |
| 56 | + |
| 57 | + |
| 58 | +def tonotopic_mapping(): |
| 59 | + parser = argparse.ArgumentParser( |
| 60 | + description="Script to extract region of interest (ROI) block around center coordinate.") |
| 61 | + |
| 62 | + parser.add_argument("-i", "--input", type=str, required=True, help="Input path to segmentation table.") |
| 63 | + parser.add_argument("-o", "--output", type=str, required=True, |
| 64 | + help="Output path. Either directory or specific file.") |
| 65 | + parser.add_argument("--force", action="store_true", help="Forcefully overwrite output.") |
| 66 | + |
| 67 | + # options for tonotopic mapping |
| 68 | + parser.add_argument("--animal", type=str, default="mouse", |
| 69 | + help="Animyl type to be used for frequency mapping. Either 'mouse' or 'gerbil'.") |
| 70 | + parser.add_argument("--otof", action="store_true", help="Use frequency mapping for OTOF cochleae.") |
| 71 | + parser.add_argument("--apex_position", type=str, default="apex_higher", |
| 72 | + help="Use frequency mapping for OTOF cochleae.") |
| 73 | + |
| 74 | + # options for post-processing |
| 75 | + parser.add_argument("--cell_type", type=str, default="sgn", |
| 76 | + help="Cell type of segmentation. Either 'sgn' or 'ihc'.") |
| 77 | + parser.add_argument("--max_edge_distance", type=float, default=30, |
| 78 | + help="Maximal distance in micrometer between points to create edges for connected components.") |
| 79 | + parser.add_argument("-c", "--components", type=str, nargs="+", default=[1], help="List of connected components.") |
| 80 | + |
| 81 | + # options for S3 bucket |
| 82 | + parser.add_argument("--s3", action="store_true", help="Flag for using S3 bucket.") |
| 83 | + parser.add_argument("--s3_credentials", type=str, default=None, |
| 84 | + help="Input file containing S3 credentials. " |
| 85 | + "Optional if AWS_ACCESS_KEY_ID and AWS_SECRET_ACCESS_KEY were exported.") |
| 86 | + parser.add_argument("--s3_bucket_name", type=str, default=None, |
| 87 | + help="S3 bucket name. Optional if BUCKET_NAME was exported.") |
| 88 | + parser.add_argument("--s3_service_endpoint", type=str, default=None, |
| 89 | + help="S3 service endpoint. Optional if SERVICE_ENDPOINT was exported.") |
| 90 | + |
| 91 | + args = parser.parse_args() |
| 92 | + |
| 93 | + tonotopic_mapping_single( |
| 94 | + table_path=args.input, |
| 95 | + output_path=args.output, |
| 96 | + force_overwrite=args.force, |
| 97 | + animal=args.animal, |
| 98 | + otof=args.otof, |
| 99 | + apex_position=args.apex_position, |
| 100 | + cell_type=args.cell_type, |
| 101 | + max_edge_distance=args.max_edge_distance, |
| 102 | + component_list=args.components, |
| 103 | + s3=args.s3, |
| 104 | + s3_credentials=args.s3_credentials, |
| 105 | + s3_bucket_name=args.s3_bucket_name, |
| 106 | + s3_service_endpoint=args.s3_service_endpoint, |
| 107 | + ) |
| 108 | + |
| 109 | + |
| 110 | +def object_measures(): |
| 111 | + parser = argparse.ArgumentParser( |
| 112 | + description="Script to compute object measures for different stainings.") |
| 113 | + |
| 114 | + parser.add_argument("-o", "--output", type=str, nargs="+", required=True, |
| 115 | + help="Output path(s). Either directory or specific file(s).") |
| 116 | + parser.add_argument("-i", "--image_paths", type=str, nargs="+", default=None, |
| 117 | + help="Input path to one or multiple image channels in ome.zarr format.") |
| 118 | + parser.add_argument("-t", "--seg_table", type=str, default=None, |
| 119 | + help="Input path to segmentation table.") |
| 120 | + parser.add_argument("-s", "--seg_path", type=str, default=None, |
| 121 | + help="Input path to segmentation channel in ome.zarr format.") |
| 122 | + parser.add_argument("--force", action="store_true", help="Forcefully overwrite output.") |
| 123 | + |
| 124 | + # options for object measures |
| 125 | + parser.add_argument("-c", "--components", type=str, nargs="+", default=[1], help="List of components.") |
| 126 | + parser.add_argument("-r", "--resolution", type=float, nargs="+", default=[0.38, 0.38, 0.38], |
| 127 | + help="Resolution of input in micrometer.") |
| 128 | + parser.add_argument("--bg_mask", action="store_true", help="Use background mask for calculating object measures.") |
| 129 | + |
| 130 | + # options for S3 bucket |
| 131 | + parser.add_argument("--s3", action="store_true", help="Flag for using S3 bucket.") |
| 132 | + parser.add_argument("--s3_credentials", type=str, default=None, |
| 133 | + help="Input file containing S3 credentials. " |
| 134 | + "Optional if AWS_ACCESS_KEY_ID and AWS_SECRET_ACCESS_KEY were exported.") |
| 135 | + parser.add_argument("--s3_bucket_name", type=str, default=None, |
| 136 | + help="S3 bucket name. Optional if BUCKET_NAME was exported.") |
| 137 | + parser.add_argument("--s3_service_endpoint", type=str, default=None, |
| 138 | + help="S3 service endpoint. Optional if SERVICE_ENDPOINT was exported.") |
| 139 | + |
| 140 | + args = parser.parse_args() |
| 141 | + |
| 142 | + object_measures_single( |
| 143 | + out_paths=args.output, |
| 144 | + image_paths=args.image_paths, |
| 145 | + table_path=args.seg_table, |
| 146 | + seg_path=args.seg_path, |
| 147 | + force_overwrite=args.force, |
| 148 | + s3=args.s3, |
| 149 | + ) |
0 commit comments