Skip to content

Commit eab9ade

Browse files
committed
Works.
1 parent 4149a26 commit eab9ade

File tree

2 files changed

+88
-52
lines changed

2 files changed

+88
-52
lines changed

BRB/PushButton.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -591,7 +591,7 @@ def GetResults(config, project, libraries):
591591
)
592592
log.info(f"Processing {dataPath}")
593593
except:
594-
print("external data")
594+
print(f"GetResults with ignore=True, {project} is external data.")
595595
ignore = True
596596
validLibraryTypes = {v: i for i, v in enumerate(config.get('Options', 'validLibraryTypes').split(','))}
597597
pipelines = config.get('Options', 'pipelines').split(',')

BRB/run.py

Lines changed: 87 additions & 51 deletions
Original file line numberDiff line numberDiff line change
@@ -14,10 +14,35 @@
1414
from pathlib import Path
1515
from rich import print
1616

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+
2146

2247
@click.command(
2348
context_settings=dict(
@@ -30,71 +55,82 @@
3055
type=click.Path(exists=True),
3156
required=False,
3257
default=os.path.expanduser('~/configs/BigRedButton.ini'),
33-
help='specify a custom ini file.',
58+
help='Specify a custom ini file.',
3459
show_default=True
3560
)
3661
@click.option(
3762
"-s",
3863
"--stats",
3964
required=False,
4065
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.'
4267
)
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):
4670

4771
while True:
4872
# Read the config file
4973
config = BRB.getConfig.getConfig(configfile)
5074

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
5681

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)
6489

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])
73103
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+
74121

75122
# 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)
89127

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 ===')
94133

95-
# Mark the flow cell as having been processed
96-
BRB.findFinishedFlowCells.markFinished(config)
97-
log.info('=== finished flowcell ===')
98134

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

Comments
 (0)