예제 #1
0
    def test_trial_normalization(self):

        db = get_db()
        db['normalize'].insert(MAPPING)

        # define test json
        with open(os.path.join(YAML_DIR, "00-001.yml")) as fin:
            test_json = yaml.load(fin)

        # do the mapping.
        entry_insert("trial", [test_json])

        build_trial_elasticsearch_fields([test_json])

        db['normalize'].drop()
예제 #2
0
    def test_trial_validation(self):

        # define test json
        with open(os.path.join(YAML_DIR, "00-003.yml")) as fin:
            test_json = yaml.load(fin)

        # post and it should fail.
        r, status_code = self.post("trial", test_json)
        assert status_code == 422, r

        # add values to database.
        self.db['normalize'].drop()
        mapping = copy.deepcopy(self.mapping)
        mapping['values']['oncotree_primary_diagnosis'][
            "Diffuse Large B-Cell Lymphoma"] = "Diffuse Large B-Cell Lymphoma"
        self.db['normalize'].insert(mapping)

        # post and it should pass
        build_trial_elasticsearch_fields([test_json])
        assert test_json['treatment_list']['step'][1]['arm'][1]['match'][0][
            'and'][1]['clinical'][
                'oncotree_primary_diagnosis'] == '!Diffuse Large B-Cell Lymphoma'
        assert test_json['status'] == 'OPEN TO ACCRUAL'

        suggestor_options = [
            'cancer_type_suggest', 'hugo_symbol_suggest', 'variant_suggest',
            'wildtype_suggest', 'cnv_suggest', 'sv_suggest',
            'protocol_no_suggest', 'disease_center_suggest',
            'disease_status_suggest', 'drug_suggest', 'investigator_suggest',
            'mmr_status_suggest', 'nct_number_suggest'
        ]
        assert sorted(
            test_json['_suggest'].keys()) == sorted(suggestor_options)

        genes = test_json['_suggest']['hugo_symbol_suggest']['input']
        assert isinstance(genes, list)
        assert 'MYC' in genes
        assert len(genes) == 1

        assert test_json['_suggest']['cancer_type_suggest'] == []
예제 #3
0
    def test_set_update(self):
        trial = set_updated(self.trial)
        trial = self._prep_trial(trial)
        assert 'last_updated' in trial, trial
        build_trial_elasticsearch_fields([trial])

        # send again
        trial = set_updated(trial)
        build_trial_elasticsearch_fields([trial])
        assert 'last_updated' in trial, trial
        assert 'curated_on' in trial and trial['curated_on'] == '', trial
        for field in self.trial_status_fields:
            assert field in trial['_summary'], '%s\n\n %s' % (
                trial['_summary'], field)

        # curate
        trial = set_curated(trial)
        assert 'last_updated' in trial, trial
        assert 'curated_on' in trial and trial['curated_on'], trial
        for field in self.trial_status_fields:
            assert field in trial['_summary'], '%s\n\n%s' % (trial['_summary'],
                                                             field)
예제 #4
0
    def test_updatedt_with_curatedt(self):

        # set up
        today = dt.datetime.now().strftime('%B %d, %Y')
        old = 'October 27, 2016'
        on_trial['_genomic'] = {'hugo_symbol': [{'value': 'TEST'}]}
        on_trial['_clinical'] = {'disease_status': [{'value': ['TEST']}]}

        # set both dates to OLD
        on_trial['curated_on'] = old
        on_trial['last_updated'] = old
        assert on_trial['curated_on'] == old, self._debug(on_trial, 'curated_on')
        assert on_trial['last_updated'] == old, self._debug(on_trial, 'last_updated')

        # set "last_updated" to TODAY
        trial = set_updated(on_trial)
        assert trial['curated_on'] == old, self._debug(trial, 'curated_on')
        assert trial['last_updated'] == today, self._debug(trial, 'last_updated')

        # check dates are preserved after trial_insert is called
        trial['protocol_no'] = '01-001'
        build_trial_elasticsearch_fields([trial])
        assert trial['curated_on'] == old, self._debug(trial, 'curated_on')
        assert trial['last_updated'] == today, self._debug(trial, 'last_updated')

        # check the other way around
        on_trial['curated_on'] = old
        trial['last_updated'] = old
        assert trial['curated_on'] == old, self._debug(trial, 'curated_on')
        assert trial['last_updated'] == old, self._debug(trial, 'last_updated')

        trial = set_curated(on_trial)
        assert trial['curated_on'] == today, self._debug(trial, 'curated_on')
        assert trial['last_updated'] == today, self._debug(trial, 'last_updated')

        build_trial_elasticsearch_fields([trial])
        assert trial['curated_on'] == today, self._debug(trial, 'curated_on')
        assert trial['last_updated'] == today, self._debug(trial, 'last_updated')
예제 #5
0
    def test_trial_reinsert(self):

        # remove extra fields.
        fields = ['_summary']
        trial = yaml_schema.yaml_test_json.copy()
        for key in fields:
            if key in trial:
                del trial[key]

        # insert it.
        self.db['trial'].insert(trial)

        # check we don't have fields.
        for trial in self.db['trial'].find():
            for x in fields:
                assert x not in trial

        # re-annotate it.
        build_trial_elasticsearch_fields([trial])

        # assert we have the fields in the output.
        for x in fields:
            assert x in trial
예제 #6
0
    def test_trial_insert(self):
        # loop over each trial.
        executed_new_yaml = False
        for trial_name in os.listdir(YAML_DIR):

            # open the trial as json
            trial_path = os.path.join(YAML_DIR, trial_name)
            with open(trial_path, "rb") as fin:

                # load yaml
                data_json = yaml.load(fin.read())

                # normalize.
                entry_insert('trial', [data_json])

                # insert it.
                build_trial_elasticsearch_fields([data_json])

                # check these fields are present.
                assert '_summary' in data_json

            # trial 15-153 contains hormone receptor status and wildtype hugo symbol fields
            if trial_name == '00-002.yml':
                assert 'PIK3CA' in data_json['_summary']["genes"]
                assert 'wt PIK3CA' in data_json['_summary']["genes"]
                assert 'Invasive Breast Carcinoma ER+/HER2-' in data_json['_summary']['tumor_types']
                assert len(data_json['_summary']['tumor_types']) == 1
                assert set(data_json['_summary']['disease_status']) == {'Metastatic', 'Advanced'}
                executed_new_yaml = True

            if trial_name == '00-001.yml':
                for diag in data_json['_summary']['tumor_types']:
                    assert diag[0] != '!'

        assert executed_new_yaml, 'Please add trial 00-002 to the tests/data/yaml directory so that' \
                                  'hormone receptor status and wildtype hugo symbol functionality can be' \
                                  'adequately tested.'