Example #1
0
def rMap_full(f_in, f_out):
	
	# Database connection parameters
	dbConn = DatabaseConn()
	db = dbConn.databaseConnect()
	cursor = db.cursor()

	gHandler = GeneralHandler(db, cursor)
	rHandler = ReagentHandler(db, cursor)
	seqHandler = SequenceHandler(db, cursor)

	infile = open(f_in, 'r')
	outfile = open(f_out, 'w')
	
	for line in infile.readlines():
		reagentID = line.strip()	# e.g. V123
		
		rID = rHandler.convertReagentToDatabaseID(reagentID)
		seqID = rHandler.findDNASequenceKey(rID)
		
		if seqID:
			mySeq = seqHandler.findSequenceByID(seqID)

                	# Construct a Seq object readable by BioPython:
			bioSeq = Seq(mySeq)
			fSeq = FormattedSeq(bioSeq)             # default linear = TRUE

			analysis = Analysis(AllEnzymes, fSeq)   # linear = true
			result = analysis.full()
			header = "==============================================\nRestriction analysis for " + reagentID + "\n==============================================\n"
			analysis.print_that(title=header+'\n\n')
Example #2
0
def rMap_full(f_in, f_out):

    # Database connection parameters
    dbConn = DatabaseConn()
    db = dbConn.databaseConnect()
    cursor = db.cursor()

    gHandler = GeneralHandler(db, cursor)
    rHandler = ReagentHandler(db, cursor)
    seqHandler = SequenceHandler(db, cursor)

    infile = open(f_in, 'r')
    outfile = open(f_out, 'w')

    for line in infile.readlines():
        reagentID = line.strip()  # e.g. V123

        rID = rHandler.convertReagentToDatabaseID(reagentID)
        seqID = rHandler.findDNASequenceKey(rID)

        if seqID:
            mySeq = seqHandler.findSequenceByID(seqID)

            # Construct a Seq object readable by BioPython:
            bioSeq = Seq(mySeq)
            fSeq = FormattedSeq(bioSeq)  # default linear = TRUE

            analysis = Analysis(AllEnzymes, fSeq)  # linear = true
            result = analysis.full()
            header = "==============================================\nRestriction analysis for " + reagentID + "\n==============================================\n"
            analysis.print_that(title=header + '\n\n')
Example #3
0
    def validateReagentID(self, form):
        db = self.__db
        cursor = self.__cursor
        hostname = self.__hostname

        rHandler = ReagentHandler(db, cursor)

        print "Content-type:text/html"
        print

        tmp_rids = form.getlist("rID")
        #tmp_rid = form.getvalue("rID").strip()
        #print `tmp_rids`

        for tmp_rid in tmp_rids:
            try:
                tmpReagentID = rHandler.convertReagentToDatabaseID(
                    tmp_rid.strip())
            except ReagentDoesNotExistException:
                i = ReagentDoesNotExistException(
                    "Reagent does not exist in database")
                print "ErrCode=" + ` i.err_code() ` + "&rID=" + tmp_rid
                break
Example #4
0
def preview():
	dbConn = DatabaseConn()
	db = dbConn.databaseConnect()
	
	cursor = db.cursor()
	hostname = dbConn.getHostname()

	rHandler = ReagentHandler(db, cursor)
	propMapper = ReagentPropertyMapper(db, cursor)
	
	prop_Alias_ID_Map = propMapper.mapPropAliasID()
	
	form = cgi.FieldStorage(keep_blank_values="True")

	#print "Content-type:text/html"		# REMOVE AFTER DEBUGGING TO HAVE SCRIPT REDIRECT PROPERLY!!!!!!
	#print					# DITTO
	#print `form`
	
	propVal = ""
	
	if form.has_key("PV"):
		pvVal = form.getvalue("PV")
		pvID = rHandler.convertReagentToDatabaseID(pvVal)
		
	if form.has_key("propAlias"):
		propAlias = form.getvalue("propAlias")
	
	
	if prop_Alias_ID_Map.has_key(propAlias):
		propID = prop_Alias_ID_Map[propAlias]	
		propVal = rHandler.findSimplePropertyValue(pvID, propID)
		
	
	print "Content-type:text/html"		# REMOVE AFTER DEBUGGING TO HAVE SCRIPT REDIRECT PROPERLY!!!!!!
	print					# DITTO
	print propVal
Example #5
0
def rMap_specific(f_in, f_out, enz_list):
	
	# Database connection parameters
	dbConn = DatabaseConn()
	db = dbConn.databaseConnect()
	cursor = db.cursor()
	
	gHandler = GeneralHandler(db, cursor)
	rHandler = ReagentHandler(db, cursor)
	seqHandler = SequenceHandler(db, cursor)

	infile = open(f_in, 'r')
	outfile = open(f_out, 'w')	

	for line in infile.readlines():
		reagentID = line.strip()	# e.g. V123
		rID = rHandler.convertReagentToDatabaseID(reagentID)
		seqID = rHandler.findDNASequenceKey(rID)

		if seqID:
			mySeq = seqHandler.findSequenceByID(seqID)
			
			# Construct a Seq object readable by BioPython:
			bioSeq = Seq(mySeq)
			fSeq = FormattedSeq(bioSeq, linear=False)		# linear = FALSE, we're dealing w/ VECTORS

			analysis = Analysis(enz_list, fSeq, linear=False)  	# linear = FALSE again for VECTORS
			result = analysis.full()

			outfile.write(reagentID + ": " + '\n')

			# calculate bandwidths
			allSites = []
			
			for enz in result.keys():
				sites = result[enz]
				
				if len(allSites) == 0:
					allSites = sites
				else:
					# concatenate
					for s in sites:
						allSites.append(s)

			allSites.sort()

			if len(allSites) > 0:
				
				# calculate distances between sites
				bandSizes = []
				
				i = 1
				
				while i < len(allSites):
					tmpLen = allSites[i] - allSites[i-1]
					bandSizes.append(tmpLen)
					i += 1
				
				# last band
				tmpLen = len(mySeq) - allSites[i-1] + allSites[0]
				bandSizes.append(tmpLen)
				
				bandSizes.sort()
				
				outfile.write(`bandSizes` + '\n')

			outfile.write('\n')
			
	infile.close()
	outfile.close()
	cursor.close()
	db.close()
