Skip to content

Instantly share code, notes, and snippets.

@piroyon
Last active October 13, 2021 23:52
Show Gist options
  • Save piroyon/ddd415bb4dda8c1072c29f5ee336877d to your computer and use it in GitHub Desktop.
Save piroyon/ddd415bb4dda8c1072c29f5ee336877d to your computer and use it in GitHub Desktop.
make_ortholog_dict
f = open('201110_allseq_colors.tsv', 'r')
orth_dict = {} ##初期化
color_dict = {}
for linen in f:
line = linen.rstrip() ##改行の削除
values = line.split("\t")
ortholog_id = values[0]
orth_dict.setdefault(ortholog_id, {}) ##1段目の辞書初期化
g = values[1].split(":")
animal = g[0]
geneid = g[1]
gene2 = values[6]
if (animal == 'plewa04') and (values[10] != '***'):
color_dict[geneid] = values[10]
orth_dict[ortholog_id].setdefault(animal, []) ##2段目の辞書初期化
if (animal == 'plewa04') or (animal == 'xentr'):
orth_dict[ortholog_id][animal].append(geneid)
else:
orth_dict[ortholog_id][animal].append(gene2)
f.close
print(orth_dict) ##チェック用のデバッグ文
# {
# {'1.24':
# {'plewa04': ['M0258755_PLEWA04'],
# 'xenla': ['gene50849', 'MSTRG.41143'],
# 'xentr': ['gene15736', 'gene33556', 'gene30112']
# }
#}
print(color_dict)
#{'M1270405_PLEWA04': 'lightcyan'}.....
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment