コード例 #1
0
def p_GIFs(
    global_lateralisation=False,
    include_paeds_and_adults=True,
    include_only_postictals=False,
    symptom_laterality='NEUTRAL',
    dominance='NEUTRAL',
):
    """
    Return the normalised/unnormalised marginal probabilities for each GIF parcellation.
        for ictal semiologies only (excluding postictals)

    see marginal_GIF_probabilities() for sensitivity analyses
        e.g. by adding include_concordance=False for data queries excluding concordance
            or changing laterality or age
    """

    # normalised
    patient_all_semiology_norm = Semiology(
        ".*",
        symptoms_side=Laterality.NEUTRAL,
        dominant_hemisphere=Laterality.NEUTRAL,
        include_postictals=False,
        include_paeds_and_adults=include_paeds_and_adults,
        normalise_to_localising_values=True,
        global_lateralisation=global_lateralisation,
    )

    if symptom_laterality == 'left':
        patient_all_semiology_norm.symptoms_side = Laterality.LEFT
    if dominance == 'left':
        patient_all_semiology_norm.dominant_hemisphere = Laterality.LEFT

    patient_all_semiology_norm.include_only_postictals = include_only_postictals
    all_combined_gifs_norm, _ = patient_all_semiology_norm.get_num_datapoints_dict(
    )
    p_GIF_norm = marginal_GIF_probabilities(all_combined_gifs_norm)

    # now not normalised version
    patient_all_semiology_notnorm = Semiology(
        ".*",
        symptoms_side=Laterality.NEUTRAL,
        dominant_hemisphere=Laterality.NEUTRAL,
        include_postictals=False,
        include_paeds_and_adults=include_paeds_and_adults,
        normalise_to_localising_values=False,
        global_lateralisation=global_lateralisation,
    )

    if symptom_laterality == 'left':
        patient_all_semiology_notnorm.symptoms_side = Laterality.LEFT
    if dominance == 'left':
        patient_all_semiology_notnorm.dominant_hemisphere = Laterality.LEFT

    patient_all_semiology_notnorm.include_only_postictals = include_only_postictals
    all_combined_gifs_notnorm, _ = patient_all_semiology_notnorm.get_num_datapoints_dict(
    )
    p_GIF_notnorm = marginal_GIF_probabilities(all_combined_gifs_notnorm)

    return p_GIF_norm, p_GIF_notnorm
コード例 #2
0
    def test_latnotloc_and_latandloc_2(self):
        """
        Test capturing the lateralising but not localising data rather than skipping it.
        integrated with lat and loc data.
        """
        patient = Semiology('lat_', Laterality.LEFT, Laterality.LEFT)
        patient.data_frame = self.df
        lat_not_loc_all_combined_gifs = patient.query_lateralisation(
            one_map_dummy)

        # inspect result
        lat_not_loc_result, _ = patient.query_semiology()

        self.assertIs(type(lat_not_loc_all_combined_gifs), pd.DataFrame)
        assert not lat_not_loc_all_combined_gifs.empty

        # drop the zero entries - should be only the IL left ones which aren't MTG of TL:
        lat_not_loc_all_combined_gifs = lat_not_loc_all_combined_gifs[[
            'Gif Parcellations', 'pt #s'
        ]].astype({
            'Gif Parcellations': 'int32',
            'pt #s': 'int32'
        })
        lat_not_loc_all_combined_gifs.set_index('Gif Parcellations',
                                                inplace=True)
        lat_not_loc_gifsclean = lat_not_loc_all_combined_gifs.loc[
            lat_not_loc_all_combined_gifs['pt #s'] != 0, :]

        gifs_right, gifs_left = gifs_lat_factor()
        lat_not_loc_gifsclean_rights = (lat_not_loc_gifsclean.drop(
            index=156).index.isin(gifs_right).all())

        # inspect result assertions
        assert (lat_not_loc_result.Localising.sum() == 1)
        assert (lat_not_loc_result['Lateralising'].sum() == 2)

        # all_combined_gifs assertions
        # all except GIF 156 (L MTG) are in the right GIFs:
        assert ((lat_not_loc_gifsclean_rights == True))
        assert ((lat_not_loc_gifsclean.index.isin(gifs_left)).any() == True)
        # assert using shape as all pt #s are 1:
        assert (lat_not_loc_gifsclean['pt #s'].sum() ==
                lat_not_loc_gifsclean.shape[0])

        # check that latnotloc gives 1 and latandloc adds zero to right MTG GIF #155
        heatmap, _ = patient.get_num_datapoints_dict(method='minmax')
        assert heatmap[155] == 1  # right
