def analysis_editor_and_grid(request, analysis_id, stand_alone=False): analysis = get_analysis_or_404(request.user, analysis_id) context = { "select_grid_column_form": SelectGridColumnForm(), "stand_alone": stand_alone, "analysis": analysis } return render(request, 'analysis/analysis_editor_and_grid.html', context)
def node_create(request, analysis_id, node_type): global NODE_TYPES_HASH if NODE_TYPES_HASH is None: NODE_TYPES_HASH = get_node_types_hash_by_class_name() analysis = get_analysis_or_404(request.user, analysis_id, write=True) node_class = NODE_TYPES_HASH[node_type] node = node_class.objects.create(analysis=analysis) update_analysis(node.analysis_id) return JsonResponse(get_rendering_dict(node))
def set_variant_tag(request, location): location = TagLocation(location) variant_id = request.POST['variant_id'] tag_id = request.POST['tag_id'] op = request.POST['op'] # Optional variant_tag_id = request.POST.get('variant_tag_id') # Pass in PK to delete genome_build_name = request.POST.get('genome_build_name') if analysis_id := request.POST.get('analysis_id'): node_id = request.POST.get('node_id') analysis = get_analysis_or_404(request.user, analysis_id, write=True)
def nodes_status(request, analysis_id): analysis = get_analysis_or_404(request.user, analysis_id) nodes = json.loads(request.GET['nodes']) qs = analysis.analysisnode_set.filter(id__in=nodes) node_status_list = [] for data in qs.values("id", "version", "status", "count", "shadow_color"): node_id = data["id"] version = data["version"] data["valid"] = not NodeStatus.is_error(data["status"]) data["ready"] = NodeStatus.is_ready(data["status"]) data["counts"] = get_node_counts(node_id, version, data["count"]) node_status_list.append(data) return JsonResponse({"node_status": node_status_list})
def analysis_settings_template_run_tab(request, analysis_id): analysis = get_analysis_or_404(request.user, analysis_id) node_variables = defaultdict(list) for node in analysis.analysisnode_set.filter( analysisvariable__isnull=False).distinct().order_by("y"): for av in node.analysisvariable_set.all().order_by("field"): node_variables[node].append(av) context = { "analysis_template_run": analysis.analysistemplaterun, "node_variables": defaultdict_to_dict(node_variables) } return render(request, 'analysis/analysis_settings_template_run_tab.html', context)
def analysis_settings_lock(request, analysis_id): analysis = get_analysis_or_404(request.user, analysis_id) if not analysis.can_unlock( request.user): # check_can_write returns false if locked raise PermissionDenied( f"You do not have write access to {analysis.pk}") lock = json.loads(request.POST["lock"]) AnalysisLock.objects.create(analysis=analysis, locked=lock, user=request.user, date=timezone.now()) # Bump version to expire cache analysis.version += 1 analysis.save() return redirect(analysis) # Reload
def view_analysis(request, analysis_id, active_node_id=0): analysis = get_analysis_or_404(request.user, analysis_id) nodes = analysis.analysisnode_set.filter(visible=True).select_subclasses() node_classes_kwargs = {} if analysis.lock_input_sources: node_classes_kwargs = {"source_nodes": False} node_help_dict = {} user_settings = UserSettings.get_for_user(request.user) if user_settings.tool_tips: node_help_dict = { label: subclass.get_help_text() for label, subclass in get_node_types_hash().items() } analysis_variables = [[ av.node_id, av.field ] for av in AnalysisVariable.objects.filter(node__analysis=analysis)] analysis_tags_node = TagNode.get_analysis_tags_node(analysis) context = { "node_classes_form": forms.AnalysisNodeClassesForm(**node_classes_kwargs), "nodes": nodes, "node_count_colors": get_node_count_colors("color"), "analysis": analysis, "analysis_settings": get_analysis_settings(request.user, analysis), "analysis_tags_node": analysis_tags_node, "active_node_id": active_node_id, "node_help": node_help_dict, "analysis_variables": analysis_variables, "has_write_permission": analysis.can_write(request.user), "warnings": analysis.get_toolbar_warnings(request.user), "ANALYSIS_DUAL_SCREEN_MODE_FEATURE_ENABLED": settings.ANALYSIS_DUAL_SCREEN_MODE_FEATURE_ENABLED } return render(request, 'analysis/analysis.html', context)
def nodes_copy(request, analysis_id): node_ids = json.loads(request.POST["nodes"]) node_ids = set([int(i) for i in node_ids]) nodes = [] edges = [] analysis = get_analysis_or_404(request.user, analysis_id, write=True) nodes_qs = analysis.analysisnode_set.filter( id__in=node_ids).select_subclasses() topo_sorted = get_toposorted_nodes(nodes_qs) old_new_map = {} for group in topo_sorted: for node in group: if analysis_id is None: analysis_id = node.analysis_id template_node = get_node_subclass_or_404(request.user, node.id) parents = template_node.analysisnode_ptr.parents().filter( id__in=old_new_map).values_list('id', flat=True) clone_node = template_node.save_clone() clone_node.x += 10 clone_node.y += 10 clone_node.status = NodeStatus.DIRTY clone_node.save() old_new_map[node.id] = clone_node clone_node.adjust_cloned_parents(old_new_map) for parent_id in parents: new_parent = old_new_map[parent_id] new_parent.add_child(clone_node) edge = clone_node.get_connection_data(new_parent) edges.append(edge) if not clone_node.is_valid(): clone_node.count = None clone_node.save() nodes.append(get_rendering_dict(clone_node)) update_analysis(analysis.pk) return JsonResponse({"nodes": nodes, "edges": edges})
def view_analysis_settings(request, analysis_id): analysis = get_analysis_or_404(request.user, analysis_id) analysis_settings = get_analysis_settings(request.user, analysis) form = forms.CreateAnalysisTemplateForm(request.POST or None, user=request.user, analysis=analysis) if request.method == "POST": if form.is_valid(): analysis_template = form.save() return JsonResponse({"analysis_id": analysis_template.analysis_id}) context = { "analysis": analysis, "create_analysis_template_form": form, "new_analysis_settings": analysis_settings, "has_write_permission": analysis.can_write(request.user), "can_unlock": analysis.can_unlock(request.user) } return render(request, 'analysis/analysis_settings.html', context)
def analysis_input_samples(request, analysis_id): analysis = get_analysis_or_404(request.user, analysis_id) input_nodes = analysis.analysisnode_set.filter( analysisnode_parent__isnull=True) input_nodes = input_nodes.select_subclasses() node_inputs = [] for node in input_nodes: if samples := node.get_samples_from_node_only_not_ancestors(): node_input_data = { "class": node.get_class_name(), "name": node.name, "samples": samples, } for field in ["trio", "pedigree", "cohort"]: try: node_input_data[field] = getattr(node, field) except AttributeError: pass node_inputs.append(node_input_data)
def analysis_settings_details_tab(request, analysis_id): analysis = get_analysis_or_404(request.user, analysis_id) old_annotation_version = analysis.annotation_version form = forms.AnalysisForm(request.POST or None, user=request.user, instance=analysis) has_write_permission = analysis.can_write(request.user) if not has_write_permission: set_form_read_only(form) reload_analysis = False if request.method == "POST": analysis.check_can_write(request.user) if form.has_changed: valid = form.is_valid() if valid: analysis = form.save() analysis.save() if reload_analysis := (old_annotation_version != analysis.annotation_version): node_utils.reload_analysis_nodes(analysis.pk) add_save_message(request, valid, "Analysis Settings")
def nodes_delete(request, analysis_id): node_ids = json.loads(request.POST["nodes"]) node_ids = set([int(i) for i in node_ids]) analysis = get_analysis_or_404(request.user, analysis_id, write=True) nodes_qs = analysis.analysisnode_set.filter( id__in=node_ids).select_subclasses() topo_sorted = get_toposorted_nodes(nodes_qs) for group in reversed(topo_sorted): for node in group: if node.id not in node_ids: continue # parent we don't care about # Detach first for kid in node.analysisnode_ptr.children.select_subclasses(): kid.remove_parent(node) kid.parents_changed = True kid.save() node.delete() update_analysis(analysis.pk) return JsonResponse({})
def clone_analysis(request, analysis_id): analysis = get_analysis_or_404(request.user, analysis_id) new_analysis = analysis.clone(request.user) reload_analysis_nodes(new_analysis.pk) return JsonResponse({"analysis_id": new_analysis.pk})
def analysis_reload(request, analysis_id): analysis = get_analysis_or_404(request.user, analysis_id, write=True) node_utils.reload_analysis_nodes(analysis.pk) return JsonResponse({})
def analysis_settings_node_counts_tab(request, analysis_id): analysis = get_analysis_or_404(request.user, analysis_id) return _analysis_settings_node_counts_tab( request, analysis, has_write_permission=analysis.can_write(request.user))
def analysis_set_panel_size(request, analysis_id): """ This is set from AJAX queries, ie dragging a panel border """ analysis = get_analysis_or_404(request.user, analysis_id, write=True) analysis.analysis_panel_fraction = request.POST["analysis_panel_fraction"] analysis.save() return JsonResponse({})
def analysis_node_versions(request, analysis_id): """ Returns a dict of {'node_versions' : [node.pk, node.version, node.appearance_version]} """ analysis = get_analysis_or_404(request.user, analysis_id) nodes_qs = analysis.analysisnode_set.filter(visible=True) node_versions = nodes_qs.values_list("pk", "version", "appearance_version") return JsonResponse({"node_versions": list(node_versions)})