Skip to content
Snippets Groups Projects
Commit f20ea50f authored by buczekp's avatar buczekp
Browse files

[LMS-1979] display sample's code in links; minor: code cleanup & documentation

SVN: 20276
parent 49a64df7
No related branches found
No related tags found
No related merge requests found
"""
Managed Property Script for handling plasmid parents of yeast samples.
@author: Piotr Buczek
"""
import re import re
""""space that all parents come from (fixed)""" """space that all parents come from (fixed)"""
SPACE = "YEAST_LAB" SPACE = "YEAST_LAB"
"""examples of input: FRP1 (DEL:URA3), FRP2 (INT), FRP3 (MOD:URA3), FRP4""" """input pattern matching one plasmid, e.g.:
- 'FRP1 (DEL:URA3)',
- 'FRP2 (INT)',
- 'FRP3(MOD:URA3)',
- 'FRP4'
"""
INPUT_PATTERN = """ INPUT_PATTERN = """
# no '^': allow whitespace at the beginning # no '^': allow whitespace at the beginning
([^ (]*) # 1st group: match code of a sample, everything before a space or '(' (e.g. 'FRP') ([^ (]*) # 1st group: match code of a sample, everything before a space or '(' (e.g. 'FRP')
...@@ -16,46 +27,82 @@ INPUT_PATTERN = """ ...@@ -16,46 +27,82 @@ INPUT_PATTERN = """
# no '$': allow whitespace at the end # no '$': allow whitespace at the end
""" """
"""tuple of supported relationship types as shortcuts"""
REL_TYPES = ('DEL', 'INT', 'MOD') REL_TYPES = ('DEL', 'INT', 'MOD')
"""dictionary from relationship type shortcut to its 'character' representation"""
REL_TYPE_CHARS = { REL_TYPE_CHARS = {
'DEL': 'd', 'DEL': '^',
'INT': '::', 'INT': '::',
'MOD': '_' 'MOD': '_'
} }
"""dictionary from relationship type shortcut to its full name/label"""
REL_TYPE_LABELS = { REL_TYPE_LABELS = {
'DEL': 'deletion', 'DEL': 'deletion',
'INT': 'integration', 'INT': 'integration',
'MOD': 'modification' 'MOD': 'modification'
} }
"""names of additional sample XML element attributes"""
ATR_CODE = "code" ATR_CODE = "code"
ATR_RELATIONSHIP = "rel" ATR_RELATIONSHIP = "rel"
ATR_ANNOTATION = "annotation" ATR_ANNOTATION = "annotation"
"""labels of table columns"""
CONNECTION_LABEL = "connection" CONNECTION_LABEL = "connection"
LINK_LABEL = "link" LINK_LABEL = "link"
CODE_LABEL = "code" CODE_LABEL = "code"
RELATIONSHIP_LABEL = "relationship" RELATIONSHIP_LABEL = "relationship"
ANNOTATION_LABEL = "annotation" ANNOTATION_LABEL = "annotation"
"""helper functions""" """helper functions"""
def _group(pattern, input): def _group(pattern, input):
"""@return: groups returned by performing pattern search with given @pattern on given @input"""
return pattern.search(input).groups() return pattern.search(input).groups()
def _translateToChar(relationship): def _translateToChar(relationship):
if relationship in REL_TYPE_CHARS: """
return REL_TYPE_CHARS[relationship] @param relationship: relationship type as a shortcut (@see REL_TYPES), may be null
@return: character representation of given @relationship,
empty string for null
'[<relationship>]' for unknown relationship
"""
if relationship:
if relationship in REL_TYPE_CHARS:
return REL_TYPE_CHARS[relationship]
else:
return "[" + relationship + "]"
else: else:
return "[" + relationship + "]" return ""
def _translateToLabel(relationship): def _translateToLabel(relationship):
if relationship in REL_TYPE_LABELS: """
return REL_TYPE_LABELS[relationship] @param relationship: relationship type as a shortcut (@see REL_TYPES), may be null
@return: full name of given @relationship,
empty string for null,
'[<relationship>]' for unknown relationship
"""
if relationship:
if relationship in REL_TYPE_LABELS:
return REL_TYPE_LABELS[relationship]
else:
return "[" + relationship + "]"
else: else:
return "[" + relationship + "]" return ""
def _createConnectionString(code, relationship, annotation): def _createConnectionString(code, relationship, annotation):
"""
@param code: code of a sample
@param relationship: relationship type as a shortcut (@see REL_TYPES), may be null
@param annotation: annotation of the relationship, may be null
@return: string representation of a connection with @relationship translated to a 'character'
"""
result = code result = code
if relationship: if relationship:
result += _translateToChar(relationship) result += _translateToChar(relationship)
...@@ -63,7 +110,25 @@ def _createConnectionString(code, relationship, annotation): ...@@ -63,7 +110,25 @@ def _createConnectionString(code, relationship, annotation):
result += annotation result += annotation
return result return result
def _createSampleLink(code, relationship, annotation): def _createSampleLink(code, relationship, annotation):
"""
Creates sample link XML element for sample with specified @code. The element will contain
given @code as 'code' attribute apart from standard 'permId' attribute. If specified
@relationship or @annotation are not null they will also be contained as attributes.
If the sample doesn't exist in DB a fake link will be created with @code as permId.
@param code: code of a sample
@param relationship: relationship type as a shortcut (@see REL_TYPES), may be null
@param annotation: annotation of the relationship, may be null
@return: sample link XML element as string, e.g.:
- '<Sample code="FRP1" permId="20110309154532868-4219"/>'
- '<Sample code="FRP2" permId="20110309154532868-4219" relationship="DEL" annotation="URA3"/>'
- '<Sample code="FAKE_SAMPLE_CODE" permId="FAKE_SAMPLE_CODE"/>
- '<Sample code="FRP4" permId="20110309154532868-4219" relationship="INT"/>'
@raise ValidationException: if the specified relationship type is unknown
"""
permId = entityInformationProvider().getSamplePermId(SPACE, code) permId = entityInformationProvider().getSamplePermId(SPACE, code)
if not permId: if not permId:
permId = code permId = code
...@@ -80,8 +145,9 @@ def _createSampleLink(code, relationship, annotation): ...@@ -80,8 +145,9 @@ def _createSampleLink(code, relationship, annotation):
sampleLink.addAttribute(ATR_ANNOTATION, annotation) sampleLink.addAttribute(ATR_ANNOTATION, annotation)
return sampleLink return sampleLink
""" """ MAIN FUNCTIONS """
Example input:
"""Example input:
FRP1 (DEL:URA3), FRP2 (INT), FRP3 (MOD:URA3), FRP4 FRP1 (DEL:URA3), FRP2 (INT), FRP3 (MOD:URA3), FRP4
...@@ -91,6 +157,7 @@ Relationship types: ...@@ -91,6 +157,7 @@ Relationship types:
- MOD: modification - MOD: modification
""" """
def updateFromBatchInput(bindings): def updateFromBatchInput(bindings):
inputPattern = re.compile(INPUT_PATTERN, re.VERBOSE) inputPattern = re.compile(INPUT_PATTERN, re.VERBOSE)
input = bindings.get('') input = bindings.get('')
plasmids = input.split(',') plasmids = input.split(',')
...@@ -101,8 +168,10 @@ def updateFromBatchInput(bindings): ...@@ -101,8 +168,10 @@ def updateFromBatchInput(bindings):
elements.append(sampleLink) elements.append(sampleLink)
property.value = propertyConverter().convertToString(elements) property.value = propertyConverter().convertToString(elements)
def configureUI(): def configureUI():
"""create table builder and add columns"""
"""Create table builder and add columns."""
tableBuilder = createTableBuilder() tableBuilder = createTableBuilder()
tableBuilder.addHeader(LINK_LABEL) tableBuilder.addHeader(LINK_LABEL)
tableBuilder.addHeader(CONNECTION_LABEL) tableBuilder.addHeader(CONNECTION_LABEL)
...@@ -119,12 +188,12 @@ def configureUI(): ...@@ -119,12 +188,12 @@ def configureUI():
row = tableBuilder.addRow() row = tableBuilder.addRow()
row.setCell(CONNECTION_LABEL, _createConnectionString(code, relationship, annotation)) row.setCell(CONNECTION_LABEL, _createConnectionString(code, relationship, annotation))
row.setCell(LINK_LABEL, plasmid) row.setCell(LINK_LABEL, plasmid, code)
row.setCell(CODE_LABEL, code) row.setCell(CODE_LABEL, code)
row.setCell(RELATIONSHIP_LABEL, relationship) row.setCell(RELATIONSHIP_LABEL, _translateToLabel(relationship))
row.setCell(ANNOTATION_LABEL, annotation) row.setCell(ANNOTATION_LABEL, annotation)
"""specify that the property should be shown in a tab and set the table output""" """Specify that the property should be shown in a tab and set the table output."""
property.setOwnTab(True) property.setOwnTab(True)
uiDesc = property.getUiDescription() uiDesc = property.getUiDescription()
uiDesc.useTableOutput(tableBuilder.getTableModel()) uiDesc.useTableOutput(tableBuilder.getTableModel())
\ No newline at end of file
"""
Managed Property Script for handling yeast parents of yeast samples.
@author: Piotr Buczek
"""
import re import re
""""space that all parents come from (fixed)""" """"space that all parents come from (fixed)"""
SPACE = "YEAST_LAB" SPACE = "YEAST_LAB"
"""code attribute name"""
ATR_CODE = "code" ATR_CODE = "code"
CONNECTION_LABEL = "connection" """labels of table columns"""
LINK_LABEL = "link" LINK_LABEL = "link"
CODE_LABEL = "code" CODE_LABEL = "code"
RELATIONSHIP_LABEL = "relationship"
ANNOTATION_LABEL = "annotation"
def _createSampleLink(code): def _createSampleLink(code):
"""
Creates sample link XML element for sample with specified 'code'. The element will contain
given code as 'code' attribute apart from standard 'permId' attribute.
If the sample doesn't exist in DB a fake link will be created with the 'code' as permId.
@return: sample link XML element as string, e.g.:
- '<Sample code="FRP1" permId="20110309154532868-4219"/>'
- '<Sample code="FAKE_SAMPLE_CODE" permId="FAKE_SAMPLE_CODE"/>
"""
permId = entityInformationProvider().getSamplePermId(SPACE, code) permId = entityInformationProvider().getSamplePermId(SPACE, code)
if not permId: if not permId:
permId = code permId = code
...@@ -19,6 +35,7 @@ def _createSampleLink(code): ...@@ -19,6 +35,7 @@ def _createSampleLink(code):
sampleLink.addAttribute(ATR_CODE, code) sampleLink.addAttribute(ATR_CODE, code)
return sampleLink return sampleLink
""" """
Example input: Example input:
...@@ -33,11 +50,13 @@ def updateFromBatchInput(bindings): ...@@ -33,11 +50,13 @@ def updateFromBatchInput(bindings):
elements.append(sampleLink) elements.append(sampleLink)
property.value = propertyConverter().convertToString(elements) property.value = propertyConverter().convertToString(elements)
def configureUI(): def configureUI():
"""create table builder and add columns"""
"""Create table builder and add columns."""
tableBuilder = createTableBuilder() tableBuilder = createTableBuilder()
tableBuilder.addHeader(LINK_LABEL) tableBuilder.addHeader(LINK_LABEL)
tableBuilder.addHeader(CODE_LABEL) tableBuilder.addHeader(CODE_LABEL, true)
"""The property value should contain XML with list of samples. Add a new row for every sample.""" """The property value should contain XML with list of samples. Add a new row for every sample."""
elements = list(propertyConverter().convertToElements(property)) elements = list(propertyConverter().convertToElements(property))
...@@ -45,10 +64,10 @@ def configureUI(): ...@@ -45,10 +64,10 @@ def configureUI():
code = plasmid.getAttribute(ATR_CODE, "") code = plasmid.getAttribute(ATR_CODE, "")
row = tableBuilder.addRow() row = tableBuilder.addRow()
row.setCell(LINK_LABEL, plasmid) row.setCell(LINK_LABEL, plasmid, code)
row.setCell(CODE_LABEL, code) row.setCell(CODE_LABEL, code)
"""specify that the property should be shown in a tab and set the table output""" """Specify that the property should be shown in a tab and set the table output."""
property.setOwnTab(True) property.setOwnTab(True)
uiDesc = property.getUiDescription() uiDesc = property.getUiDescription()
uiDesc.useTableOutput(tableBuilder.getTableModel()) uiDesc.useTableOutput(tableBuilder.getTableModel())
\ No newline at end of file
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment