First Steps with ISCHIA.jl
Setting up the Environment
Make sure that you have Julia version $\ge 1.6$ installed already. To add ISCHIA.jl
as a package dependency, we need to install it from GitHub directly, as it hasn't been released on the Julia Registery yet.
This can be done in either of the two ways:
julia> using Pkg
julia> Pkg.add(url="https://github.com/aadimator/ISCHIA.jl")
or
julia> ] # ']' should be pressed
(@v1.9) pkg> add https://github.com/aadimator/ISCHIA.jl
This will clone the repository from the GitHub and install it in your package environment.
If you already have the GitHub repository cloned on your system and you want to install the package using that, you can do so with the following commands. Make sure that you are in the cloned project directory when running the followin commands.
julia> using Pkg
julia> Pkg.add(".") # Install current directory as a package
or
julia> ] # ']' should be pressed
(@v1.9) pkg> add .
Throughout the rest of the tutorial we will assume that you have installed the ISCHIA.jl package and have already typed using ISCHIA
which loads the package:
julia> using ISCHIA
ISCHIA
provides optimized implementations of several functions from the original ISCHIA repository, which was coded in R
. Below, we'll try to replicate their Cooccurrence of ligand and receptors section, using their provided small dataset. Instructions on converting and importing their Seurat Object
into AnnData
object has been described in section.
Load the Libraries
First, let's load the required libraries. Install any library that isn't in your package environment already. Julia will automatically suggest the command to install missing packages.
using Muon
using RData
using ISCHIA
using DataFrames
using Combinatorics
Load the Data
sdata = readh5ad(joinpath(pkgdir(ISCHIA), "docs", "src", "assets", "Spatial.h5ad"))
lr_network = load(joinpath(pkgdir(ISCHIA), "docs", "src", "assets", "lr_network.rds"))
size(lr_network)
(12651, 4)
Filter LR Network
gene_names = sdata.var.name
sdata.var_names = gene_names
# Create LR_Pairs column
lr_network[!, :LR_Pairs] = string.(lr_network.from, "_", lr_network.to);
lr_network = lr_network[:, [:from, :to, :LR_Pairs]]
# Filter lr_network based on conditions
from_filter = in.(lr_network[:, :from], Ref(gene_names))
to_filter = in.(lr_network[:, :to], Ref(gene_names))
all_LR_network = lr_network[from_filter .& to_filter, :];
# Extract unique genes and common genes
all_LR_genes = unique(vcat(all_LR_network[:, :from], all_LR_network[:, :to]))
all_LR_genes_comm = intersect(all_LR_genes, collect(gene_names));
# Create LR.pairs and LR.pairs.AllCombos
LR_pairs = all_LR_network[:, :LR_Pairs]
all_combos = [join(combo, "_") for combo in combinations(all_LR_genes_comm, 2)];
length(all_combos)
1007490
Calculate LR Enrchiment
spatial_object = sdata
spatial_object.var_names = spatial_object.var.name
Condition = unique(spatial_object.obs[!, "orig.ident"])
LR_list = all_LR_genes_comm
LR_pairs = LR_pairs
exp_th = 1
corr_th = 0.2
cc4_enriched_lr = find_enriched_LR_pairs(spatial_object, ["CC4"], Condition, LR_list, LR_pairs, exp_th, corr_th);
cc7_enriched_lr = find_enriched_LR_pairs(spatial_object, ["CC7"], Condition, LR_list, LR_pairs, exp_th, corr_th);
Dict{String, Any} with 2 entries:
"cooccurrence_table" => CooccurOutput(68101×12 DataFrame…
"enriched_LRs" => 487×6 DataFrame…
Display Calculated LR Encrichment Scores
first(cc4_enriched_lr["enriched_LRs"], 5)
Row | from | to | correlation | ligand_FC | Receptor_FC | pair |
---|---|---|---|---|---|---|
String | String | Float64 | Float64 | Float64 | String | |
1 | C3 | CXCR4 | 0.79157 | 1.3346 | 3.3869 | C3_CXCR4 |
2 | CCL19 | CXCR4 | 0.757651 | 4.2714 | 3.3869 | CCL19_CXCR4 |
3 | RPS19 | RPSA | 0.647974 | 0.5695 | 0.4499 | RPS19_RPSA |
first(cc7_enriched_lr["enriched_LRs"], 5)
Row | from | to | correlation | ligand_FC | Receptor_FC | pair |
---|---|---|---|---|---|---|
String | String | Float64 | Float64 | Float64 | String | |
1 | LGALS3 | ITGB4 | 0.832963 | 0.7695 | 0.8609 | LGALS3_ITGB4 |
2 | CDHR5 | CDHR2 | 0.830117 | 0.7361 | 0.9662 | CDHR5_CDHR2 |
3 | HLA-E | ITGA6 | 0.780889 | 1.1673 | 0.7086 | HLA-E_ITGA6 |
4 | HLA-E | PLXNB2 | 0.779063 | 1.1673 | 0.7971 | HLA-E_PLXNB2 |
5 | COL1A1 | ITGA5 | 0.764293 | 1.9866 | 1.872 | COL1A1_ITGA5 |
Find Differentially Occurring LR pairs
diff_df47 = find_differentially_cooccurring_LR_pairs(cc7_enriched_lr, cc4_enriched_lr, 0.05, 0.1)
first(diff_df47, 10)
Row | pair | group1_pval | group2_pval | pval_difference | observed_cooc |
---|---|---|---|---|---|
String | Real | Real | Real | Int64 | |
1 | HLA-A_HLA-B | 0.0 | 0.27473 | 0.27473 | 235 |
2 | HLA-B_LGALS3 | 0.00122 | 0.90385 | 0.90263 | 231 |
3 | HLA-B_HLA-C | 1.0e-5 | 0.5 | 0.49999 | 230 |
4 | CD24_HLA-B | 0.00028 | 0.5 | 0.49972 | 218 |
5 | HLA-B_HLA-E | 5.0e-5 | 0.15385 | 0.1538 | 217 |
6 | HLA-A_HLA-C | 0.0 | 0.13287 | 0.13287 | 210 |
7 | HLA-A_LGALS3 | 0.0 | 0.13287 | 0.13287 | 210 |
8 | LGALS3_CD74 | 0.0 | 0.14307 | 0.14307 | 207 |
9 | HLA-B_THBS1 | 0.0 | 0.38462 | 0.38462 | 206 |
10 | HLA-C_CD74 | 0.0 | 0.14307 | 0.14307 | 204 |