{"id":17174913,"url":"https://github.com/tobiasrausch/sv","last_synced_at":"2026-03-07T20:04:50.826Z","repository":{"id":248878207,"uuid":"828831196","full_name":"tobiasrausch/sv","owner":"tobiasrausch","description":"Structural variant calling tutorial using long-reads.","archived":false,"fork":false,"pushed_at":"2025-01-21T13:03:25.000Z","size":57,"stargazers_count":6,"open_issues_count":1,"forks_count":2,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-06-11T16:25:48.834Z","etag":null,"topics":["delly","genomics","genomics-analysis","structural-variants","structural-variation"],"latest_commit_sha":null,"homepage":"","language":"R","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"bsd-3-clause","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/tobiasrausch.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null,"zenodo":null}},"created_at":"2024-07-15T08:07:03.000Z","updated_at":"2025-05-13T13:37:20.000Z","dependencies_parsed_at":"2024-07-17T17:22:19.048Z","dependency_job_id":"4ab6b42e-8f1c-4ac8-914f-fde20e939420","html_url":"https://github.com/tobiasrausch/sv","commit_stats":null,"previous_names":["tobiasrausch/vclr"],"tags_count":1,"template":false,"template_full_name":null,"purl":"pkg:github/tobiasrausch/sv","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/tobiasrausch%2Fsv","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/tobiasrausch%2Fsv/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/tobiasrausch%2Fsv/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/tobiasrausch%2Fsv/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/tobiasrausch","download_url":"https://codeload.github.com/tobiasrausch/sv/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/tobiasrausch%2Fsv/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":30229590,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-03-07T19:01:10.287Z","status":"ssl_error","status_checked_at":"2026-03-07T18:59:58.103Z","response_time":53,"last_error":"SSL_read: unexpected eof while reading","robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":false,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["delly","genomics","genomics-analysis","structural-variants","structural-variation"],"created_at":"2024-10-14T23:55:14.147Z","updated_at":"2026-03-07T20:04:50.799Z","avatar_url":"https://github.com/tobiasrausch.png","language":"R","funding_links":[],"categories":[],"sub_categories":[],"readme":"[![Docker CI](https://github.com/tobiasrausch/sv/workflows/Docker%20CI/badge.svg)](https://hub.docker.com/r/trausch/sv/)\n[![GitHub license](https://img.shields.io/badge/License-BSD%203--Clause-blue.svg)](https://github.com/tobiasrausch/sv/blob/master/LICENSE)\n[![GitHub Releases](https://img.shields.io/github/release/tobiasrausch/sv.svg)](https://github.com/tobiasrausch/sv/releases)\n\n# Structural variant calling tutorial using long-reads.\n\n## Installation\n\nInstallation of required libraries depends on your linux distribution, e.g., for Ubuntu:\n\n`apt-get update`\n\n`apt-get install -y autoconf build-essential cmake g++ git libcurl4-gnutls-dev libbz2-dev libdeflate-dev libgl1-mesa-dev libncurses-dev liblzma-dev pkg-config zlib1g-dev`\n\nThen clone the repository and install all dependencies using mamba:\n\n`git clone --recursive https://github.com/tobiasrausch/sv`\n\n`cd sv`\n\n`make all`\n\nDownload the course data:\n\n`make FILE=1PfCy8yESCxvI8RJsfxTbF-QsygfnKNA2 download`\n\n## Load the software stack\n\nLoad the mamba environment with all required tools.\n\n```bash\nif [ ! -z ${CONDA_PREFIX+x} ]; then conda deactivate; fi\nexport PATH=`pwd`/mamba/bin:${PATH}\n```\n\n## SV Calling\n\n### Reconstructing a derivative chromosome in cancer\n\nIn this practical we will analyze structural variants (SVs) of a [pancreatic cancer cell line](https://www.nist.gov/programs-projects/cancer-genome-bottle) from the [Genome in a Bottle project](https://www.nature.com/articles/sdata201625). The data was subsampled and subset to chr1 and chr5 to speed up all subsequent analysis. The tumor genome alignment file is named `tumor.bam` and the control genome alignment file is named `control.bam`.\n\n### Structural variant alignment quality control\n\nFor the discovery of structural variants, you should first assess the quality of the sequencing data as, for example, local assembly methods suffer from short reads and a high sequencing error rate and read-depth methods from uneven coverage. Common quality criteria are the percentage of reads mapped, the duplicate rate, the read-length distribution and the error rate. Popular tools to compute long-read quality control metrics are [NanoPlot](https://github.com/wdecoster/NanoPlot) and [Alfred](https://github.com/tobiasrausch/alfred).\n\n```bash\ncd data/lr/\nalfred qc -r genome.fa -o qc.tsv.gz -j qc.json.gz tumor.bam\nzcat qc.tsv.gz | grep ^ME | datamash transpose\nNanoPlot --bam tumor.bam -o qc_tumor\ncat qc_tumor/NanoStats.txt\n```\n\nAs you can see from the QC results, the data has been downsampled to fairly low coverage to speed up all analyses in this tutorial.\nThis implies that some structural variants will have only weak support. In terms of QC interpretation, there are some general things to watch out for, such as unexpected high error rates (\u003e4%), less than 80% of reads above Q10, an N50 read length below 10Kbp or unexpected patterns in the read length histogram.\n \n#### Exercises\n\n* What is the difference between the weighted read length histogram and the non-weighted histogram (WeightedHistogramReadlength.png, Non_weightedHistogramReadlength.png)?\n* How is the N50 read length calculated?\n* What is the median coverage of the tumor genome?\n\n### Germline Structural Variants\n\nBefore we dive into structural variant (SV) calling, let's get an idea of how SVs look like in long-read sequencing data. I have prepared a [BED](https://bedtools.readthedocs.io/) file with some \"simple\" germline structural variants like deletions and insertions and one complex example.\n\n```bash\ncat svs.bed\n```\n\nUsing [IGV](http://software.broadinstitute.org/software/igv/) we can browse these SVs interactively.\n\n```bash\nigv -g genome.fa\n```\n\nOnce IGV has started use 'File' and 'Load from File' to load the `tumor.bam` and `control.bam` alignment file. Then import the `svs.bed` file from your working directory using 'Regions' and 'Import Regions'.\nYou can then easily navigate to the structural variants with 'Regions' and 'Region Navigator'.\nSelect a structural variant in the region navigator and click 'View', which will center the IGV alignment view on the selected structural variant.\nYou can zoom in and out using the '+' and '-' signs in the toolbar at the top.\nYou may also want to visualize clipped reads using the 'View' menu, then click 'Preferences...' and then click the 'Alignments' tab to switch on 'Show soft-clipped reads'. For the last complex SV, you may also want to highlight one specific read named `8c0eba99-ad7d-4246-87f0-46177b9946d4` which is over 100Kbp long: Use a right click on `tumor.bam` and then 'Select by name...'. We will later use that read to visualize this complex region.\n\n#### Exercises\n\n* Which of the two insertions could be a mobile element insertion? What typical features of a mobile element can you observe for that insertion?\n* Do you see for heterozygous SVs, potential heterozygous SNPs in the vicinity that are on the same haplotype?\n\n### Plotting structural variants\n\nIGV is excellent for interactive browsing but for large numbers of SVs you can use command-line tools such as [wally](https://github.com/tobiasrausch/wally) to plot multiple SVs in batch.\n\n```bash\nwally region -R svs.bed -cp -g genome.fa tumor.bam control.bam\n```\n\n### Complex structural variants\n\nEven in germline genomes we can observe complex structural variants or potential reference errors. One example was in the `svs.bed` file.\n\n```bash\ncat svs.bed | grep \"complex\"\n```\n\nIn IGV, we already saw that a very long read named `8c0eba99-ad7d-4246-87f0-46177b9946d4` maps to that region.\nLet's do a dotplot of that read against the reference region using [wally](https://github.com/tobiasrausch/wally).\n\n```bash\nwally dotplot -g genome.fa -r 8c0eba99-ad7d-4246-87f0-46177b9946d4 -e chr1:16500000-16600000 tumor.bam\n```\n\nThis dotplot suggests a repeat expansion relative to GRCh38.\n\n#### Exercises\n\n* The [UCSC genome browser](https://genome.ucsc.edu/cgi-bin/hgTracks?db=hg38\u0026position=chr1%3A16500000%2D16650000) suggests that there is already a patch of the reference for this area of the genome, called chr1_MU273333v1_fix.fa. You may want to try and realign the read to the patched genome using minimap2.\n\n```bash\nsamtools view -F 3844 tumor.bam chr1:16500000-16650000 | grep \"^8c0eba99-ad7d-4246-87f0-46177b9946d4\" | cut -f 1,10 | awk '{print \"\u003e\"$1\"\\n\"$2;}' \u003e read.fa\nminimap2 -ax map-ont -L chr1_MU273333v1_fix.fa read.fa | samtools sort -o read.bam -\nsamtools index read.bam\nwally dotplot -g chr1_MU273333v1_fix.fa -r 8c0eba99-ad7d-4246-87f0-46177b9946d4 -e chr1_MU273333v1_fix:300000-400000 read.bam\n```\n\n### Delly structural variant calling\n\n[Delly](https://github.com/dellytools/delly) is a method for detecting structural variants using short- or long-read sequencing data.\nUsing the tumor and normal genome alignment, delly calculates structural variants and outputs them as a BCF file, the binary encoding of [VCF](https://samtools.github.io/hts-specs). Delly's long-read SV discovery mode uses the subcommand `lr`.\n\n```bash\ndelly lr -g genome.fa -o sv.bcf tumor.bam control.bam\n```\n\n#### VCF encoding of structural variants\n\nVCF was originally designed for small variants such as single-nucleotide variants (SNVs) and short insertions and deletions (InDels). That's why all SV callers heavily use the VCF INFO fields to encode additional information about the SV such as the structural variant end position (INFO:END) and the SV type (INFO:SVTYPE). You can look at the header of the BCF file using grep where '-A 2' includes the first two structural variant records after the header in the file:\n\n```bash\nbcftools view sv.bcf | grep \"^#\" -A 2\n```\n\n[Delly](https://github.com/dellytools/delly) uses the VCF:INFO fields for structural variant site information, such as how confident the structural variant prediction is and how accurate the breakpoints are. The genotyping fields contain the actual sample genotype, its genotype quality and genotype likelihoods and various count fields for the variant and reference supporting reads.\nPlease note that at this stage the BCF file contains germline and somatic structural variants but also false positives caused by mis-mappings or incomplete reference sequences.\n\n#### Querying VCF files\n\n[Bcftools](https://github.com/samtools/bcftools) offers many possibilities to query and reformat SV calls. For instance, to output a table with the chromosome, start, end, identifier and genotype of each SV we can use:\n\n```bash\nbcftools query -e 'SVTYPE==\"BND\"' -f \"%CHROM\\t%POS\\t%INFO/END\\t%ID[\\t%GT]\\n\" sv.bcf | head\n```\n\nInter-chromosomal translocations with SV type `BND` are a special case because they involve two different chromosomes.\n\n```bash\nbcftools query -i 'SVTYPE==\"BND\"' -f \"%CHROM\\t%POS\\t%INFO/CHR2\\t%INFO/POS2\\t%ID[\\t%GT]\\n\" sv.bcf\n```\n\nBcftools can also filter by genomic regions. For instance, to verify delly found the Alu (mobile element) insertion we previously looked at in IGV, you can use:\n\n```bash\ngrep \"INS02\" svs.bed\nbcftools view sv.bcf chr5:56632119-56632158\n```\n\nDelly's consensus sequence (INFO:CONSENSUS) is a local assembly of all SV-supporting reads. So we can again create a dotplot using [wally](https://github.com/tobiasrausch/wally) to highlight the insertion relative to GRCh38.\n\n```bash\nbcftools query -f \"%POS\\t%ID\\t%INFO/CONSENSUS\\n\" sv.bcf | grep \"^566321\" | awk '{print \"\u003e\"$2\"\\n\"$3;}' \u003e ins.fa\nsamtools faidx genome.fa chr5:56631000-56633000 | sed 's/^\u003e.*$/\u003ehg38/' \u003e\u003e ins.fa\nwally dotplot ins.fa\n```\n\nTo identify additional Alu candidate insertions, we can for instance filter by size and select insertions with a poly-A tail.\n\n```bash\nbcftools query -i 'SVTYPE==\"INS\" \u0026\u0026 SVLEN\u003e250 \u0026\u0026 SVLEN\u003c350' -f \"%CHROM\\t%POS\\t%ALT\\n\" sv.bcf  | grep \"AAAAAAAAAAA\"\n```\n\n#### Exercises\n\n* How many inter-chromosomal translocations were identified by delly?\n* How can bcftools be used to count the number of structural variants for the different SV types (DEL, INS, DUP, INV, BND)?\n* Using the bcftools query command above: How many potential Alu insertions are in forward and reverse orientation?\n\n### Somatic structural variant filtering\n\nDelly's initial SV calling cannot differentiate somatic and germline structural variants. We therefore now use delly's somatic filtering, which requires a sample file listing tumor and control sample names from the VCF file.\n\n```bash\ncat spl.tsv\n```\n\nThere are many parameters available to tune the somatic structural variant filtering like the minimum variant allele frequency to filter out subclonal variants, for instance. Let's leave the defaults for the time being and only filter for SVs with the VCF FILTER field set to PASS.\n\n```bash\ndelly filter -p -f somatic -o somatic.bcf -s spl.tsv sv.bcf\n```\nAs expected, the somatic SVs have a homozygous reference genotype in the control sample.\n\n```bash\nbcftools query -f \"%CHROM\\t%POS\\t%INFO/END\\t%ID[\\t%GT]\\n\" somatic.bcf\n```\n\nUsing [Bcftools](https://github.com/samtools/bcftools) and [wally](https://github.com/tobiasrausch/wally) we can also easily plot the intra-chromosomal somatic SVs.\n\n```bash\nbcftools query -e 'SVTYPE==\"BND\"' -f \"%CHROM\\t%POS\\t%INFO/END\\t%ID\\n\" somatic.bcf | awk '{print $1\"\\t\"($2-50)\"\\t\"($3+50)\"\\t\"$4;}' \u003e somatic.bed\nwally region -R somatic.bed -cp -g genome.fa tumor.bam control.bam\n```\n\n#### Exercises\n\n* Do you think all somatic variants are truly somatic? Which ones are likely false positive somatic SVs?\n\n### Reconstructing a derivative chromosome in cancer\n\n[IGV](http://software.broadinstitute.org/software/igv/) and [wally](https://github.com/tobiasrausch/wally) are good for relatively small SVs but for large SVs like the duplication-type SV or inter-chromosomal translocations we need to integrate read-depth with structural variant predictions to get a better overview of complex somatic rearrangements. Let's first create a simple read-depth plot.\n\n```bash\ndelly cnv -i 50000 -j 50000 -w 50000 -uo cnv.bcf -c cnv.cov.gz -g genome.fa -m map.fa.gz tumor.bam\nRscript cnBafSV.R cnv.cov.gz\n```\nNow we can overlay the somatic structural variants on top of the read-depth information.\n\n```bash\nbcftools query -f \"%CHROM\\t%POS\\t%INFO/END\\t%INFO/SVTYPE\\t%ID\\t%INFO/CHR2\\t%INFO/POS2\\n\" somatic.bcf \u003e svs.tsv\nRscript cnBafSV.R cnv.cov.gz svs.tsv\n```\n\nApparently, chr1 and chr5 are connected but the question is whether the left or the right end is joined from each inter-chromosomal translocation breakpoint. Delly outputs the orientation of each segment in the INFO:CT field.\n\n```bash\nbcftools query -i 'SVTYPE==\"BND\"' -f \"%INFO/CT\\n\" somatic.bcf\n```\n\nIn this case, `3to3` indicates that chr1p is joined with chr5p in inverted orientation. Here is a brief summary of the different [connection types](https://github.com/tobiasrausch/wally#paired-end-view).\n\n\n#### Exercises\n\n* Does the derivative chromosome containing chr1p and chr5p contain a centromere?\n\n### Calling and phasing small variants (SNVs and InDels)\n\nFor phasing and haplo-tagging the tumor reads we first call small variants using [longshot](https://github.com/pjedge/longshot) in the matched control.\n\n```bash\nlongshot --no_haps -s HG008-N-P --bam control.bam --ref genome.fa --out control.longshot.vcf\nbgzip control.longshot.vcf\ntabix control.longshot.vcf.gz\n```\n\nWe can then perform long-read based haplotyping using [WhatsHap](https://github.com/whatshap/whatshap) and phase heterozygous variants.\n\n```bash\nwhatshap phase --ignore-read-groups --reference genome.fa control.longshot.vcf.gz control.bam -o control.whatshap.vcf\nbgzip control.whatshap.vcf\ntabix control.whatshap.vcf.gz\n```\n\nLet's briefly inspect some phasing statistics using the [WhatsHap](https://github.com/whatshap/whatshap) `stats` subcommand.\n\n```bash\nwhatshap stats --chr-lengths \u003c(cut -f 1,2 genome.fa.fai) control.whatshap.vcf.gz\n```\n\n#### Exercises\n\n* How many mega-basepairs is the longest phased block?\n* What is the N50 phased block length?\n\n### Haplotagging of tumor reads\n\nWe can now use the haplotypes derived from the matched control to phase the tumor reads.\n\n```bash\nwhatshap haplotag -o tumor.hp.bam --reference genome.fa --ignore-read-groups --tag-supplementary control.whatshap.vcf.gz tumor.bam\nsamtools index tumor.hp.bam\n```\n\nThe `tumor.hp.bam` file now has the `HP` tag included for all the reads that could be phased to haplotype 1 or 2. [IGV](http://software.broadinstitute.org/software/igv/) can group and color reads by `HP` tag so let's revisit the SVs from the `svs.bed` file that we used in the beginning of the tutorial.\n\n```bash\nigv -g genome.fa\n```\n\nAs previously, once IGV has started use 'File' and 'Load from File' to load the `tumor.hp.bam` alignment file with the `HP` haplotype tags. Then import the `svs.bed` file from your working directory using 'Regions' and 'Import Regions'. You can then easily navigate to the structural variants with 'Regions' and 'Region Navigator'. Once you have selected an SV, right click on `tumor.hp.bam`, use 'Color alignments by' and select 'tag'. Then enter 'HP' to color by haplotype. Alternatively, you can also use 'Group alignments by' tag to sort reads according to assigned haplotype.\n\n#### Exercises\n\n* Did all heterozygous SVs separate correctly by haplotype?\n\n### Variant allele frequency of small variants across somatic copy-number alterations\n\nLet's annotate the small variants of the control genome in the matched tumor.\n\n```bash\nlongshot --no_haps --potential_variants control.longshot.vcf.gz --output-ref --min_cov 3 --min_alt_count 1 --min_alt_frac 0.1 -s HG008-T --bam tumor.bam --ref genome.fa --out tumor.longshot.vcf\nbgzip tumor.longshot.vcf\ntabix tumor.longshot.vcf.gz\n```\n\nThen we merge the tumor and control VCF files to annotate all heterozygous variants with their allelic depth in the tumor.\n\n```bash\nbcftools merge -O b -o tumor.control.bcf tumor.longshot.vcf.gz control.whatshap.vcf.gz\nbcftools query -f \"%CHROM\\t%POS[\\t%GT\\t%AD]\\n\" tumor.control.bcf  | grep \"0|1\" | cut -f 1,2,4 | sed 's/,/\\t/' | awk '$3+$4\u003e0 {print $1\"\\t\"$2\"\\t\"($3/($3+$4));}' \u003e var.vaf\nbcftools query -f \"%CHROM\\t%POS[\\t%GT\\t%AD]\\n\" tumor.control.bcf  | grep \"1|0\" | cut -f 1,2,4 | sed 's/,/\\t/' | awk '$3+$4\u003e0 {print $1\"\\t\"$2\"\\t\"($4/($3+$4));}' \u003e\u003e var.vaf\nhead var.vaf\n```\n\nWe can then overlay the variant allele frequencey (B-allele frequency) of small variants with the read-depth information.\n\n```bash\nRscript cnBafSV.R cnv.cov.gz svs.tsv var.vaf\n```\n\n#### Exercises\n\n* For the somatic duplication, we have an estimated total copy-number of 3. What are the expected B-allele frequencies in that region?\n\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ftobiasrausch%2Fsv","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Ftobiasrausch%2Fsv","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ftobiasrausch%2Fsv/lists"}