### example Source: https://github.com/zhoujt1994/schicluster/blob/master/doc/schicluster/_build/html/_modules/example.html Source code for example ```python import time import numpy as np from schicluster import * from sklearn.cluster import KMeans, SpectralClustering from sklearn.metrics.cluster import adjusted_rand_score as ARI [docs]('../api/example/index.html#example.mm9dim')mm9dim = [197195432, 181748087, 159599783, 155630120, 152537259, 149517037, 152524553, 131738871, 124076172, 129993255, 121843856, 121257530, 120284312, 125194864, 103494974, 98319150, 95272651, 90772031, 61342430] [docs]('../api/example/index.html#example.hg19dim')hg19dim = [249250621, 243199373, 198022430, 191154276, 180915260, 171115067, 159138663, 146364022, 141213431, 135534747, ``` -------------------------------- ### Directory and chromosome size setup Source: https://github.com/zhoujt1994/schicluster/blob/master/doc/schicluster/_build/html/hba/plot_example.html Sets up input/output directories and loads chromosome sizes. ```python indir = '/data/hba/domain_majortype/' ddir = f'/home/jzhou_salk_edu/sky_workdir/hba/domain_majortype/diff/{group_name}/' ldir = f'/home/jzhou_salk_edu/sky_workdir/hba/loop_majortype/diff/{group_name}/' cdir = f'/home/jzhou_salk_edu/sky_workdir/hba/compartment_majortype/diff/{group_name}/' chrom_size_path = '/home/jzhou_salk_edu/sky_workdir/hba/ref/hg38.main.chrom.sizes' chrom_sizes = cooler.read_chromsizes(chrom_size_path, all_names=True) chrom_sizes = chrom_sizes.iloc[:-3] ``` -------------------------------- ### Command Examples Source: https://github.com/zhoujt1994/schicluster/blob/master/doc/schicluster/_build/html/_sources/command_line/hicluster_merge_cool.md An example of how to use the hicluster merge-cool command. ```bash hicluster merge-cool \ --input_cool_tsv_file impute/100K/cell_table_2.tsv \ --output_cool dataset/merge-cool.100kb ``` -------------------------------- ### Command Example Source: https://github.com/zhoujt1994/schicluster/blob/master/doc/schicluster/_build/html/_sources/command_line/hicluster_cpg_ratio.md Example of calculating CpG ratio at each Chrom100K (resolution 100000). ```bash hicluster cpg-ratio \ --fasta_path /data/aging/ref/m3C/mm10_with_chrl.fa \ --hdf_output_path cpg_ratio_100k.hdf \ --chrom_size_path /data/aging/ref/m3C/mm10.main.nochrM.nochrY.chrom.sizes \ --resolution 100000 ``` -------------------------------- ### Example 1: Imputation at 100kb resolution Source: https://github.com/zhoujt1994/schicluster/blob/master/doc/schicluster/_build/html/_sources/command_line/hicluster_prepare_impute.md This example shows how to prepare for imputation at 100kb resolution. ```bash hicluster prepare-impute \ --cell_table contact_table_rmbkl.tsv \ --batch_size 1536 \ --pad 1 \ --cpu_per_job 30 \ --chr1 1 \ --pos1 2 \ --chr2 5 \ --pos2 6 \ --output_dir impute/100K/ \ --chrom_size_path /data/aging/ref/m3C/mm10.main.nochrM.nochrY.chrom.sizes \ --output_dist 500000000 \ --window_size 500000000 \ --step_size 500000000 \ --resolution 100000 \ ``` -------------------------------- ### Example 3: Imputation at 10kb resolution Source: https://github.com/zhoujt1994/schicluster/blob/master/doc/schicluster/_build/html/_sources/command_line/hicluster_prepare_impute.md This example shows how to prepare for imputation at 10kb resolution. ```bash hicluster prepare-impute \ --cell_table contact_table_rmbkl.tsv \ --batch_size 1536 \ --pad 1 \ --cpu_per_job 30 \ --chr1 1 \ --pos1 2 \ --chr2 5 \ --pos2 6 \ --output_dir impute/100K/ \ --chrom_size_path /data/aging/ref/m3C/mm10.main.nochrM.nochrY.chrom.sizes \ --output_dist 5050000 \ --window_size 30000000 \ --step_size 10000000 \ --resolution 10000 \ ``` -------------------------------- ### Install scHiCluster Source: https://github.com/zhoujt1994/schicluster/blob/master/README.md Instructions for creating a conda environment and installing scHiCluster from GitHub. ```bash conda create -n schicluster python==3.6.8 conda activate schicluster pip install git+https://github.com/zhoujt1994/scHiCluster.git ``` -------------------------------- ### Example 2: Imputation at 25kb resolution Source: https://github.com/zhoujt1994/schicluster/blob/master/doc/schicluster/_build/html/_sources/command_line/hicluster_prepare_impute.md This example shows how to prepare for imputation at 25kb resolution. ```bash hicluster prepare-impute \ --cell_table contact_table_rmbkl.tsv \ --batch_size 1536 \ --pad 1 \ --cpu_per_job 30 \ --chr1 1 \ --pos1 2 \ --chr2 5 \ --pos2 6 \ --output_dir impute/100K/ \ --chrom_size_path /data/aging/ref/m3C/mm10.main.nochrM.nochrY.chrom.sizes \ --output_dist 5050000 \ --window_size 500000000 \ --step_size 500000000 \ --resolution 25000 \ ``` -------------------------------- ### Command Example Source: https://github.com/zhoujt1994/schicluster/blob/master/doc/schicluster/_build/html/_sources/command_line/hicluster_contact_distance.md An example of how to run the hicluster contact-distance command with specific parameters. ```bash hicluster contact-distance \ --contact_table contact_table_rmbkl.tsv \ --chrom_size_path /data/aging/ref/m3C/mm10.main.nochrM.nochrY.chrom.sizes \ --output_prefix contact_distance \ --resolution 10000 \ --chr1 1 \ --pos1 2 \ --chr2 5 \ --pos2 6 \ --cpu 20 ``` -------------------------------- ### Command Example Source: https://github.com/zhoujt1994/schicluster/blob/master/doc/schicluster/_build/html/command_line/hicluster_domain.html An example of how to run the hicluster domain command. ```bash hicluster domain \ --cell_table_path impute/25K/cell_table.tsv \ --output_prefix dataset/domain \ --resolution 25000 \ --window_size 10 \ --cpu 4 ``` -------------------------------- ### impute_cell command line examples Source: https://github.com/zhoujt1994/schicluster/blob/master/doc/schicluster/_build/html/_modules/impute_cell.html These are example commands for running the impute_cell script with different parameters. ```bash # command time python /gale/ddn/snm3C/humanPFC/code/impute_cell.py --indir /gale/raidix/rdx-5/zhoujt/projects/methylHiC/PFC_batch_merged/smoothed_matrix/1cell/${res0}b_resolution/chr${c}/ --outdir /gale/ddn/snm3C/humanPFC/smoothed_matrix/${res0}b_resolution/chr${c}/ --cell ${sample} --chrom ${c} --res ${res} --chrom_file /gale/netapp/home/zhoujt/genome/hg19/hg19.autosomal.chrom.sizes --mode pad2_std1_rp0.5_sqrtvc # command time python /gale/ddn/snm3C/humanPFC/code/impute_cell.py --indir /gale/ddn/snm3C/humanPFC/cell_matrix/${res0}b_resolution/chr${c}/ --outdir /gale/ddn/snm3C/humanPFC/smoothed_matrix/${res0}b_resolution/chr${c}/ --cell ${sample} --chrom ${c} --res ${res} --chrom_file /gale/netapp/home/zhoujt/genome/hg19/hg19.autosomal.chrom.sizes --pad 2 --output_dist 10050000 --window_size 40000000 --step_size 10000000 --mode pad2_std1_rp0.5_ws40 ``` -------------------------------- ### Command Example Source: https://github.com/zhoujt1994/schicluster/blob/master/doc/schicluster/_build/html/_sources/command_line/hicluster_embedding.md An example command to generate a chromosome-by-chromosome contact matrix. ```bash hicluster embedding \ --cell_table_path cell_table.tsv \ --output_dir dataset/embedding \ --dim 50 \ --dist 1000000 \ --resolution 100000 \ --scale_factor 100000 \ --norm_sig \ --save_raw \ --cpu 20 ``` -------------------------------- ### Command Time Example 1 Source: https://github.com/zhoujt1994/schicluster/blob/master/doc/schicluster/_build/html/_modules/loop_mergechr.html Example command for processing with loop_mergechr. ```bash # command time python /gale/ddn/snm3C/humanPFC/code/loop_mergechr.py --inprefix /gale/ddn/snm3C/humanPFC/smoothed_matrix/10kb_resolution/merged/L23_${mode}_dist_trim/L23_${mode}_dist_trim --outprefix /gale/ddn/snm3C/humanPFC/smoothed_matrix/10kb_resolution/merged/L23_${mode}_dist_trim/L23_${mode}_dist_trim --chrom_file /gale/netapp/home/zhoujt/genome/hg19/hg19.autosomal.chrom.sizes ``` -------------------------------- ### Command Line Usage Examples Source: https://github.com/zhoujt1994/schicluster/blob/master/doc/schicluster/_build/html/_modules/generatematrix_cell.html Examples of how to run the generatematrix_cell script with different parameters. ```bash python /gale/ddn/snm3C/humanPFC/code/generatematrix_cell.py --infile /gale/netapp/seq4/illumina_runs/ENTEx/Pool_BX_BY/mapping/output/TrCo_A9HOW_Plate1-1-H22/hic/TrCo_A9HOW_Plate1-1-H22-A13.3C.sorted_contacts_old.txt --outdir /gale/ddn/snm3C/humanPFC/cell_matrix/test/10kb_resolution/ --chrom_file /gale/netapp/home/zhoujt/genome/hg19/hg19.autosomal.chrom.sizes --split_file /gale/netapp/home/zhoujt/genome/hg19/hg19.chrsplit.bed --res 10000 --cell TrCo_A9HOW_Plate1-1-H22-A13 ``` ```bash python /gale/ddn/snm3C/humanPFC/code/generatematrix_cell.py --infile /gale/netapp/seq4/illumina_runs/ENTEx/Pool_BX_BY/mapping/output/TrCo_A9HOW_Plate1-1-H22/hic/TrCo_A9HOW_Plate1-1-H22-A13.3C.sorted_contacts_old.txt --outdir /gale/ddn/snm3C/humanPFC/cell_matrix/test/100kb_resolution/ --chrom_file /gale/netapp/home/zhoujt/genome/hg19/hg19.autosomal.chrom.sizes --res 100000 --cell TrCo_A9HOW_Plate1-1-H22-A13 ``` -------------------------------- ### hicluster domain command example Source: https://github.com/zhoujt1994/schicluster/blob/master/doc/schicluster/_build/html/_sources/command_line/hicluster_domain.md An example of how to use the hicluster domain command. ```bash hicluster domain \ --cell_table_path impute/25K/cell_table.tsv \ --output_prefix dataset/domain \ --resolution 25000 \ --window_size 10 \ --cpu 4 ``` -------------------------------- ### Command Time Example 2 Source: https://github.com/zhoujt1994/schicluster/blob/master/doc/schicluster/_build/html/_modules/loop_mergechr.html Example command for processing and splitting with loop_mergechr. ```bash # command time python /gale/ddn/snm3C/humanPFC/code/loop_mergechr.py --inprefix /gale/ddn/snm3C/humanPFC/smoothed_matrix/10kb_resolution/merged/L23_${mode}_dist_trim/L23_${mode}_dist_trim --outprefix /gale/ddn/snm3C/humanPFC/smoothed_matrix/10kb_resolution/merged/L23_${mode}_dist_trim/L23_${mode}_dist_trim.split --chrom_file /gale/netapp/home/zhoujt/genome/hg19/hg19.autosomal.chrom.sizes --split_file /gale/netapp/home/zhoujt/genome/hg19/hg19.chrsplit.bed ``` -------------------------------- ### Command line execution example Source: https://github.com/zhoujt1994/schicluster/blob/master/doc/schicluster/_build/html/_modules/comp_cpg_cell.html Example command to run the comp_cpg_cell script with specified parameters. ```bash command time python /gale/ddn/snm3C/humanPFC/code/comp_cpg_cell.py --indir /gale/raidix/rdx-5/zhoujt/projects/methylHiC/PFC_batch_merged/smoothed_matrix/1cell/${res0}b_resolution/ --outdir /gale/ddn/snm3C/humanPFC/smoothed_matrix/${res0}b_resolution/ --cell $(cat /gale/ddn/snm3C/humanPFC/smoothed_matrix/celllist_long.txt | head -${SGE_TASK_ID} | tail -1) --chrom ${c} --mode raw --cpg_file /gale/ddn/snm3C/humanPFC/smoothed_matrix/${res0}b_resolution/bins/hg19.${res0}bin.CpG.txt ``` -------------------------------- ### Calculate loop resolution Source: https://github.com/zhoujt1994/schicluster/blob/master/doc/schicluster/_build/jupyter_execute/hba/plot_example.ipynb Calculates the start and end indices for contact maps at a specified resolution. ```python ## contact maps are plotted at loop resolution ## select region to plot in Q matrix resl = 10000 loopl, loopr = (ll//resl), (rr//resl) print(loopl, loopr) ``` -------------------------------- ### Define Directory Paths Source: https://github.com/zhoujt1994/schicluster/blob/master/doc/schicluster/_build/html/_sources/hba/plot_example.ipynb Sets up input and output directory paths for data processing. ```python indir = '/data/hba/domain_majortype/' ddir = f'/home/jzhou_salk_edu/sky_workdir/hba/domain_majortype/diff/{group_name}/' ldir = f'/home/jzhou_salk_edu/sky_workdir/hba/loop_majortype/diff/{group_name}/' cdir = f'/home/jzhou_salk_edu/sky_workdir/hba/compartment_majortype/diff/{group_name}/' ``` -------------------------------- ### Select differential compartments Source: https://github.com/zhoujt1994/schicluster/blob/master/doc/schicluster/_build/html/_sources/hba/plot_example.ipynb Selects differential compartments based on chromosome, start position, and statistical significance. ```python resc = 100000 comp = pd.read_csv(f'{cdir}DifferentialResult/fdr_result/differential.intra_sample_combined.pcQnm.bedGraph', sep=' ', header=0, index_col=None) comp.index = comp['chr'] + '_' + (comp['start'] // resc).astype(str) bincomp = comp[['chr', 'start', 'end', 'sample_maha', 'pval', 'padj']] comp = comp[leg] selc = (bincomp['chr']==chrom) & (bincomp['start']>=ll) & (bincomp['start']norm.isf(0.025)) print(selc.sum()) ``` -------------------------------- ### Thebe Kernel Configuration Source: https://github.com/zhoujt1994/schicluster/blob/master/doc/schicluster/_build/html/api/setup/index.html Configuration options for launching a Thebe kernel, including repository, kernel name, and CodeMirror settings. ```json { "requestKernel": true, "binderOptions": { "repo": "binder-examples/jupyter-stacks-datascience", "ref": "master", }, "codeMirrorConfig": { "theme": "abcdef", "mode": "python" }, "kernelOptions": { "name": "python3", "path": "./api/setup" }, "predefinedOutput": true } ``` -------------------------------- ### Example 1: Running the imputation command Source: https://github.com/zhoujt1994/schicluster/blob/master/doc/schicluster/_build/html/_sources/command_line/hicluster_prepare_impute.md This command generates the imputation cool files at 100kb resolution. ```bash bash /home/qzeng_salk_edu/project/aging/230711_m3C/impute/100K/snakemake_cmd.txt ``` -------------------------------- ### Data Loading and Preparation Source: https://github.com/zhoujt1994/schicluster/blob/master/doc/schicluster/_build/html/_modules/example.html Loads and prepares network, label, and CpG data for analysis. ```python ctlist = ['HeLa', 'HAP1', 'GM12878', 'K562'] network = [np.loadtxt('1mb_resolution/' + ct + '/sample_list.txt', dtype=np.str) for ct in ctlist] label = np.array([ctlist[i] for i in range(len(ctlist)) for j in range(len(network[i]))]).astype('U8') network = np.concatenate(network) chrom = [str(i + 1) for i in range(22)] + ['X'] chromsize = {chrom[i]: hg19dim[i] for i in range(len(chrom))} nc = 4 cg = np.loadtxt('hg19/bin/hg19.1mb.bin.CpG.txt', dtype=np.str, skiprows=1, usecols=(0, 9, 11, 12)) cgdata = cg[:, 1:].astype(float) cgdata = cgdata[:, 2] / (cgdata[:, 1] - cgdata[:, 0]) cgdata[np.isnan(cgdata)] = 0.0 chrcg = {c: cgdata[cg[:, 0] == 'chr' + c] for c in chrom} ``` -------------------------------- ### Select differential boundaries Source: https://github.com/zhoujt1994/schicluster/blob/master/doc/schicluster/_build/html/_sources/hba/plot_example.ipynb Selects differential boundaries based on chromosome, start position, and various filtering criteria. ```python binall = pd.read_hdf(f'{ddir}MajorType_boundary_stats.hdf', key='data') selb = (binall['chrom']==chrom) & (binall['start']>=ll) & (binall['start']0.05) & binall['diff_sc'] print(selb.sum()) ``` -------------------------------- ### Determine genomic region for a gene Source: https://github.com/zhoujt1994/schicluster/blob/master/doc/schicluster/_build/html/_sources/hba/plot_example.ipynb Determines the genomic start and end coordinates for a given gene based on specified slopes. ```python gtmp = 'LAMP5' lslop, rslop = 1000000, 2000000 chrom = genemeta.loc[gtmp, 0] if genemeta.loc[gtmp, 5]=='+': tss = genemeta.loc[gtmp, 1] tes = genemeta.loc[gtmp, 2] else: tss = genemeta.loc[gtmp, 2] tes = genemeta.loc[gtmp, 1] ll, rr = (tss - lslop), (tss + rslop) print(chrom, ll, rr, genemeta.loc[gtmp, 5]) ``` -------------------------------- ### Figure and Axes Setup with Differential Plots Source: https://github.com/zhoujt1994/schicluster/blob/master/doc/schicluster/_build/html/_sources/hba/plot_example.ipynb This code sets up the figure and axes for plotting various genomic features, including Chi-Square, differential feature positions, boundary probabilities, and insulation scores. ```python fig, axes = plt.subplots(len(leg)*2+1, 1, figsize=(10, np.sum([1] + np.tile([3.5,1],len(leg)).tolist())/2), gridspec_kw={'height_ratios':[1] + np.tile([3.5,1],len(leg)).tolist()}, dpi=300, sharex='all') tmpl = loopall.loc[sell, [1,4]].values // resl - loopl tmpd = binall.loc[selb, 'start'] // resl - loopl tmpc = bincomp.loc[selc, 'start'] // resl - loopl ax = axes[0] sel = (binall['chrom']==chrom) & (binall['start']>=ll) & (binall['start']