OSCR

scDIAGRAM: detecting chromatin compartments from individual single-cell Hi-C matrix without imputation or reference features.

Code ↔ Paper

The paper beside its authors' code: matches between them have not been computed for this paper yet.

Paper

Loaded from Europe PMC by your browser, not stored by OSCR: doi.org · Europe PMC

The paper is loaded when this pane is shown.

The authors' code

Python · 333 lines · 9.3 KB · MIT

  1. ## Implement MCMC in the scDIAGRAM
  2. import argparse
  3. import time
  4. from collections import Counter
  5. from multiprocessing import Pool
  6. import matplotlib.pyplot as plt
  7. import numpy as np
  8. import pandas as pd
  9. import seaborn as sns
  10. from scipy import signal, stats
  11. from scipy.stats import rankdata
  12. from sklearn.decomposition import PCA
  13. from sklearn.preprocessing import quantile_transform
  14. #from cooltools.lib import numutils
  15. parser = argparse.ArgumentParser(description='Implement MH algorithm')
  16. parser.add_argument('--file', type=str)
  17. parser.add_argument('--index', type=int, default=0)
  18. parser.add_argument('--chr', type=int, default=7)
  19. parser.add_argument('--start', type=int)
  20. parser.add_argument('--end', type=int)
  21. parser.add_argument('--step', type=int, default=1)
  22. parser.add_argument('--terminate', type=int, default=10000)
  23. parser.add_argument('--out_file', type=str, default='single-cell_res.out')
  24. #parser.add_argument('--CP_term', type=int, default=50)
  25. parser.add_argument('--contact_thre', type=float, default=99.9)
  26. #parser.add_argument('--cpg_file', type=str, default=None)
  27. parser.add_argument('--before', type=int, default=1)
  28. parser.add_argument('--species', type=str, default='mm')
  29. parser.add_argument('--resolution', type=int, default=100000)
  30. parser.add_argument('--binary', type=int, default=0)
  31. parser.add_argument('--input_version', type=str, default='v1')
  32. parser.add_argument('--reference', type=str, default='reference/mm10_chr_size.txt')
  33. parser.add_argument('--output', type=str, default='MCMC_res.npy')
  34. #parser.add_argument('--out_file', type=str, default='single-cell_res.out')
  35. args = parser.parse_args()
  36. print(args)
  37. #print(bool(args.before))
  38. file = args.file
  39. start = args.start
  40. end = args.end
  41. step = args.step
  42. index = args.index
  43. outFile = args.out_file
  44. #CP_term = args.CP_term
  45. contact_thre = args.contact_thre
  46. out_file = args.out_file
  47. ################################################################################
  48. print('Preparation. Compute the variance ...')
  49. chr = f'chr{args.chr}'
  50. resolution = args.resolution
  51. chr_data = pd.read_table('reference/mm10_chr_size.txt',header=None)
  52. length = chr_data.iloc[args.chr - 1, 1]
  53. L = length // resolution + 1
  54. def cross_entropy(k, N):
  55. if k == 0 or k == N:
  56. return 0
  57. return k * np.log(k / N) + (N - k) * np.log(1 - k / N)
  58. if args.species == 'hg':
  59. centro_pos = pd.read_table('reference/centro_pos.txt',header=None,index_col=0)
  60. before_pos = centro_pos.iloc[args.chr-1, 0]
  61. end_pos = centro_pos.iloc[args.chr-1, 1]
  62. def comp(file, index=0):
  63. global before_pos, end_pos
  64. if args.input_version == "v2":
  65. global L
  66. Mat = np.zeros((L, L))
  67. with open(file, 'rt') as f:
  68. for line in f:
  69. bb = line.split("\t")
  70. source = int(bb[1]) // resolution
  71. target = int(bb[3]) // resolution
  72. if source >= L or target >= L:
  73. continue
  74. Mat[source, target] += 1
  75. Mat[target, source] += 1
  76. row, col = np.diag_indices_from(Mat)
  77. Mat[row, col] = 0
  78. elif args.input_version == "v1":
  79. Mat = np.load(file)
  80. if len(Mat.shape)==2:
  81. row, col = np.diag_indices_from(Mat)
  82. Mat[row, col] = 0
  83. else:
  84. Mat = Mat[index,:,:]
  85. row, col = np.diag_indices_from(Mat)
  86. Mat[row, col] = 0
  87. else:
  88. print("Undefined input version, error...")
  89. return 0
  90. # X = Mat[30:, 30:]
  91. X = Mat
  92. if args.species == "hg":
  93. if args.before==True and before_pos!=0:
  94. X = X[:before_pos, :before_pos]
  95. elif args.before==True and before_pos==0:
  96. print('Centromere is on the end, no small arms before centromere.')
  97. return 0
  98. else:
  99. X = X[end_pos:, end_pos:]
  100. elif args.species == "mm":
  101. end_pos = 3000000//resolution
  102. X = X[end_pos:, end_pos:]
  103. A = X
  104. mask = A.sum(axis=0) > 0
  105. OE, _, _, _ = numutils.observed_over_expected(A, mask)
  106. clip_percentile = contact_thre
  107. if np.quantile(X,contact_thre/100)==0:
  108. OE[OE>0] = 1
  109. else:
  110. OE = np.clip(OE, 0, np.percentile(OE[mask, :][:, mask], clip_percentile))
  111. OE[~mask, :] = 0
  112. OE[:, ~mask] = 0
  113. X = OE.copy()
  114. row, col = np.diag_indices_from(X)
  115. X[row, col] = 0
  116. row = row[:-1]
  117. col = col[1:]
  118. X[row,col] = 0
  119. if args.binary == True:
  120. X[X > 0] = 1
  121. Z = X.copy()
  122. n = X.shape[0]
  123. print(n)
  124. C2 = X.copy()
  125. X = np.triu(X)
  126. Var = np.var(X[X != 0])
  127. print('var: ', Var)
  128. T = Var * 2
  129. time0 = time.time()
  130. logR = np.zeros((n, n))
  131. S_square = np.zeros((n + 1, n + 1))
  132. S = np.zeros((n + 1, n + 1))
  133. score1 = 0
  134. score2 = 0
  135. X_square = X ** 2
  136. # if T>0:
  137. for t in range(1, n + 1):
  138. time1 = time.time()
  139. # print(t,time1-time0)
  140. if t == 1:
  141. score1 += X[0, 0]
  142. score2 += X_square[0, 0]
  143. S[1, 1] = score1
  144. S_square[1, 1] = score2
  145. for s in range(2, n + 1):
  146. inc1 = np.sum(X[:s, s - 1])
  147. inc2 = np.sum(X_square[:s, s - 1])
  148. score1 += inc1
  149. score2 += inc2
  150. S[1, s] = score1
  151. S_square[1, s] = score2
  152. else:
  153. score1 = X[t - 2, t - 2]
  154. score2 = X_square[t - 2, t - 2]
  155. for s in range(t, n + 1):
  156. score1 += X[t - 2, s - 1]
  157. score2 += X_square[t - 2, s - 1]
  158. S[t, s] = S[t - 1, s] - score1
  159. S_square[t, s] = S_square[t - 1, s] - score2
  160. # X1 = X[(t - 1):s, (t - 1):s]
  161. time1 = time.time()
  162. print('used time: ', time1 - time0)
  163. N = X.shape[0]
  164. def logphi1(t, s):
  165. Nk = np.sum(X[t - 1:s, t - 1:s] != 0)
  166. N = (s - t + 1) * (s - t + 2) / 2
  167. if Nk == 0:
  168. return 0
  169. # N = (s - t + 1) * (s - t + 2) / 2
  170. V1 = S_square[t, s] / Nk - (S[t, s] / Nk) ** 2
  171. if T > 0:
  172. res = -Nk * V1 / T + cross_entropy(Nk, N)
  173. else:
  174. res = cross_entropy(S[t, s], N)
  175. return res
  176. def logphi2(t1, s1, t2, s2):
  177. Nk = np.sum(X[t1 - 1:s1, t2 - 1:s2] > 0)
  178. N = (s1 - t1 + 1) * (s2 - t2 + 1)
  179. if Nk == 0:
  180. return 0
  181. # N = (s1 - t1 + 1) * (s2 - t2 + 1)
  182. S1 = S[s1 + 1, t2 - 1] - S[t1, t2 - 1] - S[s1 + 1, s2] + S[t1, s2]
  183. S2 = S_square[s1 + 1, t2 - 1] - S_square[t1, t2 - 1] - S_square[s1 + 1, s2] + S_square[t1, s2]
  184. V1 = S2 / Nk - (S1 / Nk) ** 2
  185. if T > 0:
  186. res = -Nk * V1 / T + cross_entropy(Nk, N)
  187. else:
  188. res = cross_entropy(S1, N)
  189. return res
  190. def comp_score(m_ls, N):
  191. m_ls = [0] + m_ls + [N]
  192. kT = len(m_ls)
  193. score = 0
  194. for i in range(kT - 1):
  195. source = m_ls[i]
  196. end = m_ls[i + 1]
  197. score += logphi1(source + 1, end)
  198. for i in range(kT - 1):
  199. source1 = m_ls[i]
  200. end1 = m_ls[i + 1]
  201. for j in range(i + 1, kT - 1):
  202. source2 = m_ls[j]
  203. end2 = m_ls[j + 1]
  204. score += logphi2(source1 + 1, end1, source2 + 1, end2)
  205. return score
  206. Ind = np.arange(1, N)
  207. res_ls_tot = {}
  208. k_ls = np.arange(start, end, step)
  209. #print(k_ls)
  210. for k in k_ls:
  211. explode = 0
  212. count = 0
  213. np.random.seed(1234)
  214. m_ls = np.random.choice(N - 1, size=k) + 1
  215. m_ls.sort()
  216. m_ls = list(m_ls)
  217. ## T for variance*2.
  218. m_res = list(set(Ind) - set(m_ls))
  219. # print(m_ls)
  220. score = comp_score(m_ls, N)
  221. #L = {}
  222. logp = 0
  223. LT = []
  224. terminate = args.terminate
  225. res_ls = {}
  226. Likelih_ls = {}
  227. np.random.seed(1234)
  228. for t in range(args.end + 1):
  229. Likelih_ls[t] = -np.inf
  230. while True:
  231. m_ls_cand = m_ls.copy()
  232. m_ls_old = m_ls.copy()
  233. k = len(m_ls)
  234. flip1 = np.random.randint(N - k - 1)
  235. flip2 = np.random.randint(k)
  236. m_ls_cand.pop(flip2)
  237. m_ls_cand.append(m_res[flip1])
  238. m_ls_cand.sort()
  239. score2 = comp_score(m_ls_cand, N)
  240. prob_log = (score2 - score) + (len(m_ls_cand) - len(m_ls)) * logp
  241. accep_log = min(0, prob_log)
  242. trial_prob_log = np.log(np.random.rand())
  243. if trial_prob_log < accep_log:
  244. m_ls = m_ls_cand
  245. m_res = list(set(Ind) - set(m_ls))
  246. score = score2
  247. k = len(m_ls)
  248. if score > Likelih_ls[k]:
  249. res_ls[k] = m_ls
  250. Likelih_ls[k] = score
  251. if count % 100 == 0:
  252. print(count, m_ls, len(m_ls), accep_log, m_ls_cand, score)
  253. LT.append(len(m_ls))
  254. count += 1
  255. if count == terminate:
  256. break
  257. if explode == 1:
  258. print('explode...')
  259. continue
  260. k_most = k
  261. with open(outFile, 'a') as f:
  262. print(res_ls[k_most], Likelih_ls[k_most], k_most, file=f)
  263. print('No.', index, 'cell being processed on chr', args.chr, file=f)
  264. print(res_ls[k_most], Likelih_ls[k_most], k_most)
  265. #print(res_ls_tot)
  266. return res_ls[k_most]
  267. res = comp(file)
  268. print(res)
  269. res = np.array(res)
  270. np.save(args.output, res)
  271. print(res.shape)

