#coding:utf-8
__author__ = 'similarface'
from multiprocessing import Process
import happybase
import os
import re
import hashlib
import multiprocessing
from multiprocessing import Queue
basedir="/tmp/t8"
filterpath="/Users/similarface/Documents/20170303Morgene999ProductFullSNP.txt"
snpkey={}
pattern_barcode= re.compile(r'[0-9]{3}[-][0-9]{4}[-][0-9]{4}')
pattern_ls=re.compile(r'\s+')
def func(filepath,snpkey):
conn=happybase.Connection(host='192.168.30.250')
table=conn.table('chipdata')
barcodes=pattern_barcode.findall(filepath)
barcode=barcodes[0]
i=0
all=0
with open(filepath,'rb') as foper:
for line in foper:
try:
lines=pattern_ls.split(line.strip())
chr=lines[1]
pos=lines[2]
key=chr+":"+pos
#print key
if key in snpkey:
all=all+1
m = hashlib.md5()
m.update(pos.strip())
rowkey = m.hexdigest()+":"+chr.upper()
dictkey='d:'+barcode
columns=[dictkey]
rows_as_dict = dict(table.row(rowkey,columns))
if rows_as_dict[dictkey]==lines[3]:
i=i+1
except Exception,e:
pass
print barcode+":"+format((i+0.0)/all,'0.1%')+"match"+str(i)
#q.put(barcode+":"+format((i+0.0)/all,'0.1%'))
conn.close() def read(q):
while True:
value = q.get(True)
print 'Get %s from queue.' % value if __name__ == "__main__":
pool = multiprocessing.Pool(processes = 3)
snpkey={}
q = Queue()
pattern_s=re.compile(r'\s+')
with open(filterpath,'rb') as oper:
for line in oper:
if line.strip()!="":
lines=pattern_s.split(line.strip())
snpkey[':'.join(lines[0:2])]="" # pr = Process(target=read, args=(q,))
# pr.start() for filename in os.listdir(basedir):
if filename.endswith("snp"):
filterpath=os.path.join(basedir,filename)
pool.apply_async(func, args=(filterpath,snpkey)) #维持执行的进程总数为processes,当一个进程执行完毕后会添加新的进程进去 print "Mark~ Mark~ Mark~~~~~~~~~~~~~~~~~~~~~~"
pool.close()
pool.join() #调用join之前,先调用close函数,否则会出错。执行完close后不会有新的进程加入到pool,join函数等待所有子进程结束
print "Sub-process(es) done."
#pr.terminate()

最新文章

  1. HashMap与HashTable的区别
  2. 在IIS中实现JSP
  3. oracle 11g express 快速入门
  4. for变量作用域(vc6与vs)
  5. xmpp整理笔记:xmppFramework框架的导入和介绍
  6. css 字体超出隐藏
  7. Java中的json数据类型操作
  8. startUML常用的组合片段
  9. linux下如何执行PHP脚本
  10. Prof UIS相关
  11. kafka c++客户端编译
  12. 【转】如何实现Flex页面跳转
  13. ng-cordova(插件库)
  14. 基于NFS实现WordPress
  15. mentohust 使用
  16. 解决phpmyadmin 遇见的问题
  17. python的__new__方法
  18. zeromy quick start - python
  19. jQuery的杂项
  20. PHP与Python哪个做网站产品好?

热门文章

  1. 【set】【multiset】bzoj1058 [ZJOI2007]报表统计
  2. 1.3(Spring MVC学习笔记)数据绑定
  3. 焦点改变事件OnFocusChangeListener
  4. jQuery判断一个元素是否为另一个元素的子元素
  5. &#x开头的是什么编码?
  6. javascript 常用手势 分析
  7. nodeJs的模块依赖
  8. 【后台管理系统】—— Ant Design Pro入门学习&项目实践笔记(三)
  9. php中将SimpleXMLElement Object数组转化为普通数组
  10. 更改Eclipse下Tomcat的部署目录