找回密码
 立即注册

扫一扫,访问微社区

QQ登录

只需一步,快速开始

查看: 3990|回复: 4

[讨论] 正则表达式遇上未解之谜 有信心的不妨挑战一下

1

主题

1

帖子

1

积分

贫民

积分
1
sasasa 发表于 2016-8-16 12:54:24 | 显示全部楼层 |阅读模式
#-*-encoding:utf-8-*-
import sys
import json
import re


d=dict()
read_count_dict = {}
json_file = file(sys.argv[-1])
json_dict = json.load(json_file)
for x in json_dict['read_groups']:
    for y in json_dict['read_groups'][x]:
        r1 = re.compile(r'^(?!LC).+\d$')
        r2 = re.compile(r'.+(?!-KY)$')
        if y == 'sample'and r1.match(json_dict['read_groups'][x][y]) and r2.match(json_dict['read_groups'][x][y]):
            key = json_dict['read_groups'][x][y]
        elif y == 'index':
            values = ['%03.2i' %(json_dict['read_groups'][x][y])]
        else:
            continue
    if int(json_dict['read_groups'][x]['read_count']) > 1000000:
       d[key]=values
#
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
   
####以上是源代码##加入json文件后出现了奇怪的问题:某些尾数为9的条码(此处为index值为089的条码)输出结果不正常,为000
如图1、2所示

图1.png

图1.png

图2.png

图2.png

将 有错误的index值89改为81后(图3)

图3.png

图3.png

输出结果又正常了(图4)

图4.png

图4.png

将有错误的index值部分上方的IONXPRESS值更改,也会影响结果。
然而代码中没有提到过这个参数。
试问这是否是语法bug?
有兴趣和信心的可以运行试试。。。。
   

附上供调试的json文件

datasets_basecaller.json (165.8 KB, 下载次数: 6)
回复

使用道具 举报

1419

主题

1891

帖子

291

积分

侠客

积分
291

最佳新人热心会员默默耕耘

whydo1 发表于 2016-9-30 12:11:27 | 显示全部楼层
用这段代码:

  1. #-*-encoding:utf-8-*-
  2. import sys
  3. import json
  4. import re


  5. d=dict()
  6. read_count_dict = {}
  7. json_file = open(sys.argv[1])
  8. json_dict = json.load(json_file)
  9. key = 已取得key = 已取得values = 0
  10. getValue = "json_dict['read_groups'][x][y]"

  11. for x in json_dict['read_groups']:
  12.     for y in json_dict['read_groups'][x]:
  13.         r1 = re.compile(r'^(?!LC).+\d)    # 行首不是LC
  14.         r2 = re.compile(r'.+(?!-KY))      # 行尾不是-KY

  15.         if y == 'sample' and r1.match(eval(getValue)) \
  16.                          and r2.match(eval(getValue)):
  17.             # sample项, 且内容满足正则式要求, 则将该内容保存为 key
  18.             key = eval(getValue)
  19.             已取得key = 1
  20.             print("分组:", x, "\t 项目:", y, "\t 项目内容:", eval(getValue))
  21.         elif y == 'index':
  22.             # index项, 取其内容保存为 values
  23.             values = ['%03.2i' %(eval(getValue))]
  24.             已取得values = 1
  25.             print("分组:", x, "\t 项目:", y, "\t 项目内容:", values)
  26.         else:
  27.             # 否则继续
  28.             continue

  29.     if int(json_dict['read_groups'][x]['read_count']) > 1000000:
  30.         # 若 read_count 项大于 100万, 则将 key 和 values 存入字典
  31.         # 应首先判断 key 和 values 是否都有值
  32.         if 已取得key and 已取得values:
  33.             d[key]=values
  34.             print("    存入字典:", x, "\t sample:", key, "\t index:", values)
  35.             已取得key = 已取得values = 0

  36. #
  37. for key in d:
  38.     if not(key == 'None')and not (key == 'none'):
  39.         #
  40.         for k in d[key]:
  41.             print('Sample' + "\t" + key + "\t" + k)
  42.     else:
  43.         continue
复制代码
回复 支持 1 反对 0

使用道具 举报

2

主题

10

帖子

10

积分

贫民

积分
10
charban 发表于 2016-9-20 10:53:28 | 显示全部楼层
大神都不逛这个论坛的吗,为什么一直没有人留言
回复 支持 反对

使用道具 举报

50

主题

1057

帖子

1108

积分

管理员

Rank: 9Rank: 9Rank: 9

积分
1108

活跃会员热心会员最佳导师默默耕耘突出贡献优秀版主荣誉管理论坛元老

blueelwang 发表于 2016-10-8 10:58:35 | 显示全部楼层

{:8_204:}
回复 支持 反对

使用道具 举报

1419

主题

1891

帖子

291

积分

侠客

积分
291

最佳新人热心会员默默耕耘

whydo1 发表于 2016-10-8 19:01:31 | 显示全部楼层
多谢管理员鼓励!
回复 支持 反对

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

快速回复 返回顶部 返回列表