MCMC.py at commit 72ccce8, under MIT · at the source

Overview

Authors: Yongli Peng1, Yujing Deng2, Menghan Liu2, Zhiyuan Liu2, Ya-Hui Li3, Xiang-Yu Zhao3, Dong Xing2,4, Jinzhu Jia5, Hao Ge1,2
ORCID iDs: Dong Xing, Jinzhu Jia
  1. Beijing International Center for Mathematical Research (BICMR), Peking University, No.5 Yiheyuan Road, Haidian District, Beijing 100871, China
  2. Biomedical Pioneering Innovation Center (BIOPIC), Peking University, No.5 Yiheyuan Road, Haidian District, Beijing 100871, China
  3. Peking University Institute of Hematology, National Clinical Research Center for Hematologic Disease, Peking University People's Hospital, No.11 Xizhimen South Street, Xicheng District, Beijing 100044, China
  4. Beijing Advanced Innovation Center for Genomics, Peking University, No.5 Yiheyuan Road, Haidian District, Beijing 100871, China
  5. School of Public Health and Center for Statistical Science, Peking University, No.5 Yiheyuan Road, Haidian District, Beijing 100871, China
Journal: Briefings in bioinformatics, volume 27, issue 2, article bbag096
Dates: received 31 July 2025; accepted 7 February 2026; published online 8 March 2026; in print March 2026
Type: Research article · Language: English
License: CC BY
Identifiers: DOI 10.1093/bib/bbag096 · PMID 41795655 · PMCID PMC12967335 · OpenAlex W7134167444
Open access: gold, a free copy (OpenAlex)
Status: code verified
Categories: human (organism), mouse (organism), methods / tools (subfield)
Methods: Connectivity, Smoothing, state filtering, decompositions
Keywords: single-cell Hi-C, A/B compartment, statistical modeling, chromatin heterogeneity
MeSH: Chromatin*, Single-Cell Analysis*, Algorithms, Animals, Humans, Mice (* major topic)
Journal subjects: Problem Solving Protocol
Topic: Genomics and Chromatin Dynamics (Molecular Biology, Biochemistry, Genetics and Molecular Biology), according to OpenAlex
Funding: National Key Research and Development Program of China (2023YFF1204700); National Natural Science Foundation of China (National Science Foundation of China) (T2225001); Noncommunicable Chronic Diseases-National Science and Technology Major Project (2023ZD0501200)
Citations: not cited yet (Europe PMC); 55 references in the paper

