loqusdb 2.7.19__tar.gz → 2.7.21__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- {loqusdb-2.7.19 → loqusdb-2.7.21}/PKG-INFO +1 -1
- {loqusdb-2.7.19 → loqusdb-2.7.21}/loqusdb/__init__.py +1 -30
- {loqusdb-2.7.19 → loqusdb-2.7.21}/loqusdb/build_models/variant.py +12 -11
- {loqusdb-2.7.19 → loqusdb-2.7.21}/loqusdb/commands/cli.py +3 -1
- {loqusdb-2.7.19 → loqusdb-2.7.21}/loqusdb/commands/export.py +14 -3
- {loqusdb-2.7.19 → loqusdb-2.7.21}/loqusdb/commands/view.py +46 -11
- {loqusdb-2.7.19 → loqusdb-2.7.21}/loqusdb/constants/__init__.py +60 -28
- {loqusdb-2.7.19 → loqusdb-2.7.21}/loqusdb/utils/delete.py +16 -3
- {loqusdb-2.7.19 → loqusdb-2.7.21}/pyproject.toml +1 -1
- loqusdb-2.7.21/tests/build_models/test_build_variant.py +30 -0
- loqusdb-2.7.21/tests/build_models/test_is_greater.py +98 -0
- {loqusdb-2.7.19 → loqusdb-2.7.21}/tests/conftest.py +2 -1
- loqusdb-2.7.21/tests/plugins/mongo/test_get_sv.py +62 -0
- loqusdb-2.7.21/tests/plugins/mongo/test_load_svs.py +164 -0
- {loqusdb-2.7.19 → loqusdb-2.7.21}/tests/plugins/mongo/test_variant_operations.py +65 -2
- {loqusdb-2.7.19 → loqusdb-2.7.21}/tests/utils/test_delete.py +57 -5
- loqusdb-2.7.21/tests/utils/test_delete_variant.py +157 -0
- loqusdb-2.7.21/tests/utils/test_load_database.py +108 -0
- loqusdb-2.7.21/tests/utils/test_load_variants.py +398 -0
- {loqusdb-2.7.19 → loqusdb-2.7.21}/tests/vcf_tools/test_check_par.py +11 -10
- {loqusdb-2.7.19 → loqusdb-2.7.21}/tests/vcf_tools/test_format_sv_variant.py +60 -10
- {loqusdb-2.7.19 → loqusdb-2.7.21}/tests/vcf_tools/test_format_variant.py +91 -18
- loqusdb-2.7.19/tests/build_models/test_build_variant.py +0 -15
- loqusdb-2.7.19/tests/build_models/test_is_greater.py +0 -49
- loqusdb-2.7.19/tests/plugins/mongo/test_get_sv.py +0 -27
- loqusdb-2.7.19/tests/plugins/mongo/test_load_svs.py +0 -74
- loqusdb-2.7.19/tests/utils/test_delete_variant.py +0 -74
- loqusdb-2.7.19/tests/utils/test_load_database.py +0 -52
- loqusdb-2.7.19/tests/utils/test_load_variants.py +0 -225
- {loqusdb-2.7.19 → loqusdb-2.7.21}/LICENSE +0 -0
- {loqusdb-2.7.19 → loqusdb-2.7.21}/README.md +0 -0
- {loqusdb-2.7.19 → loqusdb-2.7.21}/loqusdb/__main__.py +0 -0
- {loqusdb-2.7.19 → loqusdb-2.7.21}/loqusdb/build_models/__init__.py +0 -0
- {loqusdb-2.7.19 → loqusdb-2.7.21}/loqusdb/build_models/case.py +0 -0
- {loqusdb-2.7.19 → loqusdb-2.7.21}/loqusdb/build_models/profile_variant.py +0 -0
- {loqusdb-2.7.19 → loqusdb-2.7.21}/loqusdb/commands/__init__.py +0 -0
- {loqusdb-2.7.19 → loqusdb-2.7.21}/loqusdb/commands/annotate.py +0 -0
- {loqusdb-2.7.19 → loqusdb-2.7.21}/loqusdb/commands/delete.py +0 -0
- {loqusdb-2.7.19 → loqusdb-2.7.21}/loqusdb/commands/identity.py +0 -0
- {loqusdb-2.7.19 → loqusdb-2.7.21}/loqusdb/commands/load.py +0 -0
- {loqusdb-2.7.19 → loqusdb-2.7.21}/loqusdb/commands/load_profile.py +0 -0
- {loqusdb-2.7.19 → loqusdb-2.7.21}/loqusdb/commands/migrate.py +0 -0
- {loqusdb-2.7.19 → loqusdb-2.7.21}/loqusdb/commands/restore.py +0 -0
- {loqusdb-2.7.19 → loqusdb-2.7.21}/loqusdb/commands/update.py +0 -0
- {loqusdb-2.7.19 → loqusdb-2.7.21}/loqusdb/commands/wipe.py +0 -0
- {loqusdb-2.7.19 → loqusdb-2.7.21}/loqusdb/exceptions/__init__.py +0 -0
- {loqusdb-2.7.19 → loqusdb-2.7.21}/loqusdb/exceptions/case.py +0 -0
- {loqusdb-2.7.19 → loqusdb-2.7.21}/loqusdb/exceptions/profile.py +0 -0
- {loqusdb-2.7.19 → loqusdb-2.7.21}/loqusdb/exceptions/vcf.py +0 -0
- {loqusdb-2.7.19 → loqusdb-2.7.21}/loqusdb/log.py +0 -0
- {loqusdb-2.7.19 → loqusdb-2.7.21}/loqusdb/models/__init__.py +0 -0
- {loqusdb-2.7.19 → loqusdb-2.7.21}/loqusdb/models/case.py +0 -0
- {loqusdb-2.7.19 → loqusdb-2.7.21}/loqusdb/models/identity.py +0 -0
- {loqusdb-2.7.19 → loqusdb-2.7.21}/loqusdb/models/profile_variant.py +0 -0
- {loqusdb-2.7.19 → loqusdb-2.7.21}/loqusdb/models/variant.py +0 -0
- {loqusdb-2.7.19 → loqusdb-2.7.21}/loqusdb/plugins/__init__.py +0 -0
- {loqusdb-2.7.19 → loqusdb-2.7.21}/loqusdb/plugins/mongo/__init__.py +0 -0
- {loqusdb-2.7.19 → loqusdb-2.7.21}/loqusdb/plugins/mongo/adapter.py +0 -0
- {loqusdb-2.7.19 → loqusdb-2.7.21}/loqusdb/plugins/mongo/case.py +0 -0
- {loqusdb-2.7.19 → loqusdb-2.7.21}/loqusdb/plugins/mongo/profile_variant.py +0 -0
- {loqusdb-2.7.19 → loqusdb-2.7.21}/loqusdb/plugins/mongo/structural_variant.py +0 -0
- {loqusdb-2.7.19 → loqusdb-2.7.21}/loqusdb/plugins/mongo/variant.py +0 -0
- {loqusdb-2.7.19 → loqusdb-2.7.21}/loqusdb/resources/__init__.py +0 -0
- {loqusdb-2.7.19 → loqusdb-2.7.21}/loqusdb/resources/loqusdb.20181005.gz +0 -0
- {loqusdb-2.7.19 → loqusdb-2.7.21}/loqusdb/resources/maf_50_sites_GRCh37.vcf.gz +0 -0
- {loqusdb-2.7.19 → loqusdb-2.7.21}/loqusdb/resources/maf_50_sites_GRCh38.vcf.gz +0 -0
- {loqusdb-2.7.19 → loqusdb-2.7.21}/loqusdb/utils/__init__.py +0 -0
- {loqusdb-2.7.19 → loqusdb-2.7.21}/loqusdb/utils/annotate.py +0 -0
- {loqusdb-2.7.19 → loqusdb-2.7.21}/loqusdb/utils/case.py +0 -0
- {loqusdb-2.7.19 → loqusdb-2.7.21}/loqusdb/utils/load.py +0 -0
- {loqusdb-2.7.19 → loqusdb-2.7.21}/loqusdb/utils/migrate.py +0 -0
- {loqusdb-2.7.19 → loqusdb-2.7.21}/loqusdb/utils/profiling.py +0 -0
- {loqusdb-2.7.19 → loqusdb-2.7.21}/loqusdb/utils/update.py +0 -0
- {loqusdb-2.7.19 → loqusdb-2.7.21}/loqusdb/utils/variant.py +0 -0
- {loqusdb-2.7.19 → loqusdb-2.7.21}/loqusdb/utils/vcf.py +0 -0
- {loqusdb-2.7.19 → loqusdb-2.7.21}/tests/build_models/test_build_case.py +0 -0
- {loqusdb-2.7.19 → loqusdb-2.7.21}/tests/commands/test_export.py +0 -0
- {loqusdb-2.7.19 → loqusdb-2.7.21}/tests/commands/test_identity.py +0 -0
- {loqusdb-2.7.19 → loqusdb-2.7.21}/tests/commands/test_view.py +0 -0
- {loqusdb-2.7.19 → loqusdb-2.7.21}/tests/fixtures/643594.clinical.SV.vcf +0 -0
- {loqusdb-2.7.19 → loqusdb-2.7.21}/tests/fixtures/643594.clinical.vcf.gz +0 -0
- {loqusdb-2.7.19 → loqusdb-2.7.21}/tests/fixtures/double_variant.vcf +0 -0
- {loqusdb-2.7.19 → loqusdb-2.7.21}/tests/fixtures/funny_trio.ped +0 -0
- {loqusdb-2.7.19 → loqusdb-2.7.21}/tests/fixtures/profile_snv.vcf +0 -0
- {loqusdb-2.7.19 → loqusdb-2.7.21}/tests/fixtures/recessive_trio.ped +0 -0
- {loqusdb-2.7.19 → loqusdb-2.7.21}/tests/fixtures/test.SV.vcf +0 -0
- {loqusdb-2.7.19 → loqusdb-2.7.21}/tests/fixtures/test.vcf +0 -0
- {loqusdb-2.7.19 → loqusdb-2.7.21}/tests/fixtures/test.vcf.gz +0 -0
- {loqusdb-2.7.19 → loqusdb-2.7.21}/tests/fixtures/test.vcf.gz.tbi +0 -0
- {loqusdb-2.7.19 → loqusdb-2.7.21}/tests/fixtures/unsorted.vcf +0 -0
- {loqusdb-2.7.19 → loqusdb-2.7.21}/tests/functional/test_cli.py +0 -0
- {loqusdb-2.7.19 → loqusdb-2.7.21}/tests/plugins/mongo/test_case_operations.py +0 -0
- {loqusdb-2.7.19 → loqusdb-2.7.21}/tests/plugins/mongo/test_connect.py +0 -0
- {loqusdb-2.7.19 → loqusdb-2.7.21}/tests/plugins/mongo/test_flask_extension.py +0 -0
- {loqusdb-2.7.19 → loqusdb-2.7.21}/tests/utils/test_case.py +0 -0
- {loqusdb-2.7.19 → loqusdb-2.7.21}/tests/utils/test_delete_family.py +0 -0
- {loqusdb-2.7.19 → loqusdb-2.7.21}/tests/utils/test_get_family.py +0 -0
- {loqusdb-2.7.19 → loqusdb-2.7.21}/tests/utils/test_load_family.py +0 -0
- {loqusdb-2.7.19 → loqusdb-2.7.21}/tests/utils/test_migrate.py +0 -0
- {loqusdb-2.7.19 → loqusdb-2.7.21}/tests/utils/test_profiling.py +0 -0
- {loqusdb-2.7.19 → loqusdb-2.7.21}/tests/vcf_tools/test_check_vcf.py +0 -0
- {loqusdb-2.7.19 → loqusdb-2.7.21}/tests/vcf_tools/test_vcf.py +0 -0
@@ -4,7 +4,7 @@ from pymongo import ASCENDING, IndexModel
|
|
4
4
|
|
5
5
|
logger = logging.getLogger(__name__)
|
6
6
|
|
7
|
-
__version__ = "2.7.
|
7
|
+
__version__ = "2.7.21"
|
8
8
|
|
9
9
|
INDEXES = {
|
10
10
|
"variant": [
|
@@ -61,32 +61,3 @@ INDEXES = {
|
|
61
61
|
),
|
62
62
|
],
|
63
63
|
}
|
64
|
-
|
65
|
-
CHROMOSOME_ORDER = (
|
66
|
-
"1",
|
67
|
-
"2",
|
68
|
-
"3",
|
69
|
-
"4",
|
70
|
-
"5",
|
71
|
-
"6",
|
72
|
-
"7",
|
73
|
-
"8",
|
74
|
-
"9",
|
75
|
-
"10",
|
76
|
-
"11",
|
77
|
-
"12",
|
78
|
-
"13",
|
79
|
-
"14",
|
80
|
-
"15",
|
81
|
-
"16",
|
82
|
-
"17",
|
83
|
-
"18",
|
84
|
-
"19",
|
85
|
-
"20",
|
86
|
-
"21",
|
87
|
-
"22",
|
88
|
-
"23",
|
89
|
-
"X",
|
90
|
-
"Y",
|
91
|
-
"MT",
|
92
|
-
)
|
@@ -15,18 +15,17 @@ Position = namedtuple("Position", "chrom pos")
|
|
15
15
|
# These are coordinate for the pseudo autosomal regions in GRCh37
|
16
16
|
|
17
17
|
|
18
|
-
def check_par(chrom, pos, genome_build
|
18
|
+
def check_par(chrom, pos, genome_build):
|
19
19
|
"""Check if a coordinate is in the PAR region
|
20
20
|
|
21
21
|
Args:
|
22
22
|
chrom(str)
|
23
23
|
pos(int)
|
24
|
+
genome_build(str): Genome build. Ex. GRCh37 or GRCh38
|
24
25
|
|
25
26
|
Returns:
|
26
27
|
par(bool)
|
27
28
|
"""
|
28
|
-
if genome_build is None:
|
29
|
-
genome_build = GRCH37
|
30
29
|
return any(
|
31
30
|
pos >= interval[0] and pos <= interval[1] for interval in PAR[genome_build].get(chrom, [])
|
32
31
|
)
|
@@ -50,24 +49,25 @@ def get_variant_id(variant, keep_chr_prefix=None):
|
|
50
49
|
return "_".join([str(chrom), str(variant.POS), str(variant.REF), str(variant.ALT[0])])
|
51
50
|
|
52
51
|
|
53
|
-
def is_greater(a, b):
|
52
|
+
def is_greater(a, b, genome_build):
|
54
53
|
"""Check if position a is greater than position b
|
55
54
|
This will look at chromosome and position.
|
56
55
|
|
57
56
|
For example a position where chrom = 2 and pos = 300 is greater than a position where
|
58
57
|
chrom = 1 and pos = 1000
|
59
58
|
|
60
|
-
If any of the chromosomes is outside [1-22,X,Y,MT] we can not say which is biggest.
|
59
|
+
If any of the chromosomes is outside [1-22,X,Y,MT] or [chr1-chr22,chrX,chrY,chrM] we can not say which is biggest.
|
61
60
|
|
62
61
|
Args:
|
63
62
|
a,b(Position)
|
63
|
+
genome_build(str): Genome build. Ex. GRCh37 or GRCh38
|
64
64
|
|
65
65
|
Returns:
|
66
66
|
bool: True if a is greater than b
|
67
67
|
"""
|
68
68
|
|
69
|
-
a_chrom = CHROM_TO_INT.get(a.chrom, 0)
|
70
|
-
b_chrom = CHROM_TO_INT.get(b.chrom, 0)
|
69
|
+
a_chrom = CHROM_TO_INT[genome_build].get(a.chrom, 0)
|
70
|
+
b_chrom = CHROM_TO_INT[genome_build].get(b.chrom, 0)
|
71
71
|
|
72
72
|
if a_chrom == 0 or b_chrom == 0:
|
73
73
|
return False
|
@@ -78,12 +78,13 @@ def is_greater(a, b):
|
|
78
78
|
return a_chrom == b_chrom and a.pos > b.pos
|
79
79
|
|
80
80
|
|
81
|
-
def get_coords(variant, keep_chr_prefix):
|
81
|
+
def get_coords(variant, keep_chr_prefix, genome_build):
|
82
82
|
"""Returns a dictionary with position information
|
83
83
|
|
84
84
|
Args:
|
85
85
|
variant(cyvcf2.Variant)
|
86
86
|
keep_chr_prefix(bool): Retain chr/CHR/Chr prefix when present
|
87
|
+
genome_build(str): Genome build. Ex. GRCh37 or GRCh38
|
87
88
|
|
88
89
|
Returns:
|
89
90
|
coordinates(dict)
|
@@ -139,7 +140,7 @@ def get_coords(variant, keep_chr_prefix):
|
|
139
140
|
end_position = Position(end_chrom, end)
|
140
141
|
|
141
142
|
# If 'start' is greater than 'end', switch positions
|
142
|
-
if is_greater(position, end_position):
|
143
|
+
if is_greater(position, end_position, genome_build=genome_build):
|
143
144
|
end_chrom = position.chrom
|
144
145
|
end = position.pos
|
145
146
|
|
@@ -201,7 +202,7 @@ def build_variant(
|
|
201
202
|
# We allways assume splitted and normalized VCFs
|
202
203
|
alt = variant.ALT[0]
|
203
204
|
|
204
|
-
coordinates = get_coords(variant, keep_chr_prefix)
|
205
|
+
coordinates = get_coords(variant, keep_chr_prefix, genome_build=genome_build)
|
205
206
|
chrom = coordinates["chrom"]
|
206
207
|
pos = coordinates["pos"]
|
207
208
|
|
@@ -239,7 +240,7 @@ def build_variant(
|
|
239
240
|
# If variant in X or Y and individual is male,
|
240
241
|
# we need to check hemizygosity
|
241
242
|
if (
|
242
|
-
chrom in ["X", "Y"]
|
243
|
+
chrom in ["X", "Y", "chrX", "chrY"]
|
243
244
|
and ind_obj["sex"] == 1
|
244
245
|
and not check_par(chrom, pos, genome_build=genome_build)
|
245
246
|
):
|
@@ -52,6 +52,8 @@ LOG = logging.getLogger(__name__)
|
|
52
52
|
@click.option(
|
53
53
|
"-g",
|
54
54
|
"--genome-build",
|
55
|
+
default="GRCh37",
|
56
|
+
show_default=True,
|
55
57
|
type=click.Choice([GRCH37, GRCH38]),
|
56
58
|
help="Specify what genome build to use",
|
57
59
|
)
|
@@ -121,7 +123,7 @@ def cli(
|
|
121
123
|
|
122
124
|
adapter = MongoAdapter(client, db_name=database)
|
123
125
|
|
124
|
-
genome_build = genome_build or configs.get("genome_build")
|
126
|
+
genome_build = genome_build or configs.get("genome_build")
|
125
127
|
keep_chr_prefix = keep_chr_prefix or configs.get("keep_chr_prefix")
|
126
128
|
|
127
129
|
ctx.obj = {}
|
@@ -2,7 +2,7 @@ import logging
|
|
2
2
|
from datetime import datetime
|
3
3
|
|
4
4
|
import click
|
5
|
-
from loqusdb import
|
5
|
+
from loqusdb.constants import CHROMOSOMES, GRCH37, GRCH38
|
6
6
|
from loqusdb.utils.variant import format_variant
|
7
7
|
from vcftoolbox import HeaderParser, print_headers, print_variant
|
8
8
|
|
@@ -43,11 +43,22 @@ def export(ctx, outfile, variant_type, freq):
|
|
43
43
|
is_sv = variant_type == "sv"
|
44
44
|
existing_chromosomes = set(adapter.get_chromosomes(sv=is_sv))
|
45
45
|
|
46
|
+
genome = ctx.obj["genome_build"]
|
47
|
+
chromosome_order = CHROMOSOMES[genome]
|
48
|
+
keep_chr_prefix = ctx.obj["keep_chr_prefix"]
|
49
|
+
|
46
50
|
ordered_chromosomes = []
|
47
|
-
for chrom in
|
48
|
-
if chrom in existing_chromosomes:
|
51
|
+
for chrom in chromosome_order:
|
52
|
+
if keep_chr_prefix and chrom in existing_chromosomes:
|
49
53
|
ordered_chromosomes.append(chrom)
|
50
54
|
existing_chromosomes.remove(chrom)
|
55
|
+
elif not keep_chr_prefix:
|
56
|
+
if genome == GRCH37 and chrom in existing_chromosomes:
|
57
|
+
ordered_chromosomes.append(chrom)
|
58
|
+
existing_chromosomes.remove(chrom)
|
59
|
+
elif genome == GRCH38 and chrom[3:] in existing_chromosomes:
|
60
|
+
ordered_chromosomes.append(chrom)
|
61
|
+
existing_chromosomes.remove(chrom)
|
51
62
|
for chrom in existing_chromosomes:
|
52
63
|
ordered_chromosomes.append(chrom)
|
53
64
|
|
@@ -117,16 +117,40 @@ def variants(
|
|
117
117
|
sv_cases = True
|
118
118
|
nr_cases = adapter.nr_cases(snv_cases=snv_cases, sv_cases=sv_cases)
|
119
119
|
|
120
|
+
if chromosome:
|
121
|
+
if chromosome.startswith("chr"):
|
122
|
+
chromosomes = [chromosome, chromosome[3:]]
|
123
|
+
elif not chromosome.startswith("chr"):
|
124
|
+
chromosomes = [chromosome, "chr" + chromosome]
|
125
|
+
|
126
|
+
if end_chromosome:
|
127
|
+
if end_chromosome.startswith("chr"):
|
128
|
+
end_chromosomes = [end_chromosome, end_chromosome[3:]]
|
129
|
+
elif not end_chromosome.startswith("chr"):
|
130
|
+
end_chromosomes = [end_chromosome, "chr" + end_chromosome]
|
131
|
+
else:
|
132
|
+
end_chromosomes = [None, None]
|
133
|
+
|
120
134
|
if variant_id:
|
121
135
|
if variant_type == "sv":
|
122
136
|
variant_query = {
|
123
|
-
"chrom":
|
124
|
-
"end_chrom":
|
137
|
+
"chrom": chromosomes[0],
|
138
|
+
"end_chrom": end_chromosomes[0] or chromosomes[0],
|
125
139
|
"sv_type": sv_type,
|
126
140
|
"pos": start,
|
127
141
|
"end": end,
|
128
142
|
}
|
129
|
-
variant = adapter.get_structural_variant(variant_query)
|
143
|
+
variant = list(adapter.get_structural_variant(variant_query))
|
144
|
+
if len(variant) == 0:
|
145
|
+
variant_query = {
|
146
|
+
"chrom": chromosomes[1],
|
147
|
+
"end_chrom": end_chromosomes[1] or chromosomes[1],
|
148
|
+
"sv_type": sv_type,
|
149
|
+
"pos": start,
|
150
|
+
"end": end,
|
151
|
+
}
|
152
|
+
variant = adapter.get_structural_variant(variant_query)
|
153
|
+
|
130
154
|
else:
|
131
155
|
variant = adapter.get_variant({"_id": variant_id})
|
132
156
|
|
@@ -145,18 +169,29 @@ def variants(
|
|
145
169
|
|
146
170
|
click.echo(variant)
|
147
171
|
return
|
148
|
-
|
149
172
|
if variant_type == "snv":
|
150
|
-
result = adapter.get_variants(chromosome=
|
173
|
+
result = list(adapter.get_variants(chromosome=chromosomes[0], start=start, end=end))
|
174
|
+
if len(result) == 0:
|
175
|
+
result = adapter.get_variants(chromosome=chromosomes[1], start=start, end=end)
|
151
176
|
else:
|
152
177
|
LOG.info("Search for svs")
|
153
|
-
result =
|
154
|
-
|
155
|
-
|
156
|
-
|
157
|
-
|
158
|
-
|
178
|
+
result = list(
|
179
|
+
adapter.get_sv_variants(
|
180
|
+
chromosome=chromosomes[0],
|
181
|
+
end_chromosome=end_chromosomes[0],
|
182
|
+
sv_type=sv_type,
|
183
|
+
pos=start,
|
184
|
+
end=end,
|
185
|
+
)
|
159
186
|
)
|
187
|
+
if len(result) == 0:
|
188
|
+
result = adapter.get_sv_variants(
|
189
|
+
chromosome=chromosomes[1],
|
190
|
+
end_chromosome=end_chromosomes[1],
|
191
|
+
sv_type=sv_type,
|
192
|
+
pos=start,
|
193
|
+
end=end,
|
194
|
+
)
|
160
195
|
|
161
196
|
if to_json:
|
162
197
|
json.dumps(variant)
|
@@ -17,35 +17,67 @@ PAR = {
|
|
17
17
|
GENOTYPE_MAP = {0: "hom_ref", 1: "het", 2: "no_call", 3: "hom_alt"}
|
18
18
|
|
19
19
|
# To keep the order of chromosomes
|
20
|
-
CHROMOSOMES =
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
20
|
+
CHROMOSOMES = {
|
21
|
+
GRCH37: [
|
22
|
+
"1",
|
23
|
+
"2",
|
24
|
+
"3",
|
25
|
+
"4",
|
26
|
+
"5",
|
27
|
+
"6",
|
28
|
+
"7",
|
29
|
+
"8",
|
30
|
+
"9",
|
31
|
+
"10",
|
32
|
+
"11",
|
33
|
+
"12",
|
34
|
+
"13",
|
35
|
+
"14",
|
36
|
+
"15",
|
37
|
+
"16",
|
38
|
+
"17",
|
39
|
+
"18",
|
40
|
+
"19",
|
41
|
+
"20",
|
42
|
+
"21",
|
43
|
+
"22",
|
44
|
+
"X",
|
45
|
+
"Y",
|
46
|
+
"MT",
|
47
|
+
],
|
48
|
+
GRCH38: [
|
49
|
+
"chr1",
|
50
|
+
"chr2",
|
51
|
+
"chr3",
|
52
|
+
"chr4",
|
53
|
+
"chr5",
|
54
|
+
"chr6",
|
55
|
+
"chr7",
|
56
|
+
"chr8",
|
57
|
+
"chr9",
|
58
|
+
"chr10",
|
59
|
+
"chr11",
|
60
|
+
"chr12",
|
61
|
+
"chr13",
|
62
|
+
"chr14",
|
63
|
+
"chr15",
|
64
|
+
"chr16",
|
65
|
+
"chr17",
|
66
|
+
"chr18",
|
67
|
+
"chr19",
|
68
|
+
"chr20",
|
69
|
+
"chr21",
|
70
|
+
"chr22",
|
71
|
+
"chrX",
|
72
|
+
"chrY",
|
73
|
+
"chrM",
|
74
|
+
],
|
75
|
+
}
|
47
76
|
|
48
|
-
CHROM_TO_INT = {
|
77
|
+
CHROM_TO_INT = {
|
78
|
+
build: {chrom: i + 1 for i, chrom in enumerate(chromosomes)}
|
79
|
+
for build, chromosomes in CHROMOSOMES.items()
|
80
|
+
}
|
49
81
|
|
50
82
|
# Ranges of hamming distances to be checked when 'loqusdb profile --stats'
|
51
83
|
# items: <range_name>: <range>
|
@@ -21,6 +21,7 @@ def delete(
|
|
21
21
|
existing_case(models.Case): If something failed during an update we need to revert
|
22
22
|
to the original case
|
23
23
|
keep_chr_prefix(bool): Retain chr/CHR/Chr prefixes in chromosome IDs when they are present
|
24
|
+
genome_build(str): Genome build. Ex. GRCh37 or GRCh38
|
24
25
|
|
25
26
|
"""
|
26
27
|
# This will overwrite the updated case with the previous one
|
@@ -48,7 +49,11 @@ def delete(
|
|
48
49
|
elif file_type == "vcf_sv_path":
|
49
50
|
LOG.info("deleting structural variants")
|
50
51
|
delete_structural_variants(
|
51
|
-
adapter=adapter,
|
52
|
+
adapter=adapter,
|
53
|
+
vcf_obj=vcf_obj,
|
54
|
+
case_obj=case_obj,
|
55
|
+
keep_chr_prefix=keep_chr_prefix,
|
56
|
+
genome_build=genome_build,
|
52
57
|
)
|
53
58
|
|
54
59
|
|
@@ -62,6 +67,7 @@ def delete_variants(
|
|
62
67
|
vcf_obj(iterable(dict))
|
63
68
|
ind_positions(dict)
|
64
69
|
case_id(str)
|
70
|
+
genome_build(str): Genome build. Ex. GRCh37 or GRCh38
|
65
71
|
|
66
72
|
Returns:
|
67
73
|
nr_deleted (int): Number of deleted variants
|
@@ -120,7 +126,9 @@ def delete_variants(
|
|
120
126
|
return nr_deleted
|
121
127
|
|
122
128
|
|
123
|
-
def delete_structural_variants(
|
129
|
+
def delete_structural_variants(
|
130
|
+
adapter, vcf_obj, case_obj, genome_build, keep_chr_prefix=None, case_id=None
|
131
|
+
):
|
124
132
|
"""Delete structural variants for a case in the database
|
125
133
|
|
126
134
|
Args:
|
@@ -128,6 +136,7 @@ def delete_structural_variants(adapter, vcf_obj, case_obj, keep_chr_prefix=None,
|
|
128
136
|
vcf_obj(iterable(dict))
|
129
137
|
ind_positions(dict)
|
130
138
|
case_id(str)
|
139
|
+
genome_build(str): Genome build. Ex. GRCh37 or GRCh38
|
131
140
|
|
132
141
|
Returns:
|
133
142
|
nr_deleted (int): Number of deleted variants"""
|
@@ -141,7 +150,11 @@ def delete_structural_variants(adapter, vcf_obj, case_obj, keep_chr_prefix=None,
|
|
141
150
|
|
142
151
|
for variant in vcf_obj:
|
143
152
|
formated_variant = build_variant(
|
144
|
-
variant=variant,
|
153
|
+
variant=variant,
|
154
|
+
case_obj=case_obj,
|
155
|
+
case_id=case_id,
|
156
|
+
genome_build=genome_build,
|
157
|
+
keep_chr_prefix=keep_chr_prefix,
|
145
158
|
)
|
146
159
|
|
147
160
|
if not formated_variant:
|
@@ -0,0 +1,30 @@
|
|
1
|
+
from loqusdb.build_models.variant import get_coords, build_variant
|
2
|
+
from loqusdb.constants import GRCH37, GRCH38
|
3
|
+
|
4
|
+
|
5
|
+
def test_build_het_variant(het_variant, case_obj):
|
6
|
+
variant_obj = build_variant(variant=het_variant, case_obj=case_obj, genome_build=GRCH37)
|
7
|
+
assert variant_obj["chrom"] == het_variant.CHROM
|
8
|
+
assert variant_obj["homozygote"] == 0
|
9
|
+
assert variant_obj["hemizygote"] == 0
|
10
|
+
|
11
|
+
|
12
|
+
def test_get_coords_for_BND(bnd_variant):
|
13
|
+
coords = get_coords(bnd_variant, True, GRCH37)
|
14
|
+
assert coords["pos"] == coords["end"]
|
15
|
+
assert coords["sv_length"] == float("inf")
|
16
|
+
assert coords["sv_type"] == "BND"
|
17
|
+
|
18
|
+
|
19
|
+
def test_build_het_variant_grch38(het_variant, case_obj):
|
20
|
+
variant_obj = build_variant(variant=het_variant, case_obj=case_obj, genome_build=GRCH38)
|
21
|
+
assert variant_obj["chrom"] == het_variant.CHROM
|
22
|
+
assert variant_obj["homozygote"] == 0
|
23
|
+
assert variant_obj["hemizygote"] == 0
|
24
|
+
|
25
|
+
|
26
|
+
def test_get_coords_for_BND_grch38(bnd_variant):
|
27
|
+
coords = get_coords(bnd_variant, True, GRCH38)
|
28
|
+
assert coords["pos"] == coords["end"]
|
29
|
+
assert coords["sv_length"] == float("inf")
|
30
|
+
assert coords["sv_type"] == "BND"
|
@@ -0,0 +1,98 @@
|
|
1
|
+
from loqusdb.build_models.variant import Position, is_greater
|
2
|
+
from loqusdb.constants import GRCH37, GRCH38
|
3
|
+
|
4
|
+
|
5
|
+
def test_is_greater_different_chrom():
|
6
|
+
## GIVEN two positions where a is smaller than b. Different chroms
|
7
|
+
a = Position("1", 100)
|
8
|
+
b = Position("3", 100)
|
9
|
+
|
10
|
+
## WHEN testing if a is greater than b
|
11
|
+
res = is_greater(a, b, genome_build=GRCH37)
|
12
|
+
## THEN assert a was not greater than b
|
13
|
+
assert res is False
|
14
|
+
|
15
|
+
## WHEN testing if b is greater than a
|
16
|
+
res = is_greater(b, a, genome_build=GRCH37)
|
17
|
+
## THEN assert b was greater than a
|
18
|
+
assert res is True
|
19
|
+
|
20
|
+
|
21
|
+
def test_is_greater_same_chrom():
|
22
|
+
## GIVEN two positions where a is smaller than b. Same chroms
|
23
|
+
a = Position("1", 100)
|
24
|
+
b = Position("1", 300)
|
25
|
+
|
26
|
+
## WHEN testing if a is greater than b
|
27
|
+
res = is_greater(a, b, genome_build=GRCH37)
|
28
|
+
## THEN assert a was not greater than b
|
29
|
+
assert res is False
|
30
|
+
|
31
|
+
## WHEN testing if b is greater than a
|
32
|
+
res = is_greater(b, a, genome_build=GRCH37)
|
33
|
+
## THEN assert b was greater than a
|
34
|
+
assert res is True
|
35
|
+
|
36
|
+
|
37
|
+
def test_is_greater_wierd_chrom():
|
38
|
+
## GIVEN two positions where one chrom is unknown b
|
39
|
+
a = Position("1", 100)
|
40
|
+
b = Position("GRLrs2", 300)
|
41
|
+
|
42
|
+
## WHEN testing if a is greater than b
|
43
|
+
res = is_greater(a, b, genome_build=GRCH37)
|
44
|
+
## THEN assert a was not greater than b
|
45
|
+
assert res is False
|
46
|
+
|
47
|
+
## WHEN testing if b is greater than a
|
48
|
+
res = is_greater(b, a, genome_build=GRCH37)
|
49
|
+
## THEN assert a was not greater than b
|
50
|
+
assert res is False
|
51
|
+
|
52
|
+
|
53
|
+
def test_is_greater_different_chrom_grch38():
|
54
|
+
## GIVEN two positions where a is smaller than b. Different chroms
|
55
|
+
a = Position("chr1", 100)
|
56
|
+
b = Position("chr3", 100)
|
57
|
+
|
58
|
+
## WHEN testing if a is greater than b
|
59
|
+
res = is_greater(a, b, genome_build=GRCH38)
|
60
|
+
## THEN assert a was not greater than b
|
61
|
+
assert res is False
|
62
|
+
|
63
|
+
## WHEN testing if b is greater than a
|
64
|
+
res = is_greater(b, a, genome_build=GRCH38)
|
65
|
+
## THEN assert b was greater than a
|
66
|
+
assert res is True
|
67
|
+
|
68
|
+
|
69
|
+
def test_is_greater_same_chrom_grch38():
|
70
|
+
## GIVEN two positions where a is smaller than b. Same chroms
|
71
|
+
a = Position("chr1", 100)
|
72
|
+
b = Position("chr1", 300)
|
73
|
+
|
74
|
+
## WHEN testing if a is greater than b
|
75
|
+
res = is_greater(a, b, genome_build=GRCH38)
|
76
|
+
## THEN assert a was not greater than b
|
77
|
+
assert res is False
|
78
|
+
|
79
|
+
## WHEN testing if b is greater than a
|
80
|
+
res = is_greater(b, a, genome_build=GRCH38)
|
81
|
+
## THEN assert b was greater than a
|
82
|
+
assert res is True
|
83
|
+
|
84
|
+
|
85
|
+
def test_is_greater_wierd_chrom_grch38():
|
86
|
+
## GIVEN two positions where one chrom is unknown b
|
87
|
+
a = Position("chr1", 100)
|
88
|
+
b = Position("GRLrs2", 300)
|
89
|
+
|
90
|
+
## WHEN testing if a is greater than b
|
91
|
+
res = is_greater(a, b, genome_build=GRCH38)
|
92
|
+
## THEN assert a was not greater than b
|
93
|
+
assert res is False
|
94
|
+
|
95
|
+
## WHEN testing if b is greater than a
|
96
|
+
res = is_greater(b, a, genome_build=GRCH38)
|
97
|
+
## THEN assert a was not greater than b
|
98
|
+
assert res is False
|
@@ -332,7 +332,7 @@ def hem_variant(request):
|
|
332
332
|
|
333
333
|
@pytest.fixture(scope="function")
|
334
334
|
def variant_chr(request):
|
335
|
-
return CyvcfVariant(chrom="chrX", pos=
|
335
|
+
return CyvcfVariant(chrom="chrX", pos=9000)
|
336
336
|
|
337
337
|
|
338
338
|
@pytest.fixture(scope="function")
|
@@ -437,6 +437,7 @@ def translocation_variant(request):
|
|
437
437
|
info_dict={"END": None, "SVLEN": None, "SVTYPE": "BND"},
|
438
438
|
)
|
439
439
|
|
440
|
+
|
440
441
|
##SVs with chr prefix
|
441
442
|
@pytest.fixture(scope="function")
|
442
443
|
def chr_del_variant(request):
|
@@ -0,0 +1,62 @@
|
|
1
|
+
from loqusdb.build_models.variant import build_variant
|
2
|
+
from loqusdb.constants import GRCH37, GRCH38
|
3
|
+
|
4
|
+
|
5
|
+
def test_get_insertion(small_insert_variant, mongo_adapter, case_obj):
|
6
|
+
adapter = mongo_adapter
|
7
|
+
## GIVEN a mongo adapter with a small insertion
|
8
|
+
variant = small_insert_variant
|
9
|
+
case_id = case_obj["case_id"]
|
10
|
+
formated_variant = build_variant(
|
11
|
+
variant=variant, case_obj=case_obj, case_id=case_id, genome_build=GRCH37
|
12
|
+
)
|
13
|
+
|
14
|
+
adapter.add_case(case_obj)
|
15
|
+
adapter.add_structural_variant(formated_variant)
|
16
|
+
for variant_obj in adapter.db.structural_variant.find():
|
17
|
+
assert variant_obj
|
18
|
+
|
19
|
+
|
20
|
+
def test_get_translocation(translocation_variant, mongo_adapter, case_obj):
|
21
|
+
adapter = mongo_adapter
|
22
|
+
## GIVEN a mongo adapter with a translocation
|
23
|
+
variant = translocation_variant
|
24
|
+
case_id = case_obj["case_id"]
|
25
|
+
formated_variant = build_variant(
|
26
|
+
variant=variant, case_obj=case_obj, case_id=case_id, genome_build=GRCH37
|
27
|
+
)
|
28
|
+
|
29
|
+
adapter.add_case(case_obj)
|
30
|
+
adapter.add_structural_variant(formated_variant)
|
31
|
+
for variant_obj in adapter.db.structural_variant.find():
|
32
|
+
assert variant_obj
|
33
|
+
|
34
|
+
|
35
|
+
def test_get_insertion_grch38(chr_small_insert_variant, mongo_adapter, case_obj):
|
36
|
+
adapter = mongo_adapter
|
37
|
+
## GIVEN a mongo adapter with a small insertion
|
38
|
+
variant = chr_small_insert_variant
|
39
|
+
case_id = case_obj["case_id"]
|
40
|
+
formated_variant = build_variant(
|
41
|
+
variant=variant, case_obj=case_obj, case_id=case_id, genome_build=GRCH38
|
42
|
+
)
|
43
|
+
|
44
|
+
adapter.add_case(case_obj)
|
45
|
+
adapter.add_structural_variant(formated_variant)
|
46
|
+
for variant_obj in adapter.db.structural_variant.find():
|
47
|
+
assert variant_obj
|
48
|
+
|
49
|
+
|
50
|
+
def test_get_translocation_grch38(chr_translocation_variant, mongo_adapter, case_obj):
|
51
|
+
adapter = mongo_adapter
|
52
|
+
## GIVEN a mongo adapter with a translocation
|
53
|
+
variant = chr_translocation_variant
|
54
|
+
case_id = case_obj["case_id"]
|
55
|
+
formated_variant = build_variant(
|
56
|
+
variant=variant, case_obj=case_obj, case_id=case_id, genome_build=GRCH38
|
57
|
+
)
|
58
|
+
|
59
|
+
adapter.add_case(case_obj)
|
60
|
+
adapter.add_structural_variant(formated_variant)
|
61
|
+
for variant_obj in adapter.db.structural_variant.find():
|
62
|
+
assert variant_obj
|