analysis.residuals#
Utilities to compute vectors of residuals.
- bulkdgd.analysis.residuals.get_genes_by_residual_threshold(df_res: DataFrame, le_than: int | float = -1, ge_than: int | float = 1, sort_genes: bool = False, ascending: bool = False) tuple[DataFrame, DataFrame, DataFrame, DataFrame]#
Get the genes whose residuals fall in specified intervals and are common to a certain number of samples.
- Parameters:
- df_res
pandas.DataFrame A data frame containing the residual vectors for a set of samples.
- le_than
intorfloat,-1 Consider only genes whose residual value in all samples is lower than or equal to the provided value.
- ge_than
intorfloat,1 Consider only genes whose residual value in all samples is greater than or equal to the provided value.
- df_res
- Returns:
- df_samples_count_le
pandas.DataFrame A data frame containing each gene with the count of samples where the gene’s residual value is lower than or equal to
le_than.The data frame’s rows are identified by each gene’s ID (as provided in the input data frame) and the data frame includes one column:
‘n_samples’: the number of samples where the gene’s residual meets the condition.
- df_genes_distribution_le
pandas.DataFrame A data frame displaying the distribution of genes having a residual value lower than or equal to
le_thanacross different sample counts.Each row represents the number of samples, and the columns are:
‘n_genes’: the number of genes that meet the condition in exactly that many samples.
‘genes’: a period-separated string listing the genes that meet the condition in exactly that many samples.
- df_samples_count_ge
pandas.DataFrame A data frame containing each gene with the count of samples where the gene’s residual value is greater than or equal to
ge_than.The data frame’s rows are identified by each gene’s ID (as provided in the input data frame) and the data frame includes one column:
‘n_samples’: the number of samples where the gene’s residual meets the condition.
- df_genes_distribution_ge
pandas.DataFrame A data frame displaying the distribution of genes having a residual value greater than or equal to
le_thanacross different sample counts.Each row represents the number of samples, and the columns are:
‘n_genes’: the number of genes that meet the condition in exactly that many samples.
‘genes’: a period-separated string listing the genes that meet the condition in exactly that many samples..
- df_samples_count_le
- bulkdgd.analysis.residuals.get_residuals(obs_counts: Series, pred_means: Series, r_values: Series | None = None, sample_name: str | None = None) Series#
Calculate the vector of residuals between the observed gene expression (counts) and the predicted means of the negative binomials modeling the expression of the different genes for a single sample.
- Parameters:
- obs_counts
pandas.Series The observed gene counts in a single sample.
This is a series whose index contains either the genes’ Ensembl IDs or names of fields containing additional information about the sample.
- pred_means
pandas.Series The predicted means of the distributions modelling the genes’ counts in a single sample.
This is a series whose index contains either the genes’ Ensembl IDs or names of fields containing additional information about the sample.
If the genes’ counts were modelled using negative binomial distributions, the predicted means are scaled by the corresponding distributions’ r-values.
- r_values
pandas.Series, optional The predicted r-values of the negative binomial distributions modelling the genes’ counts in a single sample, if the genes’ counts were modelled using negative binomial distributions.
This is a series whose index contains either the genes’ Ensembl IDs or names of fields containing additional information about the sample.
If
r_valuesis not provided, it is assumed that the genes’ counts were modelled using Poisson distributions.- sample_name
str, optional The name of the sample under consideration. It is used as name for the
pandas.Seriesreturned.If not passed, the series will be unnamed.
- obs_counts
- Returns:
- series_residuals
pandas.Series A series containing the residuals for all genes.
- series_residuals
- bulkdgd.analysis.residuals.get_significant_genes(series_residuals: Series, res_pos_threshold: int | float = 1, res_neg_threshold: int | float = -1) Series#
Get the genes that are significant at a given significance level.
- Parameters:
- series_residuals
pandas.Series A series containing the residuals for all genes in a single sample.
The series’ index contains the genes’ Ensembl IDs, and its values are the residuals.
- res_pos_threshold
intorfloat,1 The threshold above which a gene is considered significantly up-regulated.
- res_neg_threshold
intorfloat,-1 The threshold below which a gene is considered significantly down-regulated.
- series_residuals