|
用这段代码:
- #-*-encoding:utf-8-*-
- import sys
- import json
- import re
- d=dict()
- read_count_dict = {}
- json_file = open(sys.argv[1])
- json_dict = json.load(json_file)
- key = 已取得key = 已取得values = 0
- getValue = "json_dict['read_groups'][x][y]"
- for x in json_dict['read_groups']:
- for y in json_dict['read_groups'][x]:
- r1 = re.compile(r'^(?!LC).+\d) # 行首不是LC
- r2 = re.compile(r'.+(?!-KY)) # 行尾不是-KY
- if y == 'sample' and r1.match(eval(getValue)) \
- and r2.match(eval(getValue)):
- # sample项, 且内容满足正则式要求, 则将该内容保存为 key
- key = eval(getValue)
- 已取得key = 1
- print("分组:", x, "\t 项目:", y, "\t 项目内容:", eval(getValue))
- elif y == 'index':
- # index项, 取其内容保存为 values
- values = ['%03.2i' %(eval(getValue))]
- 已取得values = 1
- print("分组:", x, "\t 项目:", y, "\t 项目内容:", values)
- else:
- # 否则继续
- continue
- if int(json_dict['read_groups'][x]['read_count']) > 1000000:
- # 若 read_count 项大于 100万, 则将 key 和 values 存入字典
- # 应首先判断 key 和 values 是否都有值
- if 已取得key and 已取得values:
- d[key]=values
- print(" 存入字典:", x, "\t sample:", key, "\t index:", values)
- 已取得key = 已取得values = 0
- #
- for key in d:
- if not(key == 'None')and not (key == 'none'):
- #
- for k in d[key]:
- print('Sample' + "\t" + key + "\t" + k)
- else:
- continue
复制代码 |
|