示例#1
0
    def createBackbone(self, name, BBtype, desc, seqBefore, seqAfter,
                       features):
        """Create a BackboneDB and add it to the database.
		
		PARAMETERS:
			name: string name of the backbone
			BBtype: string type of the backbone; is either "i" for integrative or
				"r" for replicative
			desc: string description of the backbone
			seqBefore: string sequence of the backbone before the insertion region
			seqAfter: string sequence of the backbone after the insertion region
			features: string features, formatted as it should appear in a .gb file
		
		RETURNS:
			bb: created BackboneDB
		
		RAISES:
			AlreadyExistsError: if a backbone with the same name is already in
				the user's library
		"""
        #type checking
        if (type(name) != str):
            raise TypeError("backbone name not a string")
        if (type(BBtype) != str):
            raise TypeError("backbone type not a string")
        elif (BBtype not in ["i", "r"]):
            raise ValueError("backbone type not valid")
        if (type(desc) != str):
            raise TypeError("backbone desc not a string")
        if (type(seqBefore) != str):
            raise TypeError("backbone seqBefore not a string")
        if (type(seqAfter) != str):
            raise TypeError("backbone seqAfter not a string")
        if (type(features) != str):
            raise TypeError("backbone features not a string")

        print("done with the type checking")

        #see if it exists already
        try:
            self.findBackbone(name)
            raise e.AlreadyExistsError(
                "Backbone {name} already exists.".format(name=name))
        except e.BackboneNotFoundError:
            pass

        #create in database
        bb = BackboneDB(name=name,
                        type=BBtype,
                        desc=desc,
                        seqBefore=seqBefore,
                        seqAfter=seqAfter,
                        features=features,
                        user_id=self.getID())

        db.session.add(bb)
        db.session.commit()

        return bb
示例#2
0
    def addNSDB(self, namedSeq):
        """Create a copy of a NamedSequenceDB in the user's library.
		
		PARAMETER:
			namedSeq: NamedSequenceDB to copy
			
		RAISES:
			AlreadyExistsError: if a named sequence of the same name is already
				in the user's library
		"""
        #type checking
        if (type(namedSeq) != NamedSequenceDB):
            raise TypeError("namedSeq not a NamedSequenceDB.")

        #check if it already exists
        try:
            self.findNamedSequence(namedSeq.getType(), namedSeq.getName(),
                                   namedSeq.getSeq())

            #raise error if it exists
            raise e.AlreadyExistsError("Sequence already exists.")
        except e.SequenceNotFoundError:
            pass

        #get info. about namedSeq
        NStype = namedSeq.getType()
        NSname = namedSeq.getName()
        NSseq = namedSeq.getSeq()

        nameID = namedSeq.getNameID(
        )  #####<----- What if, somehow, that NameID already exists in the personal library?

        #create a new NamedSequenceDB using the information from namedSeq
        #the only difference is the user_id
        ns = NamedSequenceDB(elemType=NStype,
                             name=NSname,
                             seq=NSseq,
                             nameID=nameID,
                             user_id=self.getID())

        #add to database
        db.session.add(ns)
        db.session.commit()

        #increment NS id
        self.getEntry().incrementID(NStype)

        return ns
示例#3
0
    def addNS(self, namedSeq):
        """Add a NamedSequenceDB to the database using a NamedSequence.
		
		PARAMETERS:
			namedSeq: NamedSequence to make a NamedSequenceDB from
		
		RAISES:
			AlreadyExistsError: if a NamedSequenceDB with the same name and type
				already exists in the database for the user
		"""
        #type checking
        if (type(namedSeq) != NamedSequence):
            raise TypeError("namedSeq not a NamedSequence.")

        #check if it already exists
        try:
            self.findNamedSequenceNoSeq(namedSeq.getType(), namedSeq.getName())

            #an error will be raised if it exists
            raise e.AlreadyExistsError("Sequence already exists.")

        except e.SequenceNotFoundError:
            pass

        #make entry
        NStype = namedSeq.getType()
        NSname = namedSeq.getName()
        NSseq = namedSeq.getSeq()

        nameID = self.getEntry().getNextNSid()[NStype]

        ns = NamedSequenceDB(elemType=NStype,
                             name=NSname,
                             seq=NSseq,
                             nameID=nameID,
                             user_id=self.getID())

        #add to database
        db.session.add(ns)
        db.session.commit()

        #increment NS id
        self.getEntry().incrementID(NStype)

        return ns
示例#4
0
    def new(cls, email):
        """Create a new user: creates a UserData and a UserDataDB.
		
		PARAMTERS:
			email: string email of the user
		
		RETURN:
			newUserData: created UserData
		"""
        printIf("Calling UserData.new({email}).\n".format(email=email))

        #type validation
        if (type(email) != str):
            raise TypeError("email not a str")

        #see if a user with the email already exists
        if (UserDataDB.query.filter_by(email=email).all() != []):
            raise e.AlreadyExistsError(
                "User with email {email} already exists.".format(email=email))

        #initialize
        newUserData = cls()

        #start nextNSid (the first number for the IDs of named sequences of the user)
        if (email == "default"):
            nextNSid = 1
        else:
            nextNSid = 101

        #add user to database
        u = UserDataDB(nextNSidPR=nextNSid,
                       nextNSidRBS=nextNSid,
                       nextNSidGOI=nextNSid,
                       nextNSidTERM=nextNSid,
                       email=email)

        db.session.add(u)
        db.session.commit()

        #add database info. to the user
        newUserData.__DBid = u.id
        newUserData.__entryDB = u

        return newUserData
