Skip to content

plot_component_sizes

component_hist(data, highlight=None)

Draw a histogram for the given data.

This function is made for drawing histograms for data in small integer ranges, so the bin size is always 1.

One bar of the histogram can be highlighted in a different color. This could represent, for example, the bar corresponding to the number of samples present in the analysis.

Parameters:

Name Type Description Default
data list

Data from which to compute frequency distribution.

required
highlight int

Value frequency to highlight in a different color.

None
Source code in src/rna_clique/plot_component_sizes.py
def component_hist(data: list[int], highlight: Optional[int] = None):
    """Draw a histogram for the given data.

    This function is made for drawing histograms for data in small integer
    ranges, so the bin size is always 1.

    One bar of the histogram can be highlighted in a different color. This could
    represent, for example, the bar corresponding to the number of samples
    present in the analysis.

    Parameters:
        data (list):     Data from which to compute frequency distribution.
        highlight (int): Value frequency to highlight in a different color.
    """
    hist, bins = np.histogram(
        data,
        bins=range(1, max(data) + 2)
    )
    # embed()
    plt.bar(bins[:-1], hist, width=np.diff(bins), color="C0", align="center")
    plt.bar(
        bins[highlight - 1],
        hist[highlight - 1],
        width=np.diff(bins),
        color="C1",
        align="center"
    )

count_samples(config)

Determine the number of samples used in an analysis.

This function prefers faster ways of determining the number of samples if they are available. If the number of samples could not be determined from the command-line arguments and configuration, then a SampleCountError will be raised.

Parameters:

Name Type Description Default
config RNACliqueConfig

RNACliqueConfig for the analysis.

required

Returns:

Type Description
int

The number of samples used in the analysis.

Source code in src/rna_clique/plot_component_sizes.py
def count_samples(config: config_module.RNACliqueConfig) -> int:
    """Determine the number of samples used in an analysis.

    This function prefers faster ways of determining the number of samples if
    they are available. If the number of samples could not be determined from
    the command-line arguments and configuration, then a SampleCountError will
    be raised.

    Parameters:
        config: RNACliqueConfig for the analysis.

    Returns:
        The number of samples used in the analysis.

    """
    if config.path_to_sample is not None:
        return len(config.path_to_sample)
    if config.input_dirs is not None:
        return len(config.input_dirs)
    if config.tables_dir is not None:
        return len(
            set.union(
                *(
                    {df.iloc[0][f"{s}sample"] for s in "sq"} for df in
                    map(
                        read_table,
                        get_table_files(config.tables_dir)
                    )
                )
            )
        )
    raise SampleCountError(
        ("Could not determine number of samples from arguments "
         "and configuration.")
    )