RBCeq2 2.1.1__tar.gz → 2.1.2__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.
- {rbceq2-2.1.1/src/RBCeq2.egg-info → rbceq2-2.1.2}/PKG-INFO +8 -2
- {rbceq2-2.1.1 → rbceq2-2.1.2}/pyproject.toml +3 -3
- {rbceq2-2.1.1 → rbceq2-2.1.2/src/RBCeq2.egg-info}/PKG-INFO +8 -2
- {rbceq2-2.1.1 → rbceq2-2.1.2}/src/rbceq2/IO/record_data.py +68 -8
- {rbceq2-2.1.1 → rbceq2-2.1.2}/src/rbceq2/IO/vcf.py +37 -3
- {rbceq2-2.1.1 → rbceq2-2.1.2}/src/rbceq2/core_logic/constants.py +2 -2
- {rbceq2-2.1.1 → rbceq2-2.1.2}/src/rbceq2/main.py +22 -6
- {rbceq2-2.1.1 → rbceq2-2.1.2}/LICENSE +0 -0
- {rbceq2-2.1.1 → rbceq2-2.1.2}/README.rst +0 -0
- {rbceq2-2.1.1 → rbceq2-2.1.2}/setup.cfg +0 -0
- {rbceq2-2.1.1 → rbceq2-2.1.2}/src/RBCeq2.egg-info/SOURCES.txt +0 -0
- {rbceq2-2.1.1 → rbceq2-2.1.2}/src/RBCeq2.egg-info/dependency_links.txt +0 -0
- {rbceq2-2.1.1 → rbceq2-2.1.2}/src/RBCeq2.egg-info/entry_points.txt +0 -0
- {rbceq2-2.1.1 → rbceq2-2.1.2}/src/RBCeq2.egg-info/requires.txt +0 -0
- {rbceq2-2.1.1 → rbceq2-2.1.2}/src/RBCeq2.egg-info/top_level.txt +0 -0
- {rbceq2-2.1.1 → rbceq2-2.1.2}/src/rbceq2/IO/PDF_reports.py +0 -0
- {rbceq2-2.1.1 → rbceq2-2.1.2}/src/rbceq2/IO/__init__.py +0 -0
- {rbceq2-2.1.1 → rbceq2-2.1.2}/src/rbceq2/IO/validation.py +0 -0
- {rbceq2-2.1.1 → rbceq2-2.1.2}/src/rbceq2/__init__.py +0 -0
- {rbceq2-2.1.1 → rbceq2-2.1.2}/src/rbceq2/core_logic/__init__.py +0 -0
- {rbceq2-2.1.1 → rbceq2-2.1.2}/src/rbceq2/core_logic/alleles.py +0 -0
- {rbceq2-2.1.1 → rbceq2-2.1.2}/src/rbceq2/core_logic/co_existing.py +0 -0
- {rbceq2-2.1.1 → rbceq2-2.1.2}/src/rbceq2/core_logic/data_procesing.py +0 -0
- {rbceq2-2.1.1 → rbceq2-2.1.2}/src/rbceq2/core_logic/utils.py +0 -0
- {rbceq2-2.1.1 → rbceq2-2.1.2}/src/rbceq2/db/__init__.py +0 -0
- {rbceq2-2.1.1 → rbceq2-2.1.2}/src/rbceq2/db/db.py +0 -0
- {rbceq2-2.1.1 → rbceq2-2.1.2}/src/rbceq2/filters/__init__.py +0 -0
- {rbceq2-2.1.1 → rbceq2-2.1.2}/src/rbceq2/filters/geno.py +0 -0
- {rbceq2-2.1.1 → rbceq2-2.1.2}/src/rbceq2/phenotype/__init__.py +0 -0
- {rbceq2-2.1.1 → rbceq2-2.1.2}/src/rbceq2/phenotype/antigens.py +0 -0
- {rbceq2-2.1.1 → rbceq2-2.1.2}/src/rbceq2/phenotype/choose_pheno.py +0 -0
- {rbceq2-2.1.1 → rbceq2-2.1.2}/src/rbceq2/resources/db.tsv +0 -0
- {rbceq2-2.1.1 → rbceq2-2.1.2}/tests/test_IO.py +0 -0
- {rbceq2-2.1.1 → rbceq2-2.1.2}/tests/test_VCF.py +0 -0
- {rbceq2-2.1.1 → rbceq2-2.1.2}/tests/test_alleles.py +0 -0
- {rbceq2-2.1.1 → rbceq2-2.1.2}/tests/test_ants.py +0 -0
- {rbceq2-2.1.1 → rbceq2-2.1.2}/tests/test_choose_pheno.py +0 -0
- {rbceq2-2.1.1 → rbceq2-2.1.2}/tests/test_coexisting.py +0 -0
- {rbceq2-2.1.1 → rbceq2-2.1.2}/tests/test_data_processing.py +0 -0
- {rbceq2-2.1.1 → rbceq2-2.1.2}/tests/test_db.py +0 -0
- {rbceq2-2.1.1 → rbceq2-2.1.2}/tests/test_filters.py +0 -0
- {rbceq2-2.1.1 → rbceq2-2.1.2}/tests/test_main.py +0 -0
- {rbceq2-2.1.1 → rbceq2-2.1.2}/tests/test_pdf.py +0 -0
- {rbceq2-2.1.1 → rbceq2-2.1.2}/tests/test_utils.py +0 -0
|
@@ -1,9 +1,15 @@
|
|
|
1
1
|
Metadata-Version: 2.4
|
|
2
2
|
Name: RBCeq2
|
|
3
|
-
Version: 2.1.
|
|
3
|
+
Version: 2.1.2
|
|
4
4
|
Summary: Call ISBT alleles from VCF/s
|
|
5
5
|
Author-email: Liam McIntyre <limcintyre@redcrossblood.org.au>
|
|
6
|
-
License:
|
|
6
|
+
License: Copyright 2025 Australian Red Cross Lifeblood
|
|
7
|
+
|
|
8
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the “Software”), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
|
|
9
|
+
|
|
10
|
+
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
|
|
11
|
+
|
|
12
|
+
THE SOFTWARE IS PROVIDED “AS IS”, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
|
7
13
|
Classifier: Programming Language :: Python :: 3
|
|
8
14
|
Classifier: Programming Language :: Python :: 3.12
|
|
9
15
|
Classifier: License :: OSI Approved :: MIT License
|
|
@@ -6,10 +6,10 @@ build-backend = "setuptools.build_meta"
|
|
|
6
6
|
|
|
7
7
|
[project]
|
|
8
8
|
name = "RBCeq2"
|
|
9
|
-
version = "2.1.
|
|
9
|
+
version = "2.1.2"
|
|
10
10
|
description = "Call ISBT alleles from VCF/s"
|
|
11
11
|
readme = "README.rst" # <-- Use the RST file we created
|
|
12
|
-
license = {
|
|
12
|
+
license = { file = "LICENSE" }
|
|
13
13
|
requires-python = ">=3.12"
|
|
14
14
|
authors = [
|
|
15
15
|
{ name = "Liam McIntyre", email = "limcintyre@redcrossblood.org.au" }
|
|
@@ -54,4 +54,4 @@ where = ["src"] # Corresponds to package_dir = = src and where = src
|
|
|
54
54
|
[tool.setuptools.package-data]
|
|
55
55
|
# Corresponds to [options.package_data]
|
|
56
56
|
# The key is the package name, the value is a list of glob patterns
|
|
57
|
-
rbceq2 = ["resources/*.tsv"]
|
|
57
|
+
rbceq2 = ["resources/*.tsv"]
|
|
@@ -1,9 +1,15 @@
|
|
|
1
1
|
Metadata-Version: 2.4
|
|
2
2
|
Name: RBCeq2
|
|
3
|
-
Version: 2.1.
|
|
3
|
+
Version: 2.1.2
|
|
4
4
|
Summary: Call ISBT alleles from VCF/s
|
|
5
5
|
Author-email: Liam McIntyre <limcintyre@redcrossblood.org.au>
|
|
6
|
-
License:
|
|
6
|
+
License: Copyright 2025 Australian Red Cross Lifeblood
|
|
7
|
+
|
|
8
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the “Software”), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
|
|
9
|
+
|
|
10
|
+
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
|
|
11
|
+
|
|
12
|
+
THE SOFTWARE IS PROVIDED “AS IS”, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
|
7
13
|
Classifier: Programming Language :: Python :: 3
|
|
8
14
|
Classifier: Programming Language :: Python :: 3.12
|
|
9
15
|
Classifier: License :: OSI Approved :: MIT License
|
|
@@ -5,36 +5,79 @@ from typing import Any
|
|
|
5
5
|
|
|
6
6
|
import pandas as pd
|
|
7
7
|
from loguru import logger
|
|
8
|
+
import argparse
|
|
8
9
|
|
|
9
10
|
from rbceq2.core_logic.constants import DB_VERSION, VERSION, AlleleState
|
|
10
11
|
from rbceq2.IO.validation import validate_vcf
|
|
11
12
|
|
|
12
13
|
|
|
13
|
-
def configure_logging(args) -> str:
|
|
14
|
+
# def configure_logging(args) -> str:
|
|
15
|
+
# """
|
|
16
|
+
# Configures the logging for the application.
|
|
17
|
+
|
|
18
|
+
# Args:
|
|
19
|
+
# args: Command-line arguments containing debug flag and log file path.
|
|
20
|
+
# """
|
|
21
|
+
# log_level = "DEBUG" if args.debug else "INFO"
|
|
22
|
+
# logger.remove() # Remove default logger configuration
|
|
23
|
+
# logger.add(
|
|
24
|
+
# f"{args.out}_log.txt", # Log file path from arguments
|
|
25
|
+
# level=log_level,
|
|
26
|
+
# format="{time} {level} {message}",
|
|
27
|
+
# rotation="50 MB", # Rotate the file when it reaches 10 MB
|
|
28
|
+
# compression="zip", # Compress old logs
|
|
29
|
+
# )
|
|
30
|
+
# UUID = str(uuid.uuid4())
|
|
31
|
+
# logger.info("NOT FOR CLINICAL USE")
|
|
32
|
+
# logger.info(f"RBCeq2 Version: {VERSION}")
|
|
33
|
+
# logger.info(f"RBCeq2 database Version: {DB_VERSION}")
|
|
34
|
+
# logger.info(f"Session UUID: {UUID}")
|
|
35
|
+
|
|
36
|
+
# return UUID
|
|
37
|
+
|
|
38
|
+
|
|
39
|
+
def configure_logging(args: argparse.Namespace) -> str:
|
|
14
40
|
"""
|
|
15
|
-
Configures the logging for the application.
|
|
41
|
+
Configures the logging for the application and logs arguments line by line.
|
|
16
42
|
|
|
17
43
|
Args:
|
|
18
|
-
args: Command-line arguments
|
|
44
|
+
args: Command-line arguments (typically from argparse.parse_args()).
|
|
19
45
|
"""
|
|
20
46
|
log_level = "DEBUG" if args.debug else "INFO"
|
|
21
|
-
|
|
47
|
+
log_file_path = f"{args.out}_log.txt"
|
|
48
|
+
|
|
49
|
+
logger.remove()
|
|
22
50
|
logger.add(
|
|
23
|
-
|
|
51
|
+
log_file_path,
|
|
24
52
|
level=log_level,
|
|
25
|
-
format="{time} {level} {message}",
|
|
26
|
-
rotation="50 MB",
|
|
27
|
-
compression="zip",
|
|
53
|
+
format="{time:YYYY-MM-DD HH:mm:ss.SSS} | {level: <8} | {message}",
|
|
54
|
+
rotation="50 MB",
|
|
55
|
+
compression="zip",
|
|
28
56
|
)
|
|
57
|
+
|
|
29
58
|
UUID = str(uuid.uuid4())
|
|
59
|
+
logger.info("="*20 + " SESSION START " + "="*20)
|
|
30
60
|
logger.info("NOT FOR CLINICAL USE")
|
|
31
61
|
logger.info(f"RBCeq2 Version: {VERSION}")
|
|
32
62
|
logger.info(f"RBCeq2 database Version: {DB_VERSION}")
|
|
33
63
|
logger.info(f"Session UUID: {UUID}")
|
|
34
64
|
|
|
65
|
+
logger.info("Command-line arguments provided:")
|
|
66
|
+
args_dict = vars(args)
|
|
67
|
+
if not args_dict:
|
|
68
|
+
logger.info(" (No arguments captured)")
|
|
69
|
+
else:
|
|
70
|
+
max_key_len = max(len(key) for key in args_dict.keys())
|
|
71
|
+
for key, value in args_dict.items():
|
|
72
|
+
logger.info(f" {key:<{max_key_len}} : {value}")
|
|
73
|
+
|
|
74
|
+
|
|
75
|
+
logger.info("="*20 + " LOGGING STARTED " + "="*20)
|
|
76
|
+
|
|
35
77
|
return UUID
|
|
36
78
|
|
|
37
79
|
|
|
80
|
+
|
|
38
81
|
def record_filtered_data(results: tuple[Any]) -> None:
|
|
39
82
|
"""Record filtered data by logging debug information for each blood group.
|
|
40
83
|
|
|
@@ -112,3 +155,20 @@ def save_df(df: pd.DataFrame, name: str, UUID: str) -> None:
|
|
|
112
155
|
df = df.reindex(sorted(df.columns), axis=1)
|
|
113
156
|
df.index.name = f"UUID: {UUID}"
|
|
114
157
|
df.to_csv(name, sep="\t")
|
|
158
|
+
|
|
159
|
+
def stamps(start: pd.Timestamp) -> str:
|
|
160
|
+
|
|
161
|
+
delta = pd.Timestamp.now() - start
|
|
162
|
+
total_seconds = delta.total_seconds()
|
|
163
|
+
|
|
164
|
+
# Calculate minutes and remaining seconds
|
|
165
|
+
minutes = int(total_seconds // 60) # Get whole minutes
|
|
166
|
+
remaining_seconds = total_seconds % 60 # Get the remainder seconds
|
|
167
|
+
|
|
168
|
+
# Format the output string conditionally (optional, but nice)
|
|
169
|
+
if minutes > 0:
|
|
170
|
+
time_str = f"{minutes} minutes and {remaining_seconds:.2f} seconds"
|
|
171
|
+
else:
|
|
172
|
+
time_str = f"{remaining_seconds:.2f} seconds" # Or just total_seconds:.2f
|
|
173
|
+
|
|
174
|
+
return time_str
|
|
@@ -6,7 +6,6 @@ from pathlib import Path
|
|
|
6
6
|
from typing import Any
|
|
7
7
|
|
|
8
8
|
import pandas as pd
|
|
9
|
-
from icecream import ic
|
|
10
9
|
|
|
11
10
|
os.environ["POLARS_MAX_THREADS"] = "7" # Must be set before polars import
|
|
12
11
|
import polars as pl
|
|
@@ -212,7 +211,7 @@ def split_vcf_to_dfs(vcf_df: pd.DataFrame) -> pd.DataFrame:
|
|
|
212
211
|
|
|
213
212
|
for sample in sample_cols:
|
|
214
213
|
try:
|
|
215
|
-
assert all(row[1]
|
|
214
|
+
assert all(row[1] in ("|", "/") for row in vcf_df[sample])
|
|
216
215
|
except TypeError:
|
|
217
216
|
logger.info(f"Sample {sample} is not diploid")
|
|
218
217
|
cols: list[str] = COMMON_COLS + [sample]
|
|
@@ -342,7 +341,7 @@ def read_vcf(file_path: str) -> pl.DataFrame:
|
|
|
342
341
|
if line.startswith("#"):
|
|
343
342
|
header = line.lstrip("#").strip().split("\t")
|
|
344
343
|
if len(header) == 10:
|
|
345
|
-
header[-1] = "SAMPLE"
|
|
344
|
+
header[-1] = "SAMPLE" # for single sample
|
|
346
345
|
break
|
|
347
346
|
|
|
348
347
|
if header is None:
|
|
@@ -361,3 +360,38 @@ def read_vcf(file_path: str) -> pl.DataFrame:
|
|
|
361
360
|
raise VcfNoDataError(filename=file_path)
|
|
362
361
|
df = df.with_columns(df["CHROM"].str.replace("chr", "", literal=True))
|
|
363
362
|
return df
|
|
363
|
+
|
|
364
|
+
|
|
365
|
+
def check_if_multi_sample_vcf(file_path: str) -> bool:
|
|
366
|
+
"""Read a VCF file header.
|
|
367
|
+
|
|
368
|
+
This function manually extracts the header (line starting with "#CHROM")
|
|
369
|
+
to check if multi sample
|
|
370
|
+
|
|
371
|
+
Args:
|
|
372
|
+
file_path (str): Path to the VCF file (can be gzipped).
|
|
373
|
+
|
|
374
|
+
Returns:
|
|
375
|
+
bool: True if there's multiple samples
|
|
376
|
+
|
|
377
|
+
"""
|
|
378
|
+
header = None
|
|
379
|
+
# Use gzip.open if file is gzipped, else standard open.
|
|
380
|
+
open_func = gzip.open if str(file_path).endswith(".gz") else open
|
|
381
|
+
with open_func(file_path, "rt") as f:
|
|
382
|
+
# Find header line starting with "#CHROM"
|
|
383
|
+
for line in f:
|
|
384
|
+
if line.startswith("##"):
|
|
385
|
+
continue
|
|
386
|
+
if line.startswith("#"):
|
|
387
|
+
header = line.lstrip("#").strip().split("\t")
|
|
388
|
+
if len(header) == 10:
|
|
389
|
+
return False
|
|
390
|
+
elif len(header) < 10:
|
|
391
|
+
raise VcfMissingHeaderError(filename=file_path)
|
|
392
|
+
else:
|
|
393
|
+
assert len(header) == len(set(header))
|
|
394
|
+
# unique sample names
|
|
395
|
+
break
|
|
396
|
+
|
|
397
|
+
return True
|
|
@@ -26,11 +26,13 @@ from rbceq2.IO.record_data import (
|
|
|
26
26
|
log_validation,
|
|
27
27
|
record_filtered_data,
|
|
28
28
|
save_df,
|
|
29
|
+
stamps,
|
|
29
30
|
)
|
|
30
31
|
from rbceq2.IO.vcf import (
|
|
31
32
|
VCF,
|
|
32
33
|
filter_VCF_to_BG_variants,
|
|
33
34
|
read_vcf,
|
|
35
|
+
check_if_multi_sample_vcf,
|
|
34
36
|
split_vcf_to_dfs,
|
|
35
37
|
)
|
|
36
38
|
|
|
@@ -140,6 +142,7 @@ def main():
|
|
|
140
142
|
if args.vcf.is_dir():
|
|
141
143
|
patterns = ["*.vcf", "*.vcf.gz"]
|
|
142
144
|
vcfs = [file for pattern in patterns for file in args.vcf.glob(pattern)]
|
|
145
|
+
logger.info(f"{len(vcfs)} single sample VCF/s passed")
|
|
143
146
|
if args.validate:
|
|
144
147
|
with Pool(processes=int(args.processes)) as pool:
|
|
145
148
|
for result_valid, file_name in pool.imap_unordered(
|
|
@@ -150,9 +153,20 @@ def main():
|
|
|
150
153
|
if args.validate:
|
|
151
154
|
result_valid, file_name = check_VCF(args.vcf)
|
|
152
155
|
log_validation(result_valid, file_name)
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
+
actually_multi_vcf = check_if_multi_sample_vcf(args.vcf)
|
|
157
|
+
if actually_multi_vcf:
|
|
158
|
+
multi_vcf = read_vcf(args.vcf)
|
|
159
|
+
logger.info("Multi sample VCF passed")
|
|
160
|
+
filtered_multi_vcf = filter_VCF_to_BG_variants(
|
|
161
|
+
multi_vcf, db.unique_variants
|
|
162
|
+
)
|
|
163
|
+
vcfs = split_vcf_to_dfs(filtered_multi_vcf)
|
|
164
|
+
time_str = stamps(start)
|
|
165
|
+
logger.info(f"VCFs loaded in {time_str}")
|
|
166
|
+
print(f"VCFs loaded in {time_str}")
|
|
167
|
+
else:
|
|
168
|
+
logger.info("1 single sample VCF passed")
|
|
169
|
+
vcfs = [args.vcf]
|
|
156
170
|
|
|
157
171
|
all_alleles = defaultdict(list)
|
|
158
172
|
for a in db.make_alleles():
|
|
@@ -184,10 +198,12 @@ def main():
|
|
|
184
198
|
save_df(df_pheno_numeric, f"{args.out}_pheno_numeric.tsv", UUID)
|
|
185
199
|
df_pheno_alpha = pd.DataFrame.from_dict(dfs_pheno_alphanumeric, orient="index")
|
|
186
200
|
save_df(df_pheno_alpha, f"{args.out}_pheno_alphanumeric.tsv", UUID)
|
|
187
|
-
|
|
201
|
+
if args.PDFs:
|
|
202
|
+
generate_all_reports(df_geno, df_pheno_alpha, df_pheno_numeric, args.out, UUID)
|
|
188
203
|
|
|
189
|
-
|
|
190
|
-
|
|
204
|
+
time_str = stamps(start)
|
|
205
|
+
logger.info(f"{len(dfs_geno)} VCFs processed in {time_str}")
|
|
206
|
+
print(f"{len(dfs_geno)} VCFs processed in {time_str}")
|
|
191
207
|
|
|
192
208
|
|
|
193
209
|
def find_hits(
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|