def test_mme_add(self, populated_database, user_obj, case_obj,
                     parsed_variant):
        """test calling the controller that submits new patients to Matchmaker"""

        session = requests.Session()
        adapter = populated_database

        # Add an HPO term to this scout case
        assert case_obj.get('phenotype_terms') == None
        phenotype_term = {
            'phenotype_id': 'HP:0011031',
            'feature': 'Abnormality of iron homeostasis'
        }
        updated_case = adapter.case_collection.find_one_and_update(
            {'_id': case_obj['_id']},
            {'$set': {
                'phenotype_terms': [phenotype_term]
            }},
            return_document=pymongo.ReturnDocument.AFTER)
        assert updated_case['phenotype_terms'][0] == phenotype_term

        # Check that features (HPO) terms are obtained by MME parser
        features = hpo_terms(updated_case)
        assert features

        # Add a couple of OMIM diagnoses to this case
        assert case_obj.get('diagnosis_phenotypes') == None
        updated_case = adapter.case_collection.find_one_and_update(
            {'_id': case_obj['_id']},
            {'$set': {
                'diagnosis_phenotypes': [615349, 616833]
            }},
            return_document=pymongo.ReturnDocument.AFTER)
        assert updated_case['diagnosis_phenotypes']

        # Check that OMIM terms are obtained by MME parser
        diagnoses = omim_terms(updated_case)
        assert diagnoses

        # Add variant containing a gene to database and pin it for this case
        a_gene = adapter.hgnc_collection.find_one()
        assert a_gene['hgnc_id']
        assert adapter.variant_collection.find_one() is None
        parsed_variant['hgnc_ids'] = [a_gene['hgnc_id']]
        parsed_variant['samples'] = [
            {  # pretend the affected subject has the allele
                'sample_id': 'ADM1059A2',
                'display_name': 'NA12882',
                'genotype_call': '0/1'
            }
        ]
        adapter.variant_collection.insert_one(parsed_variant)
        assert adapter.variant_collection.find_one()

        # pin it
        updated_case = adapter.case_collection.find_one_and_update(
            {'_id': case_obj['_id']},
            {'$set': {
                'suspects': [parsed_variant['_id']]
            }},
            return_document=pymongo.ReturnDocument.AFTER)
        assert updated_case['suspects'] == [parsed_variant['_id']]

        # Check that genomic features are created correcly by MME parser
        g_feat = genomic_features(adapter, updated_case, 'NA12882', 'False')
        assert g_feat

        # use controller to send request and collect response
        mme_base_url = 'http://localhost:{port}'.format(
            port=self.mock_server_port)

        submitted_info = controllers.mme_add(store=adapter,
                                             user_obj=user_obj,
                                             case_obj=updated_case,
                                             add_gender=True,
                                             add_features=True,
                                             add_disorders=True,
                                             genes_only=False,
                                             mme_base_url=mme_base_url,
                                             mme_accepts=MME_ACCEPTS,
                                             mme_token=MME_TOKEN)

        assert submitted_info['server_responses'][0]['patient']
Beispiel #2
0
    def test_mme_add(self, populated_database, user_obj, case_obj,
                     parsed_variant):
        """test calling the controller that submits new patients to Matchmaker"""

        session = requests.Session()
        adapter = populated_database

        # Add an HPO term to this scout case
        assert len(case_obj.get("phenotype_terms")) == 0
        phenotype_term = {
            "phenotype_id": "HP:0011031",
            "feature": "Abnormality of iron homeostasis",
        }
        updated_case = adapter.case_collection.find_one_and_update(
            {"_id": case_obj["_id"]},
            {"$set": {
                "phenotype_terms": [phenotype_term]
            }},
            return_document=pymongo.ReturnDocument.AFTER,
        )
        assert updated_case["phenotype_terms"][0] == phenotype_term

        # Check that features (HPO) terms are obtained by MME parser
        features = hpo_terms(updated_case)
        assert features

        # Add a couple of OMIM diagnoses to this case
        assert case_obj.get("diagnosis_phenotypes") is None
        updated_case = adapter.case_collection.find_one_and_update(
            {"_id": case_obj["_id"]},
            {"$set": {
                "diagnosis_phenotypes": [615349, 616833]
            }},
            return_document=pymongo.ReturnDocument.AFTER,
        )
        assert updated_case["diagnosis_phenotypes"]

        # Check that OMIM terms are obtained by MME parser
        diagnoses = omim_terms(updated_case)
        assert diagnoses

        # Add variant containing a gene to database and pin it for this case
        a_gene = adapter.hgnc_collection.find_one()
        assert a_gene["hgnc_id"]
        assert adapter.variant_collection.find_one() is None
        parsed_variant["hgnc_ids"] = [a_gene["hgnc_id"]]
        parsed_variant["samples"] = [
            {  # pretend the affected subject has the allele
                "sample_id": "ADM1059A2",
                "display_name": "NA12882",
                "genotype_call": "0/1",
            }
        ]
        adapter.variant_collection.insert_one(parsed_variant)
        assert adapter.variant_collection.find_one()

        # pin it
        updated_case = adapter.case_collection.find_one_and_update(
            {"_id": case_obj["_id"]},
            {"$set": {
                "suspects": [parsed_variant["_id"]]
            }},
            return_document=pymongo.ReturnDocument.AFTER,
        )
        assert updated_case["suspects"] == [parsed_variant["_id"]]

        # Check that genomic features are created correcly by MME parser
        g_feat = genomic_features(adapter, updated_case, "NA12882", "False")
        assert g_feat

        # use controller to send request and collect response
        mme_base_url = "http://localhost:{port}".format(
            port=self.mock_server_port)

        submitted_info = controllers.mme_add(
            store=adapter,
            user_obj=user_obj,
            case_obj=updated_case,
            add_gender=True,
            add_features=True,
            add_disorders=True,
            genes_only=False,
            mme_base_url=mme_base_url,
            mme_accepts=MME_ACCEPTS,
            mme_token=MME_TOKEN,
        )

        assert submitted_info["server_responses"][0]["patient"]