Abstract

Single-cell Hi-C (scHi-C) provides unprecedented insight into 3D genome organization, but its sparse and noisy data pose challenges in accurately detecting A/B compartments, which are crucial for understanding chromatin structure and gene regulation. We presented scDIAGRAM, a data-driven method for annotating A/B compartments in single cells using direct statistical modeling and graph community detection. Unlike existing approaches, scDIAGRAM infers chromatin compartments directly from individual scHi-C matrix without imputation or external reference features, and subsequently assigns A/B labels using conventional genomic annotations. Accuracy and robustness of scDIAGRAM were illustrated through simulated scHi-C datasets and a human cell line. We applied scDIAGRAM to real scHi-C datasets from the mouse brain cortex, mouse embryonic development, and human acute myeloid leukemia, demonstrating its ability to capture compartmental shifts associated with transcriptional variation. This robust framework offers new insights into the functional roles of chromatin compartments at single-cell resolution across various biological contexts.

Reproduced under the paper's license (CC BY), from the paper cited above.

Repositories

Its files are read in the Code ↔ Paper reader above.

Ge-lab-pku/scDIAGRAM

License: MIT
State: the link answers, verified on 30 September 2026
Evidence: files inventoried
Commit: 72ccce878ac1045129eda01954e62682f1434a46, 25 January 2026
Languages: Python (12), R (1)
Size: 131 files, 13 scripts
Software Heritage: not archived
Found in: “Data availability”
Holds: README, license file
Not found: CITATION.cff, environment file, tests, continuous integration, documentation
Tools: NumPy (11 files), pandas (11 files), Matplotlib (9 files), SciPy (7 files), scikit-learn (4 files), seaborn (4 files)
Availability: 1 check, the latest on 30 September 2026: the link answers
  • 30 September 2026: the link answers
