我正在尝试编写一个程序,该程序需要一个包含数字列表的文件,并将这些数字中的每一个用于子集部分字符串。当我尝试调用我的函数(下)我得到的错误:使用数字列表的Python子集序列
TypeError: unsupported operand type(s) for -: 'str' and 'int'
我试图改变在for循环i
到int(i)
的情况下,出于某种原因,i
不是一个整数,而是导致以下错误:
ValueError: invalid literal for int() with base 10: ''
代码:
#Function Collects Sequences and Writes to a Files
def gen_insertion_seq(index, seq, gene):
output = open("%s_insertion_seq.txt" % gene, 'w')
indices = index.read()
sequence = seq.read()
for i in indices:
site = sequence[i-9:i+15]
output.write(site + '\n')
#Open Index Files
shaker_index = open("212_index.txt")
kir2_index = open("214_index.txt")
asic1a_index = open("216_index.txt")
nachra7_index = open("252_index.txt")
#Open Sequence Files
shaker_seq = open("212_seq.txt")
kir2_seq = open("214_seq.txt")
asic1a_seq = open("216_seq.txt")
nachra7_seq = open("252_seq.txt")
#Call function on Index and Sequence Files - Should output list of generated Sequences for insertion sites.
#Must hand check first couple
gen_insertion_seq(shaker_index, shaker_seq, 'shaker')
样品输入文件:
212_index.txt
1312
210
633
696
1475
637
1198
645
1504
361
651
...
212_seq.txt
ATGGCCGCCGTGGCACTGCGAGAACAACAGCTCCAACGAAATAGTCTGGATGGATACGGTTCACTGCCTAAACTGTCTAGCCAAGACGAAGAAGGTGGCGCCGGCCATGGCTTCGGTGGGGGC
你知道'read'确实会返回吗? –
我想不是在添加之前,如果我在我的函数中调用它们,我无法获得任何要打印的文本文件的内容。它不会返回变量的内容吗? – Willow
你能证明吗? –