ChromatinHD-diff¶
In [ ]:
Copied!
import chromatinhd as chd
import polyptich as pp
import matplotlib.pyplot as plt
import chromatinhd as chd
import polyptich as pp
import matplotlib.pyplot as plt
ChromatinHD-diff uses accessibility fragments to assess how accessibility changes between (clusters of) cells.
We first load in all the input data which was created in the data preparation tutorial.
In [11]:
Copied!
import pathlib
dataset_folder = pathlib.Path("example")
fragments = chd.data.Fragments(dataset_folder / "fragments")
transcriptome = chd.data.Transcriptome(dataset_folder / "transcriptome")
folds = chd.data.folds.Folds(dataset_folder / "folds" / "5x1")
clustering = chd.data.Clustering(dataset_folder / "clustering")
import pathlib
dataset_folder = pathlib.Path("example")
fragments = chd.data.Fragments(dataset_folder / "fragments")
transcriptome = chd.data.Transcriptome(dataset_folder / "transcriptome")
folds = chd.data.folds.Folds(dataset_folder / "folds" / "5x1")
clustering = chd.data.Clustering(dataset_folder / "clustering")
Train the models¶
The basic ChromatinHD-diff model can be trained as follows. Model training and inference will be much faster if a GPU is available and correctly installed:
In [14]:
Copied!
chd.get_default_device()
chd.get_default_device()
Out[14]:
'cuda:1'
In [12]:
Copied!
models = chd.models.diff.model.binary.Models(dataset_folder / "models" / "diff", reset=True)
models = chd.models.diff.model.binary.Models(dataset_folder / "models" / "diff", reset=True)
In [ ]:
Copied!
models.train_models(fragments = fragments, clustering = clustering, folds = folds)
models.train_models(fragments = fragments, clustering = clustering, folds = folds)
Interpret positionally¶
Currently, the ChromatinHD-model is purely positional, i.e. it only looks whether Tn5 insertion sites increase or decrease within a region. As such, we can only interpret it positionally:
In [23]:
Copied!
import chromatinhd.models.diff.interpret.regionpositional
import chromatinhd.models.diff.interpret.regionpositional
In [24]:
Copied!
clustering.cluster_info.index.name = "cluster"
clustering.cluster_info.index.name = "cluster"
In [25]:
Copied!
regionpositional = chromatinhd.models.diff.interpret.regionpositional.RegionPositional(
path=models.path / "interpret" / "regionpositional"
)
regionpositional.score(
fragments = fragments,
clustering = clustering,
models = models,
force=True,
)
regionpositional = chromatinhd.models.diff.interpret.regionpositional.RegionPositional(
path=models.path / "interpret" / "regionpositional"
)
regionpositional.score(
fragments = fragments,
clustering = clustering,
models = models,
force=True,
)
0%| | 0/51 [00:00<?, ?it/s]
Out[25]:
example/models/diff/interpret/regionpositional (chromatinhd.models.diff.interpret.regionpositional.RegionPositional)
- regions
- probs ( ENSG00000132465 [13,4001], 367.8Kb, ENSG00000107317 [13,4001], 384.9Kb, ENSG00000134532 [13,4001], 341.9Kb, ...)
Plot differential accessibility at a specific window¶
To avoid overplotting, we will plot only the window close to the TSS.
In [26]:
Copied!
symbol = "IRF1"
gene_id = transcriptome.gene_id(symbol)
symbol = "IRF1"
gene_id = transcriptome.gene_id(symbol)
In [27]:
Copied!
window = [-10000, 10000]
window = [-10000, 10000]
In [35]:
Copied!
fig = pp.grid.Figure(pp.grid.Grid(padding_height=0.05, padding_width=0.05))
width = 10
region = fragments.regions.coordinates.loc[transcriptome.gene_id(symbol)]
panel_genes = chd.plot.genome.genes.Genes.from_region(region, width=width, window = window)
fig.main.add_under(panel_genes)
panel_differential = chd.models.diff.plot.Differential.from_regionpositional(
transcriptome.gene_id(symbol), regionpositional, cluster_info=clustering.cluster_info, panel_height=0.5, width=width, window = window
)
fig.main.add_under(panel_differential)
panel_expression = chd.models.diff.plot.DifferentialExpression.from_transcriptome(
transcriptome=transcriptome, clustering=clustering, gene=transcriptome.gene_id(symbol), panel_height=0.5
)
fig.main.add_right(panel_expression, row=panel_differential)
fig.display()
fig = pp.grid.Figure(pp.grid.Grid(padding_height=0.05, padding_width=0.05))
width = 10
region = fragments.regions.coordinates.loc[transcriptome.gene_id(symbol)]
panel_genes = chd.plot.genome.genes.Genes.from_region(region, width=width, window = window)
fig.main.add_under(panel_genes)
panel_differential = chd.models.diff.plot.Differential.from_regionpositional(
transcriptome.gene_id(symbol), regionpositional, cluster_info=clustering.cluster_info, panel_height=0.5, width=width, window = window
)
fig.main.add_under(panel_differential)
panel_expression = chd.models.diff.plot.DifferentialExpression.from_transcriptome(
transcriptome=transcriptome, clustering=clustering, gene=transcriptome.gene_id(symbol), panel_height=0.5
)
fig.main.add_right(panel_expression, row=panel_differential)
fig.display()
Plot differential accessibility for all windows¶
In [48]:
Copied!
windows = regionpositional.select_windows(gene_id)
breaking = pp.grid.Breaking(windows)
windows = regionpositional.select_windows(gene_id)
breaking = pp.grid.Breaking(windows)
In [49]:
Copied!
fig = pp.grid.Figure(pp.grid.Grid(padding_height=0.0, padding_width=0.05))
width = 10
region = fragments.regions.coordinates.loc[transcriptome.gene_id(symbol)]
panel_genes = chd.plot.genome.genes.GenesExpanding.from_region(region, breaking=breaking)
fig.main.add_under(panel_genes)
panel_differential = chd.models.diff.plot.DifferentialBroken.from_regionpositional(
transcriptome.gene_id(symbol), regionpositional, cluster_info=clustering.cluster_info, panel_height=0.5, breaking=breaking, window = window
)
fig.main.add_under(panel_differential)
panel_expression = chd.models.diff.plot.DifferentialExpression.from_transcriptome(
transcriptome=transcriptome, clustering=clustering, gene=transcriptome.gene_id(symbol), panel_height=0.5
)
fig.main.add_right(panel_expression, row=panel_differential)
fig.display()
fig = pp.grid.Figure(pp.grid.Grid(padding_height=0.0, padding_width=0.05))
width = 10
region = fragments.regions.coordinates.loc[transcriptome.gene_id(symbol)]
panel_genes = chd.plot.genome.genes.GenesExpanding.from_region(region, breaking=breaking)
fig.main.add_under(panel_genes)
panel_differential = chd.models.diff.plot.DifferentialBroken.from_regionpositional(
transcriptome.gene_id(symbol), regionpositional, cluster_info=clustering.cluster_info, panel_height=0.5, breaking=breaking, window = window
)
fig.main.add_under(panel_differential)
panel_expression = chd.models.diff.plot.DifferentialExpression.from_transcriptome(
transcriptome=transcriptome, clustering=clustering, gene=transcriptome.gene_id(symbol), panel_height=0.5
)
fig.main.add_right(panel_expression, row=panel_differential)
fig.display()