rnalysis.filtering.FoldChangeFilter.randomization_test

FoldChangeFilter.randomization_test(ref, alpha: Fraction = 0.05, reps: PositiveInt = 10000, save_csv: bool = False, fname: str | None = None, random_seed: int | None = None) DataFrame

Perform a randomization test to examine whether the fold change of a group of specific genomic features is significantly different than the fold change of a background set of genomic features.

Parameters:
  • ref (FoldChangeFilter) – A reference FoldChangeFilter object which contains the fold change for every reference gene. Will be used to calculate the expected score and to perform randomizations.

  • alpha (float between 0 and 1) – Indicates the threshold for significance (alpha).

  • reps (int larger than 0) – How many repetitions to run the randomization for. 10,000 is the default. Recommended 10,000 or higher.

  • save_csv (bool, default False) – If True, will save the results to a .csv file, under the name specified in β€˜fname’.

  • fname (str or pathlib.Path) – The full path and name of the file to which to save the results. For example: β€˜C:/dir/file’. No β€˜.csv’ suffix is required. If None (default), fname will be requested in a manual prompt.

Return type:

pl.DataFrame

Returns:

A Dataframe with the number of given genes, the observed fold change for the given group of genes, the expected fold change for a group of genes of that size and the p value for the comparison.

Examples:
>>> from rnalysis import filtering
>>> f = filtering.FoldChangeFilter('tests/test_files/fc_1.csv' , 'numerator' , 'denominator')
>>> f_background = f.filter_biotype_from_ref_table('protein_coding', ref='tests/test_files/biotype_ref_table_for_tests.csv', inplace=False) #keep only protein-coding genes as reference
Filtered 9 features, leaving 13 of the original 22 features. Filtering result saved to new object.
>>> f_test = f_background.filter_by_attribute('attribute1', ref='tests/test_files/attr_ref_table_for_examples.csv', inplace=False)
Filtered 6 features, leaving 7 of the original 13 features. Filtering result saved to new object.
>>> rand_test_res = f_test.randomization_test(f_background)
Calculating...
shape: (1, 5)
β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
β”‚ group size ┆ observed fold change ┆ expected fold change ┆ pval     ┆ significant β”‚
β”‚ ---        ┆ ---                  ┆ ---                  ┆ ---      ┆ ---         β”‚
β”‚ f64        ┆ f64                  ┆ f64                  ┆ f64      ┆ bool        β”‚
β•žβ•β•β•β•β•β•β•β•β•β•β•β•β•ͺ══════════════════════β•ͺ══════════════════════β•ͺ══════════β•ͺ═════════════║
β”‚ 7.0        ┆ 2.806873             ┆ 2.510859             ┆ 0.354265 ┆ false       β”‚
β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”΄β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”΄β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”΄β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”΄β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