Skip to content

Repository files navigation

Codes and Analysis for Mycobacterium tuberculosis Hi-C Study

Overview

This repository contains the code and data for investigating three-dimensional (3D) genome organization in Mycobacterium tuberculosis (Mtb). The analyses integrate Hi-C, RNA-seq, and ChIP-seq data to examine chromatin architecture remodeling under different physiological conditions (WT, Hypoxia, Latent, NapM-KO, NapM-KO-Hypoxia).


Table of Contents


Dependencies

Python (≥3.7)

  • cooler, cooltools, coolbox - Hi-C analysis
  • pandas, numpy - Data processing
  • matplotlib, seaborn - Visualization
  • scikit-learn - Machine learning
  • networkx - Network analysis
  • bioframe - Genomics utilities

R (≥4.0)

  • ggplot2, dplyr - Data visualization and manipulation
  • clusterProfiler - Functional enrichment analysis

External Programs


Repository Structure

.
├── script/                      # Analysis scripts
│   ├── hicdiff.ipynb            # Differential Hi-C visualization
│   ├── moran's_shannon.ipynb    # Structural order metrics (Shannon entropy, Moran's I)
│   ├── operon-select_entropymoran's.ipynb  # Operon hub identification
│   ├── network_formation.ipynb  # Interaction network construction
│   ├── napmkolatentpre_comparedrsmd.ipynb  # Counterfactual prediction
│   ├── ABcompartment.ipynb      # A/B compartment analysis
│   ├── chipandrna.ipynb         # ChIP-seq and RNA-seq integration
│   ├── homologous.ipynb         # Homology analysis
│   ├── hiccompared_randomcidsloops.ipynb  # CID/loop statistical comparison
│   ├── four_zone_volcano.ipynb  # Volcano plot visualization
│   ├── regression_demo.ipynb    # Regression analysis
│   ├── Rv0047c_statistics.R     # Statistical analysis for NapM targets
│   ├── go_and_kegg.R            # GO/KEGG enrichment analysis
│   ├── avg.R                    # Average calculation utilities
│   ├── random_pairs.R           # Random pair generation
│   ├── venn.R                   # Venn diagram visualization
│   └── bulk RNA.Rmd             # Bulk RNA-seq analysis
├── 3d_model_pdbfile/            # 3D structure models (PDB format, 5 conditions)
├── DI_Score_results/            # Directionality Index scores (5 conditions)
├── hic_file/                    # Hi-C contact matrices (.hic format)
├── cool_file/                   # Hi-C matrices in cooler format (.cool, .mcool)
├── Interaction_network/         # Multi-layer network data
│   ├── full_nodes.csv           # DNA and protein nodes
│   └── full_edges.csv           # Interaction edges (DNA-DNA, DNA-Protein, Protein-Protein)
├── operon_metadata/             # Operon annotations and bin coverage
├── chip_seq_data/               # NapM (Rv0047c) ChIP-seq data
│   └── Rv0047c.bedgraph         # ChIP-seq signal track
├── cid_boundary/                # CID boundary coordinates (BED format, 5 conditions)
├── loops/                       # Chromatin loop calls (BEDPE format)
│   ├── wt-loops.bedpe
│   └── napm_ko-loops.bedpe
└── DEG/                         # Differential gene expression results
    ├── KOvsWT_supo_DEG_limma.csv
    ├── hypoxiaWTvsWT_supo_DEG_limma.csv
    └── LatentvsWT_supo_DEG_limma.csv

Analysis Workflows

Hi-C Contact Map Visualization

Visualize and compare Hi-C contact maps across conditions using differential analysis.

Script: hicdiff.ipynb

from coolbox.api import *

wt = DotHiC("wt.hic", style='triangular')
ko = DotHiC("napm_ko.hic", style='triangular')

frame = XAxis() + \
    HiCDiff(wt, ko, normalize='expect', diff_method='diff', 
            style='triangular', cmap='RdBu') + \
    MinValue(-2) + MaxValue(2)

frame.plot("Chromosome:1250000-1450000")

Directionality Index and CID Boundaries

The Directionality Index (DI) quantifies the bias of chromatin interactions toward upstream or downstream regions. It is used to identify chromatin interaction domain (CID) boundaries.

