Newer
Older
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
import sys
import re
"""debug sys path"""
#print(sys.path)
'''
FRP1 (DEL:URA3), FRP2 (INT), FRP3 (MOD:URA3), FRP4
Relationship types:
* DEL: deletion
* INT: integration
* MOD: modification
'''
""""space that all parents come from (fixed)"""
SPACE = "YEAST_LAB"
INPUT_PATTERN = """
# no '^': allow whitespace at the beginning
([^ (]*) # 1st group: match code of a sample, everything before a space or '(' (e.g. 'FRP')
(\ *\( # start of 2nd group (matches an optional relationship type with annotation)
# any spaces followed by a '('
([^:]*) # 3rd group: match relationship type, any character but ':' (e.g. 'DEL', 'INT', 'MOD')
:? # optional ':' separator
(.*) # 4th group: match annotation, any text (e.g. 'URA3')
\))? # end of 2nd (optional) group: closing bracket of relationship details
# no '$': allow whitespace at the end
"""
def group(pattern, input):
return pattern.search(input).groups()
EXAMPLES = [
'FRP1 (DEL:URA3)',
'FRP2 (INT)',
'FRP3 (MOD:URA3)',
'FRP4',
'FRPS5'
]
REL_TYPES = ('DEL', 'INT', 'MOD')
REL_TYPE_CHARS = {
'DEL': 'd',
'INT': '::',
'MOD': '_'
}
REL_TYPE_LABELS = {
'DEL': 'deletion',
'INT': 'integration',
'MOD': 'modification'
}
ATR_CODE = "code"
ATR_RELATIONSHIP = "rel"
ATR_ANNOTATION = "annotation"
"""helper functions"""
def translateToChar(relationship):
if relationship in REL_TYPE_CHARS:
return REL_TYPE_CHARS[relationship]
else:
return "[" + relationship + "]"
def createConnectionString(code, relationship, annotation):
result = code
if relationship:
result += translateToChar(relationship)
if annotation:
result += annotation
return result
def createSampleLink(code, relationship, annotation):
permId = entityInformationProvider().getSamplePermId(SPACE, code)
if not permId:
permId = code
sampleLink = elementFactory().createSampleLink(permId)
sampleLink.addAttribute(ATR_CODE, code)
if relationship:
sampleLink.addAttribute(ATR_RELATIONSHIP, relationship)
if relationship in REL_TYPES:
connectionString = createConnectionString(code, relationship, annotation)
else:
raise ValidationException("Unknown relationship: '" + relationship +
"'. Expected one of: " + REL_TYPES)
if annotation:
sampleLink.addAttribute(ATR_ANNOTATION, annotation)
return sampleLink
"""main functions"""
""" updateFromBatchInput """
def updateFromBatchInput(bindings):
inputPattern = re.compile(INPUT_PATTERN, re.VERBOSE)
input = bindings.get('')
plasmids = input.split(',')
elements = []
for p in plasmids:
(code, g, relationship, annotation) = group(inputPattern, p.strip())
sampleLink = createSampleLink(code, relationship, annotation)
elements.append(sampleLink)
property.value = propertyConverter().convertToString(elements)
""" configureUI """
CONNECTION_LABEL = "connection"
LINK_LABEL = "link"
CODE_LABEL = "code"
RELATIONSHIP_LABEL = "relationship"
ANNOTATION_LABEL = "annotation"
def configureUI():
inputPattern = re.compile(INPUT_PATTERN, re.VERBOSE)
"""create table builder and add columns"""
tableBuilder = createTableBuilder()
tableBuilder.addHeader(CONNECTION_LABEL)
tableBuilder.addHeader(LINK_LABEL)
tableBuilder.addHeader(CODE_LABEL)
tableBuilder.addHeader(RELATIONSHIP_LABEL)
tableBuilder.addHeader(ANNOTATION_LABEL)
"""The property value should contain XML with list of sample. Add a new row for every sample."""
elements = list(propertyConverter().convertToElements(property))
for plasmid in elements:
permId = plasmid.getPermId()
code = plasmid.getAttribute(ATR_CODE, "")
relationship = plasmid.getAttribute(ATR_RELATIONSHIP, "")
code = plasmid.getAttribute(ATR_CODE, "")
annotation = plasmid.getAttribute(ATR_ANNOTATION, "")
row = tableBuilder.addRow()
row.setCell(CONNECTION_LABEL, createConnectionString(code, relationship, annotation))
row.setCell(LINK_LABEL, plasmid)
row.setCell(CODE_LABEL, code)
row.setCell(RELATIONSHIP_LABEL, relationship)
row.setCell(ANNOTATION_LABEL, annotation)
"""specify that the property should be shown in a tab and set the table output"""
property.setOwnTab(True)
uiDesc = property.getUiDescription()
uiDesc.useTableOutput(tableBuilder.getTableModel())