Skip to content

Commit 60284dd

Browse files
authored
Initial commit (#1)
1 parent a384fa8 commit 60284dd

23 files changed

Lines changed: 2945 additions & 1 deletion

.github/workflows/unit-tests.yml

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
# This is a basic workflow to help you get started with Actions
2+
3+
name: unit tests
4+
5+
# Controls when the workflow will run
6+
on:
7+
# Triggers the workflow on push or pull request events but only for the "main" branch
8+
push:
9+
branches: [ "main" ]
10+
pull_request:
11+
branches: [ "main" ]
12+
13+
# Allows you to run this workflow manually from the Actions tab
14+
workflow_dispatch:
15+
16+
# A workflow run is made up of one or more jobs that can run sequentially or in parallel
17+
jobs:
18+
# This workflow contains a single job called "build"
19+
build:
20+
# The type of runner that the job will run on
21+
runs-on: ubuntu-latest
22+
23+
# Steps represent a sequence of tasks that will be executed as part of the job
24+
steps:
25+
# Checks-out your repository under $GITHUB_WORKSPACE, so your job can access it
26+
- uses: actions/checkout@v4
27+
28+
- name: Set up conda environment
29+
uses: conda-incubator/setup-miniconda@v3
30+
with:
31+
miniforge-variant: Miniforge3 # uses mamba automatically
32+
activate-environment: contextscore
33+
environment-file: environment.yml
34+
auto-activate-base: false
35+
use-mamba: true
36+
cache-environment: true # ← caches the env
37+
cache-downloads: true # ← caches downloaded packages
38+
39+
- name: Run tests
40+
shell: bash --login {0}
41+
run: |
42+
mkdir tests/output
43+
python -m pytest

.gitignore

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -169,3 +169,22 @@ cython_debug/
169169

170170
# PyPI configuration file
171171
.pypirc
172+
173+
# Ignore the output/ folder
174+
output/
175+
scripts/
176+
177+
# VS Code settings
178+
.vscode/launch.json
179+
180+
# Testing scripts
181+
linktoscripts
182+
truvari_results_Simulated_*/
183+
conda/contextscore-models/
184+
tests/fixtures/output.vcf.avinput
185+
tests/fixtures/output.vcf.bed
186+
tests/fixtures/annotations/features.tsv
187+
tests/fixtures/annotations/regions.hg38_multianno.txt
188+
189+
# Database files
190+
data/

.vscode/settings.json

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
{
2+
"python.testing.pytestArgs": [
3+
"tests"
4+
],
5+
"python.testing.unittestEnabled": false,
6+
"python.testing.pytestEnabled": true
7+
}

MANIFEST.in

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
include README.md
2+
include LICENSE
3+
recursive-include data *

README.md

Lines changed: 38 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,39 @@
1+
[![unit tests](https://github.com/WGLab/ContextScore/actions/workflows/unit-tests.yml/badge.svg)](https://github.com/WGLab/ContextScore/actions/workflows/unit-tests.yml)
2+
13
# ContextScore
2-
Assign confidence scores to SV datasets based on coverage, genomic context, and other important alignment features
4+
<p>
5+
<img src="https://github.com/user-attachments/assets/03603ad1-df9d-438d-911c-81af0cf612e3" alt="ContextSV" align="left" style="width:100px;"/>
6+
Filtering step for the <a href="https://github.com/WGLab/ContextSV">ContextSV</a> long-read structural variant (SV) caller, utilizing a Random Forest model trained on SV validation features. Assign confidence scores to SV datasets based on coverage, genomic context, and other important alignment features, then filter low-confidence SVs to increase the precision of the final callset. Genomic context is determined from annotations using ANNOVAR and UCSC databases.
7+
</p>
8+
<br clear="left"/>
9+
10+
## Installation
11+
```bash
12+
conda install -c wglab -c bioconda -c conda-forge contextscore
13+
14+
# Or using mamba (faster dependency resolution):
15+
mamba install -c wglab contextscore
16+
```
17+
18+
## ANNOVAR setup
19+
[ANNOVAR](https://annovar.openbioinformatics.org/en/latest/user-guide/download/) is required for annotations and must be installed separately.
20+
21+
These are the required ANNOVAR components for ContextScore:
22+
- `--annovar`: directory containing `annotate_variation.pl` and `table_annovar.pl`
23+
- `--annovar-db`: ANNOVAR database directory
24+
25+
## User Workflow
26+
```bash
27+
contextscore --input input.vcf --output scored.vcf --sample-coverage 30 --buildver {hg38,hg19} --threshold 0.2 \
28+
--annovar /path/to/annovar --annovar-db /path/to/humandb
29+
```
30+
31+
## Sources for additional annotations (under `data/` directory):
32+
| File | Source | Description | Link |
33+
| --- | --- | --- | --- |
34+
| `cytobands_hg{19,38}.txt` | UCSC Genome Browser | Cytoband annotations for human genome builds hg19 and hg38 | [UCSC hg19](https://hgdownload.soe.ucsc.edu/goldenPath/hg19/database/cytoBand.txt.gz) / [UCSC hg38](https://hgdownload.soe.ucsc.edu/goldenPath/hg38/database/cytoBand.txt.gz) |
35+
| `hg{19,38}_segmental_duplications.bed` | UCSC Genome Browser | Segmental duplication annotations for human genome builds hg19 and hg38 | [UCSC hg19](https://hgdownload.soe.ucsc.edu/goldenPath/hg19/database/segmentalDuplications.txt.gz) / [UCSC hg38](https://hgdownload.soe.ucsc.edu/goldenPath/hg38/database/segmentalDuplications.txt.gz) |
36+
| `phastcons100way_hg{19,38}.bed` | UCSC Genome Browser | PhastCons conservation scores for human genome builds hg19 and hg38 | [UCSC hg19](https://hgdownload.soe.ucsc.edu/goldenPath/hg19/database/phastCons100way.txt.gz) / [UCSC hg38](https://hgdownload.soe.ucsc.edu/goldenPath/hg38/database/phastCons100way.txt.gz) |
37+
| `simple_repeats_hg{19,38}.bed` | UCSC Genome Browser | Simple repeat annotations for human genome builds hg19 and hg38 | [UCSC hg19](https://hgdownload.soe.ucsc.edu/goldenPath/hg19/database/simpleRepeat.txt.gz) / [UCSC hg38](https://hgdownload.soe.ucsc.edu/goldenPath/hg38/database/simpleRepeat.txt.gz) |
38+
| `fragile_sites_hg38.bed` / `fragile_sites_hg19_liftover.bed` | [HumCFS](https://webs.iiitd.edu.in/raghava/humcfs/download.html) | Fragile site annotations for human genome builds hg38 and hg19 (liftover) | [HumCFS](https://webs.iiitd.edu.in/raghava/humcfs/fragile_site_bed.zip) |
39+

conda/meta.yaml

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
{% set name = "contextscore" %}
2+
{% set version = "0.1.0" %}
3+
4+
package:
5+
name: {{ name|lower }}
6+
version: {{ version }}
7+
8+
source:
9+
path: ..
10+
11+
build:
12+
number: 0
13+
skip: true # [win]
14+
script: "{{ PYTHON }} -m pip install . --no-deps -vv"
15+
16+
requirements:
17+
host:
18+
- python >=3.10,<3.11
19+
- pip
20+
- setuptools
21+
run:
22+
- python >=3.10,<3.11
23+
- numpy
24+
- pandas
25+
- scikit-learn =1.6.1 # For consistency with model training environment
26+
- joblib
27+
- bedtools
28+
- contextscore-models
29+
30+
about:
31+
home: https://github.com/WGLab/ContextScore
32+
summary: Assign confidence scores to structural variant datasets.
33+
description: |
34+
ContextScore prediction package. Model weights are distributed separately
35+
(for example via contextscore-models) and can be provided via --model or
36+
CONTEXTSCORE_MODEL_PATH.
37+
license: MIT
38+
license_file: LICENSE
39+
40+
extra:
41+
recipe-maintainers:
42+
- WGLab
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
True Positives
2+
Total Fragile Sites Telomeres Centromeres Segmental Duplications Conserved Regions

contextscore/__init__.py

Whitespace-only changes.

contextscore/__main__.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
from .predict import main
2+
3+
4+
if __name__ == '__main__':
5+
main()

contextscore/download_tables.py

Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
import pandas as pd
2+
import pymysql
3+
from pathlib import Path
4+
5+
def download_ucsc(table_name: str,
6+
genome_version: str = "hg38",
7+
output_file: str = "ucsc_table.bed") -> None:
8+
"""
9+
Downloads the UCSC Simple Repeats table and saves it as a BED file for use with BEDTools.
10+
Note: This function requires access to the UCSC MySQL database.
11+
"""
12+
print("Downloading UCSC " + table_name + " table for " + genome_version + "...")
13+
14+
# Connect to UCSC MySQL database
15+
conn = pymysql.connect(host="genome-mysql.soe.ucsc.edu",
16+
user="genome",
17+
password="",
18+
database="hg38") # Change to the desired genome version (e.g., hg19, mm10)
19+
20+
query = f"""
21+
SELECT
22+
chrom AS chr,
23+
chromStart AS start,
24+
chromEnd AS end,
25+
name
26+
FROM
27+
{table_name}
28+
WHERE
29+
chrom IS NOT NULL AND
30+
chromStart IS NOT NULL AND
31+
chromEnd IS NOT NULL
32+
AND
33+
chromStart >= 0 AND
34+
chromEnd > chromStart
35+
AND
36+
chromStart < chromEnd;
37+
"""
38+
df = pd.read_sql(query, conn)
39+
40+
# Close connection
41+
conn.close()
42+
43+
# Save as BED file for BEDTools
44+
df.to_csv(output_file, sep="\t", index=False, header=False)
45+
print("Downloaded UCSC " + table_name + " table for " + genome_version + " and saved as " + output_file)
46+
47+
if __name__ == "__main__":
48+
data_dir = Path(__file__).resolve().parents[1] / "data"
49+
data_dir.mkdir(parents=True, exist_ok=True)
50+
51+
# Download the UCSC Simple Repeats table for hg38
52+
simple_repeat_file = str(data_dir / "simple_repeats_hg38.bed")
53+
download_ucsc(table_name="simpleRepeat",
54+
genome_version="hg38",
55+
output_file=simple_repeat_file)
56+
57+
# Download the UCSC phastCons100way table for hg38
58+
phastcons_file = str(data_dir / "phastcons100way_hg38.bed")
59+
download_ucsc(table_name="phastCons100way",
60+
genome_version="hg38",
61+
output_file=phastcons_file)

0 commit comments

Comments
 (0)