1-
21"""
32KEGGAPI.get(query, option) -> Vector
43
@@ -25,18 +24,18 @@ first(kegg_get_compounds)
2524"""
2625function kegg_get (query:: Vector{String} , option:: String = " " )
2726 # This function retrieves a list of entries from a specific database from the KEGG API.
28-
27+
2928 # Set the chunk size for processing multiple elements in each request
3029 chunk_size = 10
31-
30+
3231 # Calculate the number of chunks needed to process all elements in the query
3332 query_elements = length (query)
3433 query_chunks = ceil (Int, query_elements / chunk_size)
35-
34+
3635 # Initialize arrays to store URLs and retrieved data
3736 urls = String[]
3837 data = String[]
39-
38+
4039 # Check if the option is "aaseq" or "ntseq"
4140 if option == " aaseq" || option == " ntseq"
4241 # If there are more than 10 queries, process in chunks
@@ -45,28 +44,28 @@ function kegg_get(query::Vector{String}, option::String = "")
4544 # Calculate start and end indices for the current chunk
4645 start_index = (i - 1 ) * chunk_size + 1
4746 end_index = min (i * chunk_size, query_elements)
48-
47+
4948 # Extract the current chunk of queries
5049 chunk = query[start_index: end_index]
51-
50+
5251 # Join the queries with "+" for URL construction
5352 chunk_query = join (chunk, " +" )
54-
53+
5554 # Construct the URL for the API request
5655 url = " https://rest.kegg.jp/get/$chunk_query /$option "
57-
56+
5857 # Store the URL for reference
5958 push! (urls, url)
60-
59+
6160 # Request data from the URL
6261 response_text = request (url)
63-
62+
6463 # Process the response and extract data
6564 for datum in split (response_text, r" (\n >|^>)" )[2 : end ]
6665 datum = replace (datum, r" \n $" => " " )
67- push! (data, " >" * datum)
66+ push! (data, " >" * datum)
6867 end
69-
68+
7069 # Introduce a delay before the next request
7170 sleep (0.1 )
7271 end
@@ -78,7 +77,7 @@ function kegg_get(query::Vector{String}, option::String = "")
7877 push! (urls, url)
7978 for datum in split (response_text, r" (\n >|^>)" )[2 : end ]
8079 datum = replace (datum, r" \n $" => " " )
81- push! (data, " >" * datum)
80+ push! (data, " >" * datum)
8281 end
8382 end
8483 else
@@ -88,28 +87,28 @@ function kegg_get(query::Vector{String}, option::String = "")
8887 # Calculate start and end indices for the current chunk
8988 start_index = (i - 1 ) * chunk_size + 1
9089 end_index = min (i * chunk_size, query_elements)
91-
90+
9291 # Extract the current chunk of queries
9392 chunk = query[start_index: end_index]
94-
93+
9594 # Join the queries with "+" for URL construction
9695 chunk_query = join (chunk, " +" )
97-
96+
9897 # Construct the URL for the API request
9998 url = " https://rest.kegg.jp/get/$chunk_query /$option "
100-
99+
101100 # Store the URL for reference
102101 push! (urls, url)
103-
102+
104103 # Request data from the URL
105104 response_text = request (url)
106-
105+
107106 # Process the response and extract data
108107 response_text2 = replace (response_text, r" \n ///([^/]*)$" => " " )
109108 for datum in split (response_text2, " \n ///\n " )
110109 push! (data, datum)
111110 end
112-
111+
113112 # Introduce a delay before the next request
114113 sleep (0.1 )
115114 end
@@ -125,10 +124,10 @@ function kegg_get(query::Vector{String}, option::String = "")
125124 end
126125 end
127126 end
128-
127+
129128 # Combine URLs and data into a single array
130129 kegg_data = [urls, data]
131-
130+
132131 # Return the parsed data or an empty array if not available
133132 return kegg_data
134133end
0 commit comments