def test_panel_update_description(app):
    """Test the endpoint that updates gene panel description"""

    # GIVEN a panel in the database
    panel_obj = store.gene_panels()[0]
    assert panel_obj.get("description") is None

    form_data = {
        "update_description": True,  # This is the submit button of the form
        "panel_description": "Some description",  # This is the text field
    }

    # GIVEN an initialized app
    # GIVEN a valid user and institute
    with app.test_client() as client:
        # GIVEN that the user could be logged in
        resp = client.get(url_for("auto_login"))

        # WHEN posting an update description request to panel page
        resp = client.post(
            url_for("panels.panel", panel_id=panel_obj["_id"]),
            data=form_data,
        )
        # THEN the panel object should be updated with the new description:
        panel_obj = store.gene_panels()[0]
        assert panel_obj["description"] == "Some description"
Beispiel #2
0
def panels():
    """Show all panels for a case."""
    if request.method == 'POST':
        # update an existing panel
        csv_file = request.files['csv_file']
        content = csv_file.stream.read()
        if b'\n' in content:
            lines = content.decode().split('\n')
        else:
            lines = content.decode('windows-1252').split('\r')

        new_panel_name = request.form.get('new_panel_name')
        if new_panel_name:
            panel_obj = controllers.new_panel(
                store=store,
                institute_id=request.form['institute'],
                panel_name=new_panel_name,
                display_name=request.form['display_name'],
                csv_lines=lines,
            )
            if panel_obj is None:
                return redirect(request.referrer)
            flash("new gene panel added: {}!".format(panel_obj['panel_name']))
        else:
            panel_obj = controllers.update_panel(store,
                                                 request.form['panel_name'],
                                                 lines)
            if panel_obj is None:
                return abort(
                    404, "gene panel not found: {}".format(
                        request.form['panel_name']))
        return redirect(url_for('panels.panel', panel_id=panel_obj['_id']))

    institutes = list(user_institutes(store, current_user))
    panel_names = [
        name for institute in institutes for name in store.gene_panels(
            institute_id=institute['_id']).distinct('panel_name')
    ]

    panel_versions = {}
    for name in panel_names:
        panel_versions[name] = store.gene_panels(panel_id=name)

    panel_groups = []
    for institute_obj in institutes:
        institute_panels = store.latest_panels(institute_obj['_id'])
        panel_groups.append((institute_obj, institute_panels))

    return dict(panel_groups=panel_groups,
                panel_names=panel_names,
                panel_versions=panel_versions,
                institutes=institutes)
def test_panel_modify_genes(app, real_panel_database):
    """Test the functionality to modify genes in a gene panel"""

    # GIVEN a panel in the database
    panel_obj = store.gene_panels()[0]

    # WHEN posting a delete gene request to panel page
    a_gene = panel_obj["genes"][0]  # first gene of the panel
    form_data = {"action": "delete", "hgnc_id": a_gene["hgnc_id"]}
    # GIVEN an initialized app
    # GIVEN a valid user and institute
    with app.test_client() as client:
        # GIVEN that the user could be logged in
        resp = client.get(url_for("auto_login"))
        resp = client.post(
            url_for("panels.panel", panel_id=panel_obj["_id"]),
            data=form_data,
        )
        # THEN the pending actions of panel should be updated:
        panel_obj = store.gene_panels()[0]
        assert panel_obj["pending"][0]["action"] == "delete"
        assert panel_obj["pending"][0]["hgnc_id"] == a_gene["hgnc_id"]

        # WHEN removing that gene using the client
        new_version = panel_obj["version"] + 1
        form_data = {"action": "submit", "version": new_version}

        resp = client.post(
            url_for("panels.panel_update", panel_id=panel_obj["_id"]),
            data=form_data,
        )

        # THEN the new panel object should have the correct new version
        new_panel_obj = store.gene_panel(panel_obj["panel_name"])
        assert new_panel_obj["version"] == new_version

        # remove gene from panel object using adapter:
        panel_obj["genes"] = panel_obj["genes"][1:]
        updated_panel = store.update_panel(panel_obj)

        # WHEN posting an add gene request to panel page
        form_data = {"action": "add", "hgnc_id": a_gene["hgnc_id"]}
        resp = client.post(
            url_for("panels.panel", panel_id=updated_panel["_id"]),
            data=form_data,
        )
        # Then response should redirect to gene edit page
        assert resp.status_code == 302
Beispiel #4
0
def panels():
    """Show all panels for a case."""
    if request.method == 'POST':
        # add new panel
        csv_file = request.files['csv_file']
        lines = csv_file.stream.read().decode().split('\r')
        panel_genes = parse_panel(lines)
        try:
            panel_obj = build_panel(
                adapter=store,
                institute_id=request.form['institute_id'],
                panel_name=request.form['panel_name'],
                display_name=request.form['display_name'],
                version=float(request.form['version'])
                if request.form.get('version') else 1.0,
                panel_genes=panel_genes,
            )
        except ValueError as error:
            flash(error.args[0], 'warning')
            return redirect(request.referrer)
        store.add_gene_panel(panel_obj)
        flash("new gene panel added: {}".format(panel_obj['panel_name']),
              'info')

    panel_groups = []
    for institute_obj in user_institutes(store, current_user):
        institute_panels = store.gene_panels(institute_id=institute_obj['_id'])
        panel_groups.append((institute_obj, institute_panels))
    return dict(panel_groups=panel_groups,
                institutes=user_institutes(store, current_user))
Beispiel #5
0
def panels():
    """Show all panels for a user"""
    if request.method == "POST":  # Edit/create a new panel and redirect to its page
        redirect_panel_id = controllers.panel_create_or_update(store, request)
        if redirect_panel_id:
            return redirect(url_for("panels.panel",
                                    panel_id=redirect_panel_id))

        return redirect(url_for("panels.panels"))

    institutes = list(user_institutes(store, current_user))
    panel_names = [
        name for institute in institutes for name
        in store.gene_panels(institute_id=institute["_id"],
                             include_hidden=True).distinct("panel_name")
    ]
    panel_versions = {}
    for name in panel_names:
        panels = store.gene_panels(panel_id=name, include_hidden=True)
        panel_versions[name] = [
            panel_obj for panel_obj in panels
            if controllers.shall_display_panel(panel_obj, current_user)
        ]
    panel_groups = []
    for institute_obj in institutes:
        institute_panels = (
            panel_obj
            for panel_obj in store.latest_panels(institute_obj["_id"],
                                                 include_hidden=True)
            if controllers.shall_display_panel(panel_obj, current_user))
        panel_groups.append((institute_obj, institute_panels))
    return dict(
        panel_groups=panel_groups,
        panel_names=panel_names,
        panel_versions=panel_versions,
        institutes=institutes,
    )
Beispiel #6
0
def panels():
    """Show all panels for a case."""
    if request.method == "POST":
        # update an existing panel
        csv_file = request.files["csv_file"]
        content = csv_file.stream.read()
        lines = None
        try:
            if b"\n" in content:
                lines = content.decode("utf-8-sig", "ignore").split("\n")
            else:
                lines = content.decode("windows-1252").split("\r")
        except Exception as err:
            flash(
                "Something went wrong while parsing the panel CSV file! ({})".
                format(err),
                "danger",
            )
            return redirect(request.referrer)

        new_panel_name = request.form.get("new_panel_name")
        if new_panel_name:  # create a new panel
            new_panel_id = controllers.new_panel(
                store=store,
                institute_id=request.form["institute"],
                panel_name=new_panel_name,
                display_name=request.form["display_name"],
                description=request.form["description"],
                csv_lines=lines,
            )
            if new_panel_id is None:
                flash(
                    "Something went wrong and the panel list was not updated!",
                    "warning",
                )
                return redirect(request.referrer)
            else:
                flash("new gene panel added, {}!".format(new_panel_name),
                      "success")
            return redirect(url_for("panels.panel", panel_id=new_panel_id))

        else:  # modify an existing panel
            update_option = request.form["modify_option"]
            panel_obj = controllers.update_panel(
                store=store,
                panel_name=request.form["panel_name"],
                csv_lines=lines,
                option=update_option,
            )
            if panel_obj is None:
                return abort(
                    404, "gene panel not found: {}".format(
                        request.form["panel_name"]))
            else:
                return redirect(
                    url_for("panels.panel", panel_id=panel_obj["_id"]))

    institutes = list(user_institutes(store, current_user))
    panel_names = [
        name for institute in institutes for name in store.gene_panels(
            institute_id=institute["_id"]).distinct("panel_name")
    ]

    panel_versions = {}
    for name in panel_names:
        panel_versions[name] = store.gene_panels(panel_id=name)

    panel_groups = []
    for institute_obj in institutes:
        institute_panels = store.latest_panels(institute_obj["_id"])
        panel_groups.append((institute_obj, institute_panels))

    return dict(
        panel_groups=panel_groups,
        panel_names=panel_names,
        panel_versions=panel_versions,
        institutes=institutes,
    )
