Answers.Body: <p>A typical Uniprot URL would look like the example here:</p>
  
  <p><a href="https://www.uniprot.org/uniprot/?query=ID:P26378&amp;format=tab&amp;columns=id%2Cdatabase(PDB)" rel="nofollow noreferrer">https://www.uniprot.org/uniprot/?query=ID:P26378&amp;format=tab&amp;columns=id%2Cdatabase(PDB)</a></p>
  
  <p>The response will be:</p>
  
  <blockquote>
    <p>Entry Cross-reference (PDB) </p>
    
    <p>P26378    1FXL;1G2E;</p>
  </blockquote>
  
  <p>We want our query to include the protein ID, the output format should be tab separated and the only contain the columns <code>id</code> and <code>database (PDB)</code>.</p>
  
  <p>To get the PDB IDs you would need to split the response, take the last line, split this line after each tab and split it again after each semi-colon.</p>
  
  <p>Using Python's Requests library the whole code would be.</p>
  
  <pre><code>import requests
  import time
  
  uniprot_ids = ['P26378', 'O35433', 'Q02910']
  url = 'https://www.uniprot.org/uniprot/'
  
  protein_to_pdb = {}
  for protein in uniprot_ids:
      params = {
          'format': 'tab',
          'query': 'ID:{}'.format(protein),
          'columns': 'id,database(PDB)'
      }
      contact = ""  # Please set your email address here.
      headers = {'User-Agent': 'Python {}'.format(contact)}
      r = requests.get(url, params=params, headers=headers)
  
      protein_to_pdb[protein] = str(r.text).splitlines()[-1].split('\t')[-1].split(';')
      protein_to_pdb[protein].pop(-1)
      time.sleep(1)  # be respectful and don't overwhelm the server with requests
  
  print(protein_to_pdb)
  </code></pre>
  
  <hr>
  
  <ul>
  <li>To accelerate things, you could store your <code>protein_to_pdb</code> dict in a file and only retrieve the new ones</li>
  <li>Checking if the returned ID matches your input ID is always a good idea </li>
  </ul>
  
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2018-08-27T01:46:44.527Z
Answers.Text: Thanks man, I really appreciate your answer and your time with me. Please I want to read a file which has a list of protein ids as df ,and retrieve all PDB codes for each one. I am trying to edit on your code by using :"df.iloc[i,1] = str(r.text).splitlines()[-1].split('\t')[-1].split(';')" ,but there is an error which is "list index out of range". Please can you  help me with that?
Answers.UserDisplayName: Protocol313
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2018-08-27T02:10:00.817Z
Answers.Text: I did it by using :"df.iloc[i,1] = r" instead of using a list,and I get a file with all protein ids and PDB codes. Is that correct? Or I am missing something! Thank you so much for your answer; it is really helping me a lot. I really appreciate it .
Answers.UserDisplayName: Protocol313
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2018-08-27T05:46:30.633Z
Answers.Text: Try a more simple example, just copy a few ids in the list and see if it works. Without seeing your dataframe it is hard to guess where the problem occurs.
Answers.UserDisplayName: Maximilian Peters
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2018-08-26T11:17:29.610Z
Answers.LastActivityDate: 2018-08-26T11:17:29.610Z
Answers.UserDisplayName: Maximilian Peters
Answers.Body: <p>You could use mapping between UniProt and PDB entries from the <a href="https://www.ebi.ac.uk/pdbe/docs/sifts/" rel="nofollow noreferrer">SIFTS project</a>.
  The <code>uniprot_pdb.csv</code> file there has UniProt accession names followed by a semicolon-separated list of PDB four letter codes.</p>
  
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2018-08-27T15:21:59.967Z
Answers.LastActivityDate: 2018-08-27T15:21:59.967Z
Answers.UserDisplayName: marcin
Body: <p>I am working on a project about phosphorylation, and I am creating a database of some proteins. I have a list of protein accession ids for which I need to get the corresponding PDB file for each one to map it to PSM matrix. I want to get the PDB file using Python or BioPython tools. Any suggestions will be appreciated.</p>
  
Comments.ContentLicense: CC BY-SA 4.0
Comments.CreationDate: 2018-08-26T05:00:54.527Z
Comments.Text: Thanks for your reply. I have a list of protein ids, and I want to retrieve PDB code for each one! I made the protein ids database with the phosphorylation cite for each position. However, I need PDB code because I want to map it to PSM matrix. I have no idea how to retrieve PDB code! Thanks again
Comments.UserDisplayName: Protocol313
Comments.ContentLicense: CC BY-SA 4.0
Comments.CreationDate: 2018-08-26T08:51:41.877Z
Comments.Text: Please include a few IDs and the expected outcome, i.e. ID: P26378 should map to PDB: 1FXL, etc. If you just need to do it a few times, you could use the UniProt web interface, just upload a bunch of identifiers and get the corresponding PDB IDs. https://www.uniprot.org/uploadlists/
Comments.UserDisplayName: Maximilian Peters
Comments.ContentLicense: CC BY-SA 4.0
Comments.CreationDate: 2018-08-26T09:22:08.823Z
Comments.Text: Thanks man, I really appreciate your reply. I am currently using this website to map protein accession ids to  PDB. However, I want to do it by the code because I have a big list of protein ids. I want to get PDB by code so I can map it to PSSM to get the structure of the proteins. I want to do it in the one piece of code,not separately! Again Thanks for your kind and helpful reply!
Comments.UserDisplayName: Protocol313
Tags: <python><pdb>
Title: Get a list of PDB ids from a list of sequence protein number?
ThreadText: # Get a list of PDB ids from a list of sequence protein number?
  
  (Asked by: username_0 on 2018-08-26)
  
  I am working on a project about phosphorylation, and I am creating a database of some proteins. I have a list of protein accession ids for which I need to get the corresponding PDB file for each one to map it to PSM matrix. I want to get the PDB file using Python or BioPython tools. Any suggestions will be appreciated.
  
  **Tags:** python, pdb
  
  > **Comments:**
  > **username_0**: Thanks for your reply. I have a list of protein ids, and I want to retrieve PDB code for each one! I made the protein ids database with the phosphorylation cite for each position. However, I need PDB code because I want to map it to PSM matrix. I have no idea how to retrieve PDB code! Thanks again  
  > **username_1**: Please include a few IDs and the expected outcome, i.e. ID: P26378 should map to PDB: 1FXL, etc. If you just need to do it a few times, you could use the UniProt web interface, just upload a bunch of identifiers and get the corresponding PDB IDs. https://www.uniprot.org/uploadlists/  
  > **username_0**: Thanks man, I really appreciate your reply. I am currently using this website to map protein accession ids to  PDB. However, I want to do it by the code because I have a big list of protein ids. I want to get PDB by code so I can map it to PSSM to get the structure of the proteins. I want to do it in the one piece of code,not separately! Again Thanks for your kind and helpful reply!  
  
  ---
  
  ## 2 answers
  
  ### Answer by username_1 on 2018-08-26. Score: 2
  
  A typical Uniprot URL would look like the example here:
  
  <https://www.uniprot.org/uniprot/?query=ID:P26378&format=tab&columns=id%2Cdatabase(PDB)>
  
  The response will be:
  
  > Entry Cross-reference (PDB)
  >
  > P26378 1FXL;1G2E;
  
  We want our query to include the protein ID, the output format should be tab separated and the only contain the columns `id` and `database (PDB)`.
  
  To get the PDB IDs you would need to split the response, take the last line, split this line after each tab and split it again after each semi-colon.
  
  Using Python's Requests library the whole code would be.
  
  ```
  import requests
  import time
  
  uniprot_ids = ['P26378', 'O35433', 'Q02910']
  url = 'https://www.uniprot.org/uniprot/'
  
  protein_to_pdb = {}
  for protein in uniprot_ids:
      params = {
          'format': 'tab',
          'query': 'ID:{}'.format(protein),
          'columns': 'id,database(PDB)'
      }
      contact = ""  # Please set your email address here.
      headers = {'User-Agent': 'Python {}'.format(contact)}
      r = requests.get(url, params=params, headers=headers)
  
      protein_to_pdb[protein] = str(r.text).splitlines()[-1].split('\t')[-1].split(';')
      protein_to_pdb[protein].pop(-1)
      time.sleep(1)  # be respectful and don't overwhelm the server with requests
  
  print(protein_to_pdb)
  
  ```
  
  ---
  
  * To accelerate things, you could store your `protein_to_pdb` dict in a file and only retrieve the new ones
  * Checking if the returned ID matches your input ID is always a good idea
  
  > **Comments:**
  > **username_0**: Thanks man, I really appreciate your answer and your time with me. Please I want to read a file which has a list of protein ids as df ,and retrieve all PDB codes for each one. I am trying to edit on your code by using :"df.iloc[i,1] = str(r.text).splitlines()[-1].split('\t')[-1].split(';')" ,but there is an error which is "list index out of range". Please can you  help me with that?  
  > **username_0**: I did it by using :"df.iloc[i,1] = r" instead of using a list,and I get a file with all protein ids and PDB codes. Is that correct? Or I am missing something! Thank you so much for your answer; it is really helping me a lot. I really appreciate it .  
  > **username_1**: Try a more simple example, just copy a few ids in the list and see if it works. Without seeing your dataframe it is hard to guess where the problem occurs.  
  
  ---
  
  ### Answer by username_2 on 2018-08-27. Score: 0
  
  You could use mapping between UniProt and PDB entries from the [SIFTS project](https://www.ebi.ac.uk/pdbe/docs/sifts/).
  The `uniprot_pdb.csv` file there has UniProt accession names followed by a semicolon-separated list of PDB four letter codes.
  
  
  ---
  
  