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:

pandas 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/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/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...
   group size  observed fold change  ...      pval  significant
0           7              2.806873  ...  0.360264        False

[1 rows x 5 columns]