Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
O
openbis
Manage
Activity
Members
Labels
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Model registry
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
sispub
openbis
Commits
cf9d73c8
Commit
cf9d73c8
authored
14 years ago
by
buczekp
Browse files
Options
Downloads
Patches
Plain Diff
[LMS-1979] first version of the script for plasmid parents property
SVN: 20268
parent
1fa5a3a3
No related branches found
No related tags found
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
plasmid/resource/jython-scripts/MP-plasmid_parents.py
+145
-0
145 additions, 0 deletions
plasmid/resource/jython-scripts/MP-plasmid_parents.py
with
145 additions
and
0 deletions
plasmid/resource/jython-scripts/MP-plasmid_parents.py
0 → 100644
+
145
−
0
View file @
cf9d73c8
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
())
\ No newline at end of file
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment