From 4531d28ba7b4e77ed00f53726f4a2603f102d2c3 Mon Sep 17 00:00:00 2001 From: kohleman <kohleman> Date: Tue, 19 Feb 2013 14:02:29 +0000 Subject: [PATCH] - added Space per Excel Sheet - Sort the sample (by key=int) within a flow lane SVN: 28396 --- .../dist/etc/service.properties | 1 + .../Jython/create_QGF_Invoices_simplified.py | 25 ++++++++++++------- 2 files changed, 17 insertions(+), 9 deletions(-) diff --git a/deep_sequencing_unit/createInvoices/dist/etc/service.properties b/deep_sequencing_unit/createInvoices/dist/etc/service.properties index 4df364bd855..9420d088eeb 100644 --- a/deep_sequencing_unit/createInvoices/dist/etc/service.properties +++ b/deep_sequencing_unit/createInvoices/dist/etc/service.properties @@ -15,6 +15,7 @@ openbisUserName = <username> openbisPassword = <password> connectionTimeout = 5000 principalInvestigator = PRINCIPAL_INVESTIGATOR +sampleCodePrefix = BSSE-QGF- [EXCEL] defaultFonts = Calibri diff --git a/deep_sequencing_unit/source/Jython/create_QGF_Invoices_simplified.py b/deep_sequencing_unit/source/Jython/create_QGF_Invoices_simplified.py index 49e7933cea2..da5ce6ce54a 100644 --- a/deep_sequencing_unit/source/Jython/create_QGF_Invoices_simplified.py +++ b/deep_sequencing_unit/source/Jython/create_QGF_Invoices_simplified.py @@ -115,12 +115,11 @@ def getVocabulary(service, vocabularyCode): vocabularyMap[term.getCode()] = term.getLabel() return vocabularyMap -def writeExcel(myoptions, configMap, service, piName, laneDict, sampleDict, piDict, +def writeExcel(myoptions, configMap, service, piName, laneDict, sampleDict, piDict, piSpace, flowCellProperties, flowcellName, format="xls"): ''' Writes out all data to an Excel file ''' - myRows = uniqueRow() sequencerVocabulary = getVocabulary(service, "SEQUENCER") setOfFlowcells = set () @@ -161,7 +160,7 @@ def writeExcel(myoptions, configMap, service, piName, laneDict, sampleDict, piDi writeHeader() createRow("Principal Investigator", piName) - + createRow("Data Space", piSpace) createRow("Run Folder Name", flowcellName) createRow() @@ -179,11 +178,13 @@ def writeExcel(myoptions, configMap, service, piName, laneDict, sampleDict, piDi listofLanes = piDict[piName] for lane in listofLanes: singleSampleColumns = uniqueColumn() - for sample in sampleDict[lane].keys(): + + # sort the dictionary by keys and taking the key as an integer + for sample in sorted(sampleDict[lane].iterkeys(), key=int): rowN = sheet.createRow(myRows.getNextRow()) rowN.createCell(singleSampleColumns.getNextColumn()).setCellValue(flowcellName + ":" + str(lane)) rowN.getCell(singleSampleColumns.getCurrentColumn()).setCellStyle(setFont(wb, configMap, 10)) - rowN.createCell(singleSampleColumns.getNextColumn()).setCellValue(sample) + rowN.createCell(singleSampleColumns.getNextColumn()).setCellValue(configMap['sampleCodePrefix'] + sample) rowN.getCell(singleSampleColumns.getCurrentColumn()).setCellStyle(setFont(wb, configMap, 10)) sampleValues = sampleDict[lane][sample] @@ -220,6 +221,7 @@ def writeExcel(myoptions, configMap, service, piName, laneDict, sampleDict, piDi fileName = myoptions.outdir + configMap["facilityNameShort"] + "_" + flowcell + "_" + \ sanitizeString(piName) + datetime.now().strftime("_%d_%m_%Y.") + format fileOut = FileOutputStream(fileName) + # need this print for use as an openBIS webapp print fileName wb.write(fileOut); @@ -270,6 +272,7 @@ def readConfig(logger): configMap['openbisServer'] = configParameters.get(OPENBIS, 'openbisServer') configMap['connectionTimeout'] = configParameters.getint(OPENBIS, 'connectionTimeout') configMap['pIPropertyName'] = configParameters.get(OPENBIS, 'pIPropertyName') + configMap['sampleCodePrefix'] = configParameters.get(OPENBIS, 'sampleCodePrefix') configMap['defaultFonts'] = configParameters.get(EXCEL, 'defaultFonts') @@ -329,6 +332,7 @@ def getFLowcellData(service, configMap, flowcell, logger): laneDict = {} sampleDict = {} piDict = {} + spaceDict = {} for lane in range(1, numberOfLanes + 1): myLane = flowcell + ":" + str(lane) @@ -345,7 +349,7 @@ def getFLowcellData(service, configMap, flowcell, logger): for samples in laneParents: sampleCode = samples.getCode() sampleProperties = samples.getProperties() - s[sampleCode] = sampleProperties + s[sampleCode.split("-")[-1]] = sampleProperties sampleDict[lane] = s pi = sampleProperties[configMap["pIPropertyName"]] @@ -354,12 +358,15 @@ def getFLowcellData(service, configMap, flowcell, logger): else: piDict[pi] = [lane] + spaceDict[pi] = l.getSpaceCode() + + logger.info("Found the following PIs on the lanes: ") logger.info(piDict) # simply sort the hashmap treeMap = TreeMap (flowCellProperties) - return laneDict, sampleDict, piDict, treeMap + return laneDict, sampleDict, piDict, treeMap, spaceDict ''' @@ -379,11 +386,11 @@ def main(): service = login(logger, configMap) flowcellName = myoptions.flowcell - laneDict, sampleDict, piDict, flowCellProperties = getFLowcellData(service, configMap, flowcellName, logger) + laneDict, sampleDict, piDict, flowCellProperties, spaceDict = getFLowcellData(service, configMap, flowcellName, logger) for piName in piDict: # create an Excel file for each PI - writeExcel(myoptions, configMap, service, piName, laneDict, sampleDict, piDict, + writeExcel(myoptions, configMap, service, piName, laneDict, sampleDict, piDict, spaceDict[piName], flowCellProperties, flowcellName, format) service.logout() -- GitLab