Exemplo n.º 1
0
def test_parse_matches(case_obj, match_objs):
    """tests that a list of MatchMaker matches returned by the server is interpreted
    as it should
    """
    case_id = case_obj["_id"]
    affected_id = ""

    for individual in case_obj["individuals"]:
        if individual["phenotype"] == "affected":
            affected_id = individual["individual_id"]
            assert affected_id

    # scout patient's id in matchmaker database is composed like this
    # scout_case_id.affected_individual_id
    mme_patient_id = ".".join([case_id, affected_id])

    # make sure that results are returned by parsing matching object
    parsed_obj = parse_matches(mme_patient_id, match_objs)

    assert isinstance(parsed_obj, list)
    # mme_patient_id has matches in match_objs:
    assert len(parsed_obj) == 2

    for match in parsed_obj:
        # make sure that all important fields are available in match results
        assert match["match_oid"]
        assert match["match_date"]
        matching_patients = match["patients"]
        for m_patient in matching_patients:
            assert m_patient["patient_id"]
            assert m_patient["node"]
            assert m_patient["score"]
            assert m_patient["patient"]
def test_parse_matches(case_obj, match_objs):
    """ tests that a list of MatchMaker matches returned by the server is interpreted
        as it should
    """
    case_id = case_obj['_id']
    affected_id = ''

    for individual in case_obj['individuals']:
        if individual['phenotype'] == 'affected':
            affected_id = individual['individual_id']
            assert affected_id

    # scout patient's id in matchmaker database is composed like this
    # scout_case_id.affected_individual_id
    mme_patient_id = '.'.join([case_id, affected_id])

    # make sure that results are returned by parsing matching object
    parsed_obj = parse_matches(mme_patient_id, match_objs)

    assert isinstance(parsed_obj, list)
    # mme_patient_id has matches in match_objs:
    assert len(parsed_obj) == 2

    for match in parsed_obj:
        # make sure that all important fields are available in match results
        assert match['match_oid']
        assert match['match_date']
        matching_patients = match['patients']
        for m_patient in matching_patients:
            assert m_patient['patient_id']
            assert m_patient['node']
            assert m_patient['score']
            assert m_patient['patient']
Exemplo n.º 3
0
def matchmaker_matches(request, institute_id, case_name):
    """Show Matchmaker submission data for a sample and eventual matches.

    Args:
        request(werkzeug.local.LocalProxy)
        institute_id(str): _id of an institute
        case_name(str): display name of a case

    Returns:
        data(dict): data to display in the html template
    """
    # Check that general MME request requirements are fulfilled
    matchmaker_check_requirements(request)

    institute_obj, case_obj = institute_and_case(store, institute_id, case_name)
    data = {
        "institute": institute_obj,
        "case": case_obj,
        "server_errors": [],
        "panel": 1,
    }
    matches = {}
    for patient in case_obj.get("mme_submission", {}).get("patients", []):
        patient_id = patient["id"]
        matches[patient_id] = None
        server_resp = matchmaker.patient_matches(patient_id)
        if server_resp.get("status_code") != 200:  # server returned error
            flash(
                "MatchMaker server returned error:{}".format(data["server_errors"]),
                "danger",
            )
            return redirect(request.referrer)
        # server returned a valid response
        pat_matches = []
        if server_resp.get("content", {}).get("matches"):
            pat_matches = parse_matches(patient_id, server_resp["content"]["matches"])
        matches[patient_id] = pat_matches

    data["matches"] = matches
    return data
Exemplo n.º 4
0
def mme_matches(case_obj, institute_obj, mme_base_url, mme_token):
    """Show Matchmaker submission data for a sample and eventual matches.

    Args:
        case_obj(dict): a scout case object
        institute_obj(dict): an institute object
        mme_base_url(str) base url of the MME server
        mme_token(str) auth token of the MME server

    Returns:
        data(dict): data to display in the html template
    """
    data = {
        'institute' : institute_obj,
        'case' : case_obj,
        'server_errors' : []
    }
    matches = {}
    # loop over the submitted samples and get matches from the MatchMaker server
    if not case_obj.get('mme_submission'):
        return None

    for patient in case_obj['mme_submission']['patients']:
        patient_id = patient['id']
        matches[patient_id] = None
        url = ''.join([ mme_base_url, '/matches/', patient_id])
        server_resp = matchmaker_request(url=url, token=mme_token, method='GET')
        if 'status_code' in server_resp: # the server returned a valid response
            # and this will be a list of match objects sorted by desc date
            pat_matches = []
            if server_resp.get('matches'):
                pat_matches = parse_matches(patient_id, server_resp['matches'])
            matches[patient_id] = pat_matches
        else:
            LOG.warning('Server returned error message: {}'.format(server_resp['message']))
            data['server_errors'].append(server_resp['message'])

    data['matches'] = matches

    return data
Exemplo n.º 5
0
def mme_matches(case_obj, institute_obj, mme_base_url, mme_token):
    """Show Matchmaker submission data for a sample and eventual matches.

    Args:
        case_obj(dict): a scout case object
        institute_obj(dict): an institute object
        mme_base_url(str) base url of the MME server
        mme_token(str) auth token of the MME server

    Returns:
        data(dict): data to display in the html template
    """
    data = {
        'institute' : institute_obj,
        'case' : case_obj,
        'server_errors' : []
    }
    matches = {}
    # loop over the submitted samples and get matches from the MatchMaker server
    if not case_obj.get('mme_submission'):
        return None

    for patient in case_obj['mme_submission']['patients']:
        patient_id = patient['id']
        matches[patient_id] = None
        url = ''.join([ mme_base_url, '/matches/', patient_id])
        server_resp = matchmaker_request(url=url, token=mme_token, method='GET')
        if 'status_code' in server_resp: # the server returned a valid response
            # and this will be a list of match objects sorted by desc date
            pat_matches = []
            if server_resp.get('matches'):
                pat_matches = parse_matches(patient_id, server_resp['matches'])
            matches[patient_id] = pat_matches
        else:
            LOG.warning('Server returned error message: {}'.format(server_resp['message']))
            data['server_errors'].append(server_resp['message'])

    data['matches'] = matches

    return data
Exemplo n.º 6
0
def mme_matches(case_obj, institute_obj, mme_base_url, mme_token):
    """Show Matchmaker submission data for a sample and eventual matches.

    Args:
        case_obj(dict): a scout case object
        institute_obj(dict): an institute object
        mme_base_url(str) base url of the MME server
        mme_token(str) auth token of the MME server

    Returns:
        data(dict): data to display in the html template
    """
    data = {"institute": institute_obj, "case": case_obj, "server_errors": []}
    matches = {}
    # loop over the submitted samples and get matches from the MatchMaker server
    if not case_obj.get("mme_submission"):
        return None

    for patient in case_obj["mme_submission"]["patients"]:
        patient_id = patient["id"]
        matches[patient_id] = None
        url = "".join([mme_base_url, "/matches/", patient_id])
        server_resp = matchmaker_request(url=url,
                                         token=mme_token,
                                         method="GET")
        if "status_code" in server_resp:  # the server returned a valid response
            # and this will be a list of match objects sorted by desc date
            pat_matches = []
            if server_resp.get("matches"):
                pat_matches = parse_matches(patient_id, server_resp["matches"])
            matches[patient_id] = pat_matches
        else:
            LOG.warning("Server returned error message: {}".format(
                server_resp["message"]))
            data["server_errors"].append(server_resp["message"])

    data["matches"] = matches

    return data