#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()

python使用hbase的更多相关文章

  1. 【hbase】使用thrift with python 访问HBase

    HBase 版本: 0.98.6 thrift   版本: 0.9.0 使用 thrift client with python 连接 HBase 报错: Traceback (most recent ...

  2. Hbase理论&&hbase shell&&python操作hbase&&python通过mapreduce操作hbase

    一.Hbase搭建: 二.理论知识介绍: 1Hbase介绍: Hbase是分布式.面向列的开源数据库(其实准确的说是面向列族).HDFS为Hbase提供可靠的底层数据存储服务,MapReduce为Hb ...

  3. python 操作 hbase

    python 是万能的,当然也可以通过api去操作big database 的hbase了,python是通过thrift去访问操作hbase 以下是在centos7 上安装操作,前提是hbase已经 ...

  4. python连接hbase

    安装HBase HBase是一个构建在HDFS上的分布式列存储系统,主要用于海量结构化数据存储.这里,我们的目标只是为Python访问HBase提供一个基本的环境,故直接下载二进制包,采用单机安装.下 ...

  5. ambari安装集群下python连接hbase之安装thrift

    简介: python连接hbase是需要通过thrift连进行连接的,ambari安装的服务中貌似没有自带安装hbase的thrift,我是看配置hbase的配置名称里面没有thrift,cdh版本的 ...

  6. 【Hbase三】Java,python操作Hbase

    Java,python操作Hbase 操作Hbase python操作Hbase 安装Thrift之前所需准备 安装Thrift 产生针对Python的Hbase的API 启动Thrift服务 执行p ...

  7. Python操作HBase之happybase

    安装Thrift 安装Thrift的具体操作,请点击链接 pip install thrift 安装happybase pip install happybase 连接(happybase.Conne ...

  8. python实现Hbase

    1. 下载thrift 作用:翻译python语言为hbase语言的工具 2. 运行时先启动hbase 再启动thrift,最后在pycharm中通过happybase包连接hbase 在hbase目 ...

  9. python操作Hbase

    本地操作 启动thrift服务:./bin/hbase-daemon.sh start thrift hbase模块产生: 下载thrfit源码包:thrift-0.8.0.tar.gz 解压安装 . ...

  10. python thrift hbase安装连接

    默认已装好 hbase,我的版本是hbase-0.98.24,并运行 python 2.7.x 步骤: sudo apt-get install automake bison flex g++ git ...

随机推荐

  1. java 获取系统信息及CPU的使用率(转)

    java 获取系统信息及CPU的使用率 原文:http://kakaluyi.javaeye.com/blog/211492 最近做个项目,就是要取得cpu占有率等等的系统信息,一开始以为要用动态链接 ...

  2. SpringBoot定时任务(Spring Schedule )实现方法

    FastDateFormat fdf = FastDateFormat.getInstance("yyyy-MM-dd HH:mm:ss"); fdf.format(new Dat ...

  3. Error:Execution failed for task ‘:app:processDebugManifest’.

    Error:Execution failed for task ':app:processDebugManifest'. > Manifest merger failed : Attribute ...

  4. Java几种常见的四舍五入的方法

    /* * 在上面简单地介绍了银行家舍入法,目前java支持7中舍入法: 1. ROUND_UP:远离零方向舍入.向绝对值最大的方向舍入,只要舍弃位非0即进位. 2. ROUND_DOWN:趋向零方向舍 ...

  5. [Java基础] 使用JMAP dump及分析dump文件

    转载:http://blog.csdn.net/kevin_luan/article/details/8447896 http://liulinxia02.blog.163.com/blog/stat ...

  6. javascript(JQuery)元素操作

    html代码如下: <div id="picK"> <ul> <li style="float:left;width:90px;" ...

  7. centos7 ping127.0.0.1不通

    ping 127.0.0.1,localhost和本地ip都不通,所有的配置也是正确的 检查下是否禁止了ping vim /proc/sys/net/ipv4/icmp_echo_ignore_all ...

  8. nagios系列教程地址

    http://www.sosidc.com/sort/10/page/3 http://www.sosidc.com/sort/10/page/2 http://www.sosidc.com/sort ...

  9. 深度剖析OpenGL ES中的多线程和多窗口渲染技术

    由 创新网小编 于 星期五, 2014-04-11 14:56 发表 移动设备中的CPU和GPU已经变得很强大,到处都是配备一个或多个高分辨率屏幕的设备,需要使用带有图形驱动器的复杂交互也日益增加.在 ...

  10. Git与GitLab

    Git与GitLab 一.Git Git是一个开源的分布式版本控制系统,用于敏捷高效地处理任何或小或大的项目. Git 是 Linus Torvalds 为了帮助管理 Linux 内核开发而开发的一个 ...