scDIAGRAM: detecting chromatin compartments from individual single-cell Hi-C matrix without imputation or reference features.
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
- ## Implement MCMC in the scDIAGRAM
- import argparse
- import time
- from collections import Counter
- from multiprocessing import Pool
- import matplotlib.pyplot as plt
- import numpy as np
- import pandas as pd
- import seaborn as sns
- from scipy import signal, stats
- from scipy.stats import rankdata
- from sklearn.decomposition import PCA
- from sklearn.preprocessing import quantile_transform
- #from cooltools.lib import numutils
- parser = argparse.ArgumentParser(description='Implement MH algorithm')
- parser.add_argument('--file', type=str)
- parser.add_argument('--index', type=int, default=0)
- parser.add_argument('--chr', type=int, default=7)
- parser.add_argument('--start', type=int)
- parser.add_argument('--end', type=int)
- parser.add_argument('--step', type=int, default=1)
- parser.add_argument('--terminate', type=int, default=10000)
- parser.add_argument('--out_file', type=str, default='single-cell_res.out')
- #parser.add_argument('--CP_term', type=int, default=50)
- parser.add_argument('--contact_thre', type=float, default=99.9)
- #parser.add_argument('--cpg_file', type=str, default=None)
- parser.add_argument('--before', type=int, default=1)
- parser.add_argument('--species', type=str, default='mm')
- parser.add_argument('--resolution', type=int, default=100000)
- parser.add_argument('--binary', type=int, default=0)
- parser.add_argument('--input_version', type=str, default='v1')
- parser.add_argument('--reference', type=str, default='reference/mm10_chr_size.txt')
- parser.add_argument('--output', type=str, default='MCMC_res.npy')
- #parser.add_argument('--out_file', type=str, default='single-cell_res.out')
- args = parser.parse_args()
- print(args)
- #print(bool(args.before))
- file = args.file
- start = args.start
- end = args.end
- step = args.step
- index = args.index
- outFile = args.out_file
- #CP_term = args.CP_term
- contact_thre = args.contact_thre
- out_file = args.out_file
- ################################################################################
- print('Preparation. Compute the variance ...')
- chr = f'chr{args.chr}'
- resolution = args.resolution
- chr_data = pd.read_table('reference/mm10_chr_size.txt',header=None)
- length = chr_data.iloc[args.chr - 1, 1]
- L = length // resolution + 1
- def cross_entropy(k, N):
- if k == 0 or k == N:
- return 0
- return k * np.log(k / N) + (N - k) * np.log(1 - k / N)
- if args.species == 'hg':
- centro_pos = pd.read_table('reference/centro_pos.txt',header=None,index_col=0)
- before_pos = centro_pos.iloc[args.chr-1, 0]
- end_pos = centro_pos.iloc[args.chr-1, 1]
- def comp(file, index=0):
- global before_pos, end_pos
- if args.input_version == "v2":
- global L
- Mat = np.zeros((L, L))
- with open(file, 'rt') as f:
- for line in f:
- bb = line.split("\t")
- source = int(bb[1]) // resolution
- target = int(bb[3]) // resolution
- if source >= L or target >= L:
- continue
- Mat[source, target] += 1
- Mat[target, source] += 1
- row, col = np.diag_indices_from(Mat)
- Mat[row, col] = 0
- elif args.input_version == "v1":
- Mat = np.load(file)
- if len(Mat.shape)==2:
- row, col = np.diag_indices_from(Mat)
- Mat[row, col] = 0
- else:
- Mat = Mat[index,:,:]
- row, col = np.diag_indices_from(Mat)
- Mat[row, col] = 0
- else:
- print("Undefined input version, error...")
- return 0
- # X = Mat[30:, 30:]
- X = Mat
- if args.species == "hg":
- if args.before==True and before_pos!=0:
- X = X[:before_pos, :before_pos]
- elif args.before==True and before_pos==0:
- print('Centromere is on the end, no small arms before centromere.')
- return 0
- else:
- X = X[end_pos:, end_pos:]
- elif args.species == "mm":
- end_pos = 3000000//resolution
- X = X[end_pos:, end_pos:]
- A = X
- mask = A.sum(axis=0) > 0
- OE, _, _, _ = numutils.observed_over_expected(A, mask)
- clip_percentile = contact_thre
- if np.quantile(X,contact_thre/100)==0:
- OE[OE>0] = 1
- else:
- OE = np.clip(OE, 0, np.percentile(OE[mask, :][:, mask], clip_percentile))
- OE[~mask, :] = 0
- OE[:, ~mask] = 0
- X = OE.copy()
- row, col = np.diag_indices_from(X)
- X[row, col] = 0
- row = row[:-1]
- col = col[1:]
- X[row,col] = 0
- if args.binary == True:
- X[X > 0] = 1
- Z = X.copy()
- n = X.shape[0]
- print(n)
- C2 = X.copy()
- X = np.triu(X)
- Var = np.var(X[X != 0])
- print('var: ', Var)
- T = Var * 2
- time0 = time.time()
- logR = np.zeros((n, n))
- S_square = np.zeros((n + 1, n + 1))
- S = np.zeros((n + 1, n + 1))
- score1 = 0
- score2 = 0
- X_square = X ** 2
- # if T>0:
- for t in range(1, n + 1):
- time1 = time.time()
- # print(t,time1-time0)
- if t == 1:
- score1 += X[0, 0]
- score2 += X_square[0, 0]
- S[1, 1] = score1
- S_square[1, 1] = score2
- for s in range(2, n + 1):
- inc1 = np.sum(X[:s, s - 1])
- inc2 = np.sum(X_square[:s, s - 1])
- score1 += inc1
- score2 += inc2
- S[1, s] = score1
- S_square[1, s] = score2
- else:
- score1 = X[t - 2, t - 2]
- score2 = X_square[t - 2, t - 2]
- for s in range(t, n + 1):
- score1 += X[t - 2, s - 1]
- score2 += X_square[t - 2, s - 1]
- S[t, s] = S[t - 1, s] - score1
- S_square[t, s] = S_square[t - 1, s] - score2
- # X1 = X[(t - 1):s, (t - 1):s]
- time1 = time.time()
- print('used time: ', time1 - time0)
- N = X.shape[0]
- def logphi1(t, s):
- Nk = np.sum(X[t - 1:s, t - 1:s] != 0)
- N = (s - t + 1) * (s - t + 2) / 2
- if Nk == 0:
- return 0
- # N = (s - t + 1) * (s - t + 2) / 2
- V1 = S_square[t, s] / Nk - (S[t, s] / Nk) ** 2
- if T > 0:
- res = -Nk * V1 / T + cross_entropy(Nk, N)
- else:
- res = cross_entropy(S[t, s], N)
- return res
- def logphi2(t1, s1, t2, s2):
- Nk = np.sum(X[t1 - 1:s1, t2 - 1:s2] > 0)
- N = (s1 - t1 + 1) * (s2 - t2 + 1)
- if Nk == 0:
- return 0
- # N = (s1 - t1 + 1) * (s2 - t2 + 1)
- S1 = S[s1 + 1, t2 - 1] - S[t1, t2 - 1] - S[s1 + 1, s2] + S[t1, s2]
- S2 = S_square[s1 + 1, t2 - 1] - S_square[t1, t2 - 1] - S_square[s1 + 1, s2] + S_square[t1, s2]
- V1 = S2 / Nk - (S1 / Nk) ** 2
- if T > 0:
- res = -Nk * V1 / T + cross_entropy(Nk, N)
- else:
- res = cross_entropy(S1, N)
- return res
- def comp_score(m_ls, N):
- m_ls = [0] + m_ls + [N]
- kT = len(m_ls)
- score = 0
- for i in range(kT - 1):
- source = m_ls[i]
- end = m_ls[i + 1]
- score += logphi1(source + 1, end)
- for i in range(kT - 1):
- source1 = m_ls[i]
- end1 = m_ls[i + 1]
- for j in range(i + 1, kT - 1):
- source2 = m_ls[j]
- end2 = m_ls[j + 1]
- score += logphi2(source1 + 1, end1, source2 + 1, end2)
- return score
- Ind = np.arange(1, N)
- res_ls_tot = {}
- k_ls = np.arange(start, end, step)
- #print(k_ls)
- for k in k_ls:
- explode = 0
- count = 0
- np.random.seed(1234)
- m_ls = np.random.choice(N - 1, size=k) + 1
- m_ls.sort()
- m_ls = list(m_ls)
- ## T for variance*2.
- m_res = list(set(Ind) - set(m_ls))
- # print(m_ls)
- score = comp_score(m_ls, N)
- #L = {}
- logp = 0
- LT = []
- terminate = args.terminate
- res_ls = {}
- Likelih_ls = {}
- np.random.seed(1234)
- for t in range(args.end + 1):
- Likelih_ls[t] = -np.inf
- while True:
- m_ls_cand = m_ls.copy()
- m_ls_old = m_ls.copy()
- k = len(m_ls)
- flip1 = np.random.randint(N - k - 1)
- flip2 = np.random.randint(k)
- m_ls_cand.pop(flip2)
- m_ls_cand.append(m_res[flip1])
- m_ls_cand.sort()
- score2 = comp_score(m_ls_cand, N)
- prob_log = (score2 - score) + (len(m_ls_cand) - len(m_ls)) * logp
- accep_log = min(0, prob_log)
- trial_prob_log = np.log(np.random.rand())
- if trial_prob_log < accep_log:
- m_ls = m_ls_cand
- m_res = list(set(Ind) - set(m_ls))
- score = score2
- k = len(m_ls)
- if score > Likelih_ls[k]:
- res_ls[k] = m_ls
- Likelih_ls[k] = score
- if count % 100 == 0:
- print(count, m_ls, len(m_ls), accep_log, m_ls_cand, score)
- LT.append(len(m_ls))
- count += 1
- if count == terminate:
- break
- if explode == 1:
- print('explode...')
- continue
- k_most = k
- with open(outFile, 'a') as f:
- print(res_ls[k_most], Likelih_ls[k_most], k_most, file=f)
- print('No.', index, 'cell being processed on chr', args.chr, file=f)
- print(res_ls[k_most], Likelih_ls[k_most], k_most)
- #print(res_ls_tot)
- return res_ls[k_most]
- res = comp(file)
- print(res)
- res = np.array(res)
- np.save(args.output, res)
- print(res.shape)
MCMC.py at commit 72ccce8, under MIT · at the source
Overview
- Beijing International Center for Mathematical Research (BICMR), Peking University, No.5 Yiheyuan Road, Haidian District, Beijing 100871, China
- Biomedical Pioneering Innovation Center (BIOPIC), Peking University, No.5 Yiheyuan Road, Haidian District, Beijing 100871, China
- 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
- Beijing Advanced Innovation Center for Genomics, Peking University, No.5 Yiheyuan Road, Haidian District, Beijing 100871, China
- School of Public Health and Center for Statistical Science, Peking University, No.5 Yiheyuan Road, Haidian District, Beijing 100871, China
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/
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
72ccce878ac1045129eda01954e62682f1434a46, 25 January 2026Availability: 1 check, the latest on 30 September 2026: the link answers
- 30 September 2026: the link answers
15 files
- MCMC.py, Python, 333 lines
- MCMC_parallel.py, Python, 355 lines
- S_AB.py, Python, 296 lines
- S_AB_parallel.py, Python, 329 lines
- misc/
Bulk3-1.py , Python, 61 lines - misc/
Bulk3-2.py , Python, 62 lines - misc/
Bulk4-3.py , Python, 134 lines - misc/
Comp_CpG2.R , R, 31 lines - misc/
generate_bed.py , Python, 37 lines - misc/
generate_centro.py , Python, 39 lines - misc/
hBulk1.py , Python, 72 lines - misc/
hBulk2.py , Python, 144 lines - misc/
hCpG1-0.py , Python, 81 lines - LICENSE, License, 21 lines
- README.md, Text, 154 lines
Zenodo 15855256
Availability: 1 check, the latest on 30 September 2026: the link answers (HTTP 200)
- 30 September 2026: the link answers (HTTP 200)
12 files
- MCMC.py, Python, 312 lines
- MCMC_parallel.py, Python, 333 lines
- S_AB.py, Python, 276 lines
- S_AB_parallel.py, Python, 313 lines
- misc/
Bulk3-1.py , Python, 61 lines - misc/
Bulk3-2.py , Python, 62 lines - misc/
Bulk4-3.py , Python, 134 lines - misc/
hBulk1.py , Python, 72 lines - misc/
hBulk2.py , Python, 144 lines - misc/
hCpG1-0.py , Python, 81 lines - LICENSE, License, 21 lines
- README.md, Text, 150 lines
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://
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://
BibTeX
@article{peng2026scdiagr
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/
url = {https://
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/
VL - 27
IS - 2
SP - bbag096
SN - 1467-5463
PB - Oxford University Press
DO - 10.1093/
UR - https://
LA - en
ER -
CSL-JSON
{
"id": "10.1093/
"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":
"volume": "27",
"issue": "2",
"page": "bbag096",
"DOI": "10.1093/
"PMID": "41795655",
"PMCID": "PMC12967335",
"ISSN": "1467-5463",
"publisher": "Oxford University Press",
"URL": "https://
"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 communicationsIn 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 communicationsIn 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 genomeJournal: 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 matterIn 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 communicationsIn 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 communicationsIn 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 neuroscienceIn 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 communicationsIn 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 communicationsIn 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.
Claim this paper
Correct its record
Say what each link of this record is, remove the ones that are not the paper's, add the ones that are missing. The correction becomes a new version of the record, in its Versions section.
Validate its tracing map
You validate the map as this page shows it: 2 repositories of the authors' code, each at its verified commit and with its license, 23 scripts, and 0 matches between paragraphs and code (see the Code and Map sections). It then receives a DOI on Zenodo, with you (your ORCID iD) and OSCR as its creators; the code itself is not deposited.
The map's fingerprint: sha256:5084ef043517efe4…
Add the badge to its README
The badge links the code to this page. Copy one of these into the README of the paper's code: only you decide where it goes, and nothing is changed for you.
Markdown
[, paste the snippet at the top, then “Commit changes…” and, to review it first, “Create a new branch and start a pull request”. You open the pull request; OSCR asks for no permission.
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.
