예제 #1
0
	def findWellCoordinates(self, wellID):
		db = self.db
		cursor = self.cursor	# for easy access

		wellRowNum = self.findWellRowNumber(wellID)
		wellCol = self.findWellColumn(wellID)
		wellRowLetter = Well.convertRowNumberToChar(wellRowNum)
		wellCoords = wellRowLetter + ":" + `wellCol`

		return wellCoords
예제 #2
0
	def findContainerWells(self, contID):
		db = self.db
		cursor = self.cursor	# for easy access

		wells = []
		
		cursor.execute("SELECT wellID, wellRow, wellCol FROM Wells_tbl WHERE containerID=" + `contID` + " AND status='ACTIVE'")
		results = cursor.fetchall()

		for result in results:
			wellID = int(result[0])
			wellRow = int(result[1])
			wellCol = int(result[2])

			tmpWell = Well(wellID, wellRow, wellCol, contID)
			wells.append(tmpWell)

		return wells
예제 #3
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