$$ \text{DI}_i = \frac{(B - A)}{|B - A|} \cdot \left(\frac{(A - E)^2}{E} + \frac{(B - E)^2}{E}\right) $$

Where A and B are upstream and downstream interaction counts, and E = (A + B)/2.

Data: Pre-computed DI scores available in DI_Score_results/


3D Genome Models

3D chromosome structures were modeled using LorDG (Low-rank Distance Geometry) with Hi-C contact frequencies as distance constraints.

Output: PDB files in 3d_model_pdbfile/
Visualization: Use PyMOL, Chimera, or other molecular visualization tools


Operon Interaction Network

Construct multi-layer interaction networks integrating:

  • DNA-DNA: Hi-C loops
  • DNA-Protein: ChIP-seq binding
  • Protein-Protein: Known interactions

Scripts:


Structural Plasticity Quantification

Quantify chromatin structural organization using Shannon entropy and Moran's I on DI score distributions.

Script: moran's_shannon.ipynb

Shannon Entropy (lower = more organized):

$$ H = -\sum_i p_i \log_2(p_i) $$

Moran's I (higher = more structured):

$$ I = \frac{n}{\sum_{i,j} w_{ij}} \frac{\sum_{i,j} w_{ij}(x_i - \bar{x})(x_j - \bar{x})}{\sum_i (x_i - \bar{x})^2} $$

Where $w_{ij} = 1$ for adjacent bins, 0 otherwise.


Counterfactual Prediction

Predict the NapM-KO latent Hi-C contact matrix using SVD-based counterfactual learning on observed conditions.

Script: napmkolatentpre_comparedrsmd.ipynb

Method:

  • Feature encoding: genotype (WT/KO) and environment (normal/hypoxia/latent)
  • SVD-based imputation with ridge regularization

Homology Analysis

Analyze conservation of Rv0047c (NapM) across bacterial species.

Script: homologous.ipynb

blastp -query rv0047c.faa \
       -db bacterial_proteins.fa \
       -out rv0047c_homologs.txt \
       -outfmt 6 \
       -evalue 1e-5 \
       -max_target_seqs 10000

Visualization: Manhattan plot of -log10(p-value) colored by genus


A/B Compartment Analysis

Identify A/B compartments using the first eigenvector of the Hi-C correlation matrix with GC bias correction.

Script: ABcompartment.ipynb

import cooltools
import bioframe

gc_track = bioframe.frac_gc(bins, genome)
cis_eigs = cooltools.eigs_cis(clr, gc_track, n_eigs=3)
eigenvector_track = cis_eigs[1][['chrom','start','end','E1']]

Statistical analysis: Bootstrap 95% confidence intervals for compartment strength comparison.


Figures Reproduction

Key analysis scripts for main figures:

Analysis Script Input Data
Hi-C differential maps hicdiff.ipynb hic_file/*.hic
DI and structural metrics moran's_shannon.ipynb DI_Score_results/*.csv
Operon interaction network network_formation.ipynb Interaction_network/*.csv
3D structure comparison napmkolatentpre_comparedrsmd.ipynb 3d_model_pdbfile/*.pdb
NapM homology homologous.ipynb BLASTP output
A/B compartments ABcompartment.ipynb .cool files
ChIP-RNA integration chipandrna.ipynb BigWig/BedGraph
GO/KEGG enrichment go_and_kegg.R Gene lists

Statistical Analysis: All significance tests use Benjamini-Hochberg FDR correction (α = 0.05). Bootstrap resampling (n=1000) for confidence intervals. See individual scripts for details.


Citation

If you use this code or data, please cite:

Establishment and remodeling of the Mycobacterium tuberculosis 3D genome Orchestrate Context-Dependent Transcriptional Program. (Manuscript in preparation)


Contact

For questions, please open an issue on GitHub: https://github.com/wikk-chy/mtb_hic/issues


License

MIT License

Copyright (c) 2026 wikk-chy

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

About

mycobacterium tuberculosis Hi-C data analysis

Resources

Stars

0 stars

Watchers

1 watching

Forks

Releases

Packages

Contributors

Languages