forked from UtrechtUniversity/yoda-ruleset
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathycDataset.r
175 lines (158 loc) · 5.97 KB
/
ycDataset.r
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
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
# \file
# \brief Youth Cohort - Dataset related functions.
# \author Chris Smeele
# \copyright Copyright (c) 2015, Utrecht University. All rights reserved.
# \license GPLv3, see LICENSE
# \brief Generate a dataset identifier based on WEPV values.
#
# \param[in] idComponents a kvList containing WEPV values
# \param[out] id a dataset id string
#
uuYcDatasetMakeId(*idComponents, *id){
*id =
*idComponents."wave"
++ "\t" ++ *idComponents."experiment_type"
++ "\t" ++ *idComponents."pseudocode"
++ "\t" ++ *idComponents."version"
++ "\t" ++ *idComponents."directory";
}
# \brief Parse a dataset identifier and return WEPV values.
#
# \param[in] id a dataset id string
# \param[out] idComponents a kvList containing WEPV values
#
uuYcDatasetParseId(*id, *idComponents){
*idParts = split(*id, "\t");
*idComponents."wave" = elem(*idParts, 0);
*idComponents."experiment_type" = elem(*idParts, 1);
*idComponents."pseudocode" = elem(*idParts, 2);
*idComponents."version" = elem(*idParts, 3);
*idComponents."directory" = elem(*idParts, 4);
}
# \brief Find dataset ids under *root.
#
# \param[in] root
# \param[out] ids a list of dataset ids
#
uuYcDatasetGetIds(*root, *ids) {
*idsString = "";
foreach (*item in SELECT META_DATA_ATTR_VALUE WHERE COLL_NAME = "*root" AND META_DATA_ATTR_NAME = 'dataset_id') {
# Datasets directly under *root need to be checked for separately due to limitations on the general query system.
if (strlen(*idsString) > 0) {
*idsString = *idsString ++ "\n";
}
*idsString = *idsString ++ *item."META_DATA_ATTR_VALUE";
}
foreach (*item in SELECT META_DATA_ATTR_VALUE WHERE COLL_NAME LIKE "*root/%" AND META_DATA_ATTR_NAME = 'dataset_id') {
if (strlen(*idsString) > 0) {
*idsString = *idsString ++ "\n";
}
*idsString = *idsString ++ *item."META_DATA_ATTR_VALUE";
}
*ids = split(*idsString, "\n");
}
# \brief Get a list of toplevel objects that belong to the given dataset id.
#
# \param[in] root
# \param[in] id
# \param[out] objects a list of toplevel object paths
# \param[out] isCollection whether this dataset consists of a single toplevel collection
#
uuYcDatasetGetToplevelObjects(*root, *id, *objects, *isCollection) {
*isCollection = false;
*objectsString = "";
foreach (*item in SELECT COLL_NAME WHERE COLL_NAME LIKE "*root/%" AND META_COLL_ATTR_NAME = 'dataset_toplevel' AND META_COLL_ATTR_VALUE = "*id") {
*isCollection = true;
*objectsString = *item."COLL_NAME";
}
if (!*isCollection) {
foreach (*item in SELECT DATA_NAME, COLL_NAME WHERE COLL_NAME = "*root" AND META_DATA_ATTR_NAME = 'dataset_toplevel' AND META_DATA_ATTR_VALUE = "*id") {
# Datasets directly under *root need to be checked for separately due to limitations on the general query system.
if (strlen(*objectsString) > 0) {
*objectsString = *objectsString ++ "\n";
}
*objectsString = *objectsString ++ *item."COLL_NAME" ++ "/" ++ *item."DATA_NAME";
}
foreach (*item in SELECT DATA_NAME, COLL_NAME WHERE COLL_NAME LIKE "*root/%" AND META_DATA_ATTR_NAME = 'dataset_toplevel' AND META_DATA_ATTR_VALUE = "*id") {
if (strlen(*objectsString) > 0) {
*objectsString = *objectsString ++ "\n";
}
*objectsString = *objectsString ++ *item."COLL_NAME" ++ "/" ++ *item."DATA_NAME";
}
}
*objects = split(*objectsString, "\n");
#writeLine("stdout", "Got dataset toplevel objects for <*id>: *objectsString");
}
# \brief Get a list of relative paths to all data objects in a dataset.
#
# \param[in] root
# \param[in] id
# \param[out] objects a list of relative object paths (e.g. file1.dat, some-subdir/file2.dat...)
#
uuYcDatasetGetDataObjectRelPaths(*root, *id, *objects) {
uuYcDatasetGetToplevelObjects(*root, *id, *toplevelObjects, *isCollection);
# NOTE: This will crash when an invalid dataset id is provided.
if (*isCollection) {
*parentCollection = elem(*toplevelObjects, 0);
} else {
uuChopPath(elem(*toplevelObjects, 0), *dataObjectParent, *dataObjectName);
*parentCollection = *dataObjectParent;
}
*objectsString = "";
foreach (*item in SELECT DATA_NAME, COLL_NAME WHERE COLL_NAME = "*parentCollection" AND META_DATA_ATTR_NAME = 'dataset_id' AND META_DATA_ATTR_VALUE = "*id") {
# Datasets directly under *root need to be checked for separately due to limitations on the general query system.
if (strlen(*objectsString) > 0) {
*objectsString = *objectsString ++ "\n";
}
*objectsString = *objectsString ++ *item."DATA_NAME";
}
foreach (*item in SELECT DATA_NAME, COLL_NAME WHERE COLL_NAME LIKE "*parentCollection/%" AND META_DATA_ATTR_NAME = 'dataset_id' AND META_DATA_ATTR_VALUE = "*id") {
if (strlen(*objectsString) > 0) {
*objectsString = *objectsString ++ "\n";
}
*objectsString = *objectsString
++ substr(*item."COLL_NAME", strlen(*parentCollection)+1, strlen(*item."COLL_NAME"))
++ "/"
++ *item."DATA_NAME";
}
*objects = split(*objectsString, "\n");
}
# \brief Check if a dataset id is locked.
#
# \param[in] root
# \param[in] id
# \param[out] isLocked
# \param[out] isFrozen
#
uuYcDatasetIsLocked(*root, *id, *isLocked, *isFrozen) {
uuYcDatasetGetToplevelObjects(*root, *id, *toplevelObjects, *isCollection);
*isLocked = false;
*isFrozen = false;
foreach (*item in *toplevelObjects) {
uuYcObjectIsLocked(*item, *isCollection, *isLocked, *isFrozen);
if (*isLocked || *isFrozen) {
break;
}
}
}
# \brief Adds an error to the dataset specified by *datasetId.
#
# \param[in] root
# \param[in] datasetId
# \param[in] message
#
uuYcDatasetErrorAdd(*root, *datasetId, *message) {
uuYcDatasetGetToplevelObjects(*root, *datasetId, *toplevelObjects, *isCollection);
foreach (*toplevel in *toplevelObjects) {
msiAddKeyVal(*kv, "dataset_error", "*message");
# note that we want to silently ignore any duplicates of the message (using errorcode)
errorcode(msiAssociateKeyValuePairsToObj(*kv, *toplevel, if *isCollection then "-C" else "-d"));
# This does not work for some reason.
#uuSetMetaData(
# *toplevel,
# "comment",
# *comment,
# if *isCollection then "-C" else "-d"
#);
}
}