Example #6
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
Example #7
0
from sequence_feature import SequenceFeature

# User and Project info
from user_handler import UserHandler
from project_database_handler import ProjectDatabaseHandler
from session import Session

# make global??
dbConn = DatabaseConn()
db = dbConn.databaseConnect()
hostname = dbConn.getHostname()
cursor = db.cursor()

# Handlers and Mappers
aHandler = AssociationHandler(db, cursor)
rHandler = ReagentHandler(db, cursor)
iHandler = InsertHandler(db, cursor)
raHandler = ReagentAssociationHandler(db, cursor)
sHandler = DNAHandler(db, cursor)
pHandler = ReagentPropertyHandler(db, cursor)
packetHandler = ProjectDatabaseHandler(db, cursor)
uHandler = UserHandler(db, cursor)
rtPropHandler = ReagentTypePropertyHandler(db, cursor)

propMapper = ReagentPropertyMapper(db, cursor)
aMapper = ReagentAssociationMapper(db, cursor)
rMapper = ReagentTypeMapper(db, cursor)

# Various maps
reagentType_Name_ID_Map = rMapper.mapTypeNameID()
reagentType_ID_Name_Map = rMapper.mapTypeIDName()
Example #8
0
def update():

	dbConn = DatabaseConn()
	db = dbConn.databaseConnect()
	
	cursor = db.cursor()
	hostname = dbConn.getHostname()

	form = cgi.FieldStorage(keep_blank_values="True")
	
	print "Content-type:text/html"		# REMOVE AFTER DEBUGGING TO HAVE SCRIPT REDIRECT PROPERLY!!!!!!
	print					# DITTO
	#print `form`

	# Aug 29/07
	uHandler = UserHandler(db, cursor)
	
	if form.has_key("curr_username"):
		# store the user ID for use throughout the session; add to other views in addition to create in PHP
		currUname = form.getvalue("curr_username")
		currUser = uHandler.getUserByDescription(currUname)
		
		Session.setUser(currUser)
		
	#else:	# debug
		#currUname = 'Administrator'
		#currUser = uHandler.getUserByDescription(currUname)
		
		#Session.setUser(currUser)
		
	if form.has_key("cloning_method"):
		cloning_method = form.getvalue("cloning_method")
	
	#else:	# debug
		#cloning_method = '1'
		
	# Handlers and mappers
	rHandler = ReagentHandler(db, cursor)
	#sHandler = SystemSetHandler(db, cursor)
	pHandler = ReagentPropertyHandler(db, cursor)
	raHandler = ReagentAssociationHandler(db, cursor)
	aHandler = AssociationHandler(db, cursor)

	dnaHandler = DNAHandler(db, cursor)
	commHandler = CommentHandler(db, cursor)
	protHandler = ProteinHandler(db, cursor)	
	
	propMapper = ReagentPropertyMapper(db, cursor)
	assocMapper = ReagentAssociationMapper(db, cursor)

	# August 29/07: Restrict creation by user and project access
	packetHandler = ProjectDatabaseHandler(db, cursor)

	########################################################
	# Various maps
	########################################################

	prop_Alias_ID_Map = propMapper.mapPropAliasID()		# (propAlias, propID) - e.g. ('insert_type', '48') --> represents 'type of insert' property
	prop_Name_Alias_Map = propMapper.mapPropNameAlias()	# (propName, propAlias)
	prop_Name_ID_Map = propMapper.mapPropNameID()		# (prop name, prop id)

	
	# Restriction sites
	fpcs_prop_id = pHandler.findPropID("5' cloning site")
	tpcs_prop_id = pHandler.findPropID("3' cloning site")

	newFivePrime = form.getvalue("fpcs")
	newThreePrime = form.getvalue("tpcs")

	gatewaySites = ['attb', 'attl', 'attp', 'attr']		# nov. 16/07
	
	# resulting sequence
	newSeq = ""

	# Fetch projects the user has AT LEAST Read access to (i.e. if he is explicitly declared a Writer on a project but not declared a Reader, include that project, plus all public projects)
	currReadProj = packetHandler.findMemberProjects(currUser.getUserID(), 'Reader')
	currWriteProj = packetHandler.findMemberProjects(currUser.getUserID(), 'Writer')
	publicProj = packetHandler.findAllProjects(isPrivate="FALSE")
	
	# list of Packet OBJECTS
	currUserWriteProjects = utils.unique(currReadProj + currWriteProj + publicProj)
	
	uPackets = []
	
	for p in currUserWriteProjects:
		uPackets.append(p.getNumber())

	# Get project IDs of parents
	packetPropID = pHandler.findPropID("packet id")

		
	# August 29/07: Need to verify parent project access AND (Sept. 12/07) reconstruct the sequence IFF parent values are changed
	newSeq = ""
	
	# Fetch projects the user has AT LEAST Read access to (i.e. if he is explicitly declared a Writer on a project but not declared a Reader, include that project, plus all public projects)
	currReadProj = packetHandler.findMemberProjects(currUser.getUserID(), 'Reader')
	currWriteProj = packetHandler.findMemberProjects(currUser.getUserID(), 'Writer')
	publicProj = packetHandler.findAllProjects(isPrivate="FALSE")
	
	# list of Packet OBJECTS
	currUserWriteProjects = utils.unique(currReadProj + currWriteProj + publicProj)
	
	uPackets = []
	
	for p in currUserWriteProjects:
		uPackets.append(p.getNumber())
	
	# Get project IDs of parents
	packetPropID = pHandler.findPropID("packet id")
	
	if form.has_key("PV"):
		pvVal = form.getvalue("PV")
	
		if len(pvVal) > 0:
			pvID = rHandler.convertReagentToDatabaseID(pvVal)
	
			try:
				pvProjectID = int(rHandler.findSimplePropertyValue(pvID, packetPropID))
				pvSeqID = rHandler.findDNASequenceKey(pvID)	# get sequence for reconstitution later
			except TypeError:
				#pvProjectID = 0
				e = PVProjectAccessException("You are not authorized to use this Parent Vector, since you do not have Read access to its project.")
				print `e.err_code()`
		else:
			e = UnknownPVIDException("Unknown Parent Vector value")
			print `e.err_code()`
			return
			
	# else don't do anything, maybe want to delete parents!!!
	#else:
		#e = MissingPVException("No Parent Vector provided")
		#print `e.err_code()`
	
	
	if pvProjectID > 0 and currUser.getCategory() != 'Admin' and pvProjectID not in uPackets:
		e = PVProjectAccessException("Not authorized to access parent")
		print `e.err_code()`
		return
	
	if cloning_method == '1':
		
		# Non-recombination vector - Get the Insert
		if form.has_key("I"):
			insertVal = form.getvalue("I")
			
			if len(insertVal) > 0:
				insertID = rHandler.convertReagentToDatabaseID(insertVal)
				insertSeqID = rHandler.findDNASequenceKey(insertID)	# fetch Insert sequence for reconstitution later
				
				try:
					insertProjectID = int(rHandler.findSimplePropertyValue(insertID, packetPropID))
					
				except TypeError:
					#insertProjectID = 0
					e = InsertProjectAccessException("You are not authorized to use this Insert, since you do not have Read access to its project.")
					print `e.err_code()`
			else:
				#insertID = -1
				#insertProjectID = 0
				#print "Invalid Insert value"
				e = UnknownInsertIDException("Unknown Insert value")
				print `e.err_code()`
				return
				
		#else:	# NO!!!!!!!!
			#e = MissingInsertException("No Insert provided")
			#print `e.err_code()`
	
		if insertProjectID > 0 and currUser.getCategory() != 'Admin' and insertProjectID not in uPackets:
			e = InsertProjectAccessException("You are not authorized to use this Insert, since you do not have Read access to its project.")
			print `e.err_code()`
			return
	
		if  pvID > 0 and insertID > 0 :
			
			# try to reconstruct sequence and issue warning if unable
			if pvSeqID > 0 and insertSeqID > 0:
				
				# fetch insert cloning sites
				insertCloningSites = []
	
				fpcs_prop_id = pHandler.findPropID("5' cloning site")
				tpcs_prop_id = pHandler.findPropID("3' cloning site")
		
				fp_insert_cs = rHandler.findSimplePropertyValue(insertID, fpcs_prop_id)
				tp_insert_cs = rHandler.findSimplePropertyValue(insertID, tpcs_prop_id)
				
				# Determine if this is a Gateway clone from sites
				gwSites = False;
		
				if fp_insert_cs and tp_insert_cs and fp_insert_cs.lower() == 'attl' and tp_insert_cs.lower() == 'attl':
					gwSites = True
				elif not fp_insert_cs or not tp_insert_cs:
					gwSites = True
				# nov. 16/07: added this for check
				elif fp_insert_cs.lower() in gatewaySites or tp_insert_cs.lower() in gatewaySites:
					gwSites = True
				else:
					gwSites = False;
		
				if gwSites:
					# this is a gateway clone
					# if sites were changed to something other than gateway, clear sequence	
					if newFivePrime.lower() != 'attl' or newThreePrime.lower() != 'attl':
						e = InsertSitesNotFoundOnParentSequenceException()
						print `e.err_code()`
						return
					else:
						pvSeqKey = rHandler.findDNASequenceKey(pvID)
						
						# For Gateway clones, linkers are found from primers - so find the sense and antisense Oligos for this Insert
						insertLinkers = []
			
						# Find Sense and Antisense Oligos for this Insert
						# (not using antisense just yet - verify with Karen)
						iHandler = InsertHandler(db, cursor)
			
						senseOligoID = iHandler.findSenseOligoID(insertID)
						#antisenseOligoID = iHandler.findAntisenseOligoID(insert_db_id)
			
						# Find Oligo sequences
						seqPropID = pHandler.findPropID("sequence")
						senseOligoSeqID = rHandler.findIndexPropertyValue(senseOligoID, seqPropID)
						senseOligoSequence = dnaHandler.findSequenceByID(senseOligoSeqID)
			
						# Fetch Insert sequence and find linkers from Oligo and Insert sequences
						insertSequence = dnaHandler.findSequenceByID(insertSeqID)
			
						attB_const = "ggggacaactttgtacaaaaaagttggc"
						fwd_primer_seq = senseOligoSequence[len(attB_const):]
			
						# First, find linkers from Oligos
						fwd_linker = dnaHandler.linker_from_oligo(insertSequence, fwd_primer_seq)
						#rev_linker = sHandler.linker_from_oligo(insertSequence, rev_primer_seq)
						rev_linker = ""
			
						# Now see if the Insert had its own linkers stored and append them to the Oligo linker
						fpLinkerPropID = pHandler.findPropID("5' linker")
						tpLinkerPropID = pHandler.findPropID("3' linker")
			
						fp_insert_linker = rHandler.findSimplePropertyValue(insertID, fpLinkerPropID)
						tp_insert_linker = rHandler.findSimplePropertyValue(insertID, tpLinkerPropID)
			
						if fp_insert_linker and len(fp_insert_linker) > 0 and fp_insert_linker != 0 and fp_insert_linker != '0':
							fp_insert_linker = fwd_linker + fp_insert_linker
						else:
							fp_insert_linker = fwd_linker
			
						tp_insert_linker = rev_linker
			
						insertLinkers.append(fp_insert_linker)
						insertLinkers.append(tp_insert_linker)
			
						try:
							newSeq = dnaHandler.entryVectorSequence(pvSeqKey, insertSeqID, insertLinkers)
							print newSeq
							
						except MultipleSiteOccurrenceException:
							e = MultipleSiteOccurrenceException("Sites found more than once on parent vector sequence")
							print `e.err_code()`
							
						except FivePrimeAfterThreePrimeException:
							e = FivePrimeAfterThreePrimeException("5' after 3'")
							print `e.err_code()`

						except InsertSitesNotFoundOnParentSequenceException:
							e = InsertSitesNotFoundOnParentSequenceException("Gateway sites not found on parent vector sequence")
							print `e.err_code()`
						
				else:
					# Non-Gateway non-recombination Vector
					fp_insert_cs = newFivePrime
					tp_insert_cs = newThreePrime
					
					if  fp_insert_cs:
						insertCloningSites.append(fp_insert_cs)
					else:
						insertCloningSites.append("")
	
					if  tp_insert_cs:
						insertCloningSites.append(tp_insert_cs)
					else:
						insertCloningSites.append("")
					
					# get linkers if there are any
					insertLinkers = []
	
					fpLinkerPropID = pHandler.findPropID("5' linker")
					tpLinkerPropID = pHandler.findPropID("3' linker")
					
					fp_insert_linker = rHandler.findSimplePropertyValue(insertID, fpLinkerPropID)
					tp_insert_linker = rHandler.findSimplePropertyValue(insertID, tpLinkerPropID)
	
					# sept. 3/07
					fwd_linker = ""
	
					if fp_insert_linker and len(fp_insert_linker) > 0 and fp_insert_linker != 0 and fp_insert_linker != '0':
						fp_insert_linker = fwd_linker + fp_insert_linker
					else:
						fp_insert_linker = fwd_linker
						
					insertLinkers.append(fp_insert_linker)
					insertLinkers.append(tp_insert_linker)
					
					try:
						newSeq = dnaHandler.constructNonRecombSequence(pvSeqID, insertSeqID, insertCloningSites, insertLinkers)
						print newSeq
					
					except (InsertSitesException):
						e = InsertSitesException("Could not reconstitute sequence: Unknown sites on Insert.")
						print e.err_code()
						
					except (InsertSitesNotFoundOnParentSequenceException):
						e = InsertSitesNotFoundOnParentSequenceException("Could not reconstitute sequence: Parent vector sequence does not contain restriction sites.")
						print e.err_code()
						
					except (MultipleSiteOccurrenceException):
						e = MultipleSiteOccurrenceException("Could not reconstitute sequence: Restriction sites occur more than once on parent vector sequence")
						print e.err_code()
						
					except (HybridizationException):
						e = HybridizationException("Could not reconstitute sequence: Restriction sites cannot be hybridized.")
						print e.err_code()
						
					except (FivePrimeAfterThreePrimeException):
						e = FivePrimeAfterThreePrimeException("Could not reconstitute sequence: 5' site occurs after 3' site on parent vector sequence.")
						print e.err_code()
			else:
				e = InvalidSequenceException("Invalid parent sequence")
				print `e.err_code()`
		else:
			e = UnknownPVIDException("Unknown PV ID")
			print `e.err_code()`
	
	elif cloning_method == '2':

		# Recombination vector - check IPV
		ipvVal = form.getvalue("IPV")
	
		if len(ipvVal) > 0:
			ipvID = rHandler.convertReagentToDatabaseID(ipvVal)
			ipvProjectID = int(rHandler.findSimplePropertyValue(ipvID, packetPropID))
		else:
			e = UnknownIPVIDException("Unknown IPV ID")
			print `e.err_code()`
	
		if ipvProjectID > 0 and currUser.getCategory() != 'Admin' and ipvProjectID not in uPackets:
			e = IPVProjectAccessException("Not authorized to view IPV")
			print `e.err_code()`
		
		if ipvID > 0 and pvID > 0:
			
			# If restriction sites were modified to anything other than LoxP or gateway att sites, clear the sequence
			if not (newFivePrime == newThreePrime and (newFivePrime.lower() == 'loxp' and newThreePrime.lower() == 'loxp') or (newFivePrime.lower() == 'attb' and newThreePrime.lower() == 'attb')):
				e = InsertSitesNotFoundOnParentSequenceException("Invalid restriction sites for Non-Recombination Clone - must be LoxP only")
				print `e.err_code()`
			else:
				# get internal db IDs
				pv_db_id = rHandler.convertReagentToDatabaseID(pvVal)
				ipv_db_id = rHandler.convertReagentToDatabaseID(ipvVal)
		
				# Get the Insert that belongs to the donor vector
				ipvInsertAssocID = raHandler.findReagentAssociationID(ipv_db_id)
				insertAssocPropID = aHandler.findAssocPropID("insert id")
				insert_db_id = aHandler.findAssocPropValue(ipvInsertAssocID, insertAssocPropID)
		
				# Construct a sequence for the new vector from the sequences of its parents
				pvSeqKey = rHandler.findDNASequenceKey(pv_db_id)
				#print "pv seq " + `pvSeqKey`
				ipvSeqKey = rHandler.findDNASequenceKey(ipv_db_id)
				#print "ipv seq " + `ipvSeqKey`
				insertSeqKey = rHandler.findDNASequenceKey(insert_db_id)
				#print "i seq " + `insertSeqKey`
		
				if pvSeqKey > 0 and ipvSeqKey > 0 and insertSeqKey > 0:
	
					# See if there are linkers, although there most likely aren't any
					insertLinkers = []
			
					fpLinkerPropID = pHandler.findPropID("5' linker")
					tpLinkerPropID = pHandler.findPropID("3' linker")
			
					fp_insert_linker = rHandler.findSimplePropertyValue(insert_db_id, fpLinkerPropID)
					tp_insert_linker = rHandler.findSimplePropertyValue(insert_db_id, tpLinkerPropID)
			
					# sept. 3/07
					fwd_linker = ""
			
					if fp_insert_linker and len(fp_insert_linker) > 0 and fp_insert_linker != 0 and fp_insert_linker != '0':
						fp_insert_linker = fwd_linker + fp_insert_linker
					else:
						fp_insert_linker = fwd_linker
			
					insertLinkers.append(fp_insert_linker)
					insertLinkers.append(tp_insert_linker)
			
					# Differentiate by cloning sites whether this is a recombination vector or a Gateway Expression Vector
					if newFivePrime == 'LoxP' and newThreePrime == 'LoxP':
						# recombination
						try:
							newSeq = dnaHandler.constructRecombSequence(pvSeqKey, ipvSeqKey, insertSeqKey, insertLinkers)
							newSeqID = dnaHandler.matchSequence(newSeq)
							print newSeq
						
						except InsertSitesNotFoundOnParentSequenceException:
							e = InsertSitesNotFoundOnParentSequenceException("LOXP sites not found on parent vector sequence")
							print `e.err_code()`

						except MultipleSiteOccurrenceException:

							e = MultipleSiteOccurrenceException("LOXP found more than once on parent vector sequence")
							print `e.err_code()`

					elif newFivePrime == 'attB' and newThreePrime == 'attB':
						
						# Gateway Expression
						iHandler = InsertHandler(db, cursor)
						
						senseOligoID = iHandler.findSenseOligoID(insert_db_id)
						#antisenseOligoID = iHandler.findAntisenseOligoID(insert_db_id)
			
						# Find Oligo sequences
						seqPropID = pHandler.findPropID("sequence")
						senseOligoSeqID = rHandler.findIndexPropertyValue(senseOligoID, seqPropID)
						senseOligoSequence = dnaHandler.findSequenceByID(senseOligoSeqID)
			
						# Fetch Insert sequence and find linkers from Oligo and Insert sequences
						insertSequence = dnaHandler.findSequenceByID(insertSeqKey)
			
						attB_const = "ggggacaactttgtacaaaaaagttggc"
						fwd_primer_seq = senseOligoSequence[len(attB_const):]
			
						# First, find linkers from Oligos
						fwd_linker = dnaHandler.linker_from_oligo(insertSequence, fwd_primer_seq)
						#rev_linker = sHandler.linker_from_oligo(insertSequence, rev_primer_seq)
						rev_linker = ""
			
						# Now see if the Insert had its own linkers stored and append them to the Oligo linker
						fpLinkerPropID = pHandler.findPropID("5' linker")
						tpLinkerPropID = pHandler.findPropID("3' linker")
			
						fp_insert_linker = rHandler.findSimplePropertyValue(insert_db_id, fpLinkerPropID)
						tp_insert_linker = rHandler.findSimplePropertyValue(insert_db_id, tpLinkerPropID)
			
						if fp_insert_linker and len(fp_insert_linker) > 0 and fp_insert_linker != 0 and fp_insert_linker != '0':
							fp_insert_linker = fwd_linker + fp_insert_linker
						else:
							fp_insert_linker = fwd_linker
			
						tp_insert_linker = rev_linker
			
						insertLinkers.append(fp_insert_linker)
						insertLinkers.append(tp_insert_linker)
						
						try:
							newSeq = dnaHandler.expressionVectorSequence(pvSeqKey, insertSeqKey, insertLinkers)
							print newSeq
						
						except MultipleSiteOccurrenceException:
							e = MultipleSiteOccurrenceException("Sites found more than once on parent vector sequence")
							print `e.err_code()`
							
						except FivePrimeAfterThreePrimeException:
							e = FivePrimeAfterThreePrimeException("5' after 3'")
							print `e.err_code()`

						except InsertSitesNotFoundOnParentSequenceException:
							e = InsertSitesNotFoundOnParentSequenceException("Gateway sites not found on parent vector sequence")
							print `e.err_code()`

				else:
					e = InvalidSequenceException("Invalid parent sequence")
					print `e.err_code()`
		else:
			e = ReagentDoesNotExistException("Unknown parent values")
			print `e.err_code()`
