コード例 #1
0
    def updateAttribute(self, form):
        db = self.__db
        cursor = self.__cursor
        hostname = self.__hostname

        lHandler = LocationHandler(db, cursor)
        prepPropMapper = PrepPropertyMapper(db, cursor)
        prepProp_Name_ID_Map = prepPropMapper.mapPrepPropNameToID()

        #print "Content-type:text/html"

        # Update the given attribute for each well selected
        wells_str = form.getvalue(
            "wells")  # it's a comma-delimited string, count as one value

        contID = int(form.getvalue("contID"))
        propName = form.getvalue("propName")
        propVal = form.getvalue("propVal")

        if prepProp_Name_ID_Map.has_key(propName):
            prepElemID = prepProp_Name_ID_Map[propName]
        else:
            prepElemID = 0
        '''
		if form.has_key("propID"):
			try:
				prepElemID = int(form.getvalue("propID"))

			except ValueError:
				prepElemID = 0
		'''

        # wells are provided as a comma-delimited list of 'row|col' values
        wells = wells_str.split(",")

        for well in wells:
            coords = well.split('|')

            wellRow = coords[0]
            wellCol = coords[1]

            wellID = lHandler.findWellIDByCoordinates(contID, wellRow, wellCol)
            #print wellID

            # get its prep
            prepID = lHandler.findPrepIDInWell(wellID)

            # Differentiate between update of prep element or reference/comments
            if prepElemID > 0:
                lHandler.updatePrepPropertyValue(prepID, prepElemID, propVal)
            else:
                if propName.lower() == 'reference':
                    lHandler.updatePrepReference(prepID, propVal)

                elif propName.lower() == 'comments':
                    lHandler.updatePrepComments(prepID, propVal)

        #utils.redirect(hostname + "Location.php?View=2&Mod=" + `contID`)
        print hostname + "Location.php?View=2&Mod=" + ` contID `
コード例 #2
0
    def exportPlate(self, form):
        db = self.__db
        cursor = self.__cursor
        hostname = self.__hostname

        lHandler = LocationHandler(db, cursor)
        ltHandler = LocationTypeHandler(db, cursor)
        rHandler = ReagentHandler(db, cursor)

        prepPropMapper = PrepPropertyMapper(db, cursor)
        cTypeMapper = ContainerTypeMapper(db, cursor)

        prepProp_Name_ID_Map = prepPropMapper.mapPrepPropNameToID()
        prepProp_ID_Name_Map = prepPropMapper.mapPrepPropIDToName()

        contType_Name_ID_Map = cTypeMapper.mapContainerTypeNameToID()

        contID = int(form.getvalue("contID"))
        contName = lHandler.findContainerName(contID)
        contArray = contName.split(" ")
        fname = string.join(contArray, "_") + ".csv"

        wells = lHandler.findContainerWells(contID)
        content = ""

        # debug
        #print "Content-type:text/html"
        #print

        contType = lHandler.findContainerType(contID)
        contTypeID = contType_Name_ID_Map[contType]
        contProps = ltHandler.findContainerTypeProperties(
            contTypeID)  # array of names

        iso_active = ltHandler.isIsoActive(contTypeID)

        if iso_active == 'YES':
            isoActive = True
        else:
            isoActive = False

        #print `contProps`

        # Header
        if isoActive:
            content = "Well,OpenFreezer ID,Selected Isolate,Flag,Reference,Comments,"
        else:
            content = "Well,OpenFreezer ID,Flag,Reference,Comments,"

        contPropIDs_sorted = []

        for cPropName in contProps:
            cPropID = prepProp_Name_ID_Map[cPropName]
            contPropIDs_sorted.append(cPropID)

        contPropIDs_sorted.sort()

        for cPropID in contPropIDs_sorted:
            cPropName = prepProp_ID_Name_Map[cPropID]
            content += cPropName + ','

        content += '\n'

        numRows = lHandler.getNumRows(contID)
        numCols = lHandler.getNumCols(contID)

        plate = {}

        for well in wells:
            wellRowNum = well.getWellRowNumber()
            #print wellRowNum

            if plate.has_key(wellRowNum):
                plate[wellRowNum].append(well)
            else:
                tmp_ar = []
                tmp_ar.append(well)
                plate[wellRowNum] = tmp_ar

        plate.keys().sort()

        for rowNum in range(1, numRows + 1):
            if plate.has_key(rowNum):
                wellRow = plate[rowNum]
                wellRowNum = rowNum
                wellRowLetter = Well.convertRowNumberToChar(wellRowNum)

                wellRow.sort()

                #print "ROW " + `rowNum`

                for colNum in range(1, numCols + 1):
                    for well in wellRow:
                        wellID = well.getWellID()
                        #print wellID
                        wellCol = well.getWellColumn()

                        if wellCol == colNum:

                            #print "COLUMN " + `wellCol`

                            wellCoords = wellRowLetter + ":" + ` wellCol `

                            # get prep, reference, comments, flag
                            prepID = lHandler.findPrepIDInWell(wellID)
                            #print prepID
                            prepRef = lHandler.findPrepReference(prepID)
                            #print prepRef

                            if not prepRef:
                                prepRef = ""

                            prepComms = lHandler.findPrepComments(prepID)
                            #print prepComms

                            if not prepComms:
                                prepComms = ""

                            prepFlag = lHandler.findPrepFlag(prepID)
                            #print prepFlag

                            # get isolate number, selected isolate
                            isoID = lHandler.findPrepIsolateID(prepID)
                            isoNum = lHandler.findIsolateNumber(isoID)
                            isoSelected = lHandler.isSelectedIsolate(isoID)

                            # get prep property values
                            prepPropValues = lHandler.findAllPrepProperties(
                                prepID)

                            # find the LIMS ID of the reagent stored in this well
                            expID = lHandler.findExperimentIDByIsolate(isoID)
                            rID = lHandler.findReagentIDByExperiment(expID)
                            limsID = rHandler.convertDatabaseToReagentID(rID)

                            # Output: Well , Reagent-isolate , Selected , Flag , Reference , Comments , Attributes [name1 , name2 , name3....]
                            if isoActive:
                                content += wellCoords + ',' + limsID + "-" + ` isoNum ` + ',' + isoSelected + ',' + prepFlag + ',' + prepRef + ',' + prepComms + ","
                            else:
                                content += wellCoords + ',' + limsID + ',' + prepFlag + ',' + prepRef + ',' + prepComms + ","

                            prepPropIDs_sorted = {}

                            prepProps = {}

                            for pProp in prepPropValues:
                                pName = pProp.getPropName()
                                pVal = pProp.getPropValue()
                                prepProps[pName] = pVal

                            prepProps.keys().sort(
                            )  # might not be necessary but still

                            for cPropID in contPropIDs_sorted:
                                cPropName = prepProp_ID_Name_Map[cPropID]

                                if prepProps.has_key(cPropName):
                                    pVal = prepProps[cPropName]
                                    content += pVal + ','
                                else:
                                    content += ','

                            content += '\n'

        print "Content-type: application/octet-stream"
        print "Content-Disposition: attachment; name=" + fname
        print

        print content