示例#5
0
def finishComponent():
	"""Create a component and add it to the current user's library."""
	#validation
	validInput = getAllSelected()
	succeeded = False
	newID = -1

	outputStr = ""
	
	if(validInput):
		try:
			#get info. to use later
			currUser = getCurrUser()
			selectedNS = getSelectedNS()
			#get spacers & primers, which were stored in the session in JSON
				#format, so they need to be re-created using fromJSON()
			selectedSpacers = SpacerData.fromJSON(getSelectedSD())
			selectedPrimers = PrimerData.fromJSON(getSelectedPD())
			
			#check if it already exists in defaults
			try:
				defaultUser.findComponent(selectedNS.getType(),
										  selectedNS.getName(),
										  selectedSpacers.getPosition(),
										  selectedSpacers.getTerminalLetter())
				
				#if no error has been raised, the component was found in default
				raise ee.AlreadyExistsError("Component already exists as a default component.")
			except (ee.SequenceNotFoundError, ee.ComponentNotFoundError):
				#the component was not found in default
				pass
			
			#check if it already exists in personal library
			try:
				getCurrUser().findComponent(selectedNS.getType(),
											selectedNS.getName(),
											selectedSpacers.getPosition(),
											selectedSpacers.getTerminalLetter())
				
				#if no error has been raised, the component was found in the
					#current user's library.
				raise ee.AlreadyExistsError("Component already exists as a user-made component.")
			except (ee.SequenceNotFoundError, ee.ComponentNotFoundError):
				#the component was not found in the current user
				pass
			
			#add NS to personal library if it's not from the personal library
			try:
				tempNS = currUser.addNSDB(selectedNS)
				selectedNS = tempNS
			except ee.AlreadyExistsError:
				pass
	
			#create the component
			newComponent = currUser.createComp(selectedNS, selectedSpacers, selectedPrimers)
			
			#modify output string
			libraryName = "Personal"
			outputStr = ("<a target = '_blank' href = '/library#{libraryName}{nameID}'>"
						 "{nameID}</a> created.").format(
												libraryName = libraryName,
												nameID = newComponent.getNameID())
			
			#get the ID of the new component, for the ZIP download link/button
			newID = newComponent.getID()

			succeeded = True
			
		except Exception as e:
			outputStr = "ERROR: " + str(e)

	else:
		outputStr += "ERROR: invalid input."
		
	return jsonify({"output": outputStr, "succeeded": succeeded, "newID": newID})
示例#6
0
    def createComp(self, NSentry, spacerData, primerData):
        """Make a ComponentDB and add to the database using a NamedSequenceDB in the
		database, a SpacerData, and a PrimerData.
		
		PARAMETERS:
			NSentry: NamedSequenceDB in the database that the component will use
			spacerData: SpacerData for the component
			primerData: PrimerData for the component
		
		RETURNS:
			c: created ComponentDB that is now in the database.
		"""
        #type checking
        if (type(NSentry) != NamedSequenceDB):
            raise TypeError("NSentry not a NamedSequenceDB")
        if (type(spacerData) != SpacerData):
            raise TypeError("spacerData not a SpacerData")
        if (type(primerData) != PrimerData):
            raise TypeError("primerData not a PrimerData")

        #check if the component already exists
        try:
            self.findComponent(NSentry.getType(), NSentry.getName(),
                               spacerData.getPosition(),
                               spacerData.getTerminalLetter())

            raise e.AlreadyExistsError("Component already exists.")
        except e.ComponentNotFoundError:
            pass

        #create database entries
        s = SpacerDataDB(position=spacerData.getPosition(),
                         spacerLeft=spacerData.getSpacerLeft(),
                         spacerRight=spacerData.getSpacerRight(),
                         isTerminal=spacerData.getIsTerminal(),
                         terminalLetter=spacerData.getTerminalLetter(),
                         leftNN=spacerData.getLeftNN(),
                         rightNN=spacerData.getRightNN())

        p = PrimerDataDB(primersFound=primerData.getPrimersFound(),
                         seqLeft=primerData.getLeftSeq(),
                         seqRight=primerData.getRightSeq(),
                         GCleft=primerData.getGCleft(),
                         GCright=primerData.getGCright(),
                         TMleft=primerData.getTMleft(),
                         TMright=primerData.getTMright())

        c = ComponentDB(namedSequence_id=NSentry.getID(), user_id=self.getID())

        #add to the database
        db.session.add(c)
        db.session.add(s)
        db.session.add(p)

        db.session.commit()

        #edit database entries so they have proper relations
        c.setSpacerDataID(s.getID())
        c.setPrimerDataID(p.getID())
        s.setCompID(c.getID())
        p.setCompID(c.getID())

        db.session.commit()

        return c