def __init__(self, project): self.__project_variant = project.get_variant() self.__project_dimensions = project.get_dimensions() self.__images_directory = project.get_input_image_directory() self.__waypoints_directory = project.get_artifacts_directory( "waypoints") self.jobs = cli.jobs.get_job_types() #{ # "trace": cli.jobs.trace.Trace(project), # "imdata": cli.jobs.imdata.ImageData(project), # "shapes": cli.jobs.shapes.Shapes(project), # "classedge": cli.jobs.classify.ClassifyEdges(project), # "jclass": cli.jobs.jclass.JunctionClassify(project), # "jclasssum": cli.jobs.jclasssum.JunctionClassSummarize(project), # "fastclass": cli.jobs.edgeseg.FastSegClassify(project), #} # Use this for an ordered list of the jobs in the chain job_keys = [] priortized_jobs = sorted(self.jobs.values(), key=lambda x: x.priority) for pj in priortized_jobs: job_keys.append(pj.job_name) self.job_types = job_keys
def getProject(project_hash): import cells.images import cli.operations project = get_project(project_hash) project_name = get_project_name(project_hash) project_dto = {"hash": project_hash, "name": project_name} input_image_directory = project.get_input_image_directory() variant = project.get_variant() dimensions = project.get_dimensions() image_data = cells.images.get_image_collection(input_image_directory, variant, dimensions) # Get input image count total_images = 0 stain_image_counts = {} for image_data_row in image_data: file_name = image_data_row["file_name"] image_stain = None for test_stain in variant.get("values", []): if test_stain in file_name: stain_image_counts[test_stain] = stain_image_counts.get( test_stain, 0) + 1 image_stain = test_stain break if image_stain is None: stain_image_counts["None"] = stain_image_counts.get("None", 0) + 1 total_images = total_images + 1 # Task Data waypoint_tasks, waypoint_tasks_data = get_waypoint_tasks(project) # Cell Data cell_collection = cli.operations.get_cell_collection(project, image_data) project_data_dto = { "image_count": total_images, "variant_data": stain_image_counts, "task_data": waypoint_tasks_data, "cell_count": len(cell_collection) } print project.get_project_hash() return render_template('projects/overview.html', project=project_dto, project_data=project_data_dto)
def get_waypoint_tasks(project): import cells.waypoints.seeding import cells.images input_image_directory = project.get_input_image_directory() variant = project.get_variant() dimensions = project.get_dimensions() image_data = cells.images.get_image_collection(input_image_directory, variant, dimensions) counter = 0 for image_data_row in image_data: if image_data_row.get("stain") == "TxRed": # print image_data_row counter += 1 if counter > 5: break input_waypoints_directory = project.get_artifacts_directory("waypoints") waypoint_files = glob.glob(input_waypoints_directory + os.sep + "*") waypoint_tasks = cells.waypoints.seeding.get_waypoints_tasks( waypoint_files, image_data) # Calculate task status data waypoint_tasks_data = {} tasks_total = 0 tasks_done = 0 tasks_wip = 0 tasks_open = 0 tasks_progress = 0.0 tasks_total = len(waypoint_tasks) for waypoint_task in waypoint_tasks: if waypoint_task.get("status") == "open": tasks_open = tasks_open + 1 elif waypoint_task.get("status") == "in-progress": tasks_wip = tasks_wip + 1 elif waypoint_task.get("status") == "complete": tasks_done = tasks_done + 1 if tasks_total > 0: tasks_progress = round(100.0 * float(tasks_done) / tasks_total, 2) waypoint_tasks_data["total"] = tasks_total waypoint_tasks_data["done"] = tasks_done waypoint_tasks_data["wip"] = tasks_wip waypoint_tasks_data["open"] = tasks_open waypoint_tasks_data["progress"] = tasks_progress return waypoint_tasks, waypoint_tasks_data
def createProjectConfigurationDimension(project_hash): project = get_project(project_hash) existing_dimensions = project.get_dimensions() dimension_name = request.form.get("dimension_name") dimension_type = request.form.get("dimension_type") if (dimension_name is None or dimension_name in existing_dimensions.keys() or len(dimension_name) < 4): return redirect("/projects/" + project_hash + "/config") else: project.add_dimension(dimension_name, dimension_type) return redirect("/projects/" + project_hash + "/dimensions/" + dimension_name)
def getProjectConfigurationDimension(project_hash, dimension_name): project = get_project(project_hash) dimensions = project.get_dimensions() dimension = dimensions.get(dimension_name) project_dto = {"hash": project_hash, "name": project.get_project_name()} dimension_dto = { "name": dimension_name, "type": dimension.get("type"), "data": dimension.get("data", []) } page_data = {"title": "", "active_nav_tab": "config"} return render_template('projects/dimension.html', project=project_dto, dimension=dimension_dto, page_data=page_data)
def getProjectConfiguration(project_hash): project = get_project(project_hash) project_name = get_project_name(project_hash) project_dto = {"hash": project_hash, "name": project_name} project_configuration_dto = { "variant": project.get_variant(), "dimensions": project.get_dimensions(), "parameters": project.get_parameters(), "dep": [{ "name": "Experiment Date", "type": "function", "data": "parse_date" }, { "name": "Experiment Name", "type": "mapping", "data": [ { "tokens": [], "value": "" }, ] }] } page_data = {"title": "", "active_nav_tab": "config"} return render_template('projects/config.html', project=project_dto, configuration=project_configuration_dto, page_data=page_data)
def getProjectProblems(project_hash): import cells.images project = get_project(project_hash) project_name = get_project_name(project_hash) project_dto = {"hash": project_hash, "name": project_name} problems = [] input_image_directory = project.get_input_image_directory() variant = project.get_variant() dimensions = project.get_dimensions() if variant.get("name") is None or variant.get("name") == "": problems.append({ "level": "info", "css": "info", "summary": "You have not configured a variant (stain) and values for this project" }) image_data = cells.images.get_image_collection(input_image_directory, variant, dimensions) # TODO: A variant value is not found in any images stain_image_counts = {} missing_variant_images = [] for image_data_row in image_data: file_name = image_data_row["file_name"] image_stain = None for test_stain in variant.get("values", []): if test_stain in file_name: stain_image_counts[test_stain] = stain_image_counts.get( test_stain, 0) + 1 image_stain = test_stain break if image_stain is None: missing_variant_images.append(file_name) for variant_value in variant.get("values", []): if stain_image_counts.get(variant_value, 0) == 0: problems.append({ "level": "warning", "css": "warning", "summary": "The variant/stain '%s' did not match any images." % variant_value }) # Image has no variant for missing_variant_image in missing_variant_images: problems.append({ "level": "warning", "css": "warning", "summary": "Image '%s' does not have a variant." % missing_variant_image }) # Image has missing related variant image(s) for image_data_row in image_data: file_name = image_data_row["file_name"] image_stain = None for test_stain in variant.get("values", []): if test_stain in file_name: stain_image_counts[test_stain] = stain_image_counts.get( test_stain, 0) + 1 image_stain = test_stain break missing_variants = [] if image_stain is not None: for variant_value in variant.get("values", []): related_file_name = file_name.replace(image_stain, variant_value) related_file = os.path.join(input_image_directory, related_file_name) if not os.path.isfile(related_file): missing_variants.append(variant_value) for missing_variant in missing_variants: if missing_variant == variant.get("primary_value"): problems.append({ "level": "error", "css": "danger", "summary": "Missing variant with value '%s' for image '%s'. No output will be generated for this file." % (missing_variant, file_name), }) else: problems.append({ "level": "warning", "css": "warning", "summary": "Missing variant with value '%s' for image '%s'." % (missing_variant, file_name) }) page_data = {"title": "", "active_nav_tab": "problems"} return render_template('projects/problems.html', project=project_dto, problems=problems, page_data=page_data)
def getProjectDataSummary(project_hash): import cells.images import cli.operations project = get_project(project_hash) project_name = get_project_name(project_hash) project_dto = {"hash": project_hash, "name": project_name} input_image_directory = project.get_input_image_directory() variant = project.get_variant() dimensions = project.get_dimensions() image_data = cells.images.get_image_collection(input_image_directory, variant, dimensions) # Get input image count total_images = 0 variant_counts = {} for image_data_row in image_data: file_name = image_data_row["file_name"] image_stain = None for test_stain in variant.get("values", []): if test_stain in file_name: variant_counts[test_stain] = variant_counts.get(test_stain, 0) + 1 image_stain = test_stain break if image_stain is None: variant_counts["None"] = variant_counts.get("None", 0) + 1 total_images = total_images + 1 dimension_counts = {} for key, value in dimensions.iteritems(): dimension_counts[key] = {} for image_data_row in image_data: for key in dimensions.keys(): dimension_value = image_data_row.get("dimensions", {}).get(key) dimension_counts[key][dimension_value] = \ dimension_counts[key].get(dimension_value, 0) + 1 # Get counts for cells cell_collection = cli.operations.get_cell_collection(project, image_data) cell_variant_counts = {} for key in variant_counts.keys(): cell_variant_counts[key] = 0 cell_dimension_counts = {} for key, value in dimensions.iteritems(): cell_dimension_counts[key] = {} for cell_data_row in cell_collection: variant_value = cell_data_row.get("variant") cell_variant_counts[variant_value] = cell_variant_counts.get( variant_value, 0) + 1 for key in dimensions.keys(): dimension_value = cell_data_row.get("dimensions", {}).get(key) cell_dimension_counts[key][dimension_value] = \ cell_dimension_counts[key].get(dimension_value, 0) + 1 variant_name = project.get_variant()["name"] project_data_dto = { "image_count": total_images, "variant_name": variant_name, "variant_data": variant_counts, "cell_variant_data": cell_variant_counts, "dimension_counts": dimension_counts, "cell_dimension_counts": cell_dimension_counts } page_data = {"title": "", "active_nav_tab": "data"} return render_template('projects/data.html', project=project_dto, project_data=project_data_dto, page_data=page_data)