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 获取相关的信息

上一篇:IntelliJ IDEA 2019年最新版2019.3.1 安装激活教程【最强,可用至2100、2089年】


下一篇:Json的序列化与反序列化以及乱入的k_BackingField