Example #1
0
def mark_validation(institute_id, case_name, variant_id):
    """Mark a variant as sanger validated."""
    institute_obj, case_obj = institute_and_case(store, institute_id, case_name)
    variant_obj = store.variant(variant_id)
    user_obj = store.user(current_user.email)
    validate_type = request.form['type'] or None
    link = url_for('variants.variant', institute_id=institute_id, case_name=case_name,
                   variant_id=variant_id)
    store.validate(institute_obj, case_obj, user_obj, link, variant_obj, validate_type)
    return redirect(request.referrer or link)
Example #2
0
def mark_validation(institute_id, case_name, variant_id):
    """Mark a variant as sanger validated."""
    institute_obj, case_obj = institute_and_case(store, institute_id, case_name)
    variant_obj = store.variant(variant_id)
    user_obj = store.user(current_user.email)
    validate_type = request.form['type'] or None
    link = url_for('variants.variant', institute_id=institute_id, case_name=case_name,
                   variant_id=variant_id)
    store.validate(institute_obj, case_obj, user_obj, link, variant_obj, validate_type)
    return redirect(request.referrer or link)
def test_export_verified(mock_app, case_obj, user_obj, institute_obj):
    """Test the CLI command that exports verified variants into excel files"""

    runner = mock_app.test_cli_runner()
    assert runner

    # Load snv variants using the cli
    result = runner.invoke(cli, [
        'load',
        'variants',
        case_obj['_id'],
        '--snv',
    ])

    assert store.variant_collection.find_one() is not None

    # Test the cli without verified variants available
    result = runner.invoke(cli, ['export', 'verified'])
    assert result.exit_code == 0
    assert 'There are no verified variants for institute cust000 in database!' in result.output

    # Set a variant as verified
    variant_obj = store.variant_collection.find_one()

    # Validate the above variant:
    store.validate(institute=institute_obj,
                   case=case_obj,
                   user=user_obj,
                   link='link_to_var',
                   variant=variant_obj,
                   validate_type='True positive')
    var_res = store.variant_collection.find({'validation': 'True positive'})
    assert sum(1 for i in var_res) == 1
    event_res = store.event_collection.find({'verb': 'validate'})
    assert sum(1 for i in event_res) == 1

    # Test the cli without parameters
    result = runner.invoke(cli, ['export', 'verified', '--test'])
    assert result.exit_code == 0
    # Variant should be found now
    assert 'Success. Verified variants file contains' in result.output

    # Test the cli with with a wrong collaborator param
    result = runner.invoke(cli,
                           ['export', 'verified', '--test', '-c', 'cust666'])
    assert result.exit_code == 0
    # Variant should not be found now
    assert 'There are no verified variants for institute cust666 in database!' in result.output

    # Test the cli with the right collaborator param
    result = runner.invoke(
        cli, ['export', 'verified', '--test', '-c', case_obj['owner']])
    assert result.exit_code == 0
    # Variant should be found again
    assert 'Success. Verified variants file contains' in result.output
def test_export_verified(mock_app, case_obj, user_obj, institute_obj):
    """Test the CLI command that exports verified variants into excel files"""

    runner = mock_app.test_cli_runner()
    assert runner

    # Load snv variants using the cli
    result = runner.invoke(cli, ["load", "variants", case_obj["_id"], "--snv"])

    assert store.variant_collection.find_one() is not None

    # Test the cli without verified variants available
    result = runner.invoke(cli, ["export", "verified"])
    assert result.exit_code == 0
    assert ("There are no verified variants for institute cust000 in database!"
            in result.output)

    # Set a variant as verified
    variant_obj = store.variant_collection.find_one()

    # Validate the above variant:
    store.validate(
        institute=institute_obj,
        case=case_obj,
        user=user_obj,
        link="link_to_var",
        variant=variant_obj,
        validate_type="True positive",
    )
    var_res = store.variant_collection.find({"validation": "True positive"})
    assert sum(1 for i in var_res) == 1
    event_res = store.event_collection.find({"verb": "validate"})
    assert sum(1 for i in event_res) == 1

    # Test the cli without parameters
    result = runner.invoke(cli, ["export", "verified", "--test"])
    assert result.exit_code == 0
    # Variant should be found now
    assert "Success. Verified variants file contains" in result.output

    # Test the cli with with a wrong collaborator param
    result = runner.invoke(cli,
                           ["export", "verified", "--test", "-c", "cust666"])
    assert result.exit_code == 0
    # Variant should not be found now
    assert ("There are no verified variants for institute cust666 in database!"
            in result.output)

    # Test the cli with the right collaborator param
    result = runner.invoke(
        cli, ["export", "verified", "--test", "-c", case_obj["owner"]])
    assert result.exit_code == 0
    # Variant should be found again
    assert "Success. Verified variants file contains" in result.output
Example #5
0
def test_reload_variants(mock_app, case_obj, user_obj, institute_obj):
    """Testing loading again variants after rerun"""

    runner = mock_app.test_cli_runner()
    assert runner

    # Given an empty variant database
    assert sum(1 for i in store.variant_collection.find()) == 0

    # After using the CLI uploading SNV variants for a case
    result = runner.invoke(
        cli,
        ["load", "variants", case_obj["_id"], "--snv", "--rank-treshold", 10])
    assert result.exit_code == 0

    # Variants collection should be populated
    assert sum(1 for i in store.variant_collection.find()) > 0

    ## Order Sanger for one variant and set it to validated
    one_variant = store.variant_collection.find_one()
    store.order_verification(
        institute=institute_obj,
        case=case_obj,
        user=user_obj,
        link="sanger_link",
        variant=one_variant,
    )

    # then one variant should have an associated Sanger event
    assert (sum(1 for i in store.event_collection.find({
        "verb": "sanger",
        "category": "variant"
    })) == 1)

    store.validate(
        institute=institute_obj,
        case=case_obj,
        user=user_obj,
        link="validated_link",
        variant=one_variant,
        validate_type="True positive",
    )

    # then one variant should have an associated Sanger event
    assert (sum(1 for i in store.event_collection.find({
        "verb": "validate",
        "category": "variant"
    })) == 1)

    # Check that the variant is validated
    new_variant = store.variant_collection.find_one(
        {"display_name": one_variant["display_name"]})
    assert new_variant["validation"] == "True positive"

    # force re-upload the same variants using the command line:
    result = runner.invoke(
        cli,
        [
            "load",
            "variants",
            case_obj["_id"],
            "--snv",
            "--rank-treshold",
            10,
            "--force",
        ],
    )
    assert result.exit_code == 0

    # Then the variant from before should be already validated:
    new_variant = store.variant_collection.find_one(
        {"display_name": one_variant["display_name"]})
    assert new_variant["validation"] == "True positive"

    # And 2 Sanger events shouls be found associated with the variants
    assert (sum(1 for i in store.event_collection.find({
        "verb": "sanger",
        "category": "variant"
    })) == 2)