@@ -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 ("Instantiating ScoringFile from accession" )
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,9 @@ 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
+
403
+ logger .debug (f"Downloading { self .path } to { out_path } " )
404
+
398
405
https_download (
399
406
url = self .path ,
400
407
out_path = out_path ,
@@ -467,6 +474,19 @@ def normalise(
467
474
('rs78540526', '11', 69701882)
468
475
469
476
A :class:`LiftoverError` is only raised when many converted coordinates are missing.
477
+
478
+ Normalising converts the is_dominant and is_recessive optional fields in
479
+ scoring files into an EffectType:
480
+
481
+ >>> testpath = Config.ROOT_DIR / "tests" / "PGS000802_hmPOS_GRCh37.txt"
482
+ >>> variants = ScoringFile(testpath).normalise()
483
+ >>> for i, x in enumerate(variants): # doctest: +ELLIPSIS
484
+ ... (x.is_dominant, x.is_recessive, x.effect_type)
485
+ ... if i == 2:
486
+ ... break
487
+ (True, False, EffectType.DOMINANT)
488
+ (False, True, EffectType.RECESSIVE)
489
+ (True, False, EffectType.DOMINANT)
470
490
"""
471
491
yield from normalise (
472
492
scoring_file = self ,
@@ -478,6 +498,9 @@ def normalise(
478
498
479
499
def get_log (self , drop_missing = False , variant_log = None ):
480
500
"""Create a JSON log from a ScoringFile's header and variant rows."""
501
+
502
+ logger .debug (f"Creating JSON log for { self !r} " )
503
+
481
504
log = {}
482
505
483
506
for attr in self ._header .fields :
@@ -630,6 +653,7 @@ def __init__(self, *args, target_build=None, **kwargs):
630
653
for arg in flargs :
631
654
match arg :
632
655
case ScoringFile () if arg .target_build == target_build :
656
+ logger .info ("ScoringFile build matches target build" )
633
657
scorefiles .append (arg )
634
658
case ScoringFile () if arg .target_build != target_build :
635
659
raise ValueError (
@@ -638,11 +662,18 @@ def __init__(self, *args, target_build=None, **kwargs):
638
662
case _ if pathlib .Path (arg ).is_file () and target_build is None :
639
663
scorefiles .append (ScoringFile (arg ))
640
664
case _ if pathlib .Path (arg ).is_file () and target_build is not None :
665
+ logger .info (f"Local path: { arg } , no target build is OK" )
666
+ scorefiles .append (ScoringFile (arg ))
667
+ case _ if pathlib .Path (arg ).is_file () and target_build is not None :
668
+ logger .critical (f"{ arg } is a local file and { target_build = } " )
641
669
raise ValueError (
642
670
"Can't load local scoring file when target_build is set"
643
671
"Try .normalise() method to do liftover, or load harmonised scoring files from PGS Catalog"
644
672
)
645
673
case str () if arg .startswith ("PGP" ) or "_" in arg :
674
+ logger .info (
675
+ "Term associated with multiple scores detected (PGP or trait)"
676
+ )
646
677
self .include_children = kwargs .get ("include_children" , None )
647
678
traitpub_query = CatalogQuery (
648
679
accession = arg , include_children = self .include_children
@@ -656,6 +687,7 @@ def __init__(self, *args, target_build=None, **kwargs):
656
687
]
657
688
)
658
689
case str () if arg .startswith ("PGS" ):
690
+ logger .info ("PGS ID detected" )
659
691
pgs_batch .append (arg )
660
692
case str ():
661
693
raise ValueError (f"{ arg !r} is not a valid path or an accession" )
@@ -664,6 +696,7 @@ def __init__(self, *args, target_build=None, **kwargs):
664
696
665
697
# batch PGS IDs to avoid overloading the API
666
698
batched_queries = CatalogQuery (accession = pgs_batch ).score_query ()
699
+ logger .debug (f"Batching queries to PGS Catalog API: { pgs_batch } " )
667
700
batched_scores = [
668
701
ScoringFile (x , target_build = target_build ) for x in batched_queries
669
702
]
0 commit comments