defaultdict(<type 'int'>, {'match': 1})
[(0, 0)]
[]
[]
[]
Traceback (most recent call last):
File "Joinomattic_1.py", line 409, in <module>
verboseprint (magic(matching))
File "Joinomattic_1.py", line 408, in <lambda>
magic = lambda matching: int(''.join(str(i) for i in matching)) # Generator exp.
ValueError: invalid literal for int() with base 10: '''
上面的错误在我下面的代码中不断发生,但是它仅在较大程序的一部分时发生,当它自己运行时不会发生错误并且输出被写入 output_file。这个错误是什么意思,为什么它只发生在其他代码中?以下是我作为大型程序一部分的代码:
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(<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