Example #9
0
def rMap_specific(f_in, f_out, enz_list):

    # Database connection parameters
    dbConn = DatabaseConn()
    db = dbConn.databaseConnect()
    cursor = db.cursor()

    gHandler = GeneralHandler(db, cursor)
    rHandler = ReagentHandler(db, cursor)
    seqHandler = SequenceHandler(db, cursor)

    infile = open(f_in, 'r')
    outfile = open(f_out, 'w')

    for line in infile.readlines():
        reagentID = line.strip()  # e.g. V123
        rID = rHandler.convertReagentToDatabaseID(reagentID)
        seqID = rHandler.findDNASequenceKey(rID)

        if seqID:
            mySeq = seqHandler.findSequenceByID(seqID)

            # Construct a Seq object readable by BioPython:
            bioSeq = Seq(mySeq)
            fSeq = FormattedSeq(
                bioSeq,
                linear=False)  # linear = FALSE, we're dealing w/ VECTORS

            analysis = Analysis(
                enz_list, fSeq,
                linear=False)  # linear = FALSE again for VECTORS
            result = analysis.full()

            outfile.write(reagentID + ": " + '\n')

            # calculate bandwidths
            allSites = []

            for enz in result.keys():
                sites = result[enz]

                if len(allSites) == 0:
                    allSites = sites
                else:
                    # concatenate
                    for s in sites:
                        allSites.append(s)

            allSites.sort()

            if len(allSites) > 0:

                # calculate distances between sites
                bandSizes = []

                i = 1

                while i < len(allSites):
                    tmpLen = allSites[i] - allSites[i - 1]
                    bandSizes.append(tmpLen)
                    i += 1

                # last band
                tmpLen = len(mySeq) - allSites[i - 1] + allSites[0]
                bandSizes.append(tmpLen)

                bandSizes.sort()

                outfile.write( ` bandSizes ` + '\n')

            outfile.write('\n')

    infile.close()
    outfile.close()
    cursor.close()
    db.close()
