forked from bridgedb/data
-
Notifications
You must be signed in to change notification settings - Fork 0
/
update.groovy
66 lines (60 loc) · 2.53 KB
/
update.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
60
61
62
63
64
65
// Copyright (C) 2020 Egon Willighagen
// License: MIT
import groovy.json.JsonSlurper
templateFile = "gene_database/template.md"
licenseNames = [
"http://creativecommons.org/publicdomain/zero/1.0/" : "CC0"
]
def createBioSchemas(file, type) {
content = "<script type=\"application/ld+json\">{"
content += "\"@context\": \"https://schema.org/\","
content += "\"@type\": \"Dataset\","
content += "\"http://purl.org/dc/terms/conformsTo\": { \"@type\": \"CreativeWork\", \"@id\": \"https://bioschemas.org/profiles/Dataset/0.4-DRAFT/\" },"
content += "\"name\": \"${file.file}\","
extra = type.toLowerCase() == "species" ? " for genes and proteins" : " (species independent)"
content += "\"description\": \"BridgeDb identifier mapping file for ${file[type.toLowerCase()]}${extra}\","
content += "\"identifier\": \"${file.doi}/${file.file}\","
extra = type.toLowerCase() == "species" ? file[type.toLowerCase()] + ", gene, protein" : type.toLowerCase()
if (file.license) content += "\"license\": \"${file.license}\","
content += "\"keywords\": \"BridgeDb, mapping file, identifier, ELIXIR RIR, ${extra}\","
content += "\"url\": \"https://doi.org/${file.doi}\","
content += "\"distribution\": [ { \"@type\": \"DataDownload\", \"name\": \"$file.file\", \"contentURL\": \"${file.downloadURL}\" } ],"
content += "\"isAccessibleForFree\": true"
content += "}</script> "
return 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
def data = jsonSlurper.parseText(fileContents)
println "| ${data.type} | BridgeDb Download | Size | DOI | License | Date |"
println "|-------|--------|---------|"
for (file in data.mappingFiles) {
print "| "
print createBioSchemas(file, data.type)
print "${file[data.type.toLowerCase()]} "
print "| [${file.file}](${file.downloadURL}) "
print "| " + (file.size ? file.size : "")
print "| (doi:[${file.doi}](https://doi.org/${file.doi})) "
licenseStr = ""
if (file.license) {
licenseStr = "[" +
(licenseNames[file.license] ?
licenseNames[file.license] :
"license") +
"](" + file.license + ") "
}
print "| ${licenseStr}"
dateStr = ""
if (file.date) dateStr = file.date
print "| ${dateStr} "
println "|"
}
} else {
println line
}
}