• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

Python mysql.switch_to_db函数代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了Python中mysql.switch_to_db函数的典型用法代码示例。如果您正苦于以下问题:Python switch_to_db函数的具体用法?Python switch_to_db怎么用?Python switch_to_db使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。



在下文中一共展示了switch_to_db函数的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Python代码示例。

示例1: find_mammals

def find_mammals(cursor, trivial_name_list):
    
    mammals = []
    for trivial_name in trivial_name_list:
        switch_to_db(cursor, get_compara_name(cursor))
        tax_id = trivial2taxid (cursor, trivial_name)
        parent_id = taxid2parentid (cursor, tax_id)

        tax_id = parent_id
        is_mammal = False
        while tax_id:
            qry  = "select name_txt from names where tax_id= %d " % int(tax_id)
            qry += " and name_class = 'scientific name'";
            rows = search_db (cursor, qry)
            if rows and rows[0][0]:
                if 'mammal' in rows[0][0].lower():
                    is_mammal = True
                    break
                elif 'vertebrat' in  rows[0][0].lower():
                    # if the thing wasa mammal, we would have found it by now
                    is_mammal = False
                    break
               
            parent_id = taxid2parentid (cursor, tax_id)
            if parent_id and parent_id>1:
                tax_id = parent_id
            else:
                tax_id = None

        if is_mammal: 
            mammals.append(trivial_name)

            
    return mammals
开发者ID:ivanamihalek,项目名称:exolocator,代码行数:34,代码来源:ncbi.py


示例2: build

    def build (self, cursor):
        switch_to_db(cursor, get_compara_name(cursor))
        for leaf in self.leafs:
            leaf.tax_id = species2taxid (cursor, leaf.name)
            leaf.is_leaf = True
            self.node[leaf.tax_id] = leaf

        # build the tree using ncbi_tax.nodes
        # fill in the names using ncbi_tax.names
        switch_to_db(cursor, get_ncbi_tax_name(cursor))
        for leaf in self.leafs:
            parent_id = taxid2parentid (cursor, leaf.tax_id)
            leaf.parent_id = parent_id
            current_id     = leaf.tax_id
            # move to the root
            while current_id:
                current_node = self.node[current_id]
                parent_id    = taxid2parentid (cursor, parent_id)
                if (not parent_id or  current_id == parent_id):
                    current_node.is_root = True
                    self.root = self.node[current_id]
                    current_id = None

                else:

                    # does parent exist by any chance
                    if self.node.has_key(parent_id):
                        parent_node = self.node[parent_id]
                        parent_node.children.append(current_node)
                        # we are done here
                        current_id = None
                    else: # make new node
                        parent_name    = taxid2name(cursor, parent_id)
                        parent_node    = Node(parent_name)
                        parent_node.tax_id = parent_id
                        # grampa:
                        parent_node.parent_id = taxid2parentid (cursor, parent_id)
                        parent_node.children.append(current_node)
                        self.node[parent_id]  = parent_node
                        # attach the current node to the parent
                        current_id = parent_id
        
        # shortcircuit nodes with a single child
        new_root = self.root.__cleanup__()
        if (new_root):
            new_root.is_root = True
            self.root = new_root

        del_ids  = []
        for node_id, node in self.node.iteritems():
            if node.is_leaf:
                continue
            if (not node.children):
                del_ids.append(node_id)

        for node_id in del_ids:
            del self.node[node_id]
                              
        self.__set_parent_ids__ (self.root)
开发者ID:ivanamihalek,项目名称:exolocator,代码行数:59,代码来源:tree.py


示例3: add

 def add(self, cursor, name):
     leaf = Node(name)
     # get tax ids from the gene_db table in compara database
     switch_to_db(cursor, get_compara_name(cursor))
     leaf.tax_id = species2taxid (cursor, leaf.name)
     leaf.is_leaf = True
     self.leafs.append(leaf)
     self.node[leaf.tax_id] = leaf
开发者ID:ivanamihalek,项目名称:exolocator,代码行数:8,代码来源:tree.py


示例4: taxid2trivial

def taxid2trivial (cursor, tax_id):
    switch_to_db (cursor, get_ncbi_tax_name (cursor))
    qry  = "select name_txt from names where tax_id= %d " % int(tax_id)
    qry += " and name_class = 'trivial'";
    rows = search_db (cursor, qry)
    if (not rows or 'ERROR' in rows[0]):
        rows = search_db (cursor, qry, verbose = True)
        return ""
    return rows[0][0]
开发者ID:ivanamihalek,项目名称:exolocator,代码行数:9,代码来源:ncbi.py


示例5: trivial2taxid

def trivial2taxid (cursor, trivial_name):
    switch_to_db (cursor, get_ncbi_tax_name (cursor))
    qry  = "select tax_id from names where name_txt= '%s' " % trivial_name
    qry += " and name_class = 'trivial'";
    rows = search_db (cursor, qry)
    if (not rows or 'ERROR' in rows[0]):
        rows = search_db (cursor, qry, verbose = True)
        return ""
    return int(rows[0][0])
开发者ID:ivanamihalek,项目名称:exolocator,代码行数:9,代码来源:ncbi.py


示例6: taxid2name

def taxid2name (cursor, tax_id):
    switch_to_db (cursor, get_ncbi_tax_name (cursor))
    qry  = "select name_txt from names where tax_id= %d " % int(tax_id)
    qry += " and name_class = 'scientific name'";
    rows = search_db (cursor, qry)
    if (not rows):
        rows = search_db (cursor, qry, verbose = True)
        return ""
    return rows[0][0]
开发者ID:ivanamihalek,项目名称:exolocator,代码行数:9,代码来源:ncbi.py


示例7: taxid2parentid

def taxid2parentid (cursor, tax_id):
    switch_to_db (cursor, get_ncbi_tax_name (cursor))
    qry = "select parent_tax_id from nodes where tax_id= %d " % int(tax_id)
    rows = search_db (cursor, qry)
    if (not rows):
        rows = search_db (cursor, qry, verbose = True)
        return ""
    try:
        retval = int(rows[0][0])
    except:
        retval = ""
    return retval
开发者ID:ivanamihalek,项目名称:exolocator,代码行数:12,代码来源:ncbi.py


示例8: genome_db_id2species

def genome_db_id2species(cursor, genome_db_id):

    switch_to_db(cursor, get_compara_name(cursor))

    qry = "select name from genome_db where genome_db_id = %d" % int(genome_db_id)

    rows = search_db(cursor, qry)
    if not rows:
        search_db(cursor, qry, verbose=True)
        return ""

    return rows[0][0]
开发者ID:ivanamihalek,项目名称:exolocator,代码行数:12,代码来源:ensembl.py


示例9: species2genome_db_id

def species2genome_db_id(cursor, species):

    switch_to_db(cursor, get_compara_name(cursor))

    qry = "select genome_db_id from genome_db where name = '%s'" % species

    rows = search_db(cursor, qry)
    if not rows:
        search_db(cursor, qry, verbose=True)
        return 0

    return int(rows[0][0])
开发者ID:ivanamihalek,项目名称:exolocator,代码行数:12,代码来源:ensembl.py


示例10: species2taxid

def species2taxid(cursor, species):

    switch_to_db(cursor, get_compara_name(cursor))
    qry = "select taxon_id from genome_db where name = '%s'" % species
    rows = search_db(cursor, qry)
    if not rows:
        search_db(cursor, qry, verbose=True)
        return ""

    try:
        retval = int(rows[0][0])
    except:
        retval = ""
    return retval
开发者ID:ivanamihalek,项目名称:exolocator,代码行数:14,代码来源:ensembl.py


示例11: get_canonical_coding_exons

def get_canonical_coding_exons (cursor, gene_id, db_name=None):

    if db_name and not switch_to_db(cursor, db_name):
        return []

    all_exons =  gene2exon_list (cursor, gene_id)
    if not all_exons:  return []

    exons = filter (lambda x: x.is_coding and x.is_canonical, all_exons)
    if not exons:   return []
    # now, the problem is that an exon can be coding, 
    # but not in the canonical version of the transcript
    exons.sort(key=lambda exon: exon.start_in_gene)
    if not exons:   return []
    # is there info about the beginning and the end of canonical translation?
    canonical_transcript_id  = get_canonical_transcript_id (cursor, gene_id, db_name=None)
    if not canonical_transcript_id:   return []
    ret = get_canonical_coordinates (cursor, canonical_transcript_id)
    if not ret or not len(ret) == 4:  return []
    [canonical_start_in_exon, canonical_start_exon_id,
     canonical_end_in_exon, canonical_end_exon_id] = ret
    if canonical_start_exon_id is None or  canonical_end_exon_id is None:  return []
    
    # filter the exons that are within the start and end bracket
    canonical_exons = []
    reading = 0
    for exon in exons:
        if exon.exon_id == canonical_start_exon_id or  exon.exon_id == canonical_end_exon_id:
            reading = 1 - reading
            canonical_exons.append(exon)
        elif reading:
            canonical_exons.append(exon)
        
    return canonical_exons
开发者ID:ivanamihalek,项目名称:tcga,代码行数:34,代码来源:ensembl.py


示例12: get_exon

def get_exon(cursor, exon_id, is_known=None, db_name=None):

    exon = Exon()

    if db_name:
        if not switch_to_db(cursor, db_name):
            return exon

    if is_known == 2:
        # sw# exon
        qry = "select * from sw_exon where exon_id = %d" % exon_id
        rows = search_db(cursor, qry, verbose=False)
        if not rows:
            return exon
        exon.load_from_novel_exon(rows[0], "sw_exon")
    elif is_known == 3:
        # sw# exon
        qry = "select * from usearch_exon where exon_id = %d" % exon_id
        rows = search_db(cursor, qry, verbose=False)
        if not rows:
            return exon
        exon.load_from_novel_exon(rows[0], "usearch_exon")
    else:
        qry = "select * from gene2exon where exon_id = %d" % exon_id
        if is_known:
            qry += " and is_known = %s " % is_known
        rows = search_db(cursor, qry, verbose=False)
        if not rows:
            return exon
        exon.load_from_gene2exon(rows[0])

    return exon
开发者ID:ivanamihalek,项目名称:exolocator,代码行数:32,代码来源:ensembl.py


示例13: gene2exon_list

def gene2exon_list(cursor, gene_id, db_name=None, verbose=False):

    exons = []

    if db_name:
        if not switch_to_db(cursor, db_name):
            return False

    qry = "select * from gene2exon where gene_id = %d " % gene_id
    rows = search_db(cursor, qry)

    if not rows:
        rows = search_db(cursor, "select database()")
        if verbose:
            print "database ", rows[0][0]
            rows = search_db(cursor, qry, verbose=True)
            print rows
        return []

    for row in rows:
        exon = Exon()
        if not exon.load_from_gene2exon(row):
            continue
        exons.append(exon)

    return exons
开发者ID:ivanamihalek,项目名称:exolocator,代码行数:26,代码来源:ensembl.py


示例14: get_common_name

def get_common_name (cursor, species):
    switch_to_db(cursor, get_compara_name(cursor))
    tax_id = species2taxid (cursor, species)
    switch_to_db(cursor,get_ncbi_tax_name (cursor))
    qry   = "select name_txt from names where "
    qry  += "tax_id = %d and " % tax_id
    qry  += "name_class = 'genbank common name'"
    rows = search_db (cursor, qry)
    if rows:
        if ('ERROR' in rows[0]):
            search_db (cursor, qry, verbose = True)
            return ""
        else:
            return rows[0][0]

    return ""
开发者ID:ivanamihalek,项目名称:exolocator,代码行数:16,代码来源:ncbi.py


示例15: get_exon_seq_by_db_id

def get_exon_seq_by_db_id(cursor, exon_seq_id, db_name=None):

    if db_name:
        if not switch_to_db(cursor, db_name):
            return False

    qry = "select exon_seq_id, protein_seq, pepseq_transl_start, pepseq_transl_end, "
    qry += " left_flank, right_flank, dna_seq  "
    qry += " from exon_seq where exon_seq_id = %d" % exon_seq_id
    rows = search_db(cursor, qry)
    if not rows:
        # rows = search_db(cursor, qry, verbose = True)
        return []

    [exon_seq_id, protein_seq, pepseq_transl_start, pepseq_transl_end, left_flank, right_flank, dna_seq] = rows[0]
    if protein_seq is None:
        protein_seq = ""
    if left_flank is None:
        left_flank = ""
    if right_flank is None:
        right_flank = ""
    if dna_seq is None:
        dna_seq = ""

    return [exon_seq_id, protein_seq, pepseq_transl_start, pepseq_transl_end, left_flank, right_flank, dna_seq]
开发者ID:ivanamihalek,项目名称:exolocator,代码行数:25,代码来源:ensembl.py


示例16: get_exon_pepseq

def get_exon_pepseq(cursor, exon, db_name=None, verbose=False):

    if db_name:
        if not switch_to_db(cursor, db_name):
            return False

    if exon.exon_seq_id:
        exon_seq_id = exon.exon_seq_id
        qry = "select protein_seq "
        qry += " from exon_seq where exon_seq_id = %d" % exon_seq_id
    else:
        exon_id = exon.exon_id
        is_known = exon.is_known
        qry = "select protein_seq  "
        qry += " from exon_seq where exon_id = %d and is_known = %d" % (exon_id, is_known)

    rows = search_db(cursor, qry)

    if not rows:
        if verbose:
            rows = search_db(cursor, qry, verbose=True)
            print rows
        return ""

    protein_seq = rows[0][0]
    if protein_seq is None:
        protein_seq = ""

    return protein_seq
开发者ID:ivanamihalek,项目名称:exolocator,代码行数:29,代码来源:ensembl.py


示例17: get_maps

def get_maps(cursor, ensembl_db_name, exon_id, is_known):
    
    maps = []

    switch_to_db (cursor,  ensembl_db_name['homo_sapiens'])
    qry  = "select * from exon_map where exon_id = %d " % exon_id
    qry += " and exon_known = %d " % is_known

    rows = search_db (cursor, qry)
    if not rows or "ERROR" in rows[0]:
        return []

    for row in rows:
        map = Map()
        map.load_from_db(row, cursor)
        maps.append(map)
    return maps
开发者ID:ivanamihalek,项目名称:el_server,代码行数:17,代码来源:map.py


示例18: get_pepseq_transl_range

def get_pepseq_transl_range(cursor, exon_id, exon_known, db_name=None):
    if db_name and not switch_to_db(cursor, db_name):
        return []
    qry = "select pepseq_transl_start, pepseq_transl_end from exon_seq "
    qry += "where exon_id = %d " % int(exon_id)
    qry += "and is_known = %d " % int(exon_known)
    if not rows:
        return []
    return rows[0]
开发者ID:ivanamihalek,项目名称:exolocator,代码行数:9,代码来源:ensembl.py


示例19: exon_id2gene_id

def exon_id2gene_id(cursor, ensembl_db_name, exon_id, is_known):

    switch_to_db(cursor, ensembl_db_name)
    if is_known == 3:  # sw_sharp exon
        qry = "select gene_id from usearch_exon where "
        qry += "exon_id = %d " % exon_id
    elif is_known == 2:  # sw_sharp exon
        qry = "select gene_id from sw_exon where "
        qry += "exon_id = %d " % exon_id
    else:
        qry = "select gene_id from gene2exon where "
        qry += "exon_id = %s and is_known = %s " % (exon_id, is_known)

    rows = search_db(cursor, qry)
    if not rows or "ERROR" in rows[0]:
        rows = search_db(cursor, qry, verbose=True)
        return ""

    return rows[0][0]
开发者ID:ivanamihalek,项目名称:exolocator,代码行数:19,代码来源:ensembl.py


示例20: get_description

def get_description(cursor, gene_id, db_name=None):

    if db_name:
        if not switch_to_db(cursor, db_name):
            return False
    qry = "select description from gene where gene_id = %d " % int(gene_id)
    rows = search_db(cursor, qry)
    if rows:
        return rows[0][0]

    return ""
开发者ID:ivanamihalek,项目名称:exolocator,代码行数:11,代码来源:ensembl.py



注:本文中的mysql.switch_to_db函数示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Python mysql.Mysql类代码示例发布时间:2022-05-27
下一篇:
Python mysql.search_db函数代码示例发布时间:2022-05-27
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap