我正在尝试将一些 OTU id 与字典中的值与文件中的标头进行比较,如果值与 OTU匹配,则为字典中的每个键创建一个单独的文件。我有以下字典和文件:
header_dict = {'nem.35_Desmoscolex': ['OTU134265,1.0,CL:0.730', 'OTU133750,1.0,CL:0.770', 'OTU129715,1.0,CL:0.750', 'OTU121577,1.0,CL:0.720', 'OTU100169,1.0,CL:0.810', 'AY854235.1.1409,1.0,CL:1.000'], 'nem.153_Spirinia': ['OTU269240,8287.0,CL:1.000', 'OTU175662,1685.0,CL:1.000', 'OTU12936,882.0,CL:1.000', 'OTU14847,318.0,CL:0.850']})
->OTU12936
TGTAGTAGCCGTTTCTCAGGCTGCTTCTC
->OTU133750
TGTGGTAGCCGTTTCTCAGGCTCCCTCTC
->OTU134265
TGTAGTAGCCGTTTCTCAGGCTGCTTCTC
->OTU99971
TGTGGTAGCTGTTTCTCAGGCTCCCTCT
repfile = open(args.reps, "r")
for key in header_dict:
print(key)
outFile = open(os.path.join(args.output, key + ".fna"), "w")
#outFile.write("{0}".format(key))
for value in header_dict[key]:
print(value)
for eachLine in repfile:
eachLine = eachLine.rstrip()
flag = False
if eachLine.startswith(">"):
if value.split(",")[0] == eachLine.split(" ")[0][1:]:
outFile.write("{0} {1}".format(eachLine, value))
flag = True
else:
if flag:
outFile.write("{0}\n".format(eachLine))
我的outFiles为空或仅包含一个序列。我似乎找不到毛刺。有什么建议吗?