# ----ROSALIND_12: ----
# Overlap Graphs
# 读取文件
with open ("12_Overlap Graphs.txt") as f:
DNA_string = f.readlines()
DNA_string = [x.strip("\n") for x in DNA_string]
def get_adj_name(seq,k):
newDNA_strings = []
DNA_seq = []
ROSname = [x for x in DNA_string if "Rosalind" in x]
ROSindex = [DNA_string.index(x) for x in ROSname]
for i in range(0, len(DNA_string), int(ROSindex[1]) - int(ROSindex[0])):
newDNA_strings.append(DNA_string[i: i + (int(ROSindex[1]) - int(ROSindex[0]))])
# 合并 ROSname后面的字符串
DNA_seq = ["".join(x[1:]) for x in newDNA_strings]
DNA_string_dict = {}
DNA_string_dict = dict(zip(ROSname,DNA_seq))
#遍历字典根据每一列最大值返回键值
DNA_string_dict_values = list(DNA_string_dict.values())
DNA_string_dict_keys = list(DNA_string_dict.keys())
# 制造一个前缀的list
DNA_string_dict_prefix_values = []
DNA_string_dict_prefix_values = [x[0:k] for x in DNA_string_dict_values]
# 制造一个后缀的list
DNA_string_dict_suffix_values = []
DNA_string_dict_suffix_values = [x[k+1:] for x in DNA_string_dict_values]
for i in range(len(DNA_string_dict_prefix_values)):
for j in range(len(DNA_string_dict_suffix_values)):
# 如果DNA_string_dict_prefix_values[i] 和 DNA_string_dict_suffix_values[i]相同,则返回索引值
if (DNA_string_dict_prefix_values[i] == DNA_string_dict_suffix_values[j] and i != j):
print(DNA_string_dict_keys[i][1:], DNA_string_dict_keys[j][1:])
else:
pass
# return(DNA_string_dict_suffix_values[1:])
image.png
网友评论