Code Snippets
Introduction
This section provides multiple templates, starting from the folder and data storage structure, followed by data download, processing, and the various ways to use FastCCC for different conditions. It aims to guide users in understanding how to apply our methods and help them reproduce our results effectively.
Code snippets for using FastCCC with a single \(CS\) statistic
Example1: using CPDBTD dataset
Data is available for download here.
Directory Structure
┌─ ...
├─ (your files)
├─ FastCCC (download from github)
├─ db
├─ CPDBv4.1.0 (LRI database provided.)
└─ ...
├─ ...
├─ code_snippets.py (run your code here.)
└─ ...
├─ data
├─ examples (save your downloads here.)
├─ metadata.tsv
├─ normalised_log_counts.h5ad
└─ ...
└─ ...
├─ (your files)
└─ ...
templates
# copy following templates to code_snippets.py
import fastccc
LRI_db_file_path = './db/CPDBv4.1.0/'
meta_file_path = '../data/examples/metadata.tsv'
counts_file_path = '../data/examples/normalised_log_counts.h5ad'
convert_type = 'hgnc_symbol'
interactions_strength, pvals, percents_analysis = fastccc.statistical_analysis_method(
LRI_db_file_path,
meta_file_path,
counts_file_path,
convert_type
)
output
2025-01-25 21:33:20 | INFO | Task id is 41bc60. 2025-01-25 21:33:20 | INFO | Results will be saved to "./results/". 2025-01-25 21:33:20 | INFO | Directory already exists: ./results/ 2025-01-25 21:33:21 | SUCCESS | Data preprocessing done. 2025-01-25 21:33:21 | INFO | Running: -> Mean for single-unit summary function. -> Minimum for multi-unit complex aggregation. -> Arithmetic for L-R combination to compute the CS. -> Percentile is 0.1. 2025-01-25 21:33:45 | SUCCESS | FastCCC calculation done.
Example2: using \(90^{th}\) percentile as single-unit summary
templates
# copy following templates to code_snippets.py
import fastccc
LRI_db_file_path = './db/CPDBv4.1.0/'
meta_file_path = '../data/examples/metadata.tsv'
counts_file_path = '../data/examples/normalised_log_counts.h5ad'
convert_type = 'hgnc_symbol'
interactions_strength, pvals, percents_analysis = fastccc.statistical_analysis_method(
LRI_db_file_path,
meta_file_path,
counts_file_path,
convert_type,
single_unit_summary = 'Quantile_0.9',
)
output
2025-01-26 09:01:53 | INFO | Task id is 504f09. 2025-01-26 09:01:53 | INFO | Results will be saved to "./results/". 2025-01-26 09:01:53 | INFO | Directory already exists: ./results/ 2025-01-26 09:01:54 | SUCCESS | Data preprocessing done. 2025-01-26 09:01:54 | INFO | Running: -> Quantile_0.9 for single-unit summary function. -> Minimum for multi-unit complex aggregation. -> Arithmetic for L-R combination to compute the CS. -> Percentile is 0.1. 2025-01-26 09:02:14 | SUCCESS | FastCCC calculation done.
Example3: using geometric average as \(h(\cdot)\)
templates
# copy following templates to code_snippets.py
import fastccc
LRI_db_file_path = './db/CPDBv4.1.0/'
meta_file_path = '../data/examples/metadata.tsv'
counts_file_path = '../data/examples/normalised_log_counts.h5ad'
convert_type = 'hgnc_symbol'
interactions_strength, pvals, percents_analysis = fastccc.statistical_analysis_method(
LRI_db_file_path,
meta_file_path,
counts_file_path,
convert_type,
single_unit_summary = 'Quantile_0.9',
LR_combination = 'Geometric',
)
output
2025-01-26 09:07:09 | INFO | Task id is 1de6e1. 2025-01-26 09:07:09 | INFO | Results will be saved to "./results/". 2025-01-26 09:07:09 | INFO | Directory already exists: ./results/ 2025-01-26 09:07:10 | SUCCESS | Data preprocessing done. 2025-01-26 09:07:10 | INFO | Running: -> Quantile_0.9 for single-unit summary function. -> Minimum for multi-unit complex aggregation. -> Geometric for L-R combination to compute the CS. -> Percentile is 0.1. 2025-01-26 09:07:42 | SUCCESS | FastCCC calculation done.
Code snippets for using FastCCC with multiple \(CS\) statistics
Example1: using default FastCCC’s multiple analysis
templates
# copy following templates to code_snippets.py
import fastccc
LRI_db_file_path = './db/CPDBv4.1.0/'
meta_file_path = '../data/examples/metadata.tsv'
counts_file_path = '../data/examples/normalised_log_counts.h5ad'
convert_type = 'hgnc_symbol'
fastccc.Cauchy_combination_of_statistical_analysis_methods(
LRI_db_file_path,
meta_file_path,
counts_file_path,
convert_type
)
output
2025-01-26 12:16:33 | INFO | Task id is 70b408. 2025-01-26 12:16:33 | INFO | Results will be saved to "./results/". 2025-01-26 12:16:33 | INFO | Directory already exists: ./results/ 2025-01-26 12:16:34 | SUCCESS | Data preprocessing done. 2025-01-26 12:16:42 | INFO | Running: -> Mean for single-unit summary function.. -> Minimum for multi-unit complex aggregation. -> Arithmetic for L-R combination to compute the CS. -> Percentile is 0.1. 2025-01-26 12:17:01 | SUCCESS | CS scoring module calculation done. 2025-01-26 12:17:01 | INFO | Running: -> Mean for single-unit summary function.. -> Minimum for multi-unit complex aggregation. -> Geometric for L-R combination to compute the CS. -> Percentile is 0.1. 2025-01-26 12:17:25 | SUCCESS | CS scoring module calculation done. 2025-01-26 12:17:26 | INFO | Running: -> Mean for single-unit summary function. -> Average for multi-unit complex aggregation. -> Arithmetic for L-R combination to compute the CS. -> Percentile is 0.1. 2025-01-26 12:17:46 | SUCCESS | CS scoring module calculation done. 2025-01-26 12:17:46 | INFO | Running: -> Mean for single-unit summary function.. -> Average for multi-unit complex aggregation. ... 2025-01-26 12:21:36 | SUCCESS | CS scoring module calculation done. 2025-01-26 12:21:36 | SUCCESS | All CCC branches calculation done. 2025-01-26 12:21:36 | INFO | Task ID for combining is :70b408 2025-01-26 12:21:36 | INFO | There are 16 pval files. 2025-01-26 12:22:13 | SUCCESS | Cauthy combination done. 2025-01-26 12:22:13 | INFO | Integrating 16 interactions_strength files. 2025-01-26 12:22:18 | SUCCESS | Average CS across all scoring methods calculation done.
Example2: using \(2\times1\times2=4\) scoring modules
templates
# copy following templates to code_snippets.py
import fastccc
LRI_db_file_path = './db/CPDBv4.1.0/'
meta_file_path = '../data/examples/metadata.tsv'
counts_file_path = '../data/examples/normalised_log_counts.h5ad'
convert_type = 'hgnc_symbol'
fastccc.Cauchy_combination_of_statistical_analysis_methods(
LRI_db_file_path,
meta_file_path,
counts_file_path,
convert_type,
single_unit_summary_list = ['Mean', 'Quantile_0.9'],
complex_aggregation_list = ['Minimum'],
LR_combination_list = ['Arithmetic', 'Geometric'],
save_path = '../../results/temp/',
use_DEG = True
)
output
2025-01-26 09:38:39 | INFO | Task id is c68f2f. 2025-01-26 09:38:39 | INFO | Directory already exists: ../../results/temp/ 2025-01-26 09:38:40 | SUCCESS | Data preprocessing done. 2025-01-26 09:38:48 | INFO | Running: -> Mean for single-unit summary function. -> Minimum for multi-unit complex aggregation. -> Arithmetic for L-R combination to compute the CS. -> Percentile is 0.1. 2025-01-26 09:39:08 | SUCCESS | CS scoring module calculation done. 2025-01-26 09:39:08 | INFO | Running: -> Mean for single-unit summary function.. -> Minimum for multi-unit complex aggregation. -> Geometric for L-R combination to compute the CS. -> Percentile is 0.1. 2025-01-26 09:39:31 | SUCCESS | CS scoring module calculation done. 2025-01-26 09:39:36 | INFO | Running: -> Quantile_0.9 for single-unit summary function.. -> Minimum for multi-unit complex aggregation. -> Arithmetic for L-R combination to compute the CS. -> Percentile is 0.1. 2025-01-26 09:39:52 | SUCCESS | CS scoring module calculation done. 2025-01-26 09:39:52 | INFO | Running: -> Quantile_0.9 for single-unit summary function.. -> Minimum for multi-unit complex aggregation. -> Geometric for L-R combination to compute the CS. -> Percentile is 0.1. 2025-01-26 09:40:38 | SUCCESS | CS scoring module calculation done. 2025-01-26 09:40:38 | SUCCESS | All scoring modules calculation done. 2025-01-26 09:40:38 | INFO | Task ID for combining is :c68f2f 2025-01-26 09:40:38 | INFO | There are 4 pval files. 2025-01-26 09:40:44 | SUCCESS | Cauthy combination done. 2025-01-26 09:40:58 | SUCCESS | DEGs selection done. 2025-01-26 09:40:58 | INFO | Integrating 4 interactions_strength files. 2025-01-26 09:41:01 | SUCCESS | Average CS across all scoring methods calculation done.