15 files

Zenodo 15855256

License: MIT
State: the link answers, verified on 30 September 2026
Evidence: files inventoried
Size: 1 file
Software Heritage: not checked
Found in: “Data availability”
Not found: README, license file, CITATION.cff, environment file, tests, continuous integration, documentation
Tools: NumPy (10 files), pandas (10 files), Matplotlib (9 files), SciPy (7 files), scikit-learn (4 files), seaborn (4 files)
Availability: 1 check, the latest on 30 September 2026: the link answers (HTTP 200)
  • 30 September 2026: the link answers (HTTP 200)
12 files

The paper's code and data availability statement is in the Data section.

Tracing map

Proposed by the machine: these links were found in the paper and verified at the source, without human review. The map will receive a Zenodo DOI once one of the paper's authors has validated it with their ORCID.

What the map holds:

  • 2 repositories of the authors' code, each at its verified commit, with its license and how the link was found in the paper;
  • 23 scripts, each with its path and the digest of its content;
  • no match between paragraphs and code yet;
  • neither the text of the paper nor the code itself.

Its JSON (tracing-map.json) is deposited on Zenodo with its DOI once the map is validated.

Data

No dataset and no data link were found in the paper.

Data availability

The single-cell AML data generated in this study have been deposited in Gene Expression Omnibus (GEO) under accession code GSE302267. AML subtypes were provided in Supplementary Table S1. The corresponding processed cell-by-gene scRNA-seq data have also been uploaded to the GEO. Other data are publicly available, and source code of scDIAGRAM are on Github (https://github.com/Ge-lab-pku/scDIAGRAM) and Zenodo (https://doi.org/10.5281/zenodo.15855256).

Reproduced under the paper's license (CC BY), from the paper cited above.

Versions

The history of this record: each version stored by the harvester or made by a correction of its authors or of the maintainers of its code, and what changed in its facts. The texts of the paper (its abstract, its availability statements) are not part of it; versions that changed only those are not listed.

Version 1, 30 September 2026: the first record

Recorded: type, language, journal, volume, issue, pages, dates, 9 authors, 4 keywords, 6 MeSH terms, 3 funders, 54 references.

Cite

This paper

Peng, Y., Deng, Y., Liu, M., Liu, Z., Li, Y.-H., Zhao, X.-Y., Xing, D., Jia, J., & Ge, H. (2026). scDIAGRAM: detecting chromatin compartments from individual single-cell Hi-C matrix without imputation or reference features. Briefings in bioinformatics, 27(2), bbag096. https://doi.org/10.1093/bib/bbag096

BibTeX

@article{peng2026scdiagram,
author = {Peng, Yongli and Deng, Yujing and Liu, Menghan and Liu, Zhiyuan and Li, Ya-Hui and Zhao, Xiang-Yu and Xing, Dong and Jia, Jinzhu and Ge, Hao},
title = {{scDIAGRAM: detecting chromatin compartments from individual single-cell Hi-C matrix without imputation or reference features}},
journal = {Briefings in bioinformatics},
year = {2026},
month = mar,
volume = {27},
number = {2},
pages = {bbag096},
publisher = {Oxford University Press},
issn = {1467-5463},
doi = {10.1093/bib/bbag096},
url = {https://doi.org/10.1093/bib/bbag096},
pmid = {41795655},
pmcid = {PMC12967335}
}

RIS

TY - JOUR
AU - Peng, Yongli
AU - Deng, Yujing
AU - Liu, Menghan
AU - Liu, Zhiyuan
AU - Li, Ya-Hui
AU - Zhao, Xiang-Yu
AU - Xing, Dong
AU - Jia, Jinzhu
AU - Ge, Hao
TI - scDIAGRAM: detecting chromatin compartments from individual single-cell Hi-C matrix without imputation or reference features
T2 - Briefings in bioinformatics
J2 - Brief Bioinform
PY - 2026
DA - 2026/03/01
VL - 27
IS - 2
SP - bbag096
SN - 1467-5463
PB - Oxford University Press
DO - 10.1093/bib/bbag096
UR - https://doi.org/10.1093/bib/bbag096
LA - en
ER -

CSL-JSON

{
"id": "10.1093/bib/bbag096",
"type": "article-journal",
"title": "scDIAGRAM: detecting chromatin compartments from individual single-cell Hi-C matrix without imputation or reference features",
"container-title": "Briefings in bioinformatics",
"author": [
{
"family": "Peng",
"given": "Yongli"
},
{
"family": "Deng",
"given": "Yujing"
},
{
"family": "Liu",
"given": "Menghan"
},
{
"family": "Liu",
"given": "Zhiyuan"
},
{
"family": "Li",
"given": "Ya-Hui"
},
{
"family": "Zhao",
"given": "Xiang-Yu"
},
{
"family": "Xing",
"given": "Dong"
},
{
"family": "Jia",
"given": "Jinzhu"
},
{
"family": "Ge",
"given": "Hao"
}
],
"container-title-short": "Brief Bioinform",
"volume": "27",
"issue": "2",
"page": "bbag096",
"DOI": "10.1093/bib/bbag096",
"PMID": "41795655",
"PMCID": "PMC12967335",
"ISSN": "1467-5463",
"publisher": "Oxford University Press",
"URL": "https://doi.org/10.1093/bib/bbag096",
"language": "en",
"issued": {
"date-parts": [
[
2026,
3,
1
]
]
}
}

The tracing map gets a citation of its own once an author has validated it and it has a DOI.

Similar papers

The papers with a page that share the most with this one: the tools found in their code, their categories, datasets, cited references and authors, the rarest counting most.

[1] doi:10.1038/s41467-026-71406-y [code]
CellLoop: Identifying single-cell 3D genome chromatin loops.
Journal: Nature communications
In common: seaborn, scikit-learn, pandas, 3 other tools, mouse, 11 references
[2] doi:10.1038/s41467-026-73773-y [code]
MINTsC learns multi-way chromatin interactions from single cell high throughput chromatin conformation data.
Journal: Nature communications
In common: 11 references
[3] doi:10.21203/rs.3.rs-9927928/v1 [code]
Genome-wide and allele-resolved maps of the radial architecture of the mouse genome
Journal: Research Square (preprint)
In common: pandas, SciPy, Matplotlib, 1 other tool, mouse, 6 references
[4] doi:10.1039/d5sm01116g [code]
How human-derived brain organoids are built differently from brain organoids derived from genetically-close relatives: a multi-scale hypothesis.
Journal: Soft matter
In common: 5 references
[5] doi:10.1038/s41467-026-76506-3 [code]
Allele-specific chromatin architecture shapes imprinted domains and coordinates a distal enhancer and antisense transcription at the mouse Mest-Copg2 domain.
Journal: Nature communications
In common: mouse, 5 references
[6] doi:10.1038/s41467-026-73770-1 [code]
Non-coding structural variants disrupt FOXG1 transcriptional regulation in early neurodevelopment.
Journal: Nature communications
In common: seaborn, scikit-learn, pandas, 3 other tools, 2 references
[7] doi:10.1038/s41593-026-02293-1 [code]
Optics-free spatial genomics for mapping mammalian brain aging by IRISeq.
Journal: Nature neuroscience
In common: seaborn, scikit-learn, pandas, 3 other tools, mouse, 2 references
[8] doi:10.1038/s41467-026-71877-z [code]
Hi-Compass: a depth-aware deep learning framework for predicting cell-type-specific 3D genome organization from single-cell to spatial resolution.
Journal: Nature communications
In common: pandas, Matplotlib, NumPy, mouse, 3 references
[9] doi:10.1093/bioinformatics/btag652 [code]
mmVelo: a deep generative model for estimating cell state-dependent dynamics across multiple modalities.
Journal: Bioinformatics (Oxford, England)
In common: seaborn, scikit-learn, pandas, 3 other tools, mouse, 1 reference
[10] doi:10.1038/s41467-026-76939-w [code]
HIPPIE: a generative model for electrophysiological analysis across species, technologies, and modalities.
Journal: Nature communications
In common: seaborn, scikit-learn, pandas, 3 other tools, methods / tools, mouse, 1 reference

Contribute

The authors of this paper can claim it, correct its record and validate its tracing map, and the maintainers of its code (its owner, or a public member of its organization) correct what it says of their repository; anyone signed in can ask for its removal. Every request goes to OSCR's own machine, which answers it; your account page follows them.

Sign in with ORCID to claim this paper as one of its authors, correct its record or validate its tracing map: when the paper's metadata lists your ORCID iD, you are recognized at once. Maintainers of its code: sign in with GitHub, then claim the repository on your account page.

Request its removal

To ask OSCR to remove this record, the copies of its authors' scripts or its tracing map, use the removal request page: signed in, you say who you are, what to remove and why, then review and confirm the request. Published rules decide every request (how).

Discussion, reproductions, activity

Discussion: questions and error reports about this paper and its code, from signed-in readers and its authors. It opens with sign-in.

Reproductions: reports from readers who ran the authors' code: what they reproduced, with which environment, commit and data. It opens with sign-in.

Activity: what happens around this paper: new versions of its record, its map's validation, discussions and reproductions. It opens with sign-in.