Пример #1
0
async def get_docs_results(matchengine: MatchEngine, needed_clinical,
                           needed_extended):
    """
    Matching criteria for clinical and extended_attributes values can be set/extended in config.json
    :param matchengine:
    :param needed_clinical:
    :param needed_extended:
    :return:
    """
    clinical_projection = matchengine.match_criteria_transform.projections[
        "clinical"]
    clinical_query = MongoQuery({"_id": {"$in": list(needed_clinical)}})
    db_calls = list()
    db_calls.append(
        perform_db_call(matchengine, "clinical", clinical_query,
                        clinical_projection))
    for extended_collection, extended_ids in needed_extended.items():
        genomic_query = MongoQuery({"_id": {"$in": list(extended_ids)}})
        projection = matchengine.match_criteria_transform.projections[
            extended_collection]
        db_calls.append(
            perform_db_call(matchengine, extended_collection, genomic_query,
                            projection))

    results = await asyncio.gather(*db_calls)
    return results
Пример #2
0
async def get_all_except(matchengine: MatchEngine, protocol_no: str,
                         trial_matches_by_sample_id: dict) -> list:
    """Return all matches except ones matching current protocol_no"""

    # get clinical ids with matches
    clinical_ids = {
        matchengine.sample_mapping[sample_id]
        for sample_id in trial_matches_by_sample_id.keys()
    }

    # if protocol has been run previously, subtract clinical ids from current run from
    # previously run clinical ids for a specific protocol. The remainder are ids
    # which were run previously, but not in the current run.
    if protocol_no in matchengine.clinical_run_log_entries:
        clinical_ids = matchengine.clinical_run_log_entries[
            protocol_no] - clinical_ids

    query = {
        matchengine.match_criteria_transform.match_trial_link_id: protocol_no,
        "clinical_id": {
            '$in': [clinical_id for clinical_id in clinical_ids]
        }
    }
    projection = {'_id': 1, 'hash': 1, 'clinical_id': 1}

    results = await perform_db_call(
        matchengine,
        collection=matchengine.trial_match_collection,
        query=MongoQuery(query),
        projection=projection)

    return [result for result in results]
Пример #3
0
async def get_matches_to_disable(matchengine: MatchEngine,
                                 new_matches_hashes: list, protocol_no: str,
                                 sample_id: str) -> list:
    """
    Get matches to disable by looking for existing, enabled matches whose
    hashes are not present in newly generated matches during current run.

    Done for every sample_id

    :param matchengine:
    :param new_matches_hashes:
    :param protocol_no:
    :param sample_id:
    :return:
    """
    query = {
        matchengine.match_criteria_transform.match_trial_link_id: protocol_no,
        'sample_id': sample_id,
        'is_disabled': False,
        'hash': {
            '$nin': new_matches_hashes
        }
    }
    matches_to_disable_query = MongoQuery(query)
    projection = {"hash": 1, "is_disabled": 1}
    matches = await asyncio.gather(
        perform_db_call(matchengine, matchengine.trial_match_collection,
                        matches_to_disable_query, projection))
    return matches[0]
Пример #4
0
async def get_all_except(matchengine: MatchEngine,
                         protocol_no: str,
                         trial_matches_by_sample_id: dict) -> list:
    """Return all matches except ones matching current protocol_no"""
    clinical_ids = {matchengine.sample_mapping[sample_id] for sample_id in trial_matches_by_sample_id.keys()}

    if protocol_no in matchengine.clinical_run_log_entries:
        clinical_ids = matchengine.clinical_run_log_entries[protocol_no] - clinical_ids

    query = {
        'protocol_no': protocol_no,
        "clinical_id": {
            '$in': [clinical_id for clinical_id in clinical_ids]
        }
    }
    projection = {
        '_id': 1,
        'hash': 1,
        'clinical_id': 1
    }

    results = await perform_db_call(matchengine,
                                    collection=matchengine.trial_match_collection,
                                    query=MongoQuery(query),
                                    projection=projection)

    return [result for result in results]
Пример #5
0
async def get_docs_results(matchengine: MatchEngine, needed_clinical,
                           needed_genomic):
    """
    Matching criteria for clinical and genomic values can be set/extended in config.json
    :param matchengine:
    :param needed_clinical:
    :param needed_genomic:
    :return:
    """
    genomic_projection = matchengine.match_criteria_transform.genomic_projection
    clinical_projection = matchengine.match_criteria_transform.clinical_projection
    clinical_query = MongoQuery({"_id": {"$in": list(needed_clinical)}})
    genomic_query = MongoQuery({"_id": {"$in": list(needed_genomic)}})
    results = await asyncio.gather(
        perform_db_call(matchengine, "clinical", clinical_query,
                        clinical_projection),
        perform_db_call(matchengine, "genomic", genomic_query,
                        genomic_projection))
    return results
Пример #6
0
async def get_existing_matches(matchengine: MatchEngine, new_matches_hashes: list) -> list:
    matches_to_not_change_query = MongoQuery({'hash': {'$in': new_matches_hashes}})
    projection = {"hash": 1, "is_disabled": 1}
    matches = await asyncio.gather(
        perform_db_call(matchengine,
                        matchengine.trial_match_collection,
                        matches_to_not_change_query,
                        projection)
    )
    return matches[0]
Пример #7
0
async def get_matches_to_disable(matchengine: MatchEngine,
                                 new_matches_hashes: list,
                                 protocol_no: str,
                                 sample_id: str) -> list:
    matches_to_disable_query = MongoQuery({'protocol_no': protocol_no,
                                           'sample_id': sample_id,
                                           'is_disabled': False,
                                           'hash': {'$nin': new_matches_hashes}})
    projection = {"hash": 1, "is_disabled": 1}
    matches = await asyncio.gather(
        perform_db_call(matchengine,
                        matchengine.trial_match_collection,
                        matches_to_disable_query,
                        projection)
    )
    return matches[0]
Пример #8
0
async def get_existing_matches(matchengine: MatchEngine,
                               new_matches_hashes: list) -> list:
    """
    Get matches in db which have the same hashes as newly found matches.
    :param matchengine:
    :param new_matches_hashes:
    :return:
    """
    matches_to_not_change_query = MongoQuery(
        {'hash': {
            '$in': new_matches_hashes
        }})
    projection = {"hash": 1, "is_disabled": 1}
    matches = await asyncio.gather(
        perform_db_call(matchengine, matchengine.trial_match_collection,
                        matches_to_not_change_query, projection))
    return matches[0]