Nextflow-based pipeline for cophasing of GAM reads.
- GAM experiment samples in the BAM format,
- Reference genome in the FASTA format,
- Phased SNPs in the VCF format.
A set of tables of the form {genome_name}.{bin_size}.{hap}.coverage.tsv and {genome_name}.{bin_size}.{hap}.segregation.tsv for different bin sizes with the number of reads per bin per sample. Haplotype hap is either hap1, hap2, or both. The columns are:
chrom: chromosome namestart: start position of the binstop: the stop position of the bin[sample]: The number of reads in the bin forcoverage.tsv, and 1 or 0 forsegregation.tsv, with 1 meaning the bin has been determined to be covered after filtering, 0 the opposite.
Note: For segregation, only autosomes are considered. The filter requires that the chromosomes are named in either the UCSC (chr1-chr22) or Ensembl format (1-22).
- filter out positions without phasing information
- convert VCF to BED format
- find the closest SNP for each read and merge
- bin the genome into fixed sized, non-overlapping windows of desired resolution, eg 50kb, 100kb, 200kb
- for comparison, calculate the coverage of each window using the original unsplit GAM samples,
- calculate coverage files of all split GAM samples for each haplotype,
- combine coverage files of all samples into one coverage table, per resolution
The coverage table describes the number of bases covered by reads in each window; therefore, it is possible that the sum of coverage from both haplotypes is higher than the total number of bases covered in a window, as some bases may be covered by both haplotypes.
The segregation algorithm removes spurious bins in particular the following two steps:
- Finds a separation threshold for bin count to remove noise reads.
- Remove orphan bins (bins with no neighbours).
Use the provided conda environment file pcp-env.yaml to install all the required software.
To execute, run:
nextflow run main.nf [parameters]
By default the results are written to the ./out folder.
Random testing data are provided as a part of the package. Run the following command to test the pipeline:
nextflow run main.nf -c test_data.config
NOTE: The parameters for the execution are stored in the Nextflow configuration file test_data.config.
--bam pathalignment files either as.bamor.sam. This can be a glob pattern (e.g.sample*.bam). All files matching the pattern are used then.--fa pathreference file either as.faor.fa.gz.--vcf patha variant call file either as.vcfor.vcf.gz. Must contain phased GT information.
Note: GATK requires .gz files to be compressed with bgzip, not gzip.
--name stringthe prefix that will be given to the samples,default=<the name of the reference file>,--bins [int]the bin sizes to be used,default=[50000, 100000, 200000],--out patha path to a folder where the output is stored,default=./out,--min_depth inta minimum read depth per SNP to be included,default=1,--min_ratio inttests that the dominant base for a SNP is at leastmin_ratiotimes more often present than the remaining observed bases BCFTools,default=5--cutoff intmaximum distance from a read to a closest so that the read is still matched to the SNP,default=0.
A sample visualization method is shown in the notebook NMPI_matrix_vis.ipynb. This notebook loads a singular segregation table and plots a contact map for one chromosome in a specified region.
A downstream Nextflow-based pipeline that takes the segregation tables produced by the Cophasing pipeline and identifies differential contacts between haplotypes using permutation testing.
The output directory of the main co-phasing pipeline (--out).
Naming convention: tables are located by *_{cutoff}_cutoff.{resolution}.{hap}.segregation*,
falling back to *.{resolution}.{hap}.segregation* when nothing matches. Encoding the
cutoff in the name parameter of the CoPhasing config keeps runs at the same resolution
apart, e.g. params { name = "cophasing_10Mb_cutoff" }. It is only required when
input_dir holds more than one run at a given resolution; the pipeline aborts rather
than guessing if several tables still match.
Results are written to subdirectories inside output_dir:
01_curated_segregation_tables/— segregation tables after WDF-based data curation02_permutation_test/— per-chromosome permutation test results (.pkl)03_thresholds/— knee-point threshold tables (.tsv) per chromosome04_cool_files/— contact matrices in.coolformat
- Curation — filters segregation tables based on windowed deviation from median (WDF), removing undersampled or oversampled bins
- Permutation test — runs a chromosome-level permutation test (
num_permpermutations) to calculate empirical p-values for each contact - Threshold identification — identifies a significance threshold per chromosome
- Cool file generation — converts significant permutation test results into
.coolcontact matrices
---
config:
flowchart:
nodeSpacing: 10
rankSpacing: 10
diagramPadding: 1
padding: 1
themeVariables:
fontSize: 10px
---
flowchart TD
IN[/"CoPhasing output\nhap1 · hap2 · both\nsegregation tables"/]
IN ==> S1
subgraph S1["`① **Curation**`"]
P1["Window detection frequency-based bin filtering\ncurates segregation tables and generates masking file"]
end
S1 ==> CUR[/"curated_*_cutoff.*.hap1.segregation.tsv\ncurated_*_cutoff.*.hap2.segregation.tsv\ncurated_*_cutoff.*.both.segregation.tsv"/]
S1 ==> BINS[/"bins_rm_hap1_hap2.tsv"/]
CUR ==> S2
BINS ==> S2
subgraph S2["`② **Permutation Test**`"]
P2["• calculate contact frequencies (CF) per haplotype<br/>• calculate ∆CF (hap1-hap2)<br/>• build null distribution by randomly reshuffling segregation tables across haplotypes"]
end
S2 ==> PKL[/"permutation_test_results\n_chr_multiprocessing.pkl"/]
PKL ==> S3
BINS ==> S3
subgraph S3["`③ **Threshold Identification**`"]
P3["• p-value calculation<br/>• normalized Gaussian smoothing<br/>• knee-point detection per chromosome"]
end
S3 ==> KNEE[/"knee_point_table_threshold_steps.tsv"/]
S3 ==> RATIO[/"ratios_table_threshold_steps.tsv\nratio_differential_contacts_info.tsv"/]
CUR ==> S4
PKL ==> S4
KNEE ==> S4
BINS ==> S4
subgraph S4["`④ **Cool File Generation**`"]
P4["• Identification of differential contacts based on thresholding<br/>• save results as long format .tsv and .cool files"]
end
S4 ==> COOL[/"permutation_test_results_*.cool\npermutation_test_results_*.tsv.gz"/]
classDef input fill:#b5c7eb,stroke:#0d47a1,color:#000,stroke-width:2px;
classDef process fill:#f5f5f5,stroke:#555555,color:#000,stroke-width:2px;
classDef file fill:#99c5c4,stroke:#008080,color:#000,stroke-width:2px;
classDef output fill:#ffe2a6,stroke:#ffcc80,color:#000,stroke-width:2px;
class IN input;
class P1,P2,P3,P4 process;
class CUR,BINS,PKL,KNEE,RATIO file;
class COOL output;
classDef leftAlign text-align:left;
class P1,P2,P3,P4 leftAlign;
nextflow run pipeline-permutation-test.nf -c permutation_test.config
--input_dir pathinput directory containing the cophasing pipeline output,--output_dir pathpath to a directory where results are stored,--chromosomes strcomma-separated list of chromosomes to process (e.g. chr1,chr2,...,chr22),--cutoff strcutoff value used in the cophasing pipeline (e.g. 10Mb),--resolution intbin size in bp used in the cophasing pipeline (e.g. 40000),--num_perm intnumber of permutations for the null distribution (e.g. 2000),--gaussian_kernel_size intkernel size for Gaussian smoothing in threshold detection (e.g. 1),--high_factor floatupper WDF factor for marking oversampled bins,default=1.8,--low_factor floatlower WDF factor for marking undersampled bins,default=1.8,--pseudocount intpseudocount added to contact frequencies,default=0,--num_workers intnumber of parallel workers for the permutation test,default=10
Note: The permutation test pipeline is partially hg38-specific.
This pipeline has been developed at Max Delbrück Center for Molecular Medicine, Berlin. Authors:
- Dr. Adam Streck: cophasing pipeline development,
- Dr. Julia Markowski: creator of the co-phasing method,
- Dr. Alexander Kukalev: creator of the separation algorithm,
- Claudia Robens: permutation test pipeline development.
Email questions, feature requests and bug reports to Adam Streck, adam.streck@iccb-cologne.org.
This repository is available under the MIT License.
