-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathutils.groovy
59 lines (49 loc) · 1.81 KB
/
utils.groovy
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
// Given the tsv file containing the run parameters, creates a dictionary whose keys are
// column names, and whose entries are columns
def createParamDictionary(parFile) {
parDict = [:]
parDict["parDir"] = parFile.getParent()
parDict["parPrefix"] = parFile.getBaseName()
firstLine = true
parFile.eachLine { line ->
if (firstLine) {
columns = line.split("\t")
firstLine = false
for (c in columns) { parDict[c] = [] }
}
else {
for (x in [columns, line.split("\t")].transpose()) {
parDict[x[0]].add(x[1])
}
}
}
return parDict
}
// function to check that all items in a list are the same
def checkSame(list) {
return !list.any { l -> l != list[0] }
}
// Performs sanity checks and formatting on the parameter dictionary
def formatParamDict(parDict) {
newParDict = [:]
newParDict["parDir"] = parDict["parDir"]
newParDict["parPrefix"] = parDict["parPrefix"]
// check that values are consistent
keys = ["flow_cell_id", "flow_cell_type", "kit", "barcode_kits", "guppy_config_file", "nanopore_data_root_dir"]
for (k in keys) {
if (!checkSame(parDict[k])) {
throw new Exception("ERROR: not all values in column $k of file ${parDict.parPrefix}.tsv are the same")
}
else {newParDict[k] = parDict[k][0]}
}
// make sure that barcode kits are separated by double quotation marks
newParDict.barcode_kits = "\"" + newParDict.barcode_kits.replace("\"","") + "\""
// list of valid barcodes
newParDict["barcode_id"] = []
for (x in parDict.barcode_id) {
newParDict["barcode_id"].add(x as Integer)
}
// capture timestamp
newParDict["timeNow"] = (new Date()).format("yyyy-MM-dd--HH-mm-ss")
return newParDict
}