コード例 #1
0
def meas_plot_zscores(path,
                      metric_cols,
                      extra_cols,
                      composites,
                      size=None,
                      show=True):
    """Measure and plot z-scores for given columns in a data frame.
    
    Args:
        path (str): Path to data frame.
        metric_cols (List[str]): Sequence of column names for which to 
            compute z-scores.
        extra_cols (List[str]): Additional columns to included in the 
            output data frame.
        composites (List[Enum]): Sequence of enums specifying the 
            combination, typically from :class:`vols.MetricCombos`.
        size (List[int]): Sequence of ``width, height`` to size the figure; 
            defaults to None.
        show (bool): True to display the image; defaults to True.

    """
    # generate z-scores
    df = pd.read_csv(path)
    df = df_io.zscore_df(df, "Region", metric_cols, extra_cols, True)

    # generate composite score column
    df_comb = df_io.combine_cols(df, composites)
    df_io.data_frames_to_csv(
        df_comb, libmag.insert_before_ext(config.filename, "_zhomogeneity"))

    # shift metrics from each condition to separate columns
    conds = np.unique(df["Condition"])
    df = df_io.cond_to_cols_df(df, ["Sample", "Region"], "Condition",
                               "original", metric_cols)
    path = libmag.insert_before_ext(config.filename, "_zscore")
    df_io.data_frames_to_csv(df, path)

    # display as probability plot
    lims = (-3, 3)
    plot_2d.plot_probability(path,
                             conds,
                             metric_cols,
                             "Volume",
                             xlim=lims,
                             ylim=lims,
                             title="Region Match Z-Scores",
                             fig_size=size,
                             show=show,
                             suffix=None,
                             df=df)
コード例 #2
0
def meas_plot_coefvar(path, id_cols, cond_col, cond_base, metric_cols, 
                      composites, size_col=None, size=None, show=True):
    """Measure and plot coefficient of variation (CV) as a scatter plot.
    
    CV is computed two ways:
    
    - Based on columns and equation specified in ``composites``, applied 
      across all samples regardless of group
    - For each metric in ``metric_cols``, separated by groups
    
    Args:
        path (str): Path to data frame.
        id_cols (List[str]): Sequence of columns to serve as index/indices.
        cond_col (str): Name of the condition column.
        cond_base (str): Name of the condition to which all other conditions 
            will be normalized.
        metric_cols (List[str]): Sequence of column names for which to 
            compute z-scores.
        composites (List[Enum]): Sequence of enums specifying the 
            combination, typically from :class:`vols.MetricCombos`.
        size_col (str): Name of weighting column for coefficient of 
            variation measurement; defaults to None.
        size (List[int]): Sequence of ``width, height`` to size the figure; 
            defaults to None.
        show (bool): True to display the image; defaults to True.

    """
    # measure coefficient of variation per sample-region regardless of group
    df = pd.read_csv(path)
    df = df_io.combine_cols(df, composites)
    df_io.data_frames_to_csv(
        df, libmag.insert_before_ext(config.filename, "_coefvar"))
    
    # measure CV within each condition and shift metrics from each 
    # condition to separate columns
    df = df_io.coefvar_df(df, [*id_cols, cond_col], metric_cols, size_col)
    conds = np.unique(df[cond_col])
    df = df_io.cond_to_cols_df(df, id_cols, cond_col, cond_base, metric_cols)
    path = libmag.insert_before_ext(config.filename, "_coefvartransp")
    df_io.data_frames_to_csv(df, path)
    
    # display CV measured by condition as probability plot
    lims = (0, 0.7)
    plot_2d.plot_probability(
        path, conds, metric_cols, "Volume",
        xlim=lims, ylim=lims, title="Coefficient of Variation", 
        fig_size=size, show=show, suffix=None, df=df)