def get_translation_from_GeneID(self, GeneID): self.c = db_conf.db_conf(username=self.username, password=self.password, server=self.server, db=self.database).get_cursor() self.db = pham.db(c=self.c) return phamerator_manage_db.get_translation_from_GeneID(self.c, GeneID)
def get_scores(self, query, subject): self.c = db_conf.db_conf(username=self.username, password=self.password, server=self.server, db=self.database).get_cursor() self.db = pham.db(c=self.c) return phamerator_manage_db.get_scores(self.c, query, subject)
def get_unique_phams(self): self.c = db_conf.db_conf(username=self.username, password=self.password, server=self.server, db=self.database).get_cursor() self.db = pham.db(c=self.c) return phamerator_manage_db.get_unique_phams(self.c)
def create_genome_map(self,phages): self.c = db_conf.db_conf(username=self.username,password=self.password,server=self.server,db=self.database).get_cursor() self.db = pham.db(c = self.c) lengths = [] for phage in phages: length = phamerator_manage_db.get_length_of_genome(self.c,phage["PhageID"]) lengths.append(length) length = max(lengths) self.canvas = goocanvas.Canvas() canvasInterface = cartographer.CanvasInterface(self.c, self.canvas) self.canvas.set_root_item_model(canvasInterface.create_canvas_model(phages, length)) zoomFactor = 20.0 self.canvas.set_bounds(0,0,length/zoomFactor, 100000) needs_new = True while needs_new == True: name = "/tmp/phageSOAP/tmp" + str(hash(str(random.randint(1,64563))+str(hash(self.canvas)))) if os.path.exists(name): needs_new = True else: needs_new = False self.current_genome_map = name surface = cairo.SVGSurface (self.current_genome_map, (length/zoomFactor)+72, 5*72*len(phages)) cr = cairo.Context (surface) cr.translate (36, 130) self.canvas.render (cr, None, 0.1) cr.show_page () print "\n>genome map generated\n" return "genome map generated\n"
def get_genes_from_PhageID(self, PhageID): self.c = db_conf.db_conf(username=self.username, password=self.password, server=self.server, db=self.database).get_cursor() self.db = pham.db(c=self.c) return phamerator_manage_db.get_genes_from_PhageID(self.c, PhageID)
def get_fasta_from_pham(self, phamName): self.c = db_conf.db_conf(username=self.username, password=self.password, server=self.server, db=self.database).get_cursor() self.db = pham.db(c=self.c) return phamerator_manage_db.get_fasta_from_pham(self.c, phamName)
def get_all_scores(self, alignmentType='both'): self.c = db_conf.db_conf(username=self.username, password=self.password, server=self.server, db=self.database).get_cursor() self.db = pham.db(c=self.c) return phamerator_manage_db.get_all_scores(self.c, alignmentType=alignmentType)
def get_gene_start_stop_length_orientation_from_GeneID(self, GeneID): self.c = db_conf.db_conf(username=self.username, password=self.password, server=self.server, db=self.database).get_cursor() self.db = pham.db(c=self.c) return phamerator_manage_db.get_gene_start_stop_length_orientation_from_GeneID( self.c, GeneID)
def create_pham_circle(self,phamName,alignmentColor,adjustment,radius): self.c = db_conf.db_conf(username=self.username,password=self.password,server=self.server,db=self.database).get_cursor() self.db = pham.db(c = self.c) filename = str(phamName) + str(alignmentColor) + str(adjustment) + str(radius) filelist = os.listdir(self.cachedir) for item in filelist: if item == filename: self.current_phamCircle = self.cachedir + filename string = "phamCircle " + str(phamName) + " found in cache, using cached version\n" print ">" + string return string self.radius = radius self.alignmentColor = alignmentColor self.threshold = 0.70 self.phamCircleCanvas = goocanvas.Canvas() GeneIDs = phamerator_manage_db.get_members_of_pham(self.c, phamName) memberPhages, self.nonMemberPhages = [], [] for GeneID in GeneIDs: PhageID = phamerator_manage_db.get_PhageID_from_GeneID(self.c, GeneID) if PhageID not in memberPhages: memberPhages.append(PhageID) totalPhages = phamerator_manage_db.get_PhageIDs(self.c) for p in totalPhages: if p not in memberPhages: self.nonMemberPhages.append(phamerator_manage_db.get_phage_name_from_PhageID(self.c, p)) self.l = [] self.genes = [] for a in GeneIDs: for b in GeneIDs: if a != b: for gene in [a, b]: if gene not in self.genes: self.genes.append(gene) clustalwScore, blastScore = phamerator_manage_db.get_scores(self.c, a, b) if clustalwScore >= 0.275: self.l.append((a, b, 'clustalw',clustalwScore)) if blastScore and blastScore <= 0.0001: self.l.append((a, b, 'blast',blastScore)) self.phamCircle = PhamDisplay.PhamCircle(phamName, self.c,verbose=True,radius=self.radius) if self.alignmentColor == True: self.phamCircleCanvas.set_root_item_model(self.phamCircle.create_canvas_model(self.nonMemberPhages, self.genes, self.l,adjustment,self.threshold,blastColor='#ff0000', clustalwColor='#0000ff')) else: phamColorFromDataBase = self.db.select('pham_color','color',name = phamName)[0][0] self.phamCircleCanvas.set_root_item_model(self.phamCircle.create_canvas_model(self.nonMemberPhages, self.genes, self.l,adjustment,self.threshold,allColor = phamColorFromDataBase)) """x, y = (600, 500) self.phamCircleCanvas.set_size_request(x, y) self.defaultPhamCircleCanvasSize = (x, y) self.phamCircleCanvas.show() self.window.window.set_cursor(None) return False""" self.current_phamCircle = self.cachedir + filename self.phamCircleCanvas.set_bounds(0,0, 10000, 10000) surface = cairo.SVGSurface (self.current_phamCircle, 15*72, 15*72) cr = cairo.Context (surface) cr.translate (10, 0) self.phamCircleCanvas.render (cr, None, 0.1) cr.show_page() string = "phamCircle " + str(phamName) + " generated\n" print ">" + string return string
def get_GeneIDs(self, type=None, PhageID=None): self.c = db_conf.db_conf(username=self.username, password=self.password, server=self.server, db=self.database).get_cursor() self.db = pham.db(c=self.c) return phamerator_manage_db.get_GeneIDs(self.c, type=type, PhageID=PhageID)
def get_number_of_pham_members(self, phamName, PhageID=None): self.c = db_conf.db_conf(username=self.username, password=self.password, server=self.server, db=self.database).get_cursor() self.db = pham.db(c=self.c) return phamerator_manage_db.get_number_of_pham_members(self.c, phamName, PhageID=PhageID)
def get_relatives(self, GeneID, alignmentType='both', blastThreshold=None, clustalwThreshold=None): self.c = db_conf.db_conf(username=self.username, password=self.password, server=self.server, db=self.database).get_cursor() self.db = pham.db(c=self.c) return phamerator_manage_db.get_relatives( self.c, GeneID, alignmentType=alignmentType, blastThreshold=blastThreshold, clustalwThreshold=clustalwThreshold)
def create_genome_map(self, phages): self.c = db_conf.db_conf(username=self.username, password=self.password, server=self.server, db=self.database).get_cursor() self.db = pham.db(c=self.c) lengths = [] for phage in phages: length = phamerator_manage_db.get_length_of_genome( self.c, phage["PhageID"]) lengths.append(length) length = max(lengths) self.canvas = goocanvas.Canvas() canvasInterface = cartographer.CanvasInterface(self.c, self.canvas) self.canvas.set_root_item_model( canvasInterface.create_canvas_model(phages, length)) zoomFactor = 20.0 self.canvas.set_bounds(0, 0, length / zoomFactor, 100000) needs_new = True while needs_new == True: name = "/tmp/phageSOAP/tmp" + str( hash(str(random.randint(1, 64563)) + str(hash(self.canvas)))) if os.path.exists(name): needs_new = True else: needs_new = False self.current_genome_map = name surface = cairo.SVGSurface(self.current_genome_map, (length / zoomFactor) + 72, 5 * 72 * len(phages)) cr = cairo.Context(surface) cr.translate(36, 130) self.canvas.render(cr, None, 0.1) cr.show_page() print "\n>genome map generated\n" return "genome map generated\n"
def get_all_scores(self, alignmentType='both'): self.c = db_conf.db_conf(username=self.username,password=self.password,server=self.server,db=self.database).get_cursor() self.db = pham.db(c = self.c) return phamerator_manage_db.get_all_scores(self.c, alignmentType=alignmentType)
def get_genes_from_PhageID(self, PhageID): self.c = db_conf.db_conf(username=self.username,password=self.password,server=self.server,db=self.database).get_cursor() self.db = pham.db(c = self.c) return phamerator_manage_db.get_genes_from_PhageID(self.c, PhageID)
def get_GeneIDs(self, type=None, PhageID=None): self.c = db_conf.db_conf(username=self.username,password=self.password,server=self.server,db=self.database).get_cursor() self.db = pham.db(c = self.c) return phamerator_manage_db.get_GeneIDs(self.c, type=type, PhageID=PhageID)
def get_seq_from_GeneID(self, GeneID, extra=None): self.c = db_conf.db_conf(username=self.username,password=self.password,server=self.server,db=self.database).get_cursor() self.db = pham.db(c = self.c) return phamerator_manage_db.get_seq_from_GeneID(self.c, GeneID, extra=extra)
def main(): argDict = get_options(sys.argv[1:]) # cfg = ConfigParser.RawConfigParser() # cfg.read(os.path.join(os.environ['HOME'], '.my.cnf')) # try: # username = cfg.get('client','user') # except ConfigParser.NoOptionError: if argDict['user']: username = argDict['user'] else: username = raw_input('database username: '******'client','password') # except ConfigParser.NoOptionError: if "password" in argDict: password = getpass.getpass('database password: '******'' database = argDict['database'] server = argDict['server'] cthreshold = argDict['clustalw_threshold'] bthreshold = argDict['blast_threshold'] c = db_conf.db_conf(username=username, password=password, server=server, db=database).get_cursor() db = pham.db(c) GeneIDs = get_GeneIDs(c) # get all the phams that are in the database oldController = pham.PhamController(c, source='db') # create an empty PhamController object that will be populated with phams for pre-existing genes only # this checks to make sure these phams are still valid based on new BLAST scores currentController = pham.PhamController(c) new_genes = [] for GeneID in GeneIDs: if not oldController.find_phams_with_gene(str(GeneID)): #print '%s is not in a pham' % str(GeneID) new_genes.append(str(GeneID)) print 'there are %s genes that are not assigned to a pham' % len(new_genes) print 'ignoring these and verifying the old phams...' # Make sure that the existing phams in the database are still valid based on the # current alignment scores for GeneID in GeneIDs: if GeneID in new_genes: continue relatives = follow_rel_chain2(c, GeneID, [], ignore=new_genes, cthreshold=cthreshold, bthreshold=bthreshold) p = pham.Pham(name=None, members=[], children=[]) p.add_members((GeneID, )) p.add_members(relatives) print 'created pham' try: #print 'creating a new pham and adding it to the currentController:', p currentController.add_pham(p) except pham.DuplicatePhamError: pass #print 'pham %s is already in the current controller:' % p # Look for phams that should be joined because they each contain the same gene. # Join any that are found. for GeneID in GeneIDs: pwg = currentController.find_phams_with_gene( str(GeneID)) #pwg = phams with gene #print 'GeneID: %s, pwg: %s' % (GeneID, pwg) if pwg: # one (and only one) pham already contains this gene, don't do anything if len(pwg) == 1: p = pwg[0] # if this gene is already in more than one pham, join those phams elif len(pwg) > 1: p = currentController.join_phams(pwg) print "there are %s total phams when ignoring new genes" % len( currentController.phams) currentController = currentController - oldController print "there are %s split phams that need to be phixed" % len( currentController.phams) currentController.save() # create an empty PhamController object that will be populated with phams for new and pre-existing genes # the pre-existing phams will be subtracted out of this object's pham list newController = pham.PhamController(c) oldController = pham.PhamController(c, source='db') # for every gene in the database, figure out if it is already in a pham for GeneID in GeneIDs: append = True relatives = follow_rel_chain2(c, GeneID, [], cthreshold=cthreshold, bthreshold=bthreshold) pwg = newController.find_phams_with_gene( str(GeneID)) #pwg = phams with gene #print 'GeneID: %s, pwg: %s' % (GeneID, pwg) if pwg: # one (and only one) pham already contains this gene, don't do anything if len(pwg) == 1: p = pwg[0] # if this gene is already in more than one pham, join those phams elif len(pwg) > 1: ###print 'joining phams...' #for item in pwg: print item.members p = newController.join_phams(pwg) # if this gene isn't in a pham already, create a new pham else: p = pham.Pham(name=None, members=[], children=[]) p.add_members((GeneID, )) # add any genes related to this gene to the pham that it's in p.add_members(relatives) toJoin = [p] for gene in p.members: for result in newController.find_phams_with_gene(gene): if result not in toJoin: toJoin.append(result) if len(toJoin) > 1: #print 'joining phams with these members:' #for j in toJoin: print j, j.name, j.members p = newController.join_phams(toJoin) if append: ###print 'adding pham', p, 'with members:', p.members try: newController.add_pham(p) except: pham.DuplicatePhamError newController = newController - oldController print "there are", len(newController.phams), "new phams." for newPham in newController.phams: print newPham print "Saving..." newController.save()
def get_number_of_pham_members(self, phamName, PhageID=None): self.c = db_conf.db_conf(username=self.username,password=self.password,server=self.server,db=self.database).get_cursor() self.db = pham.db(c = self.c) return phamerator_manage_db.get_number_of_pham_members(self.c, phamName, PhageID=PhageID)
def get_unique_phams(self): self.c = db_conf.db_conf(username=self.username,password=self.password,server=self.server,db=self.database).get_cursor() self.db = pham.db(c = self.c) return phamerator_manage_db.get_unique_phams(self.c)
def get_pham(self): db = pham.db(c) pham = db.select('pham', name, GeneID = self.GeneID) return pham
def main(): argDict = get_options(sys.argv[1:]) # cfg = ConfigParser.RawConfigParser() # cfg.read(os.path.join(os.environ['HOME'], '.my.cnf')) # try: # username = cfg.get('client','user') # except ConfigParser.NoOptionError: if argDict['user']: username = argDict['user'] else: username = raw_input('database username: '******'client','password') # except ConfigParser.NoOptionError: if "password" in argDict: password = getpass.getpass('database password: '******'' database = argDict['database'] server = argDict['server'] cthreshold = argDict['clustalw_threshold'] bthreshold = argDict['blast_threshold'] c = db_conf.db_conf(username=username, password=password, server=server, db=database).get_cursor() db = pham.db(c) GeneIDs = get_GeneIDs(c) # get all the phams that are in the database oldController = pham.PhamController(c, source='db') # create an empty PhamController object that will be populated with phams for pre-existing genes only # this checks to make sure these phams are still valid based on new BLAST scores currentController = pham.PhamController(c) new_genes = [] for GeneID in GeneIDs: if not oldController.find_phams_with_gene(str(GeneID)): #print '%s is not in a pham' % str(GeneID) new_genes.append(str(GeneID)) print 'there are %s genes that are not assigned to a pham' % len(new_genes) print 'ignoring these and verifying the old phams...' # Make sure that the existing phams in the database are still valid based on the # current alignment scores for GeneID in GeneIDs: if GeneID in new_genes: continue relatives = follow_rel_chain2(c, GeneID, [], ignore=new_genes, cthreshold=cthreshold, bthreshold=bthreshold) p = pham.Pham(name=None, members=[], children=[]) p.add_members((GeneID,)) p.add_members(relatives) print 'created pham' try: #print 'creating a new pham and adding it to the currentController:', p currentController.add_pham(p) except pham.DuplicatePhamError: pass #print 'pham %s is already in the current controller:' % p # Look for phams that should be joined because they each contain the same gene. # Join any that are found. for GeneID in GeneIDs: pwg = currentController.find_phams_with_gene(str(GeneID)) #pwg = phams with gene #print 'GeneID: %s, pwg: %s' % (GeneID, pwg) if pwg: # one (and only one) pham already contains this gene, don't do anything if len(pwg) == 1: p = pwg[0] # if this gene is already in more than one pham, join those phams elif len(pwg) > 1: p = currentController.join_phams(pwg) print "there are %s total phams when ignoring new genes" % len(currentController.phams) currentController = currentController - oldController print "there are %s split phams that need to be phixed" % len(currentController.phams) currentController.save() # create an empty PhamController object that will be populated with phams for new and pre-existing genes # the pre-existing phams will be subtracted out of this object's pham list newController = pham.PhamController(c) oldController = pham.PhamController(c, source='db') # for every gene in the database, figure out if it is already in a pham for GeneID in GeneIDs: append=True relatives = follow_rel_chain2(c, GeneID, [], cthreshold=cthreshold, bthreshold=bthreshold) pwg = newController.find_phams_with_gene(str(GeneID)) #pwg = phams with gene #print 'GeneID: %s, pwg: %s' % (GeneID, pwg) if pwg: # one (and only one) pham already contains this gene, don't do anything if len(pwg) == 1: p = pwg[0] # if this gene is already in more than one pham, join those phams elif len(pwg) > 1: ###print 'joining phams...' #for item in pwg: print item.members p = newController.join_phams(pwg) # if this gene isn't in a pham already, create a new pham else: p = pham.Pham(name=None, members=[], children=[]) p.add_members((GeneID,)) # add any genes related to this gene to the pham that it's in p.add_members(relatives) toJoin = [p] for gene in p.members: for result in newController.find_phams_with_gene(gene): if result not in toJoin: toJoin.append(result) if len(toJoin) > 1: #print 'joining phams with these members:' #for j in toJoin: print j, j.name, j.members p = newController.join_phams(toJoin) if append: ###print 'adding pham', p, 'with members:', p.members try: newController.add_pham(p) except: pham.DuplicatePhamError newController = newController - oldController print "there are", len(newController.phams), "new phams." for newPham in newController.phams: print newPham print "Saving..." newController.save()
def get_fasta_from_pham(self, phamName): self.c = db_conf.db_conf(username=self.username,password=self.password,server=self.server,db=self.database).get_cursor() self.db = pham.db(c = self.c) return phamerator_manage_db.get_fasta_from_pham(self.c, phamName)
def get_relatives(self, GeneID, alignmentType='both', blastThreshold=None, clustalwThreshold=None): self.c = db_conf.db_conf(username=self.username,password=self.password,server=self.server,db=self.database).get_cursor() self.db = pham.db(c = self.c) return phamerator_manage_db.get_relatives(self.c, GeneID, alignmentType=alignmentType, blastThreshold=blastThreshold, clustalwThreshold=clustalwThreshold)
def get_scores(self, query, subject): self.c = db_conf.db_conf(username=self.username,password=self.password,server=self.server,db=self.database).get_cursor() self.db = pham.db(c = self.c) return phamerator_manage_db.get_scores(self.c, query, subject)
def get_gene_start_stop_length_orientation_from_GeneID(self, GeneID): self.c = db_conf.db_conf(username=self.username,password=self.password,server=self.server,db=self.database).get_cursor() self.db = pham.db(c = self.c) return phamerator_manage_db.get_gene_start_stop_length_orientation_from_GeneID(self.c, GeneID)
def create_pham_circle(self, phamName, alignmentColor, adjustment, radius): self.c = db_conf.db_conf(username=self.username, password=self.password, server=self.server, db=self.database).get_cursor() self.db = pham.db(c=self.c) filename = str(phamName) + str(alignmentColor) + str(adjustment) + str( radius) filelist = os.listdir(self.cachedir) for item in filelist: if item == filename: self.current_phamCircle = self.cachedir + filename string = "phamCircle " + str( phamName) + " found in cache, using cached version\n" print ">" + string return string self.radius = radius self.alignmentColor = alignmentColor self.threshold = 0.70 self.phamCircleCanvas = goocanvas.Canvas() GeneIDs = phamerator_manage_db.get_members_of_pham(self.c, phamName) memberPhages, self.nonMemberPhages = [], [] for GeneID in GeneIDs: PhageID = phamerator_manage_db.get_PhageID_from_GeneID( self.c, GeneID) if PhageID not in memberPhages: memberPhages.append(PhageID) totalPhages = phamerator_manage_db.get_PhageIDs(self.c) for p in totalPhages: if p not in memberPhages: self.nonMemberPhages.append( phamerator_manage_db.get_phage_name_from_PhageID( self.c, p)) self.l = [] self.genes = [] for a in GeneIDs: for b in GeneIDs: if a != b: for gene in [a, b]: if gene not in self.genes: self.genes.append(gene) clustalwScore, blastScore = phamerator_manage_db.get_scores( self.c, a, b) if clustalwScore >= 0.275: self.l.append((a, b, 'clustalw', clustalwScore)) if blastScore and blastScore <= 0.0001: self.l.append((a, b, 'blast', blastScore)) self.phamCircle = PhamDisplay.PhamCircle(phamName, self.c, verbose=True, radius=self.radius) if self.alignmentColor == True: self.phamCircleCanvas.set_root_item_model( self.phamCircle.create_canvas_model(self.nonMemberPhages, self.genes, self.l, adjustment, self.threshold, blastColor='#ff0000', clustalwColor='#0000ff')) else: phamColorFromDataBase = self.db.select('pham_color', 'color', name=phamName)[0][0] self.phamCircleCanvas.set_root_item_model( self.phamCircle.create_canvas_model( self.nonMemberPhages, self.genes, self.l, adjustment, self.threshold, allColor=phamColorFromDataBase)) """x, y = (600, 500) self.phamCircleCanvas.set_size_request(x, y) self.defaultPhamCircleCanvasSize = (x, y) self.phamCircleCanvas.show() self.window.window.set_cursor(None) return False""" self.current_phamCircle = self.cachedir + filename self.phamCircleCanvas.set_bounds(0, 0, 10000, 10000) surface = cairo.SVGSurface(self.current_phamCircle, 15 * 72, 15 * 72) cr = cairo.Context(surface) cr.translate(10, 0) self.phamCircleCanvas.render(cr, None, 0.1) cr.show_page() string = "phamCircle " + str(phamName) + " generated\n" print ">" + string return string
def get_pham(self): db = pham.db(c) pham = db.select("pham", name, GeneID=self.GeneID) return pham