#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. 【暴力】vijos P1897 学姐吃牛排

    判断堆:递归判断每个节点的孩子是否都比其父亲大(小). 判断BST:中序遍历是否有序. #include<cstdio> using namespace std; #define lc ( ...

  2. [HDU6271]Master of Connected Component

    [HDU6271]Master of Connected Component 题目大意: 给出两棵\(n(n\le10000)\)个结点的以\(1\)为根的树\(T_a,T_b\),和一个拥有\(m( ...

  3. Java高级架构师(一)第10节:Spring+Mybatis实现DAO

    maven配置memcached.jar 由于目前java memcached client没有官方的maven repository可供使用,因此使用时需要手动将其安装到本地repository. ...

  4. C# 6.0语法新特性体验(二)

    之前我在文章通过Roslyn体验C# 6.0的新语法中介绍了一些C# 6.0的语法特性,现在随着Visual Studio 14 CTP3的发布,又陆续可以体验一些新的特性了,这里简单的介绍一下之前没 ...

  5. winform groupbox控件放到窗体中间位置

    1. 在Form中放一个控件,让其在启动时始终居中 int gLeft = this.Width / 2 - groupControl1.Width / 2; int gTop = this.Heig ...

  6. checkbox与文字对齐方式(同样可用于radio单选框)

    checkbox 在chrome 和 firefox中 间距是由margin撑开, IE中则是由padding,并且无法设置边框:   主要参考大神的博客,http://www.zhangxinxu. ...

  7. ubuntu14.04使用samba共享文件

    samba是linux中常用的共享文件的软件 ubuntu12.04及以上版本中已经安装了samba 开始配置: samba配置文件: /etc/samba/smb.conf可以修改配置文件来设置sa ...

  8. 虚拟机设置NAT上网

    需要开启虚拟机网络相关服务, 安装虚拟网卡VMware虚拟机下实现NAT方式上网1. 把你的虚拟网卡VMnet8设置为自动获得IP.自动获得DNS服务器,启用.2. 把你虚拟机中操作系统的“本地连接” ...

  9. Spark(十) -- Spark Streaming API编程

    本文测试的Spark版本是1.3.1 Spark Streaming编程模型: 第一步: 需要一个StreamingContext对象,该对象是Spark Streaming操作的入口 ,而构建一个S ...

  10. IDEA默认VIM模式

    Intellij Idea, 每次打开文件都进入了vim模式,必须输入i才可编辑,实在是非常困扰. 终于找到了解决办法:取消Vim Emulator的选择: