Warning: file_get_contents(/data/phpspider/zhask/data//catemap/7/python-2.7/5.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python ValueError:以10为基数的int()的文本无效:'';错误发生在较大代码的一部分时,而不是单独出现时_Python_Python 2.7_Fastq - Fatal编程技术网

Python ValueError:以10为基数的int()的文本无效:'';错误发生在较大代码的一部分时,而不是单独出现时

Python ValueError:以10为基数的int()的文本无效:'';错误发生在较大代码的一部分时,而不是单独出现时,python,python-2.7,fastq,Python,Python 2.7,Fastq,这里是独立的: n = 0 consec_matches = [] chars = defaultdict(int) for k, group in groupby(zip(line1_u_i, line2_u_rev_comp_i), class_chars): elems = len(list(group)) chars[k] += elems if k == 'match': consec_matches.append((n, n+elems-1)

这里是独立的:

n = 0
consec_matches = []
chars = defaultdict(int)

for k, group in groupby(zip(line1_u_i, line2_u_rev_comp_i), class_chars):
    elems = len(list(group))
    chars[k] += elems
    if k == 'match':
        consec_matches.append((n, n+elems-1))
    n += elems

verboseprint (chars)
verboseprint (consec_matches)
verboseprint ([x for x in consec_matches if x[1]-x[0] >= 9])
list = [x for x in consec_matches if x[1]-x[0] >= 9]
flatten_list= [x for y in list for x in y]
verboseprint (flatten_list)
matching=[y[1] for y in list for x in y if x ==0 ]
verboseprint (matching)
magic = lambda matching: int(''.join(str(i) for i in matching)) # Generator exp.
verboseprint (magic(matching))
line2_u_rev_comp_i_l = line2_u_rev_comp_i[magic(matching):]
line3=line1_u_i+line2_u_rev_comp_i_l
verboseprint (line3)
if line3:
    verboseprint(line3, file = output_file)
独立时,输出为:

from __future__ import print_function
from collections import defaultdict
from itertools import groupby
import argparse #imports the argparse module so it can be used
from itertools import izip





parser = argparse.ArgumentParser() #simplifys the wording of using argparse as stated in the python tutorial
parser.add_argument("-r1", type=str, action='store',  dest='input1', help="input the forward read file") # allows input of the forward read
parser.add_argument("-r2", type=str, action='store', dest='input2', help="input the reverse read file") # allows input of the reverse read
parser.add_argument("-v", "--verbose", action="store_true", help=" Increases the output, only needs to be used to provide feedback to Tom for debugging")
parser.add_argument("-n", action="count", default=0, help="Allows for up to 5 mismatches, however this will reduce accuracy of matching and cause mismatches. Default is 0")
parser.add_argument("-fastq", action="store_true", help=" States your input as fastq format")
parser.add_argument("-fasta", action="store_true", help=" States your input as fasta format")
parser.add_argument("-o", "--output", help="Directs the output to a name of your choice")
args = parser.parse_args()

output = str(args.output)


def class_chars(chrs):
    if 'N' in chrs:
        return 'unknown'
    elif chrs[0] == chrs[1]:
        return 'match'
    else:
        return 'not_match'


#with open(args.output, 'w') as output_file:

output_file= open(output, "w")

s1 = 'aaaaaaaaaaN123bbbbbbbbbbQccc'
s2 = 'aaaaaaaaaaN456bbbbbbbbbbPccc'
n = 0
consec_matches = []
chars = defaultdict(int)

for k, group in groupby(zip(s1, s2), class_chars):
    elems = len(list(group))
    chars[k] += elems
    if k == 'match':
        consec_matches.append((n, n+elems-1))
    n += elems

print (chars)
print (consec_matches)
print ([x for x in consec_matches if x[1]-x[0] >= 9])
list = [x for x in consec_matches if x[1]-x[0] >= 9]
flatten_list= [x for y in list for x in y]
print (flatten_list)
matching=[y[1] for y in list for x in y if x ==0 ]
print (matching)
magic = lambda matching: int(''.join(str(i) for i in matching)) # Generator exp.
print (magic(matching))
s2_l = s2[magic(matching):]
line3=s1+s2_l
print (line3)
if line3:
    print(line3, file = output_file)
defaultdict(,{'not_match':4,'unknown':1,'match':23})
[(0, 9), (14, 23), (25, 27)]
[(0, 9), (14, 23)]
[0, 9, 14, 23]
[9]
9
aaaaaaaaaaaaaN123bbbbbbbbqccan456bbbbbbbbbbbpccc

正如您的输出所示,
匹配
是一个空列表。因此,在
联接之后,您会得到一个空字符串
'
,不能转换为整数。尝试:

defaultdict(<type 'int'>, {'not_match': 4, 'unknown': 1, 'match': 23})
[(0, 9), (14, 23), (25, 27)]
[(0, 9), (14, 23)]
[0, 9, 14, 23]
[9]
9
aaaaaaaaaaN123bbbbbbbbbbQcccaN456bbbbbbbbbbPccc

这将
返回0
如果
匹配==[]

是,这似乎解决了该问题,但现在出现了下面的错误,但这完全是另一个问题line3=line1\u u\u i+line2\u u\u rev\u comp\u i\u l TypeError:无法连接'str'和'list'对象您需要什么更多信息
line1\u\u i
是一个字符串,
line2\u\u rev\u comp\u i\u l
是一个列表,因此不能将它们添加在一起。为什么要将列表添加到字符串中,或者您认为哪一个是其他内容?我原以为这两个都是字符串,所以我试图找到一种方法将列表中的第2行转换为字符串。
defaultdict(<type 'int'>, {'not_match': 4, 'unknown': 1, 'match': 23})
[(0, 9), (14, 23), (25, 27)]
[(0, 9), (14, 23)]
[0, 9, 14, 23]
[9]
9
aaaaaaaaaaN123bbbbbbbbbbQcccaN456bbbbbbbbbbPccc
lambda matching: int(''.join(str(i) for i in matching) or 0)