-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathfindFinishedFlowCells.py
More file actions
84 lines (71 loc) · 2.7 KB
/
findFinishedFlowCells.py
File metadata and controls
84 lines (71 loc) · 2.7 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
import glob
import requests
from rich import print
from pathlib import Path
from BRB.logger import log
def flowCellProcessed(config):
return Path(
config.get("Paths","baseData"),
config.get("Options","runID"),
'analysis.done'
).exists()
def markFinished(config):
_p = Path(
config["Paths"]["baseData"],
config["Options"]["runID"],
'analysis.done'
)
_p.touch()
log.info(f"{_p} created, flow cell processed.")
print(f"{_p} created, flow cell processed.")
def queryParkour(config):
basePath= config.get("Paths","baseData")
sequencer_type = config.get("Options", "sequencerType")
if sequencer_type == "Aviti":
FCID = config.get("Options", "runID").split("_")[2]
if '-' in FCID:
FCID = FCID.split('-')[-1]
d = {'flowcell_id': FCID}
else:
FCID = config.get("Options", "runID").split("_")[3][1:] # C605HACXX from 150416_SN7001180_0196_BC605HACXX
if '-' in FCID:
FCID = FCID.split('-')[-1]
d = {'flowcell_id': FCID}
res = requests.get(config.get("Parkour", "QueryURL"), auth=(config.get("Parkour", "user"), config.get("Parkour", "password")), params=d, verify=config.get("Parkour", "cert"))
if res.status_code == 200:
return res.json()
return dict()
def detect_sequencer_type(base_path: str) -> str:
"""
Detect whether a sequencing run is Aviti or Illumina
based on the presence of the Aviti-specific RunManifest.csv file.
"""
aviti_check = glob.glob(f"{base_path}/*/RunManifest.csv")
if aviti_check:
return "Aviti"
else:
return "Illumina"
def newFlowCell(config):
dirs = glob.glob("{}/*/fastq.made".format(config.get("Paths","baseData")))
for d in dirs :
#Get the flow cell ID (e.g., 150416_SN7001180_0196_BC605HACXX)
run_id = Path(d).parents[0].name
config.set('Options','runID',run_id)
if config.get("Options","runID")[:4] < "1804":
continue
# Detect sequencer type
base_path = str(Path(d).parents[0])
seq_type = detect_sequencer_type(base_path)
config.set("Options", "sequencerType", seq_type)
if not flowCellProcessed(config):
print(f'Found new flow cell: [green]{config.get("Options","runID")}[/green]')
# Query parkour to see if there's anything to be done for this
ParkourDict = queryParkour(config)
if len(ParkourDict) == 0:
markFinished(config)
config.set('Options','runID', '')
ParkourDict = None
continue
return config, ParkourDict
print("No new flow cells found...")
return config, None