From d70b08e1b9752e8e2d1c8a04884f107d2628f54a Mon Sep 17 00:00:00 2001
From: kohleman <kohleman>
Date: Wed, 14 Mar 2012 10:57:23 +0000
Subject: [PATCH] added the split of run statistics which is put into a
 separate drop box

SVN: 24723
---
 .../dist/etc/data-set-handler-cell.py         | 80 +++++++++++++++++--
 1 file changed, 73 insertions(+), 7 deletions(-)

diff --git a/deep_sequencing_unit/dist/etc/data-set-handler-cell.py b/deep_sequencing_unit/dist/etc/data-set-handler-cell.py
index 64156443ea8..c128eba34f5 100755
--- a/deep_sequencing_unit/dist/etc/data-set-handler-cell.py
+++ b/deep_sequencing_unit/dist/etc/data-set-handler-cell.py
@@ -1,12 +1,57 @@
 '''
+expected incoming Name for HiSeq2000 runs: 110715_SN792_0054_BC035RACXX
+expected incoming Name for GAII runs: 110812_6353WAAXX
 
 Note: 
 print statements go to: ~openbis/sprint/datastore_server/log/startup_log.txt
 '''
 
 import os
+import shutil
+import glob
+import xml.etree.ElementTree as etree
 from ch.systemsx.cisd.openbis.generic.shared.api.v1.dto import SearchCriteria
 
+IS_HISEQ_RUN=False
+RUNPARAMETERS = 'runParameters.xml'
+XML_ELEMENTS = {'FLOWCELL': 'Flowcell', 'RTAVERSION': 'RTAVersion',
+  'CONTROLLANE': 'ControlLane', 'SBS': 'Sbs', 'INDEX': 'Index'}
+
+RUNINFO_FOLDER='/links/shared/dsu-dss/dss/incoming-jython-runinfostatistics/'
+REGEX_RUNINFO_SAMPLE = '/Data/Status*'
+REGEX_RUNINFO_REPORTS = '/Data/reports'
+MARKER_STRING='.MARKER_is_finished_'
+
+
+def parseXml(xmlFile):
+  '''
+  Parses an XML file and returns the root leaf  
+  '''
+  tree = etree.parse(xmlFile)
+  root = tree.getroot()
+  return root
+
+
+def getXmlElement (elementName):
+  '''
+  Returns the text value of a given XML element
+  '''
+  for e in root.getchildren():
+    element = e.find(elementName)
+    if element is None:
+      return 'None'
+    else:
+      print(element.text)
+      return element.text
+
+def touch_markerfile(filename):
+  try:
+    # do a touch
+    open(filename, 'w').close()
+  except:
+    print('Could not touch ' + filename)
+
+
 # Create a "transaction" -- a way of grouping operations together so they all
 # happen or none of them do.
 transaction = service.transaction()
@@ -17,28 +62,49 @@ folders=os.listdir(incomingPath)
 
 # Get the incoming name 
 name = incoming.getName()
-# expected incoming Name for HiSeq2000 runs: 110715_SN792_0054_BC035RACXX
-# expected incoming Name for GAII runs: 110812_6353WAAXX
 
 split=name.split("_")
 if (len(split) == 4):
   dataSet = transaction.createNewDataSet("ILLUMINA_HISEQ_OUTPUT")
-if (len(split) ==2):
+  IS_HISEQ_RUN=True
+if (len(split) == 2):
   dataSet = transaction.createNewDataSet("ILLUMINA_GA_OUTPUT")
 
+#move RunInfo into a different drop box
+runInfoSample=glob.glob(incomingPath + REGEX_RUNINFO_SAMPLE)
+runInfoReport=glob.glob(incomingPath + REGEX_RUNINFO_REPORTS)
+runInfoList = runInfoSample + runInfoReport
+for runInfo in runInfoList:
+  try:
+    if os.path.isdir(runInfo):
+      shutil.copytree(runInfo, RUNINFO_FOLDER + name + '/Data/' + os.path.basename(runInfo))
+    else:
+      shutil.copy2(runInfo, RUNINFO_FOLDER + name + '/Data/')
+  except (IOError, os.error), why:
+    print (runInfo, RUNINFO_FOLDER + name, str(why))
+
+touch_markerfile(RUNINFO_FOLDER+MARKER_STRING+name)
+
 # Create a data set and set type
 dataSet.setMeasuredData(False)
-
+  
 # Get the search service
 search_service = transaction.getSearchService()
  
-# Add the incoming file into the data set
-transaction.moveFile(incomingPath, dataSet)
-  
 # Search for the sample
 sc = SearchCriteria()
 sc.addMatchClause(SearchCriteria.MatchClause.createAttributeMatch(SearchCriteria.MatchClauseAttribute.CODE, name));
 foundSamples = search_service.searchForSamples(sc)
 
 if foundSamples.size() > 0:
+  if IS_HISEQ_RUN:
+    sa = transaction.getSampleForUpdate(foundSamples[0].getSampleIdentifier())
+    root = parseXml(incomingPath + '/' + RUNPARAMETERS)
+#    sa.setPropertyValue("ILLUMINA_PIPELINE_VERSION", getXmlElement(XML_ELEMENTS['RTAVERSION']))
+#    sa.setPropertyValue("FLOWCELLTYPE", getXmlElement(XML_ELEMENTS['FLOWCELL']))
+#    sa.setPropertyValue("CONTROL_LANE", getXmlElement(XML_ELEMENTS['CONTROLLANE']))
+  
+  # Add the incoming file into the data set
+  transaction.moveFile(incomingPath, dataSet)
+  
   dataSet.setSample(foundSamples[0])
-- 
GitLab