java if 局部变量赋值,为什么我的代码不写入文件输出?赋值前引用的局部变量...

论坛 期权论坛 编程之家     
选择匿名的用户   2021-5-21 09:12   53   0

我写了一些代码,通过阅读我的文本文件,找到一组与基因相关的数字,然后用这些数字搜索基因本身,这样我就可以提取一堆包含每个基因的文本文件。我已经成功地得到了数字,但我有问题的文件写作。得到错误“local variable”gene_substring“referenced before assignation”。我做了一些研究,并尝试使用global来修复它,但它在其他地方抛出了错误。#function to extract the genes by using the numbers in my list

end_file = "/Users...."

def extract_genes(start_stop, genome_sequence):

for start,stop in start_stop:

# extracts start:stop gene from the sequence

if start > stop:

gene_substring = genome_sequence[0:start] + genome_sequence[stop:]

# store in file

with open(end_file + "/" + name + "+" + ".txt", "w",) as file:

file.write(gene_substring)#My code to get the output

work_dir = "/Users/"

for path in glob.glob(os.path.join(work_dir, "*.gbff")):

numbers = extract_numbers(path)

sequences = extract_seq(path)

extract_genes(start_stop, sequences)

print(path)

我该怎么解决这个?谢谢:)

分享到 :
0 人收藏
您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

积分:3875789
帖子:775174
精华:0
期权论坛 期权论坛
发布
内容

下载期权论坛手机APP