Example #10
0
def update():

    dbConn = DatabaseConn()
    db = dbConn.databaseConnect()

    cursor = db.cursor()
    hostname = dbConn.getHostname()

    form = cgi.FieldStorage(keep_blank_values="True")

    print "Content-type:text/html"  # REMOVE AFTER DEBUGGING TO HAVE SCRIPT REDIRECT PROPERLY!!!!!!
    print  # DITTO
    #print `form`

    # Aug 29/07
    uHandler = UserHandler(db, cursor)

    if form.has_key("curr_username"):
        # store the user ID for use throughout the session; add to other views in addition to create in PHP
        currUname = form.getvalue("curr_username")
        currUser = uHandler.getUserByDescription(currUname)

        Session.setUser(currUser)

    #else:	# debug
    #currUname = 'Administrator'
    #currUser = uHandler.getUserByDescription(currUname)

    #Session.setUser(currUser)

    if form.has_key("cloning_method"):
        cloning_method = form.getvalue("cloning_method")

    #else:	# debug
    #cloning_method = '1'

    # Handlers and mappers
    rHandler = ReagentHandler(db, cursor)
    #sHandler = SystemSetHandler(db, cursor)
    pHandler = ReagentPropertyHandler(db, cursor)
    raHandler = ReagentAssociationHandler(db, cursor)
    aHandler = AssociationHandler(db, cursor)

    dnaHandler = DNAHandler(db, cursor)
    commHandler = CommentHandler(db, cursor)
    protHandler = ProteinHandler(db, cursor)

    propMapper = ReagentPropertyMapper(db, cursor)
    assocMapper = ReagentAssociationMapper(db, cursor)

    # August 29/07: Restrict creation by user and project access
    packetHandler = ProjectDatabaseHandler(db, cursor)

    ########################################################
    # Various maps
    ########################################################

    prop_Alias_ID_Map = propMapper.mapPropAliasID(
    )  # (propAlias, propID) - e.g. ('insert_type', '48') --> represents 'type of insert' property
    prop_Name_Alias_Map = propMapper.mapPropNameAlias(
    )  # (propName, propAlias)
    prop_Name_ID_Map = propMapper.mapPropNameID()  # (prop name, prop id)

    # Restriction sites
    fpcs_prop_id = pHandler.findPropID("5' cloning site")
    tpcs_prop_id = pHandler.findPropID("3' cloning site")

    newFivePrime = form.getvalue("fpcs")
    newThreePrime = form.getvalue("tpcs")

    gatewaySites = ['attb', 'attl', 'attp', 'attr']  # nov. 16/07

    # resulting sequence
    newSeq = ""

    # Fetch projects the user has AT LEAST Read access to (i.e. if he is explicitly declared a Writer on a project but not declared a Reader, include that project, plus all public projects)
    currReadProj = packetHandler.findMemberProjects(currUser.getUserID(),
                                                    'Reader')
    currWriteProj = packetHandler.findMemberProjects(currUser.getUserID(),
                                                     'Writer')
    publicProj = packetHandler.findAllProjects(isPrivate="FALSE")

    # list of Packet OBJECTS
    currUserWriteProjects = utils.unique(currReadProj + currWriteProj +
                                         publicProj)

    uPackets = []

    for p in currUserWriteProjects:
        uPackets.append(p.getNumber())

    # Get project IDs of parents
    packetPropID = pHandler.findPropID("packet id")

    # August 29/07: Need to verify parent project access AND (Sept. 12/07) reconstruct the sequence IFF parent values are changed
    newSeq = ""

    # Fetch projects the user has AT LEAST Read access to (i.e. if he is explicitly declared a Writer on a project but not declared a Reader, include that project, plus all public projects)
    currReadProj = packetHandler.findMemberProjects(currUser.getUserID(),
                                                    'Reader')
    currWriteProj = packetHandler.findMemberProjects(currUser.getUserID(),
                                                     'Writer')
    publicProj = packetHandler.findAllProjects(isPrivate="FALSE")

    # list of Packet OBJECTS
    currUserWriteProjects = utils.unique(currReadProj + currWriteProj +
                                         publicProj)

    uPackets = []

    for p in currUserWriteProjects:
        uPackets.append(p.getNumber())

    # Get project IDs of parents
    packetPropID = pHandler.findPropID("packet id")

    if form.has_key("PV"):
        pvVal = form.getvalue("PV")

        if len(pvVal) > 0:
            pvID = rHandler.convertReagentToDatabaseID(pvVal)

            try:
                pvProjectID = int(
                    rHandler.findSimplePropertyValue(pvID, packetPropID))
                pvSeqID = rHandler.findDNASequenceKey(
                    pvID)  # get sequence for reconstitution later
            except TypeError:
                #pvProjectID = 0
                e = PVProjectAccessException(
                    "You are not authorized to use this Parent Vector, since you do not have Read access to its project."
                )
                print ` e.err_code() `
        else:
            e = UnknownPVIDException("Unknown Parent Vector value")
            print ` e.err_code() `
            return

    # else don't do anything, maybe want to delete parents!!!
    #else:
    #e = MissingPVException("No Parent Vector provided")
    #print `e.err_code()`

    if pvProjectID > 0 and currUser.getCategory(
    ) != 'Admin' and pvProjectID not in uPackets:
        e = PVProjectAccessException("Not authorized to access parent")
        print ` e.err_code() `
        return

    if cloning_method == '1':

        # Non-recombination vector - Get the Insert
        if form.has_key("I"):
            insertVal = form.getvalue("I")

            if len(insertVal) > 0:
                insertID = rHandler.convertReagentToDatabaseID(insertVal)
                insertSeqID = rHandler.findDNASequenceKey(
                    insertID)  # fetch Insert sequence for reconstitution later

                try:
                    insertProjectID = int(
                        rHandler.findSimplePropertyValue(
                            insertID, packetPropID))

                except TypeError:
                    #insertProjectID = 0
                    e = InsertProjectAccessException(
                        "You are not authorized to use this Insert, since you do not have Read access to its project."
                    )
                    print ` e.err_code() `
            else:
                #insertID = -1
                #insertProjectID = 0
                #print "Invalid Insert value"
                e = UnknownInsertIDException("Unknown Insert value")
                print ` e.err_code() `
                return

        #else:	# NO!!!!!!!!
        #e = MissingInsertException("No Insert provided")
        #print `e.err_code()`

        if insertProjectID > 0 and currUser.getCategory(
        ) != 'Admin' and insertProjectID not in uPackets:
            e = InsertProjectAccessException(
                "You are not authorized to use this Insert, since you do not have Read access to its project."
            )
            print ` e.err_code() `
            return

        if pvID > 0 and insertID > 0:

            # try to reconstruct sequence and issue warning if unable
            if pvSeqID > 0 and insertSeqID > 0:

                # fetch insert cloning sites
                insertCloningSites = []

                fpcs_prop_id = pHandler.findPropID("5' cloning site")
                tpcs_prop_id = pHandler.findPropID("3' cloning site")

                fp_insert_cs = rHandler.findSimplePropertyValue(
                    insertID, fpcs_prop_id)
                tp_insert_cs = rHandler.findSimplePropertyValue(
                    insertID, tpcs_prop_id)

                # Determine if this is a Gateway clone from sites
                gwSites = False

                if fp_insert_cs and tp_insert_cs and fp_insert_cs.lower(
                ) == 'attl' and tp_insert_cs.lower() == 'attl':
                    gwSites = True
                elif not fp_insert_cs or not tp_insert_cs:
                    gwSites = True
                # nov. 16/07: added this for check
                elif fp_insert_cs.lower(
                ) in gatewaySites or tp_insert_cs.lower() in gatewaySites:
                    gwSites = True
                else:
                    gwSites = False

                if gwSites:
                    # this is a gateway clone
                    # if sites were changed to something other than gateway, clear sequence
                    if newFivePrime.lower() != 'attl' or newThreePrime.lower(
                    ) != 'attl':
                        e = InsertSitesNotFoundOnParentSequenceException()
                        print ` e.err_code() `
                        return
                    else:
                        pvSeqKey = rHandler.findDNASequenceKey(pvID)

                        # For Gateway clones, linkers are found from primers - so find the sense and antisense Oligos for this Insert
                        insertLinkers = []

                        # Find Sense and Antisense Oligos for this Insert
                        # (not using antisense just yet - verify with Karen)
                        iHandler = InsertHandler(db, cursor)

                        senseOligoID = iHandler.findSenseOligoID(insertID)
                        #antisenseOligoID = iHandler.findAntisenseOligoID(insert_db_id)

                        # Find Oligo sequences
                        seqPropID = pHandler.findPropID("sequence")
                        senseOligoSeqID = rHandler.findIndexPropertyValue(
                            senseOligoID, seqPropID)
                        senseOligoSequence = dnaHandler.findSequenceByID(
                            senseOligoSeqID)

                        # Fetch Insert sequence and find linkers from Oligo and Insert sequences
                        insertSequence = dnaHandler.findSequenceByID(
                            insertSeqID)

                        attB_const = "ggggacaactttgtacaaaaaagttggc"
                        fwd_primer_seq = senseOligoSequence[len(attB_const):]

                        # First, find linkers from Oligos
                        fwd_linker = dnaHandler.linker_from_oligo(
                            insertSequence, fwd_primer_seq)
                        #rev_linker = sHandler.linker_from_oligo(insertSequence, rev_primer_seq)
                        rev_linker = ""

                        # Now see if the Insert had its own linkers stored and append them to the Oligo linker
                        fpLinkerPropID = pHandler.findPropID("5' linker")
                        tpLinkerPropID = pHandler.findPropID("3' linker")

                        fp_insert_linker = rHandler.findSimplePropertyValue(
                            insertID, fpLinkerPropID)
                        tp_insert_linker = rHandler.findSimplePropertyValue(
                            insertID, tpLinkerPropID)

                        if fp_insert_linker and len(
                                fp_insert_linker
                        ) > 0 and fp_insert_linker != 0 and fp_insert_linker != '0':
                            fp_insert_linker = fwd_linker + fp_insert_linker
                        else:
                            fp_insert_linker = fwd_linker

                        tp_insert_linker = rev_linker

                        insertLinkers.append(fp_insert_linker)
                        insertLinkers.append(tp_insert_linker)

                        try:
                            newSeq = dnaHandler.entryVectorSequence(
                                pvSeqKey, insertSeqID, insertLinkers)
                            print newSeq

                        except MultipleSiteOccurrenceException:
                            e = MultipleSiteOccurrenceException(
                                "Sites found more than once on parent vector sequence"
                            )
                            print ` e.err_code() `

                        except FivePrimeAfterThreePrimeException:
                            e = FivePrimeAfterThreePrimeException(
                                "5' after 3'")
                            print ` e.err_code() `

                        except InsertSitesNotFoundOnParentSequenceException:
                            e = InsertSitesNotFoundOnParentSequenceException(
                                "Gateway sites not found on parent vector sequence"
                            )
                            print ` e.err_code() `

                else:
                    # Non-Gateway non-recombination Vector
                    fp_insert_cs = newFivePrime
                    tp_insert_cs = newThreePrime

                    if fp_insert_cs:
                        insertCloningSites.append(fp_insert_cs)
                    else:
                        insertCloningSites.append("")

                    if tp_insert_cs:
                        insertCloningSites.append(tp_insert_cs)
                    else:
                        insertCloningSites.append("")

                    # get linkers if there are any
                    insertLinkers = []

                    fpLinkerPropID = pHandler.findPropID("5' linker")
                    tpLinkerPropID = pHandler.findPropID("3' linker")

                    fp_insert_linker = rHandler.findSimplePropertyValue(
                        insertID, fpLinkerPropID)
                    tp_insert_linker = rHandler.findSimplePropertyValue(
                        insertID, tpLinkerPropID)

                    # sept. 3/07
                    fwd_linker = ""

                    if fp_insert_linker and len(
                            fp_insert_linker
                    ) > 0 and fp_insert_linker != 0 and fp_insert_linker != '0':
                        fp_insert_linker = fwd_linker + fp_insert_linker
                    else:
                        fp_insert_linker = fwd_linker

                    insertLinkers.append(fp_insert_linker)
                    insertLinkers.append(tp_insert_linker)

                    try:
                        newSeq = dnaHandler.constructNonRecombSequence(
                            pvSeqID, insertSeqID, insertCloningSites,
                            insertLinkers)
                        print newSeq

                    except (InsertSitesException):
                        e = InsertSitesException(
                            "Could not reconstitute sequence: Unknown sites on Insert."
                        )
                        print e.err_code()

                    except (InsertSitesNotFoundOnParentSequenceException):
                        e = InsertSitesNotFoundOnParentSequenceException(
                            "Could not reconstitute sequence: Parent vector sequence does not contain restriction sites."
                        )
                        print e.err_code()

                    except (MultipleSiteOccurrenceException):
                        e = MultipleSiteOccurrenceException(
                            "Could not reconstitute sequence: Restriction sites occur more than once on parent vector sequence"
                        )
                        print e.err_code()

                    except (HybridizationException):
                        e = HybridizationException(
                            "Could not reconstitute sequence: Restriction sites cannot be hybridized."
                        )
                        print e.err_code()

                    except (FivePrimeAfterThreePrimeException):
                        e = FivePrimeAfterThreePrimeException(
                            "Could not reconstitute sequence: 5' site occurs after 3' site on parent vector sequence."
                        )
                        print e.err_code()
            else:
                e = InvalidSequenceException("Invalid parent sequence")
                print ` e.err_code() `
        else:
            e = UnknownPVIDException("Unknown PV ID")
            print ` e.err_code() `

    elif cloning_method == '2':

        # Recombination vector - check IPV
        ipvVal = form.getvalue("IPV")

        if len(ipvVal) > 0:
            ipvID = rHandler.convertReagentToDatabaseID(ipvVal)
            ipvProjectID = int(
                rHandler.findSimplePropertyValue(ipvID, packetPropID))
        else:
            e = UnknownIPVIDException("Unknown IPV ID")
            print ` e.err_code() `

        if ipvProjectID > 0 and currUser.getCategory(
        ) != 'Admin' and ipvProjectID not in uPackets:
            e = IPVProjectAccessException("Not authorized to view IPV")
            print ` e.err_code() `

        if ipvID > 0 and pvID > 0:

            # If restriction sites were modified to anything other than LoxP or gateway att sites, clear the sequence
            if not (newFivePrime == newThreePrime and
                    (newFivePrime.lower() == 'loxp'
                     and newThreePrime.lower() == 'loxp') or
                    (newFivePrime.lower() == 'attb'
                     and newThreePrime.lower() == 'attb')):
                e = InsertSitesNotFoundOnParentSequenceException(
                    "Invalid restriction sites for Non-Recombination Clone - must be LoxP only"
                )
                print ` e.err_code() `
            else:
                # get internal db IDs
                pv_db_id = rHandler.convertReagentToDatabaseID(pvVal)
                ipv_db_id = rHandler.convertReagentToDatabaseID(ipvVal)

                # Get the Insert that belongs to the donor vector
                ipvInsertAssocID = raHandler.findReagentAssociationID(
                    ipv_db_id)
                insertAssocPropID = aHandler.findAssocPropID("insert id")
                insert_db_id = aHandler.findAssocPropValue(
                    ipvInsertAssocID, insertAssocPropID)

                # Construct a sequence for the new vector from the sequences of its parents
                pvSeqKey = rHandler.findDNASequenceKey(pv_db_id)
                #print "pv seq " + `pvSeqKey`
                ipvSeqKey = rHandler.findDNASequenceKey(ipv_db_id)
                #print "ipv seq " + `ipvSeqKey`
                insertSeqKey = rHandler.findDNASequenceKey(insert_db_id)
                #print "i seq " + `insertSeqKey`

                if pvSeqKey > 0 and ipvSeqKey > 0 and insertSeqKey > 0:

                    # See if there are linkers, although there most likely aren't any
                    insertLinkers = []

                    fpLinkerPropID = pHandler.findPropID("5' linker")
                    tpLinkerPropID = pHandler.findPropID("3' linker")

                    fp_insert_linker = rHandler.findSimplePropertyValue(
                        insert_db_id, fpLinkerPropID)
                    tp_insert_linker = rHandler.findSimplePropertyValue(
                        insert_db_id, tpLinkerPropID)

                    # sept. 3/07
                    fwd_linker = ""

                    if fp_insert_linker and len(
                            fp_insert_linker
                    ) > 0 and fp_insert_linker != 0 and fp_insert_linker != '0':
                        fp_insert_linker = fwd_linker + fp_insert_linker
                    else:
                        fp_insert_linker = fwd_linker

                    insertLinkers.append(fp_insert_linker)
                    insertLinkers.append(tp_insert_linker)

                    # Differentiate by cloning sites whether this is a recombination vector or a Gateway Expression Vector
                    if newFivePrime == 'LoxP' and newThreePrime == 'LoxP':
                        # recombination
                        try:
                            newSeq = dnaHandler.constructRecombSequence(
                                pvSeqKey, ipvSeqKey, insertSeqKey,
                                insertLinkers)
                            newSeqID = dnaHandler.matchSequence(newSeq)
                            print newSeq

                        except InsertSitesNotFoundOnParentSequenceException:
                            e = InsertSitesNotFoundOnParentSequenceException(
                                "LOXP sites not found on parent vector sequence"
                            )
                            print ` e.err_code() `

                        except MultipleSiteOccurrenceException:

                            e = MultipleSiteOccurrenceException(
                                "LOXP found more than once on parent vector sequence"
                            )
                            print ` e.err_code() `

                    elif newFivePrime == 'attB' and newThreePrime == 'attB':

                        # Gateway Expression
                        iHandler = InsertHandler(db, cursor)

                        senseOligoID = iHandler.findSenseOligoID(insert_db_id)
                        #antisenseOligoID = iHandler.findAntisenseOligoID(insert_db_id)

                        # Find Oligo sequences
                        seqPropID = pHandler.findPropID("sequence")
                        senseOligoSeqID = rHandler.findIndexPropertyValue(
                            senseOligoID, seqPropID)
                        senseOligoSequence = dnaHandler.findSequenceByID(
                            senseOligoSeqID)

                        # Fetch Insert sequence and find linkers from Oligo and Insert sequences
                        insertSequence = dnaHandler.findSequenceByID(
                            insertSeqKey)

                        attB_const = "ggggacaactttgtacaaaaaagttggc"
                        fwd_primer_seq = senseOligoSequence[len(attB_const):]

                        # First, find linkers from Oligos
                        fwd_linker = dnaHandler.linker_from_oligo(
                            insertSequence, fwd_primer_seq)
                        #rev_linker = sHandler.linker_from_oligo(insertSequence, rev_primer_seq)
                        rev_linker = ""

                        # Now see if the Insert had its own linkers stored and append them to the Oligo linker
                        fpLinkerPropID = pHandler.findPropID("5' linker")
                        tpLinkerPropID = pHandler.findPropID("3' linker")

                        fp_insert_linker = rHandler.findSimplePropertyValue(
                            insert_db_id, fpLinkerPropID)
                        tp_insert_linker = rHandler.findSimplePropertyValue(
                            insert_db_id, tpLinkerPropID)

                        if fp_insert_linker and len(
                                fp_insert_linker
                        ) > 0 and fp_insert_linker != 0 and fp_insert_linker != '0':
                            fp_insert_linker = fwd_linker + fp_insert_linker
                        else:
                            fp_insert_linker = fwd_linker

                        tp_insert_linker = rev_linker

                        insertLinkers.append(fp_insert_linker)
                        insertLinkers.append(tp_insert_linker)

                        try:
                            newSeq = dnaHandler.expressionVectorSequence(
                                pvSeqKey, insertSeqKey, insertLinkers)
                            print newSeq

                        except MultipleSiteOccurrenceException:
                            e = MultipleSiteOccurrenceException(
                                "Sites found more than once on parent vector sequence"
                            )
                            print ` e.err_code() `

                        except FivePrimeAfterThreePrimeException:
                            e = FivePrimeAfterThreePrimeException(
                                "5' after 3'")
                            print ` e.err_code() `

                        except InsertSitesNotFoundOnParentSequenceException:
                            e = InsertSitesNotFoundOnParentSequenceException(
                                "Gateway sites not found on parent vector sequence"
                            )
                            print ` e.err_code() `

                else:
                    e = InvalidSequenceException("Invalid parent sequence")
                    print ` e.err_code() `
        else:
            e = ReagentDoesNotExistException("Unknown parent values")
            print ` e.err_code() `