-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmap_ingr_flavcmp.py
36 lines (28 loc) · 1018 Bytes
/
map_ingr_flavcmp.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
import csv
from codecs import open
import numpy as np
import pandas as pd
ingredients_single_recipe = []
ingrs_id = []
ingredients_id = []
comp_id = []
compounds_id = []
ingredients_names = np.load('recipes_ingr_mapped_name.npy')
ingr_info = pd.read_csv("ingr_comp/ingr_info.tsv", sep="\t", index_col='# id')
ingr_comp = pd.read_csv("ingr_comp/ingr_comp.tsv", sep="\t")
for ingr_names in ingredients_names:
ingrs_id = []
for ingredient in ingr_names:
ingrs_index = ingr_info[ingr_info['ingredient name'] == ingredient].index.tolist()
if ingrs_index:
ingrs_id.append(ingrs_index[0])
ingredients_id.append(ingrs_id)
for rec in ingredients_id:
comp_id = []
for ing in rec:
comp_id.append(ingr_comp['compound id'][ingr_comp['ingredient id'] == ing].tolist())
compounds_id.append(comp_id)
compounds_id = np.array(compounds_id)
ingredients_id = np.array(ingredients_id)
np.save('recipes_compunds_id', compounds_id)
np.save('ingredients_id', ingredients_id)