Skip to content
Snippets Groups Projects
Commit 44b0934e authored by UMEC Mathieu's avatar UMEC Mathieu
Browse files

change on ontologie level 2 more case

parent 453f00c9
No related branches found
No related tags found
No related merge requests found
......@@ -470,10 +470,18 @@ def ontologie_gap_kegg_chebi(csv_file, out_folder):
ontologie_level_chebi = ["associated ontologie level of ChEBI ID"]
ontologie_level_equiv_kegg = ["positional difference betwen kegg et chebi ID"]
chebi_on_kegg = ["ID chebi from KEGG"]
for i_ac_k, ac_kegg in enumerate(l_kegg):
accheb = l_cheb[i_ac_k].strip().upper()
for i_ac_k, ac_kegg in enumerate(l_kegg[1:]):
accheb = l_cheb[i_ac_k+1].strip().upper()
ackegg = ac_kegg.strip().upper()
if accheb == "NA":
#print(accheb)
#print(ackegg)
if accheb == "NA" and ackegg == "NA":
chebi_on_kegg.append("NA")
name_chebi.append("NA")
ontologie_level_chebi.append("NA")
ontologie_level_equiv_kegg.append("NA")
name_kegg.append("NA")
elif accheb == "NA":
url_kegg = "https://www.genome.jp/entry/"+ackegg
print(url_kegg)
soupk = BeautifulSoup(urllib.request.urlopen(url_kegg).read().decode("utf-8"), "html.parser")
......@@ -519,19 +527,39 @@ def ontologie_gap_kegg_chebi(csv_file, out_folder):
name_chebi.append("NA")
ontologie_level_chebi.append("NA")
ontologie_level_equiv_kegg.append("NA")
print(chebi_on_kegg)
#print(name_kegg)
out_df = pd.DataFrame([l_kegg, name_kegg, chebi_on_kegg, l_cheb, name_chebi,
ontologie_level_chebi, ontologie_level_equiv_kegg]).transpose()
outf_name = out_folder + "KEGG_and_ChEBI_dif_ontologie_test.xlsx"
excel_file_writer(out_df, outf_name, sheetname="resume_ontology")
"""
elif ackegg == "NA":
name_kegg.append("NA")
name_chebi.append(accheb)
ontologie_level_chebi.append("NA") # voir si on sort le niveau de l'ontologie
chebi_on_kegg.append("NA")
ontologie_level_equiv_kegg.append("NA")
print(accheb)
url_chebi = "https://www.ebi.ac.uk/chebi/chebiOntology.do?chebiId="+accheb +"&treeView=true#vizualisation"
chebi_soup = BeautifulSoup(urllib.request.urlopen(url_chebi).read().decode("utf-8"), "html.parser")
text_chebi = chebi_soup.get_text()
#print(text_chebi)
i_beg_p_name = text_chebi.find("ChEBI Name")
inter_name = text_chebi[i_beg_p_name: i_beg_p_name+300]
i_end_p_name = inter_name.find("ChEBI ID")
name_cheb_treat= text_chebi[i_beg_p_name+10: i_beg_p_name + i_end_p_name]
name_cheb_treat = name_cheb_treat.strip()
print(name_cheb_treat)
name_chebi.append(name_cheb_treat)
onto_name = accheb + " " + name_cheb_treat
print(onto_name)
begin_tree = text_chebi.find("Tree View")
end_tree = text_chebi.find("Relationship Types")
tree = text_chebi[begin_tree: end_tree]
onto_pos = tree.find(onto_name)
#print(tree)
print(onto_pos)
#print(tree[0:onto_pos])
ont_lev_che = 0
index = tree[0:onto_pos].find("CHEBI:")
while index != -1:
ont_lev_che += 1
index = tree[0:onto_pos].find("CHEBI:", index + 1)
ontologie_level_chebi.append(ont_lev_che)
"""
else:
url = "https://www.ebi.ac.uk/chebi/searchId.do?chebiId="+ac_chebi
soup = BeautifulSoup(urllib.request.urlopen(url).read().decode("utf-8"), "html.parser")
......@@ -542,8 +570,12 @@ def ontologie_gap_kegg_chebi(csv_file, out_folder):
name_chebi = text[i_beg_p_name+10: i_beg_p_name + i_end_p_name]
name_chebi = name_chebi.strip()
"""
out_df = pd.DataFrame([l_kegg, name_kegg, chebi_on_kegg, l_cheb, name_chebi,
ontologie_level_chebi, ontologie_level_equiv_kegg]).transpose()
outf_name = out_folder + "KEGG_and_ChEBI_dif_ontologie_test2.xlsx"
excel_file_writer(out_df, outf_name, sheetname="resume_ontology")
if __name__ == "__main__":
LOCAL = "C:\\Users\\mumec\\Desktop\\Mini_codes\\ontologie_kegg_chebi\\"
infile = LOCAL + "ontologie_gap_chebi_na.csv"
infile = LOCAL + "ontologie_gap_2.csv"
ontologie_gap_kegg_chebi(infile, LOCAL)
\ No newline at end of file
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment