예제 #1
0
파일: views.py 프로젝트: terestahl/scout
def sv_variant(institute_id, case_name, variant_id):
    """Display a specific structural variant."""
    data = variant_controller(store, institute_id, case_name, variant_id, add_other=False)

    if current_app.config.get("LOQUSDB_SETTINGS"):
        LOG.debug("Fetching loqusdb information for %s", variant_id)
        data["observations"] = observations(store, loqusdb, data["case"], data["variant"])

    return data
예제 #2
0
파일: views.py 프로젝트: terestahl/scout
def variant(institute_id, case_name, variant_id):
    """Display a specific SNV variant."""
    LOG.debug("Variants view requesting data for variant %s", variant_id)

    data = variant_controller(store, institute_id, case_name, variant_id=variant_id)
    if data is None:
        LOG.warning(
            "An error occurred: variants view requesting data for variant {}".format(variant_id)
        )
        flash("An error occurred while retrieving variant object", "danger")
        return redirect(request.referrer)

    if current_app.config.get("LOQUSDB_SETTINGS"):
        LOG.debug("Fetching loqusdb information for %s", variant_id)
        data["observations"] = observations(store, loqusdb, data["case"], data["variant"])

    return data
예제 #3
0
def test_observations_controller(app, real_variant_database, case_obj, loqusdb):
    ## GIVEN a database and a loqusdb mock with one variant from the database
    var_obj = real_variant_database.variant_collection.find_one()
    assert var_obj

    loqusdb._add_variant(var_obj)

    ## WHEN updating the case_id for the variant
    var_obj["case_id"] = "internal_id2"

    data = None
    with app.test_client() as client:
        resp = client.get(url_for("auto_login"))
        data = observations(real_variant_database, loqusdb, case_obj, var_obj)

    ## THEN assert that the data was found
    assert data
예제 #4
0
def test_observations_controller_non_existing(app, real_variant_database, case_obj, loqusdb):
    ## GIVEN a database and a loqusdb mock without the variant
    var_obj = real_variant_database.variant_collection.find_one()
    assert var_obj

    ## WHEN updating the case_id for the variant
    var_obj["case_id"] = "internal_id2"

    data = None
    with app.test_client() as client:
        resp = client.get(url_for("auto_login"))
        data = observations(real_variant_database, loqusdb, case_obj, var_obj)

    ## THEN assert that the number of cases is still returned
    assert data["total"] == loqusdb.nr_cases
    ## THEN assert the cases variable is in data
    assert "cases" in data
    ## THEN assert there are no case information returned
    assert data["cases"] == []
예제 #5
0
def test_observations_controller_sv(app, sv_variant_obj, institute_obj, loqusdburl):
    """Testing observations controller to retrieve observations for one SV variant.
    Test that SV variant similar to a given one from another case is returned
    """
    case_obj = store.case_collection.find_one()

    # GIVEN an app with a connected loqusdb instance
    loqus_id = "test"
    assert app.config["LOQUSDB_SETTINGS"][loqus_id]

    # GIVEN that the institute is associated to the same loqusdb instance
    store.institute_collection.find_one_and_update(
        {"_id": institute_obj["_id"]}, {"$set": {"loqusdb_id": loqus_id}}
    )

    # GIVEN a database with a case with a specific SV variant
    store.variant_collection.insert_one(sv_variant_obj)

    ## GIVEN patched request to the loqusdbapi instance
    req_url = f"{loqusdburl}/svs/?chrom={sv_variant_obj['chromosome']}&end_chrom={sv_variant_obj['end_chrom']}&pos={sv_variant_obj['position']}&end={sv_variant_obj['end']}&sv_type={sv_variant_obj['sub_category'].upper()}"
    responses.add(
        responses.GET,
        req_url,
        json={"families": [sv_variant_obj["case_id"]], "observations": 1},
        status=200,
    )

    # WHEN the same variant is in another case
    sv_variant_obj["case_id"] = "internal_id2"
    # And has a different variant_id
    sv_variant_obj["variant_id"] = "someOtherVarID"

    with app.test_client() as client:
        resp = client.get(url_for("auto_login"))
        # THEN the observation of the original case should be found
        data = observations(store, loqusdb, case_obj, sv_variant_obj)

    ## THEN loqus should return the occurrence from the first case
    assert case_obj["_id"] in data[loqus_id]["families"]
    assert data[loqus_id]["cases"][0]["case"] == case_obj
    assert data[loqus_id]["cases"][0]["variant"]["_id"] == sv_variant_obj["_id"]
예제 #6
0
def sv_variant(institute_id, case_name, variant_id):
    """Display a specific structural variant."""
    data = variant_controller(store,
                              institute_id,
                              case_name,
                              variant_id,
                              add_other=False)

    if data is None:
        flash("An error occurred while retrieving variant object", "danger")
        return redirect(
            url_for("variants.sv_variants",
                    institute_id=institute_id,
                    case_name=case_name))

    if current_app.config.get("LOQUSDB_SETTINGS"):
        LOG.debug("Fetching loqusdb information for %s", variant_id)
        data["observations"] = observations(store, loqusdb, data["case"],
                                            data["variant"])

    return data
예제 #7
0
def test_observations_controller_snv(app, institute_obj, loqusdburl):
    """Testing observation controller to retrieve observations for one SNV variant"""

    case_obj = store.case_collection.find_one()

    # GIVEN an app with a connected loqusdb instance
    loqus_id = "test"
    assert app.config["LOQUSDB_SETTINGS"][loqus_id]

    var_obj = store.variant_collection.find_one()
    assert var_obj["category"] == "snv"
    assert var_obj

    ## GIVEN patched request to the loqusdbapi instance
    var_name = f"{var_obj['chromosome']}_{var_obj['position']}_{var_obj['reference']}_{var_obj['alternative']}"

    responses.add(
        responses.GET,
        f"{loqusdburl}/variants/{var_name}",
        json={"families": [var_obj["case_id"]], "observations": 1},
        status=200,
    )

    # GIVEN that the institute is associated to the same loqusdb instance
    store.institute_collection.find_one_and_update(
        {"_id": institute_obj["_id"]}, {"$set": {"loqusdb_id": loqus_id}}
    )

    ## WHEN updating the case_id for the variant
    var_obj["case_id"] = "internal_id2"

    data = None
    with app.test_client() as client:
        resp = client.get(url_for("auto_login"))
        data = observations(store, loqusdb, case_obj, var_obj)

    ## THEN loqus should return the occurrence from the first case
    assert case_obj["_id"] in data[loqus_id]["families"]
    assert data[loqus_id]["cases"][0]["case"] == case_obj
    assert data[loqus_id]["cases"][0]["variant"]["_id"] == var_obj["_id"]
예제 #8
0
def test_observations_controller_non_existing(app, institute_obj, case_obj, loqusdburl):

    # GIVEN an app with a connected loqusdb instance
    loqus_id = "test"
    assert app.config["LOQUSDB_SETTINGS"][loqus_id]

    var_obj = store.variant_collection.find_one()
    assert var_obj

    ## GIVEN patched request to the loqusdbapi instance
    n_cases = 102
    var_name = f"{var_obj['chromosome']}_{var_obj['position']}_{var_obj['reference']}_{var_obj['alternative']}"
    responses.add(
        responses.GET,
        f"{loqusdburl}/variants/{var_name}",
        json={"total": n_cases, "cases": []},
        status=200,
    )

    # GIVEN that the institute is associated to the same loqusdb instance
    store.institute_collection.find_one_and_update(
        {"_id": institute_obj["_id"]}, {"$set": {"loqusdb_id": loqus_id}}
    )

    ## WHEN updating the case_id for the variant
    var_obj["case_id"] = "internal_id2"

    data = None
    with app.test_client() as client:
        resp = client.get(url_for("auto_login"))
        data = observations(store, loqusdb, case_obj, var_obj)

    ## THEN assert that the number of cases is still returned
    assert data[loqus_id]["total"] == n_cases
    ## THEN assert the cases variable is in data but it's an empty list
    assert data[loqus_id]["cases"] == []