Beispiel #7
0
def panels():
    """Show all panels for a case."""
    if request.method == 'POST':
        # update an existing panel
        csv_file = request.files['csv_file']
        content = csv_file.stream.read()
        lines = None
        try:
            if b'\n' in content:
                lines = content.decode('utf-8', 'ignore').split('\n')
            else:
                lines = content.decode('windows-1252').split('\r')
        except Exception as err:
            flash('Something went wrong while parsing the panel CSV file! ({})'.format(err), 'danger')
            return redirect(request.referrer)

        new_panel_name = request.form.get('new_panel_name')
        if new_panel_name: #create a new panel
            new_panel_id = controllers.new_panel(
                store=store,
                institute_id=request.form['institute'],
                panel_name=new_panel_name,
                display_name=request.form['display_name'],
                description=request.form['description'],
                csv_lines=lines,
            )
            if new_panel_id is None:
                flash('Something went wrong and the panel list was not updated!','warning')
                return redirect(request.referrer)
            else:
                flash("new gene panel added, {}!".format(new_panel_name),'success')
            return redirect(url_for('panels.panel', panel_id=new_panel_id))

        else: # modify an existing panel
            update_option = request.form['modify_option']
            panel_obj= controllers.update_panel(
                                   store=store,
                                   panel_name=request.form['panel_name'],
                                   csv_lines=lines,
                                   option=update_option
             )
            if panel_obj is None:
                return abort(404, "gene panel not found: {}".format(request.form['panel_name']))
            else:
                return redirect(url_for('panels.panel', panel_id=panel_obj['_id']))

    institutes = list(user_institutes(store, current_user))
    panel_names = [name
                   for institute in institutes
                   for name in
                   store.gene_panels(institute_id=institute['_id']).distinct('panel_name')]

    panel_versions = {}
    for name in panel_names:
        panel_versions[name]=store.gene_panels(panel_id=name)

    panel_groups = []
    for institute_obj in institutes:
         institute_panels = store.latest_panels(institute_obj['_id'])
         panel_groups.append((institute_obj, institute_panels))

    return dict(panel_groups=panel_groups, panel_names=panel_names,
                panel_versions=panel_versions, institutes=institutes)
Beispiel #8
0
def panels():
    """Show all panels for a case."""
    if request.method == 'POST':
        # update an existing panel
        csv_file = request.files['csv_file']
        content = csv_file.stream.read()
        lines = None
        try:
            if b'\n' in content:
                lines = content.decode('utf-8', 'ignore').split('\n')
            else:
                lines = content.decode('windows-1252').split('\r')
        except Exception as err:
            flash('Something went wrong while parsing the panel CSV file! ({})'.format(err), 'danger')
            return redirect(request.referrer)

        new_panel_name = request.form.get('new_panel_name')
        if new_panel_name: #create a new panel
            new_panel_id = controllers.new_panel(
                store=store,
                institute_id=request.form['institute'],
                panel_name=new_panel_name,
                display_name=request.form['display_name'],
                csv_lines=lines,
            )
            if new_panel_id is None:
                flash('Something went wrong and the panel list was not updated!','warning')
                return redirect(request.referrer)
            else:
                flash("new gene panel added, {}!".format(new_panel_name),'success')
            return redirect(url_for('panels.panel', panel_id=new_panel_id))

        else: # modify an existing panel
            update_option = request.form['modify_option']
            panel_obj= controllers.update_panel(
                                   store=store,
                                   panel_name=request.form['panel_name'],
                                   csv_lines=lines,
                                   option=update_option
             )
            if panel_obj is None:
                return abort(404, "gene panel not found: {}".format(request.form['panel_name']))
            else:
                return redirect(url_for('panels.panel', panel_id=panel_obj['_id']))

    institutes = list(user_institutes(store, current_user))
    panel_names = [name
                   for institute in institutes
                   for name in
                   store.gene_panels(institute_id=institute['_id']).distinct('panel_name')]

    panel_versions = {}
    for name in panel_names:
        panel_versions[name]=store.gene_panels(panel_id=name)

    panel_groups = []
    for institute_obj in institutes:
         institute_panels = store.latest_panels(institute_obj['_id'])
         panel_groups.append((institute_obj, institute_panels))

    return dict(panel_groups=panel_groups, panel_names=panel_names,
                panel_versions=panel_versions, institutes=institutes)