@@ -259,6 +259,8 @@ def __init__(self, identifier, target_build=None, query_result=None, **kwargs):
259
259
self ._directory = self .local_path .parent
260
260
261
261
def _init_from_accession (self , accession , target_build ):
262
+ logger .debug (f"Instantiating ScoringFile from accession { accession .pgs_id } " )
263
+
262
264
match self ._identifier :
263
265
case ScoreQueryResult ():
264
266
# skip hitting the API unnecessarily
@@ -288,6 +290,8 @@ def _init_from_accession(self, accession, target_build):
288
290
self .local_path = None
289
291
290
292
def _init_from_path (self , target_build = None ):
293
+ logger .debug (f"Instantiating ScoringFile from { self .local_path = } " )
294
+
291
295
if target_build is not None :
292
296
raise ValueError (
293
297
"target_build must be None for local files. "
@@ -395,6 +399,7 @@ def download(self, directory, overwrite=False):
395
399
self ._directory = pathlib .Path (directory )
396
400
fn = pathlib .Path (self .path ).name
397
401
out_path = self ._directory / fn
402
+ logger .debug (f"Downloading { self .path } to { out_path } " )
398
403
https_download (
399
404
url = self .path ,
400
405
out_path = out_path ,
@@ -467,6 +472,19 @@ def normalise(
467
472
('rs78540526', '11', 69701882)
468
473
469
474
A :class:`LiftoverError` is only raised when many converted coordinates are missing.
475
+
476
+ Normalising converts the is_dominant and is_recessive optional fields in
477
+ scoring files into an EffectType:
478
+
479
+ >>> testpath = Config.ROOT_DIR / "tests" / "PGS000802_hmPOS_GRCh37.txt"
480
+ >>> variants = ScoringFile(testpath).normalise()
481
+ >>> for i, x in enumerate(variants): # doctest: +ELLIPSIS
482
+ ... (x.is_dominant, x.is_recessive, x.effect_type)
483
+ ... if i == 2:
484
+ ... break
485
+ (True, False, EffectType.DOMINANT)
486
+ (False, True, EffectType.RECESSIVE)
487
+ (True, False, EffectType.DOMINANT)
470
488
"""
471
489
yield from normalise (
472
490
scoring_file = self ,
@@ -478,6 +496,7 @@ def normalise(
478
496
479
497
def get_log (self , drop_missing = False , variant_log = None ):
480
498
"""Create a JSON log from a ScoringFile's header and variant rows."""
499
+ logger .debug (f"Creating JSON log for { self !r} " )
481
500
log = {}
482
501
483
502
for attr in self ._header .fields :
@@ -630,19 +649,25 @@ def __init__(self, *args, target_build=None, **kwargs):
630
649
for arg in flargs :
631
650
match arg :
632
651
case ScoringFile () if arg .target_build == target_build :
652
+ logger .info ("ScoringFile build matches target build" )
633
653
scorefiles .append (arg )
634
654
case ScoringFile () if arg .target_build != target_build :
635
655
raise ValueError (
636
656
f"{ arg .target_build = } doesn't match { target_build = } "
637
657
)
638
658
case _ if pathlib .Path (arg ).is_file () and target_build is None :
659
+ logger .info (f"Local path: { arg } , no target build is OK" )
639
660
scorefiles .append (ScoringFile (arg ))
640
661
case _ if pathlib .Path (arg ).is_file () and target_build is not None :
662
+ logger .critical (f"{ arg } is a local file and { target_build = } " )
641
663
raise ValueError (
642
664
"Can't load local scoring file when target_build is set"
643
665
"Try .normalise() method to do liftover, or load harmonised scoring files from PGS Catalog"
644
666
)
645
667
case str () if arg .startswith ("PGP" ) or "_" in arg :
668
+ logger .info (
669
+ "Term associated with multiple scores detected (PGP or trait)"
670
+ )
646
671
self .include_children = kwargs .get ("include_children" , None )
647
672
traitpub_query = CatalogQuery (
648
673
accession = arg , include_children = self .include_children
@@ -656,6 +681,7 @@ def __init__(self, *args, target_build=None, **kwargs):
656
681
]
657
682
)
658
683
case str () if arg .startswith ("PGS" ):
684
+ logger .info ("PGS ID detected" )
659
685
pgs_batch .append (arg )
660
686
case str ():
661
687
raise ValueError (f"{ arg !r} is not a valid path or an accession" )
@@ -664,6 +690,7 @@ def __init__(self, *args, target_build=None, **kwargs):
664
690
665
691
# batch PGS IDs to avoid overloading the API
666
692
batched_queries = CatalogQuery (accession = pgs_batch ).score_query ()
693
+ logger .debug (f"Batching queries to PGS Catalog API: { pgs_batch } " )
667
694
batched_scores = [
668
695
ScoringFile (x , target_build = target_build ) for x in batched_queries
669
696
]
0 commit comments