コード例 #3
0
    def test_latexceedsloc_3(self):
        """
        Test capturing lateralisation value when it exceeds localising value (part1) and combining with lat_no_loc and lat_and_loc (part 2).
        Note that the default in Q_L of  normalise_lat_to_loc = False and using norm_ratio = lower_value / higher_value
            results in capping of lateralisation influence on data visualisation.

        In the specific case of latexceedsloc semiology, despite 500 lat cumulative datapoints and 2 localising points,
            the GIF results are:
            {155: 2.0, 156:1.0}
        """
        patient = Semiology('latexceedsloc', Laterality.LEFT, Laterality.LEFT)
        patient.data_frame = self.df

        # (part 1) test latexceedsloc alone using norm_ratio/oddsratio method of Q_L:
        heatmap, _ = patient.get_num_datapoints_dict(method='minmax')
        assert heatmap[156] == 200.0
        assert heatmap[155] == 300.0

        # (part 2) combine above with lat_not_loc and lat_and_loc:
        patient = Semiology('lat', Laterality.LEFT, Laterality.LEFT)
        patient.data_frame = self.df

        lat_allgifs = patient.query_lateralisation(one_map_dummy)

        # drop the zero entries - should be only the IL left ones which aren't MTG of TL:
        lat_allgifs = lat_allgifs[['Gif Parcellations', 'pt #s']].astype({
            'Gif Parcellations':
            'int32',
            'pt #s':
            'int32'
        })
        lat_allgifs.set_index('Gif Parcellations', inplace=True)
        lat_allgifs = lat_allgifs.loc[lat_allgifs['pt #s'] != 0, :]

        # assert using shape this not all are 1 so should not be the same:
        assert not lat_allgifs['pt #s'].sum() == lat_allgifs.shape[0]
        # check the MTG on the left (IL) GIF # 156 is == 3,
        #   which it isn't due to the norm_ratio method in Q_L - as can be seen from part 1
        #   so instead we see in part 1 156 was 1, but in the spreadsheet it was 2. so will give 2.
        #   3 is better but lost due to norm_ratio method in Q_L
        assert (lat_allgifs.loc[156, 'pt #s'] == 201)

        # for the right sided GIF, 155, latexceedsloc gives 2 [/],
        #   lat_not_loc gives 1 (CL) (See test_lat_not_loc_1)[/], and
        #   lat_and_loc adds none [/]
        assert (lat_allgifs.loc[155, 'pt #s'] == 301)
コード例 #4
0
    def test_lat_not_loc_1(self):
        """
        Test capturing the lateralising but not localising data rather than skipping it.
        As implemented in QUERY_LATERALISATION in branch "Lateralising but no localising value".
        """
        patient = Semiology('lat_not_loc', Laterality.LEFT, Laterality.LEFT)
        patient.data_frame = self.df
        lat_not_loc_all_combined_gifs = patient.query_lateralisation(
            one_map_dummy)

        # inspect result
        lat_not_loc_result, num_query_loc = patient.query_semiology()

        self.assertIs(type(lat_not_loc_all_combined_gifs), pd.DataFrame)
        assert not lat_not_loc_all_combined_gifs.empty

        # drop the zero entries as these are from the CL/IL zeros:
        lat_not_loc_all_combined_gifs = lat_not_loc_all_combined_gifs[[
            'Gif Parcellations', 'pt #s'
        ]].astype({
            'Gif Parcellations': 'int32',
            'pt #s': 'int32'
        })
        lat_not_loc_all_combined_gifs.set_index('Gif Parcellations',
                                                inplace=True)
        lat_not_loc_gifsclean = lat_not_loc_all_combined_gifs.loc[
            lat_not_loc_all_combined_gifs['pt #s'] != 0, :]
        # now we know only the CL data remains in this dummy data, which is on the RIGHT.
        gifs_right, gifs_left = gifs_lat_factor()
        lat_not_loc_gifsclean_rights = (
            lat_not_loc_gifsclean.index.isin(gifs_right).all())

        # inspect result assertions
        assert (lat_not_loc_result.Localising.sum() == 0)
        assert (lat_not_loc_result['Lateralising'].sum() == 1)

        # all_combined_gifs assertions
        assert ((lat_not_loc_gifsclean_rights == True))
        assert ((lat_not_loc_gifsclean.index.isin(gifs_left)).any() == False)
        assert (lat_not_loc_gifsclean['pt #s'].sum() ==
                lat_not_loc_gifsclean.shape[0])

        # test MTG on right 155 gif # gives 1:
        heatmap, _ = patient.get_num_datapoints_dict(method='minmax')
        assert 156 not in heatmap  # left
        assert heatmap[155] == 1  # right
コード例 #5
0
    def test_only_postictal_cases(self):
        """
        Include only the single postictal aphasia. Note Dominant in dummy data.
        cf test_postictal_exclusions
        """
        # Low level test
        df_postictal = only_postictal_cases(self.df)
        query, num_query_lat, num_query_loc = QUERY_SEMIOLOGY(
            df_postictal,
            semiology_term=['aphasia'],
            ignore_case=True,
            semiology_dict_path=None,
            col1='Reported Semiology',
            col2='Semiology Category',
        )
        assert (query['Localising'].sum() == 1)
        assert (query['Lateralising'].sum() == 1)

        # High level test
        patient = Semiology('aphasia',
                            Laterality.NEUTRAL,
                            dominant_hemisphere=Laterality.LEFT)
        patient.data_frame = self.df
        patient.include_postictals = True
        patient.include_only_postictals = True
        patient.granular = True

        lat_allgifs = patient.query_lateralisation(one_map_dummy)
        lat_allgifs = lat_allgifs[['Gif Parcellations', 'pt #s']].astype({
            'Gif Parcellations':
            'int32',
            'pt #s':
            'int32'
        })
        lat_allgifs.set_index('Gif Parcellations', inplace=True)

        # note that dominant_hemisphere == Laterality.LEFT as set above. Just to clarify results change if dominace changes. Also 1's become 2's if not granular.
        assert (lat_allgifs.loc[164, 'pt #s'] == 1)
        assert (lat_allgifs.loc[166, 'pt #s'] == 1)
        assert (lat_allgifs.loc[163, 'pt #s'] == 0)
        assert (lat_allgifs.loc[165, 'pt #s'] == 0)

        lat_allgifs = lat_allgifs.loc[lat_allgifs['pt #s'] != 0, :]
        SVT_output, _ = patient.get_num_datapoints_dict(method='minmax')
        assert SVT_output == dict((lat_allgifs)['pt #s'])