|
14 | 14 | from pathlib import Path
|
15 | 15 | from rich import print
|
16 | 16 |
|
17 |
| -# def validate_fcid_with_stats(ctx, param, value): |
18 |
| -# if ctx.params.get('stats') and not value: |
19 |
| -# raise click.UsageError('--fcid is required when --stats is used') |
20 |
| -# return value |
| 17 | + |
| 18 | +def process_data(config, ParkourDict): |
| 19 | + bdir = "{}/{}".format(config.get('Paths', 'baseData'), config.get('Options', 'runID')) |
| 20 | + msg = [] |
| 21 | + for k, v in ParkourDict.items(): |
| 22 | + if not os.path.exists("{}/Project_{}".format(bdir, BRB.misc.pacifier(k))): |
| 23 | + log.info("{}/Project_{} doesn't exist, probably lives on another lane.".format(bdir, BRB.misc.pacifier(k))) |
| 24 | + continue |
| 25 | + try: |
| 26 | + msg = msg + BRB.PushButton.GetResults(config, k, v) |
| 27 | + except Exception as e: |
| 28 | + BRB.email.errorEmail(config, sys.exc_info(), "Received an error running PushButton.GetResults() with {} and {}".format(k, v)) |
| 29 | + log.critical("Received an error running PushButton.GetResults() with {} and {}".format(k, v)) |
| 30 | + print("Received an error running PushButton.GetResults() with {} and {}".format(k, v), file=sys.stderr) |
| 31 | + raise |
| 32 | + |
| 33 | + # Email finished message |
| 34 | + log.info('Create e-mail') |
| 35 | + log.info(msg) |
| 36 | + BRB.email.finishedEmail(config, msg) |
| 37 | + |
| 38 | + return |
| 39 | + |
| 40 | + |
| 41 | +def validate_fcid_with_stats(ctx, param, value): |
| 42 | + if ctx.params.get('stats') and not value: |
| 43 | + raise click.UsageError('--fcid is required when --stats standalone run is active.') |
| 44 | + return value |
| 45 | + |
21 | 46 |
|
22 | 47 | @click.command(
|
23 | 48 | context_settings=dict(
|
|
30 | 55 | type=click.Path(exists=True),
|
31 | 56 | required=False,
|
32 | 57 | default=os.path.expanduser('~/configs/BigRedButton.ini'),
|
33 |
| - help='specify a custom ini file.', |
| 58 | + help='Specify a custom ini file.', |
34 | 59 | show_default=True
|
35 | 60 | )
|
36 | 61 | @click.option(
|
37 | 62 | "-s",
|
38 | 63 | "--stats",
|
39 | 64 | required=False,
|
40 | 65 | is_flag=True,
|
41 |
| - help='specify a flowcell ID to push its stats, (WIP: --fcid not implemented yet).' |
| 66 | + help='Standalone run, will not run any pipelines. Requires --fcid to indicate target.' |
42 | 67 | )
|
43 |
| -# @click.option('--fcid', callback=validate_fcid_with_stats, help='Flowcell ID that lacks stats.' |
44 |
| -# def run_brb(configfile, stats, fcid): |
45 |
| -def run_brb(configfile, stats): |
| 68 | +@click.option('--fcid', callback=validate_fcid_with_stats, help='Flowcell ID to push stats.') |
| 69 | +def run_brb(configfile, stats, fcid): |
46 | 70 |
|
47 | 71 | while True:
|
48 | 72 | # Read the config file
|
49 | 73 | config = BRB.getConfig.getConfig(configfile)
|
50 | 74 |
|
51 |
| - # Get the next flow cell to process, or sleep |
52 |
| - config, ParkourDict = BRB.findFinishedFlowCells.newFlowCell(config) |
53 |
| - if(config.get('Options','runID') == '') or ParkourDict is None or stats is None: |
54 |
| - sleep(60*60) |
55 |
| - continue |
| 75 | + if not stats: |
| 76 | + # Get the next flow cell to process, or sleep |
| 77 | + config, ParkourDict = BRB.findFinishedFlowCells.newFlowCell(config) |
| 78 | + if (config.get('Options','runID') == '') or ParkourDict is None: |
| 79 | + sleep(60*60) |
| 80 | + continue |
56 | 81 |
|
57 |
| - # Open log file |
58 |
| - logFile = Path( |
59 |
| - config['Paths']['logPath'], |
60 |
| - config.get('Options','runID') + '.log' |
61 |
| - ) |
62 |
| - print(f"Logging into: {logFile}") |
63 |
| - setLog(logFile) |
| 82 | + # Open log file |
| 83 | + logFile = Path( |
| 84 | + config['Paths']['logPath'], |
| 85 | + config.get('Options','runID') + '.log' |
| 86 | + ) |
| 87 | + print(f"Logging into: {logFile}") |
| 88 | + setLog(logFile) |
64 | 89 |
|
65 |
| - # Push stats on-demand |
66 |
| - if stats is not None: |
67 |
| - # stats: is the FCID specified by using CLI argument |
68 |
| - d = [d for d in glob.glob("{}/*/fastq.made".format(config.get('Paths', 'baseData'))) if stats in d] |
69 |
| - assert len(d) == 1 |
70 |
| - config.set('Options','runID',d[1].split("/")[-2]) |
71 |
| - if not BRB.findFinishedFlowCells.flowCellProcessed(config): |
72 |
| - print(f"Found new flow cell, this is terribly wrong: [red]{config.get("Options","runID")}[/red]") |
| 90 | + else: |
| 91 | + # Push stats on-demand |
| 92 | + log.info(f"Pushing stats for flowcell: {fcid}") |
| 93 | + d = [d for d in glob.glob("{}/*/fastq.made".format(config.get('Paths', 'baseData'))) if fcid in d] |
| 94 | + dual_lane = len(d) == 2 |
| 95 | + if len(d) == 0: |
| 96 | + log.error(f"No fastq.made files found for {fcid}") |
| 97 | + return # Exit BRB if no files found. |
| 98 | + elif len(d) > 2: |
| 99 | + log.error(f"How many lanes does {fcid} have?!") |
| 100 | + return # Exit BRB this error shouldn't happen at all. |
| 101 | + |
| 102 | + config.set('Options','runID',d[0].split("/")[-2]) |
73 | 103 | ParkourDict = BRB.findFinishedFlowCells.queryParkour(config)
|
| 104 | + |
| 105 | + if dual_lane: |
| 106 | + config1 = BRB.getConfig.getConfig(configfile) |
| 107 | + config1.set('Options','runID',d[1].split("/")[-2]) |
| 108 | + ParkourDict1 = BRB.findFinishedFlowCells.queryParkour(config) |
| 109 | + |
| 110 | + # Open log file |
| 111 | + if not dual_lane: |
| 112 | + logFile = Path(config['Paths']['logPath'], config.get('Options','runID') + '.log') |
| 113 | + else: |
| 114 | + logFile = Path(config['Paths']['logPath'], config.get('Options','runID') + '_2' + '.log') |
| 115 | + print(f"Logging into: {logFile}") |
| 116 | + setLog(logFile) |
| 117 | + |
| 118 | + if dual_lane: |
| 119 | + log.info("Same log-file is being used for both lanes. Hopefully this is not too confusing :$") |
| 120 | + |
74 | 121 |
|
75 | 122 | # Process each group's data, ignore cases where the project isn't in the lanes being processed
|
76 |
| - bdir = "{}/{}".format(config.get('Paths', 'baseData'), config.get('Options', 'runID')) |
77 |
| - msg = [] |
78 |
| - for k, v in ParkourDict.items(): |
79 |
| - if not os.path.exists("{}/Project_{}".format(bdir, BRB.misc.pacifier(k))): |
80 |
| - log.info("{}/Project_{} doesn't exist, probably lives on another lane.".format(bdir, BRB.misc.pacifier(k))) |
81 |
| - continue |
82 |
| - try: |
83 |
| - msg = msg + BRB.PushButton.GetResults(config, k, v) |
84 |
| - except Exception as e: |
85 |
| - BRB.email.errorEmail(config, sys.exc_info(), "Received an error running PushButton.GetResults() with {} and {}".format(k, v)) |
86 |
| - log.critical("Received an error running PushButton.GetResults() with {} and {}".format(k, v)) |
87 |
| - print("Received an error running PushButton.GetResults() with {} and {}".format(k, v), file=sys.stderr) |
88 |
| - raise |
| 123 | + process_data(config, ParkourDict) |
| 124 | + |
| 125 | + if stats and dual_lane: |
| 126 | + process_data(config1, ParkourDict1) |
89 | 127 |
|
90 |
| - # Email finished message |
91 |
| - log.info('Create e-mail') |
92 |
| - log.info(msg) |
93 |
| - BRB.email.finishedEmail(config, msg) |
| 128 | + |
| 129 | + if not stats: |
| 130 | + # Mark the flow cell as having been processed |
| 131 | + BRB.findFinishedFlowCells.markFinished(config) |
| 132 | + log.info('=== finished flowcell ===') |
94 | 133 |
|
95 |
| - # Mark the flow cell as having been processed |
96 |
| - BRB.findFinishedFlowCells.markFinished(config) |
97 |
| - log.info('=== finished flowcell ===') |
98 | 134 |
|
99 |
| - if stats is not None: |
100 |
| - break # exit the main loop, don't do anything else. |
| 135 | + if stats: |
| 136 | + return # don't do anything else. |
0 commit comments