Answers.Body: <p>I whipped this little script up using the <a href="http://www.kegg.jp/kegg/rest/" rel="noreferrer">KEGG API</a>:</p>
  
  <pre class="lang-python prettyprint-override"><code>#!/usr/bin/env python3
  import urllib.request
  import re
  import sys
  pathway = 'hsa00010' # glycolysis
  url = "http://rest.kegg.jp/get/" + pathway
  with urllib.request.urlopen(url) as f:
      lines = f.read().decode('utf-8').splitlines()
      want = 0
      for line in lines:
          fields = line.split()
          ## The list of genes starts here
          if fields[0] == 'GENE':
              want = 1
              ## The line with GENE is different
              print(fields[2].rstrip(';'))
          ## We reached the next section of the file
          elif want == 1 and re.match('^\S', line):
              sys.exit();
          ## We're still in the list of genes
          if want == 1 and len(fields)&gt;1:
              print(fields[1].rstrip(';'))
  </code></pre>
  
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2017-09-24T12:39:48.910Z
Answers.LastActivityDate: 2017-09-24T12:39:48.910Z
Answers.UserDisplayName: terdon
Answers.Body: <p>using the REST API of <a href="http://togows.dbcls.jp/" rel="noreferrer">togows</a>: one can fetch a json structure of the genes associated to a kegg pathway. eg: <a href="http://togows.org/entry/kegg-pathway/hsa00010/genes.json" rel="noreferrer">http://togows.org/entry/kegg-pathway/hsa00010/genes.json</a></p>
  
  <pre><code>[
    {
      "3101": "HK3; hexokinase 3 [KO:K00844] [EC:2.7.1.1]",
      "3098": "HK1; hexokinase 1 [KO:K00844] [EC:2.7.1.1]",
      "3099": "HK2; hexokinase 2 [KO:K00844] [EC:2.7.1.1]",
      "80201": "HKDC1; hexokinase domain containing 1 [KO:K00844] [EC:2.7.1.1]",
      "2645": "GCK; glucokinase [KO:K12407] [EC:2.7.1.2]",
      "2821": "GPI; glucose-6-phosphate isomerase [KO:K01810] [EC:5.3.1.9]",
      "5213": "PFKM; phosphofructokinase, muscle [KO:K00850] [EC:2.7.1.11]",
      "5214": "PFKP; phosphofructokinase, platelet [KO:K00850] [EC:2.7.1.11]",
      "5211": "PFKL; phosphofructokinase, liver type [KO:K00850] [EC:2.7.1.11]",
      "2203": "FBP1; fructose-bisphosphatase 1 [KO:K03841] [EC:3.1.3.11]",
      "8789": "FBP2; fructose-bisphosphatase 2 [KO:K03841] [EC:3.1.3.11]",
      "230": "ALDOC; aldolase, fructose-bisphosphate C [KO:K01623] [EC:4.1.2.13]",
      "226": "ALDOA; aldolase, fructose-bisphosphate A [KO:K01623] [EC:4.1.2.13]",
      "229": "ALDOB; aldolase, fructose-bisphosphate B [KO:K01623] [EC:4.1.2.13]",
      "7167": "TPI1; triosephosphate isomerase 1 [KO:K01803] [EC:5.3.1.1]",
      "2597": "GAPDH; glyceraldehyde-3-phosphate dehydrogenase [KO:K00134] [EC:1.2.1.12]",
      "26330": "GAPDHS; glyceraldehyde-3-phosphate dehydrogenase, spermatogenic [KO:K10705] [EC:1.2.1.12]",
      "5232": "PGK2; phosphoglycerate kinase 2 [KO:K00927] [EC:2.7.2.3]",
      "5230": "PGK1; phosphoglycerate kinase 1 [KO:K00927] [EC:2.7.2.3]",
      "5223": "PGAM1; phosphoglycerate mutase 1 [KO:K01834] [EC:5.4.2.11]",
      "5224": "PGAM2; phosphoglycerate mutase 2 [KO:K01834] [EC:5.4.2.11]",
      "441531": "PGAM4; phosphoglycerate mutase family member 4 [KO:K01834] [EC:5.4.2.11]",
      "2027": "ENO3; enolase 3 [KO:K01689] [EC:4.2.1.11]",
      "2026": "ENO2; enolase 2 [KO:K01689] [EC:4.2.1.11]",
      "2023": "ENO1; enolase 1 [KO:K01689] [EC:4.2.1.11]",
      "5315": "PKM; pyruvate kinase, muscle [KO:K00873] [EC:2.7.1.40]",
      "5313": "PKLR; pyruvate kinase, liver and RBC [KO:K12406] [EC:2.7.1.40]",
      "5161": "PDHA2; pyruvate dehydrogenase alpha 2 [KO:K00161] [EC:1.2.4.1]",
      "5160": "PDHA1; pyruvate dehydrogenase alpha 1 [KO:K00161] [EC:1.2.4.1]",
      "5162": "PDHB; pyruvate dehydrogenase (lipoamide) beta [KO:K00162] [EC:1.2.4.1]",
      "1737": "DLAT; dihydrolipoamide S-acetyltransferase [KO:K00627] [EC:2.3.1.12]",
      "1738": "DLD; dihydrolipoamide dehydrogenase [KO:K00382] [EC:1.8.1.4]",
      "160287": "LDHAL6A; lactate dehydrogenase A like 6A [KO:K00016] [EC:1.1.1.27]",
      "92483": "LDHAL6B; lactate dehydrogenase A like 6B [KO:K00016] [EC:1.1.1.27]",
      "3939": "LDHA; lactate dehydrogenase A [KO:K00016] [EC:1.1.1.27]",
      "3945": "LDHB; lactate dehydrogenase B [KO:K00016] [EC:1.1.1.27]",
      "3948": "LDHC; lactate dehydrogenase C [KO:K00016] [EC:1.1.1.27]",
      "124": "ADH1A; alcohol dehydrogenase 1A (class I), alpha polypeptide [KO:K13951] [EC:1.1.1.1]",
      "125": "ADH1B; alcohol dehydrogenase 1B (class I), beta polypeptide [KO:K13951] [EC:1.1.1.1]",
      "126": "ADH1C; alcohol dehydrogenase 1C (class I), gamma polypeptide [KO:K13951] [EC:1.1.1.1]",
      "131": "ADH7; alcohol dehydrogenase 7 (class IV), mu or sigma polypeptide [KO:K13951] [EC:1.1.1.1]",
      "127": "ADH4; alcohol dehydrogenase 4 (class II), pi polypeptide [KO:K13980] [EC:1.1.1.1]",
      "128": "ADH5; alcohol dehydrogenase 5 (class III), chi polypeptide [KO:K00121] [EC:1.1.1.1 1.1.1.284]",
      "130": "ADH6; alcohol dehydrogenase 6 (class V) [KO:K13952] [EC:1.1.1.1]",
      "10327": "AKR1A1; aldo-keto reductase family 1 member A1 [KO:K00002] [EC:1.1.1.2]",
      "217": "ALDH2; aldehyde dehydrogenase 2 family (mitochondrial) [KO:K00128] [EC:1.2.1.3]",
      "224": "ALDH3A2; aldehyde dehydrogenase 3 family member A2 [KO:K00128] [EC:1.2.1.3]",
      "219": "ALDH1B1; aldehyde dehydrogenase 1 family member B1 [KO:K00128] [EC:1.2.1.3]",
      "501": "ALDH7A1; aldehyde dehydrogenase 7 family member A1 [KO:K14085] [EC:1.2.1.3 1.2.1.8 1.2.1.31]",
      "223": "ALDH9A1; aldehyde dehydrogenase 9 family member A1 [KO:K00149] [EC:1.2.1.3 1.2.1.47]",
      "221": "ALDH3B1; aldehyde dehydrogenase 3 family member B1 [KO:K00129] [EC:1.2.1.5]",
      "222": "ALDH3B2; aldehyde dehydrogenase 3 family member B2 [KO:K00129] [EC:1.2.1.5]",
      "220": "ALDH1A3; aldehyde dehydrogenase 1 family member A3 [KO:K00129] [EC:1.2.1.5]",
      "218": "ALDH3A1; aldehyde dehydrogenase 3 family member A1 [KO:K00129] [EC:1.2.1.5]",
      "84532": "ACSS1; acyl-CoA synthetase short chain family member 1 [KO:K01895] [EC:6.2.1.1]",
      "55902": "ACSS2; acyl-CoA synthetase short chain family member 2 [KO:K01895] [EC:6.2.1.1]",
      "130589": "GALM; galactose mutarotase [KO:K01785] [EC:5.1.3.3]",
      "5236": "PGM1; phosphoglucomutase 1 [KO:K01835] [EC:5.4.2.2]",
      "55276": "PGM2; phosphoglucomutase 2 [KO:K15779] [EC:5.4.2.7 5.4.2.2]",
      "2538": "G6PC; glucose-6-phosphatase catalytic subunit [KO:K01084] [EC:3.1.3.9]",
      "57818": "G6PC2; glucose-6-phosphatase catalytic subunit 2 [KO:K01084] [EC:3.1.3.9]",
      "92579": "G6PC3; glucose-6-phosphatase catalytic subunit 3 [KO:K01084] [EC:3.1.3.9]",
      "83440": "ADPGK; ADP dependent glucokinase [KO:K08074] [EC:2.7.1.147]",
      "669": "BPGM; bisphosphoglycerate mutase [KO:K01837] [EC:5.4.2.11 5.4.2.4]",
      "9562": "MINPP1; multiple inositol-polyphosphate phosphatase 1 [KO:K03103] [EC:3.1.3.80 3.1.3.62]",
      "5105": "PCK1; phosphoenolpyruvate carboxykinase 1 [KO:K01596] [EC:4.1.1.32]",
      "5106": "PCK2; phosphoenolpyruvate carboxykinase 2, mitochondrial [KO:K01596] [EC:4.1.1.32]"
    }
  ]
  </code></pre>
  
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2017-09-24T14:20:25.117Z
Answers.LastActivityDate: 2017-09-24T14:20:25.117Z
Answers.UserDisplayName: Pierre
Answers.Body: <p>Answers from Biostars:</p>
  
  <p><a href="https://www.biostars.org/p/108669/" rel="nofollow noreferrer">GeneSCF</a> 'prepare_database' module will extract all the pathways with corresponding genes as simple table format in plain text file. Check 'Two step process' (sub-heading) from the provided link (First step will do your job).</p>
  
  <hr>
  
  <p>You can use <a href="http://www.kegg.jp/kegg/docs/keggapi.html" rel="nofollow noreferrer">KEGG REST API</a> for extracting gene names from the pathway. <a href="http://docs.python-requests.org/en/master/" rel="nofollow noreferrer">Python request library</a> can be used to make the REST calls to KEGG REST API and query information. Please follow <a href="http://www.pythonforbeginners.com/requests/using-requests-in-python" rel="nofollow noreferrer">this tutorial</a> if you are a newbie to the Python programming and REST web services.</p>
  
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2018-01-12T02:29:43.930Z
Answers.LastActivityDate: 2018-01-12T02:29:43.930Z
Answers.UserDisplayName: gringer
Body: <p><em>Note: this question has also been asked on <a href="https://www.biostars.org/p/274321/" rel="nofollow noreferrer">Biostars</a></em></p>
  
  <p>I need the get the list of gene names involved in glycolysis (to put an example). Not manually, I need to do this in a script. Ideally with Python. I think KEGG is the proper database to do this, but any other (free) suggestion would do.</p>
  
  <p>How can I do it?</p>
  
Comments.ContentLicense: CC BY-SA 4.0
Comments.CreationDate: 2021-10-29T13:49:09.147Z
Comments.Text: How to do vice verse, if i want to find all pathways associated with a list of genes using R or python? Please advise
Comments.UserDisplayName: Sadaf Raza
Comments.ContentLicense: CC BY-SA 3.0
Comments.CreationDate: 2017-09-24T15:50:25.367Z
Comments.Text: To your knowledge there are other metabolic pathways, including metaCyc, reactome,...
Comments.UserDisplayName: llrs
Comments.ContentLicense: CC BY-SA 3.0
Comments.CreationDate: 2017-09-24T17:24:38.557Z
Comments.Text: I could see that this question is reposted on Biostars. Here is the solution, [https://www.biostars.org/p/274321/#274326](https://www.biostars.org/p/274321/#274326)
Comments.UserDisplayName: EagleEye
Tags: <python><pathway>
Title: How can I extract gene names for a metabolic pathway from KEGG?
ThreadText: # How can I extract gene names for a metabolic pathway from KEGG?
  
  (Asked by: username_0 on 2017-09-24)
  
  *Note: this question has also been asked on [Biostars](https://www.biostars.org/p/274321/)*
  
  I need the get the list of gene names involved in glycolysis (to put an example). Not manually, I need to do this in a script. Ideally with Python. I think KEGG is the proper database to do this, but any other (free) suggestion would do.
  
  How can I do it?
  
  **Tags:** python, pathway
  
  > **Comments:**
  > **username_2**: To your knowledge there are other metabolic pathways, including metaCyc, reactome,...  
  > **username_3**: I could see that this question is reposted on Biostars. Here is the solution, [https://www.biostars.org/p/274321/#274326](https://www.biostars.org/p/274321/#274326)  
  > **username_1**: How to do vice verse, if i want to find all pathways associated with a list of genes using R or python? Please advise  
  
  ---
  
  ## 3 answers
  
  ### Answer by username_4 on 2017-09-24. Score: 6
  
  I whipped this little script up using the [KEGG API](http://www.kegg.jp/kegg/rest/):
  
  ```python
  #!/usr/bin/env python3
  import urllib.request
  import re
  import sys
  pathway = 'hsa00010' # glycolysis
  url = "http://rest.kegg.jp/get/" + pathway
  with urllib.request.urlopen(url) as f:
      lines = f.read().decode('utf-8').splitlines()
      want = 0
      for line in lines:
          fields = line.split()
          ## The list of genes starts here
          if fields[0] == 'GENE':
              want = 1
              ## The line with GENE is different
              print(fields[2].rstrip(';'))
          ## We reached the next section of the file
          elif want == 1 and re.match('^\S', line):
              sys.exit();
          ## We're still in the list of genes
          if want == 1 and len(fields)>1:
              print(fields[1].rstrip(';'))
  
  ```
  
  
  ---
  
  ### Answer by username_5 on 2017-09-24. Score: 6
  
  using the REST API of [togows](http://togows.dbcls.jp/): one can fetch a json structure of the genes associated to a kegg pathway. eg: <http://togows.org/entry/kegg-pathway/hsa00010/genes.json>
  
  ```
  [
    {
      "3101": "HK3; hexokinase 3 [KO:K00844] [EC:2.7.1.1]",
      "3098": "HK1; hexokinase 1 [KO:K00844] [EC:2.7.1.1]",
      "3099": "HK2; hexokinase 2 [KO:K00844] [EC:2.7.1.1]",
      "80201": "HKDC1; hexokinase domain containing 1 [KO:K00844] [EC:2.7.1.1]",
      "2645": "GCK; glucokinase [KO:K12407] [EC:2.7.1.2]",
      "2821": "GPI; glucose-6-phosphate isomerase [KO:K01810] [EC:5.3.1.9]",
      "5213": "PFKM; phosphofructokinase, muscle [KO:K00850] [EC:2.7.1.11]",
      "5214": "PFKP; phosphofructokinase, platelet [KO:K00850] [EC:2.7.1.11]",
      "5211": "PFKL; phosphofructokinase, liver type [KO:K00850] [EC:2.7.1.11]",
      "2203": "FBP1; fructose-bisphosphatase 1 [KO:K03841] [EC:3.1.3.11]",
      "8789": "FBP2; fructose-bisphosphatase 2 [KO:K03841] [EC:3.1.3.11]",
      "230": "ALDOC; aldolase, fructose-bisphosphate C [KO:K01623] [EC:4.1.2.13]",
      "226": "ALDOA; aldolase, fructose-bisphosphate A [KO:K01623] [EC:4.1.2.13]",
      "229": "ALDOB; aldolase, fructose-bisphosphate B [KO:K01623] [EC:4.1.2.13]",
      "7167": "TPI1; triosephosphate isomerase 1 [KO:K01803] [EC:5.3.1.1]",
      "2597": "GAPDH; glyceraldehyde-3-phosphate dehydrogenase [KO:K00134] [EC:1.2.1.12]",
      "26330": "GAPDHS; glyceraldehyde-3-phosphate dehydrogenase, spermatogenic [KO:K10705] [EC:1.2.1.12]",
      "5232": "PGK2; phosphoglycerate kinase 2 [KO:K00927] [EC:2.7.2.3]",
      "5230": "PGK1; phosphoglycerate kinase 1 [KO:K00927] [EC:2.7.2.3]",
      "5223": "PGAM1; phosphoglycerate mutase 1 [KO:K01834] [EC:5.4.2.11]",
      "5224": "PGAM2; phosphoglycerate mutase 2 [KO:K01834] [EC:5.4.2.11]",
      "441531": "PGAM4; phosphoglycerate mutase family member 4 [KO:K01834] [EC:5.4.2.11]",
      "2027": "ENO3; enolase 3 [KO:K01689] [EC:4.2.1.11]",
      "2026": "ENO2; enolase 2 [KO:K01689] [EC:4.2.1.11]",
      "2023": "ENO1; enolase 1 [KO:K01689] [EC:4.2.1.11]",
      "5315": "PKM; pyruvate kinase, muscle [KO:K00873] [EC:2.7.1.40]",
      "5313": "PKLR; pyruvate kinase, liver and RBC [KO:K12406] [EC:2.7.1.40]",
      "5161": "PDHA2; pyruvate dehydrogenase alpha 2 [KO:K00161] [EC:1.2.4.1]",
      "5160": "PDHA1; pyruvate dehydrogenase alpha 1 [KO:K00161] [EC:1.2.4.1]",
      "5162": "PDHB; pyruvate dehydrogenase (lipoamide) beta [KO:K00162] [EC:1.2.4.1]",
      "1737": "DLAT; dihydrolipoamide S-acetyltransferase [KO:K00627] [EC:2.3.1.12]",
      "1738": "DLD; dihydrolipoamide dehydrogenase [KO:K00382] [EC:1.8.1.4]",
      "160287": "LDHAL6A; lactate dehydrogenase A like 6A [KO:K00016] [EC:1.1.1.27]",
      "92483": "LDHAL6B; lactate dehydrogenase A like 6B [KO:K00016] [EC:1.1.1.27]",
      "3939": "LDHA; lactate dehydrogenase A [KO:K00016] [EC:1.1.1.27]",
      "3945": "LDHB; lactate dehydrogenase B [KO:K00016] [EC:1.1.1.27]",
      "3948": "LDHC; lactate dehydrogenase C [KO:K00016] [EC:1.1.1.27]",
      "124": "ADH1A; alcohol dehydrogenase 1A (class I), alpha polypeptide [KO:K13951] [EC:1.1.1.1]",
      "125": "ADH1B; alcohol dehydrogenase 1B (class I), beta polypeptide [KO:K13951] [EC:1.1.1.1]",
      "126": "ADH1C; alcohol dehydrogenase 1C (class I), gamma polypeptide [KO:K13951] [EC:1.1.1.1]",
      "131": "ADH7; alcohol dehydrogenase 7 (class IV), mu or sigma polypeptide [KO:K13951] [EC:1.1.1.1]",
      "127": "ADH4; alcohol dehydrogenase 4 (class II), pi polypeptide [KO:K13980] [EC:1.1.1.1]",
      "128": "ADH5; alcohol dehydrogenase 5 (class III), chi polypeptide [KO:K00121] [EC:1.1.1.1 1.1.1.284]",
      "130": "ADH6; alcohol dehydrogenase 6 (class V) [KO:K13952] [EC:1.1.1.1]",
      "10327": "AKR1A1; aldo-keto reductase family 1 member A1 [KO:K00002] [EC:1.1.1.2]",
      "217": "ALDH2; aldehyde dehydrogenase 2 family (mitochondrial) [KO:K00128] [EC:1.2.1.3]",
      "224": "ALDH3A2; aldehyde dehydrogenase 3 family member A2 [KO:K00128] [EC:1.2.1.3]",
      "219": "ALDH1B1; aldehyde dehydrogenase 1 family member B1 [KO:K00128] [EC:1.2.1.3]",
      "501": "ALDH7A1; aldehyde dehydrogenase 7 family member A1 [KO:K14085] [EC:1.2.1.3 1.2.1.8 1.2.1.31]",
      "223": "ALDH9A1; aldehyde dehydrogenase 9 family member A1 [KO:K00149] [EC:1.2.1.3 1.2.1.47]",
      "221": "ALDH3B1; aldehyde dehydrogenase 3 family member B1 [KO:K00129] [EC:1.2.1.5]",
      "222": "ALDH3B2; aldehyde dehydrogenase 3 family member B2 [KO:K00129] [EC:1.2.1.5]",
      "220": "ALDH1A3; aldehyde dehydrogenase 1 family member A3 [KO:K00129] [EC:1.2.1.5]",
      "218": "ALDH3A1; aldehyde dehydrogenase 3 family member A1 [KO:K00129] [EC:1.2.1.5]",
      "84532": "ACSS1; acyl-CoA synthetase short chain family member 1 [KO:K01895] [EC:6.2.1.1]",
      "55902": "ACSS2; acyl-CoA synthetase short chain family member 2 [KO:K01895] [EC:6.2.1.1]",
      "130589": "GALM; galactose mutarotase [KO:K01785] [EC:5.1.3.3]",
      "5236": "PGM1; phosphoglucomutase 1 [KO:K01835] [EC:5.4.2.2]",
      "55276": "PGM2; phosphoglucomutase 2 [KO:K15779] [EC:5.4.2.7 5.4.2.2]",
      "2538": "G6PC; glucose-6-phosphatase catalytic subunit [KO:K01084] [EC:3.1.3.9]",
      "57818": "G6PC2; glucose-6-phosphatase catalytic subunit 2 [KO:K01084] [EC:3.1.3.9]",
      "92579": "G6PC3; glucose-6-phosphatase catalytic subunit 3 [KO:K01084] [EC:3.1.3.9]",
      "83440": "ADPGK; ADP dependent glucokinase [KO:K08074] [EC:2.7.1.147]",
      "669": "BPGM; bisphosphoglycerate mutase [KO:K01837] [EC:5.4.2.11 5.4.2.4]",
      "9562": "MINPP1; multiple inositol-polyphosphate phosphatase 1 [KO:K03103] [EC:3.1.3.80 3.1.3.62]",
      "5105": "PCK1; phosphoenolpyruvate carboxykinase 1 [KO:K01596] [EC:4.1.1.32]",
      "5106": "PCK2; phosphoenolpyruvate carboxykinase 2, mitochondrial [KO:K01596] [EC:4.1.1.32]"
    }
  ]
  
  ```
  
  
  ---
  
  ### Answer by username_6 on 2018-01-12. Score: 3
  
  Answers from Biostars:
  
  [GeneSCF](https://www.biostars.org/p/108669/) 'prepare\_database' module will extract all the pathways with corresponding genes as simple table format in plain text file. Check 'Two step process' (sub-heading) from the provided link (First step will do your job).
  
  ---
  
  You can use [KEGG REST API](http://www.kegg.jp/kegg/docs/keggapi.html) for extracting gene names from the pathway. [Python request library](http://docs.python-requests.org/en/master/) can be used to make the REST calls to KEGG REST API and query information. Please follow [this tutorial](http://www.pythonforbeginners.com/requests/using-requests-in-python) if you are a newbie to the Python programming and REST web services.
  
  
  ---
  
  