1
+ import datetime
1
2
import logging
2
3
import os
3
4
import subprocess
4
5
from typing import Union
5
6
6
7
import bbconf
7
- import yaml
8
8
import pephubclient
9
9
import peppy
10
10
import pypiper
11
+ import yaml
11
12
from bbconf .bbagent import BedBaseAgent
12
13
from bbconf .const import DEFAULT_LICENSE
13
14
from bbconf .models .base_models import FileModel
14
15
from eido import validate_project
15
- import datetime
16
+ from geniml . bbclient import BBClient
16
17
from pephubclient .helpers import MessageHandler as m
17
18
from pephubclient .helpers import is_registry_path
18
- from geniml .bbclient import BBClient
19
19
20
20
from bedboss ._version import __version__
21
21
from bedboss .bedbuncher import run_bedbuncher
32
32
)
33
33
from bedboss .refgenome_validator .main import ReferenceValidator
34
34
from bedboss .skipper import Skipper
35
- from bedboss .utils import get_genome_digest , standardize_genome_name , calculate_time
35
+ from bedboss .utils import calculate_time , get_genome_digest , standardize_genome_name
36
36
from bedboss .utils import standardize_pep as pep_standardizer
37
37
38
38
_LOGGER = logging .getLogger (PKG_NAME )
@@ -50,6 +50,7 @@ def requirements_check() -> None:
50
50
)
51
51
52
52
53
+ @calculate_time
53
54
def run_all (
54
55
input_file : str ,
55
56
input_type : str ,
@@ -264,6 +265,7 @@ def run_all(
264
265
return bed_metadata .bed_digest
265
266
266
267
268
+ @calculate_time
267
269
def insert_pep (
268
270
bedbase_config : str ,
269
271
output_folder : str ,
@@ -278,6 +280,7 @@ def insert_pep(
278
280
ensdb : str = None ,
279
281
just_db_commit : bool = False ,
280
282
force_overwrite : bool = False ,
283
+ update : bool = False ,
281
284
upload_s3 : bool = False ,
282
285
upload_pephub : bool = False ,
283
286
upload_qdrant : bool = False ,
@@ -306,6 +309,7 @@ def insert_pep(
306
309
:param str ensdb: a full path to the ensdb gtf file required for genomes not in GDdata
307
310
:param bool just_db_commit: whether save only to the database (Without saving locally )
308
311
:param bool force_overwrite: whether to overwrite the existing record
312
+ :param bool update: whether to update the record in the database. This option will overwrite the force_overwrite option. [Default: False]
309
313
:param bool upload_s3: whether to upload to s3
310
314
:param bool upload_pephub: whether to push bedfiles and metadata to pephub (default: False)
311
315
:param bool upload_qdrant: whether to execute qdrant indexing
@@ -378,6 +382,7 @@ def insert_pep(
378
382
ensdb = ensdb ,
379
383
just_db_commit = just_db_commit ,
380
384
force_overwrite = force_overwrite ,
385
+ update = update ,
381
386
upload_qdrant = upload_qdrant ,
382
387
upload_s3 = upload_s3 ,
383
388
upload_pephub = upload_pephub ,
@@ -427,12 +432,12 @@ def insert_pep(
427
432
428
433
429
434
@calculate_time
430
- def run_unprocessed_beds (
435
+ def reprocess_all (
431
436
bedbase_config : Union [str , BedBaseAgent ],
432
437
output_folder : str ,
433
438
limit : int = 10 ,
434
439
nofail : bool = False ,
435
- ):
440
+ ) -> None :
436
441
"""
437
442
Run bedboss pipeline for all unprocessed beds in the bedbase
438
443
@@ -504,7 +509,7 @@ def run_unprocessed_beds(
504
509
) as file :
505
510
yaml .dump (failed_samples , file )
506
511
507
- from rich import print
512
+ m . print_warning ( f"Logs with failed samples are saved in { output_folder } " )
508
513
509
514
m .print_success (f"Processing completed successfully" )
510
515
@@ -515,3 +520,113 @@ def run_unprocessed_beds(
515
520
success_files = unprocessed_beds .limit - len (failed_samples ),
516
521
)
517
522
print (print_values )
523
+
524
+
525
+ @calculate_time
526
+ def reprocess_one (
527
+ bedbase_config : Union [str , BedBaseAgent ],
528
+ output_folder : str ,
529
+ identifier : str ,
530
+ ) -> None :
531
+ """
532
+ Run bedboss pipeline for one bed in the bedbase [Reprocess]
533
+
534
+ :param bedbase_config: bedbase configuration file path
535
+ :param output_folder: output folder of the pipeline
536
+ :param identifier: bed identifier
537
+
538
+ :return: None
539
+ """
540
+
541
+ if isinstance (bedbase_config , str ):
542
+ bbagent = BedBaseAgent (config = bedbase_config )
543
+ elif isinstance (bedbase_config , bbconf .BedBaseAgent ):
544
+ bbagent = bedbase_config
545
+ else :
546
+ raise BedBossException ("Incorrect bedbase_config type. Exiting..." )
547
+
548
+ bbclient = BBClient ()
549
+
550
+ bed_annot = bbagent .bed .get (identifier )
551
+ bed_file = bbclient .load_bed (bed_annot .id )
552
+
553
+ run_all (
554
+ input_file = bed_file .path ,
555
+ input_type = "bed" ,
556
+ outfolder = output_folder ,
557
+ genome = bed_annot .genome_alias ,
558
+ bedbase_config = bbagent ,
559
+ name = bed_annot .name ,
560
+ license_id = bed_annot .license_id ,
561
+ rfg_config = None ,
562
+ check_qc = False ,
563
+ validate_reference = True ,
564
+ chrom_sizes = None ,
565
+ open_signal_matrix = None ,
566
+ ensdb = None ,
567
+ other_metadata = None ,
568
+ just_db_commit = False ,
569
+ update = True ,
570
+ upload_qdrant = True ,
571
+ upload_s3 = True ,
572
+ upload_pephub = True ,
573
+ light = False ,
574
+ universe = False ,
575
+ universe_method = None ,
576
+ universe_bedset = None ,
577
+ pm = None ,
578
+ )
579
+
580
+ _LOGGER .info (f"Successfully processed { identifier } " )
581
+
582
+
583
+ @calculate_time
584
+ def reprocess_bedset (
585
+ bedbase_config : Union [str , BedBaseAgent ],
586
+ output_folder : str ,
587
+ identifier : str ,
588
+ no_fail : bool = True ,
589
+ heavy : bool = False ,
590
+ ):
591
+ """
592
+ Recalculate bedset from the bedbase
593
+
594
+ :param bedbase_config: bedbase configuration file path
595
+ :param output_folder: output folder of the pipeline
596
+ :param identifier: bedset identifier
597
+ :param no_fail: whether to raise an error if bedset was not added to the database
598
+ :param heavy: whether to use heavy processing. Calculate plots for bedset
599
+
600
+ :return: None
601
+ """
602
+
603
+ if isinstance (bedbase_config , str ):
604
+ bbagent = BedBaseAgent (config = bedbase_config )
605
+ elif isinstance (bedbase_config , bbconf .BedBaseAgent ):
606
+ bbagent = bedbase_config
607
+ else :
608
+ raise BedBossException ("Incorrect bedbase_config type. Exiting..." )
609
+
610
+ bedset_annot = bbagent .bedset .get (identifier )
611
+
612
+ run_bedbuncher (
613
+ bedbase_config = bbagent ,
614
+ record_id = bedset_annot .id ,
615
+ bed_set = bedset_annot .bed_ids ,
616
+ name = bedset_annot .name ,
617
+ output_folder = output_folder ,
618
+ description = bedset_annot .description ,
619
+ heavy = heavy ,
620
+ upload_pephub = False ,
621
+ upload_s3 = heavy ,
622
+ no_fail = no_fail ,
623
+ force_overwrite = True ,
624
+ annotation = {
625
+ ** bedset_annot .model_dump (
626
+ exclude = {
627
+ "bed_ids" ,
628
+ }
629
+ )
630
+ },
631
+ light = False ,
632
+ )
0 commit comments