<commit_before># http://www.kegg.jp/kegg/docs/keggapi.html

import os
import csv

import restapi

class KEGGRESTAPI(restapi.RESTAPI):

    def __init__(self, download_folder="kegg_files"):
        self._download_folder = download_folder
        self._base_url = "http://rest.kegg.jp/"
        self._create_download_folder()        

    def reference_pathway(self, map_number):
        """e.g. 00630"""
        data = self._get_data(
            "%s/map%s.kegg", "get/pathway:map%s", map_number)
        return(data)

    def pathway(self, map_number):
        """e.g. sax00270"""
        data = self._get_data(
            "%s/%s.kegg", "get/pathway:%s", map_number)
        return(data)

    def linked_pathways(self, entity_id):
        """entity_id can be e.g. a gene id, a KO id or a reaction id"""
        data = self._get_data(
            "%s/%s_linked_pathways.kegg", "link/pathway/%s", entity_id)
        return(self._clean_list(self._second_column_to_list(data), "path:"))

    def linked_reactions(self, entity_id):
        """entity_id can be e.g. a gene id, a KO id or as pathway id"""
        data = self._get_data(
            "%s/%s_linked_reactions.kegg", "link/reaction/%s", entity_id)
        return(self._clean_list(self._second_column_to_list(data), "rn:"))

    def _clean_list(self, id_list, prefix_to_remove):
        return([item.replace(prefix_to_remove, "") for item in id_list])
<commit_msg>Add ortholog retrival for KEGG<commit_after># http://www.kegg.jp/kegg/docs/keggapi.html

import os
import csv

import restapi

class KEGGRESTAPI(restapi.RESTAPI):

    def __init__(self, download_folder="kegg_files"):
        self._download_folder = download_folder
        self._base_url = "http://rest.kegg.jp/"
        self._create_download_folder()

    def reference_pathway(self, map_number):
        """e.g. 00630"""
        data = self._get_data(
            "%s/map%s.kegg", "get/pathway:map%s", map_number)
        return(data)

    def pathway(self, map_number):
        """e.g. sax00270"""
        data = self._get_data(
            "%s/%s.kegg", "get/pathway:%s", map_number)
        return(data)

    def ortholog_of_gene(self, gene_id):
        """e.g. hsa:5236"""
        data = self._get_data(
            "%s/%s_ortholog.kegg", "link/orthology/%s", gene_id)
        return(self._clean_list(self._second_column_to_list(data), "ko:"))

    def linked_pathways(self, entity_id):
        """entity_id can be e.g. a gene id, a KO id or a reaction id"""
        data = self._get_data(
            "%s/%s_linked_pathways.kegg", "link/pathway/%s", entity_id)
        return(self._clean_list(self._second_column_to_list(data), "path:"))

    def linked_reactions(self, entity_id):
        """entity_id can be e.g. a gene id, a KO id or as pathway id"""
        data = self._get_data(
            "%s/%s_linked_reactions.kegg", "link/reaction/%s", entity_id)
        return(self._clean_list(self._second_column_to_list(data), "rn:"))

    def _clean_list(self, id_list, prefix_to_remove):
        return([item.replace(prefix_to_remove, "") for item in id_list])

{'fraction_non_alphanumeric': 0.143042071197411, 'fraction_numerical': 0.007766990291262136, 'mean_word_length': 2.8734335839599, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 8, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5413114', 'n_tokens_mistral': 1115, 'n_tokens_neox': 1068, 'n_words': 210}