From 28486e02064b6eeac4aa0a25f498e8849fb55b19 Mon Sep 17 00:00:00 2001
From: buczekp <buczekp>
Date: Wed, 9 Mar 2011 14:34:47 +0000
Subject: [PATCH] [LMS-1979] cleanup and new script for yeast parents

SVN: 20270
---
 .../jython-scripts/MP-plasmid_parents.py      | 83 ++++++++-----------
 .../jython-scripts/MP-yeast_parents.py        | 55 ++++++++++++
 2 files changed, 89 insertions(+), 49 deletions(-)
 create mode 100644 plasmid/resource/jython-scripts/MP-yeast_parents.py

diff --git a/plasmid/resource/jython-scripts/MP-plasmid_parents.py b/plasmid/resource/jython-scripts/MP-plasmid_parents.py
index c100ebe57e2..0aa98dd95d4 100644
--- a/plasmid/resource/jython-scripts/MP-plasmid_parents.py
+++ b/plasmid/resource/jython-scripts/MP-plasmid_parents.py
@@ -1,22 +1,9 @@
-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"
 
+"""examples of input: FRP1 (DEL:URA3), FRP2 (INT), FRP3 (MOD:URA3), FRP4"""
 INPUT_PATTERN = """
                  # no '^': allow whitespace at the beginning
     ([^ (]*)     # 1st group: match code of a sample, everything before a space or '(' (e.g. 'FRP')
@@ -29,17 +16,6 @@ INPUT_PATTERN = """
                  # 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', 
@@ -56,23 +32,38 @@ ATR_CODE = "code"
 ATR_RELATIONSHIP = "rel"
 ATR_ANNOTATION = "annotation"
 
+CONNECTION_LABEL = "connection"
+LINK_LABEL = "link"
+CODE_LABEL = "code"
+RELATIONSHIP_LABEL = "relationship"
+ANNOTATION_LABEL = "annotation"
+
 """helper functions"""
 
-def translateToChar(relationship):
+def _group(pattern, input):
+    return pattern.search(input).groups()
+
+def _translateToChar(relationship):
     if relationship in REL_TYPE_CHARS:
         return REL_TYPE_CHARS[relationship]
     else:
         return "[" + relationship + "]"
+    
+def _translateToLabel(relationship):
+    if relationship in REL_TYPE_LABELS:
+        return REL_TYPE_LABELS[relationship]
+    else:
+        return "[" + relationship + "]"    
 
-def createConnectionString(code, relationship, annotation):
+def _createConnectionString(code, relationship, annotation):
     result = code
     if relationship:
-        result += translateToChar(relationship)
+        result += _translateToChar(relationship)
     if annotation:
         result += annotation
     return result
 
-def createSampleLink(code, relationship, annotation):
+def _createSampleLink(code, relationship, annotation):
     permId = entityInformationProvider().getSamplePermId(SPACE, code)
     if not permId:
         permId = code
@@ -81,40 +72,36 @@ def createSampleLink(code, relationship, annotation):
     if relationship:
         sampleLink.addAttribute(ATR_RELATIONSHIP, relationship)
         if relationship in REL_TYPES:
-            connectionString = createConnectionString(code, relationship, annotation)
+            connectionString = _createConnectionString(code, relationship, annotation)
         else:
             raise ValidationException("Unknown relationship: '" + relationship + 
-                                     "'. Expected one of: " + REL_TYPES)
+                                      "'. Expected one of: " + REL_TYPES)
     if annotation:
         sampleLink.addAttribute(ATR_ANNOTATION, annotation)
     return sampleLink    
 
-"""main functions"""
+"""
+Example input:
 
-""" updateFromBatchInput """
+FRP1 (DEL:URA3), FRP2 (INT), FRP3 (MOD:URA3), FRP4
 
+Relationship types:
+- DEL: deletion
+- INT: integration
+- MOD: modification
+"""
 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)
+        (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)
@@ -123,17 +110,15 @@ def configureUI():
     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."""
+    """The property value should contain XML with list of samples. 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(CONNECTION_LABEL, _createConnectionString(code, relationship, annotation))
         row.setCell(LINK_LABEL, plasmid)
         row.setCell(CODE_LABEL, code)
         row.setCell(RELATIONSHIP_LABEL, relationship)
diff --git a/plasmid/resource/jython-scripts/MP-yeast_parents.py b/plasmid/resource/jython-scripts/MP-yeast_parents.py
new file mode 100644
index 00000000000..3ce90e5fdf5
--- /dev/null
+++ b/plasmid/resource/jython-scripts/MP-yeast_parents.py
@@ -0,0 +1,55 @@
+import re
+
+""""space that all parents come from (fixed)"""
+SPACE = "YEAST_LAB"
+
+ATR_CODE = "code"
+
+CONNECTION_LABEL = "connection"
+LINK_LABEL = "link"
+CODE_LABEL = "code"
+RELATIONSHIP_LABEL = "relationship"
+ANNOTATION_LABEL = "annotation"
+
+def _createSampleLink(code):
+    permId = entityInformationProvider().getSamplePermId(SPACE, code)
+    if not permId:
+        permId = code
+    sampleLink = elementFactory().createSampleLink(permId)
+    sampleLink.addAttribute(ATR_CODE, code)
+    return sampleLink    
+
+
+"""
+Example input:
+
+FRY1, FRY2, FRY3, FRY4
+"""
+def updateFromBatchInput(bindings):
+    input = bindings.get('')
+    samples = input.split(',')
+    elements = []
+    for p in samples:
+        sampleLink = createSampleLink(code)
+        elements.append(sampleLink)
+    property.value = propertyConverter().convertToString(elements)
+
+def configureUI():
+    """create table builder and add columns"""
+    tableBuilder = createTableBuilder()
+    tableBuilder.addHeader(LINK_LABEL)
+    tableBuilder.addHeader(CODE_LABEL)
+
+    """The property value should contain XML with list of samples. Add a new row for every sample."""
+    elements = list(propertyConverter().convertToElements(property))
+    for plasmid in elements:
+        code = plasmid.getAttribute(ATR_CODE, "")
+   
+        row = tableBuilder.addRow()
+        row.setCell(LINK_LABEL, plasmid)
+        row.setCell(CODE_LABEL, code)
+        
+    """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
-- 
GitLab