zoukankan      html  css  js  c++  java
  • test python

    #coding = utf-8
    import conn as con
    from mysql import mysql as my

    def link_ppd( pre = 'ppd' ):
    #link ppd db
        ppd_config = con.data[pre];
        ppd_db = my(ppd_config['host'],ppd_config['user'],ppd_config['pw'],ppd_config['dbname'],ppd_config['port'])
        return ppd_db

    ppd_db = link_ppd( 'uniprot' )

    def get_uniprot_data( uniprot_id , select = '*'):
        results = ppd_db.fetchall_data("select "+select+"  from  p_uniprot where `accession` like '"+uniprot_id+"' ")
        return results

    def rep(chars):
        return chars.replace(',',",")       

    ######根据uniprot id 获取相关的信息存储为 csv
    try:
        f = open("C:/Users/li_hao/Desktop/uniprot.txt")
        con = f.read()
        import csv
        csvfile = open('C:/Users/li_hao/Desktop/un.csv', 'wb+')
        spamwriter = csv.writer(csvfile, delimiter=',',quotechar='|', quoting=csv.QUOTE_MINIMAL)
        spamwriter.writerow(['uniprot', 'antigen_source', 'function', 'reference', 'other_name'])
        if(con):        
            list_arr = con.splitlines()
            for i in list_arr :
                j = i.strip(' ')
                item = j.strip('@')
                if(item == ''):
                    continue
                res = get_uniprot_data(item,"accession as uniprot,antigen_source,function,reference,other_name")
                
                if( len(res) == 0 ):
                    spamwriter.writerow([item])
             
                print 'writing data...'
                for item in res:
                     #特殊字符“ ,”,替换为“,”
                    data = [item[0],item[1],rep(item[2]),rep(item[3]),rep(item[4])]
                    spamwriter.writerow(data)
                print 'write data ok'
        csvfile.close()
        
    except IOError,msg:
        print msg



            
    ######根据uniprot id 获取相关的信息

  • 相关阅读:
    修改 MySQL 的 sql_mode 模式方法
    PHP 实现 Redis 连接池
    【转载】php解决高并发问题
    PHP 7 不适用函数:password_hash
    PDO 防止 SQL 注入示例
    记录一次 header 参数格式引发的错误
    Laravel 框架数据库查询构造器中 when 的易犯错误
    PHP 7.3.4 安装 Redis 4.0(Windows系统)
    汇编语言全梳理(精简版)
    Anaconda安装和使用
  • 原文地址:https://www.cnblogs.com/legend-song/p/4607290.html
Copyright © 2011-2022 走看看