From 6efd9cedb0c30bd60b75dbd418c5f5930a4d3691 Mon Sep 17 00:00:00 2001
From: kohleman <kohleman>
Date: Thu, 14 Jun 2012 08:17:58 +0000
Subject: [PATCH] used as a 'Script' and Dynamic property within QGF

SVN: 25688
---
 .../source/Jython/barcodeCecker.py            | 62 +++++++++++++++++++
 1 file changed, 62 insertions(+)
 create mode 100644 deep_sequencing_unit/source/Jython/barcodeCecker.py

diff --git a/deep_sequencing_unit/source/Jython/barcodeCecker.py b/deep_sequencing_unit/source/Jython/barcodeCecker.py
new file mode 100644
index 00000000000..d44c5aafc9c
--- /dev/null
+++ b/deep_sequencing_unit/source/Jython/barcodeCecker.py
@@ -0,0 +1,62 @@
+def checkBarcodes():
+  '''
+  'parents' are a HashSet of SamplePropertyPE
+  ''' 
+  VOCABULARY_INDEX1 = 'BARCODE'
+  VOCABULARY_INDEX2 = 'INDEX2'
+
+  RED = set(['A', 'C'])
+  GREEN = set(['T', 'G'])
+
+  SUCCESS_MESSAGE = "OK"
+  NO_INDEX = "No Index"
+  
+  listofIndices = []
+  boolList = []
+  positionList = []
+  returnString = " "
+
+  for e in entity.entityPE().parents:
+    for s in e.properties:
+      if s.entityTypePropertyType.propertyType.simpleCode == VOCABULARY_INDEX1:
+        index = s.getVocabularyTerm().code
+
+        if len(listofIndices) > 0:
+          for n in range(0, len(index) - 1):
+            listofIndices[n].append(index[n])
+        else:
+          for n in range(0, len(index) - 1):
+            listofIndices.append([index[n]])
+       
+      # remove any duplicates   
+      setofIndices = [set(list) for list in listofIndices]    
+ 
+      # Test whether every element in the set 's' is in the RED set
+      boolList = [setofNuc.issubset(RED) for setofNuc in setofIndices]
+
+  if boolList:
+    for b in boolList:
+      if b:
+        positionList.append(boolList.index(b) + 1)
+        # set the value to False, because 'index' returns only the first occurrence
+        boolList[boolList.index(b)] = False
+  else:
+   return NO_INDEX
+
+    #  if s.entityTypePropertyType.propertyType.simpleCode == VOCABULARY_INDEX2:
+    #   pass 
+
+  if positionList:
+    for pos in positionList:
+      returnString += "WARNING! The following base position of " + \
+                         VOCABULARY_INDEX1 + \
+                         " does not have both color channels the index read: " + str(pos) + \
+                         "\n" 
+  else:
+    returnString = SUCCESS_MESSAGE
+
+  return returnString
+
+def calculate(): 
+    """Main script function. The result will be used as the value of appropriate dynamic property."""
+    return checkBarcodes()
-- 
GitLab