forked from bridgedb/data
-
Notifications
You must be signed in to change notification settings - Fork 0
/
makeGDBconfig.groovy
31 lines (28 loc) · 986 Bytes
/
makeGDBconfig.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
// Copyright (C) 2021 Egon Willighagen
// License: MIT
import groovy.json.JsonSlurper
templateFile = "gene_database/template.md"
// create the GDB config file content
lines = new File(templateFile).readLines()
lines.each { String line ->
if (line.startsWith("<files>")) {
def instruction = new XmlSlurper().parseText(line)
def input = instruction.text()
def jsonSlurper = new JsonSlurper()
fileContents = new File(input).text
new File("${input}.config").withWriter('utf-8') { writer ->
def data = jsonSlurper.parseText(fileContents)
data.mappingFiles.each { mappingFile ->
if (data.type == "Species") {
if (mappingFile.species == "Human Coronaviruses") { // exception
writer.writeLine "*\t${mappingFile.file}"
} else {
writer.writeLine "${mappingFile.species}\t${mappingFile.file}"
}
} else {
writer.writeLine "*\t${mappingFile.file}"
}
}
}
}
}