Answers.Body: <p>Something like this will work, it did just now for me.  You might want to extract different info from the records though.<br />
  This exports to a table (bibliography.tsv) columns containing:</p>
  <ul>
  <li>pmid</li>
  <li>authors</li>
  <li>title</li>
  <li>journal</li>
  <li>year</li>
  </ul>
  <pre class="lang-py prettyprint-override"><code>max_attempts = 5
  def fetch_pubmed_data(pmid):
      Entrez.email = &quot;you@email.com&quot;  # Replace with your email address    
      handle = Entrez.efetch(db=&quot;pubmed&quot;, id=pmid, rettype=&quot;xml&quot;, retmode=&quot;text&quot;)
      record = Entrez.read(handle)
      time.sleep(1)
      return record
  
  
  def extract_cited_articles(pmid):
      
      record = fetch_pubmed_data(pmid)
      cited_pmids = []
  
      record_article = record['PubmedArticle']
  
      if &quot;PubmedData&quot; in record_article[0] and &quot;ReferenceList&quot; in record_article[0][&quot;PubmedData&quot;]:
          for reference in record_article[0][&quot;PubmedData&quot;][&quot;ReferenceList&quot;][0][&quot;Reference&quot;]:
              if &quot;ArticleIdList&quot; in reference and len(reference[&quot;ArticleIdList&quot;]) &gt; 0:
                  cited_pmids.append(reference[&quot;ArticleIdList&quot;][0])
  
      return cited_pmids
  
  
  def extract_bibliographic_info(pmid_list, max_attempts):
      bibliographic_info = {}
      bibliographic_info_ls = []
  
      for pmid in pmid_list:
  
          authors = title = journal = year = &quot;&quot;
          record = {}
  
          for attempt in range(max_attempts):
              try:
                  record = fetch_pubmed_data(pmid)
                  break
  
              except:
                  time.sleep(5)
  
          if 'PubmedArticle' in record:
              if len(record['PubmedArticle']) &gt;0:
                  article = record['PubmedArticle'][0][&quot;MedlineCitation&quot;][&quot;Article&quot;]
  
                  if &quot;AuthorList&quot; in article:
                      authors = &quot;, &quot;.join([f&quot;{author['LastName']} {author['Initials']}&quot; for author in article[&quot;AuthorList&quot;] if 'LastName' in author and 'Initials' in author])
                      title = article[&quot;ArticleTitle&quot;]
                      journal = article[&quot;Journal&quot;][&quot;Title&quot;]
                      year = article[&quot;Journal&quot;][&quot;JournalIssue&quot;][&quot;PubDate&quot;][&quot;Year&quot;]
  
  
          print (pmid, authors, title, journal, year)
          bibliographic_info_ls.append([pmid, authors, title, journal, year])
  
      return bibliographic_info_ls
  
  
  def main():
      pmid = input(&quot;Enter the PubMed article ID: &quot;)
      cited_pmids = extract_cited_articles(pmid)
      bibliographic_info_ls = extract_bibliographic_info(cited_pmids, max_attempts)
  
      df = pd.DataFrame(bibliographic_info_ls, columns=[&quot;pmid&quot;, &quot;authors&quot;, &quot;title&quot;, &quot;journal&quot;, &quot;year&quot;])
      df.to_csv(&quot;bibliography.tsv&quot;, sep=&quot;\t&quot;, index=False)
      return df
      
  if __name__ == &quot;__main__&quot;:
      df = main()
  </code></pre>
  
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2023-04-10T12:01:25.750Z
Answers.Text: Really amazing code. Thank you very much. I just had to change to change cited_pmids.append(reference["ArticleIdList"][0]) to cited_pmids.append(reference["ArticleIdList"][-1]) to get the PMIDs instead of the PMCIDs! Thank you!
Answers.UserDisplayName: Cristian Riccio
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2023-04-06T08:52:53.623Z
Answers.LastActivityDate: 2023-04-06T15:35:01.110Z
Answers.LastEditDate: 2023-04-06T15:35:01.110Z
Answers.UserDisplayName: LamarcksLament
Body: <p>I want to do a systematic literature review of genetic variant annotation. As part of this I am interested in all the databases available to annotate genetic variants.</p>
  <p>I want to export all the references cited by the article with PubMed ID 35943817 (<a href="https://pubmed.ncbi.nlm.nih.gov/35943817/" rel="nofollow noreferrer">https://pubmed.ncbi.nlm.nih.gov/35943817/</a>), because many of these references are relevant to my review. I can see that they number 93. I want them in a CSV table with their PubMed ID, Title, etc., similar to CSV tables obtained in a search after clicking &quot;Save citations to file&quot;, Format &quot;CSV&quot;.</p>
  
Comments.ContentLicense: CC BY-SA 4.0
Comments.CreationDate: 2023-04-04T13:27:16.390Z
Comments.Text: Hi @CristianRiccio, your question is fine, but I am not sure this is 'bioinformatics'. The nearest bioinformatics solution is NCBI's Entrez, often used for sequence retrieval, but will retrieve citations from Pubmed - so if you parse the titles in the paper, e.g. [Pdfminer](https://euske.github.io/pdfminer/index.html) you can use those to obtain this data in Entrez, e.g. within Biopython.
Comments.UserDisplayName: M__
Comments.ContentLicense: CC BY-SA 4.0
Comments.CreationDate: 2023-04-05T20:04:00.947Z
Comments.Text: You're posting this as a bioinformatics question, which suggests you want code for this. Given that it's only 93 citations, it sounds like you only need to do this once, and they're all in a standard format in the paper. Is there any reason why copying the references from the paper and manually inserting field separators would not be appropriate?
Comments.UserDisplayName: gringer
Tags: <literature-search>
Title: How can I export all and only the publications cited by a specific article?
ThreadText: # How can I export all and only the publications cited by a specific article?
  
  (Asked by: username_0 on 2023-04-04)
  
  I want to do a systematic literature review of genetic variant annotation. As part of this I am interested in all the databases available to annotate genetic variants.
  
  I want to export all the references cited by the article with PubMed ID 35943817 (<https://pubmed.ncbi.nlm.nih.gov/35943817/>), because many of these references are relevant to my review. I can see that they number 93. I want them in a CSV table with their PubMed ID, Title, etc., similar to CSV tables obtained in a search after clicking "Save citations to file", Format "CSV".
  
  **Tags:** literature-search
  
  > **Comments:**
  > **username_1**: Hi @username_0, your question is fine, but I am not sure this is 'bioinformatics'. The nearest bioinformatics solution is NCBI's Entrez, often used for sequence retrieval, but will retrieve citations from Pubmed - so if you parse the titles in the paper, e.g. [Pdfminer](https://euske.github.io/pdfminer/index.html) you can use those to obtain this data in Entrez, e.g. within Biopython.  
  > **username_2**: You're posting this as a bioinformatics question, which suggests you want code for this. Given that it's only 93 citations, it sounds like you only need to do this once, and they're all in a standard format in the paper. Is there any reason why copying the references from the paper and manually inserting field separators would not be appropriate?  
  
  ---
  
  ## 1 answers
  
  ### Answer by username_3 on 2023-04-06. Score: 2
  
  Something like this will work, it did just now for me. You might want to extract different info from the records though.  
  This exports to a table (bibliography.tsv) columns containing:
  
  * pmid
  * authors
  * title
  * journal
  * year
  
  ```py
  max_attempts = 5
  def fetch_pubmed_data(pmid):
      Entrez.email = "you@email.com"  # Replace with your email address    
      handle = Entrez.efetch(db="pubmed", id=pmid, rettype="xml", retmode="text")
      record = Entrez.read(handle)
      time.sleep(1)
      return record
  
  def extract_cited_articles(pmid):
      
      record = fetch_pubmed_data(pmid)
      cited_pmids = []
  
      record_article = record['PubmedArticle']
  
      if "PubmedData" in record_article[0] and "ReferenceList" in record_article[0]["PubmedData"]:
          for reference in record_article[0]["PubmedData"]["ReferenceList"][0]["Reference"]:
              if "ArticleIdList" in reference and len(reference["ArticleIdList"]) > 0:
                  cited_pmids.append(reference["ArticleIdList"][0])
  
      return cited_pmids
  
  def extract_bibliographic_info(pmid_list, max_attempts):
      bibliographic_info = {}
      bibliographic_info_ls = []
  
      for pmid in pmid_list:
  
          authors = title = journal = year = ""
          record = {}
  
          for attempt in range(max_attempts):
              try:
                  record = fetch_pubmed_data(pmid)
                  break
  
              except:
                  time.sleep(5)
  
          if 'PubmedArticle' in record:
              if len(record['PubmedArticle']) >0:
                  article = record['PubmedArticle'][0]["MedlineCitation"]["Article"]
  
                  if "AuthorList" in article:
                      authors = ", ".join([f"{author['LastName']} {author['Initials']}" for author in article["AuthorList"] if 'LastName' in author and 'Initials' in author])
                      title = article["ArticleTitle"]
                      journal = article["Journal"]["Title"]
                      year = article["Journal"]["JournalIssue"]["PubDate"]["Year"]
  
          print (pmid, authors, title, journal, year)
          bibliographic_info_ls.append([pmid, authors, title, journal, year])
  
      return bibliographic_info_ls
  
  def main():
      pmid = input("Enter the PubMed article ID: ")
      cited_pmids = extract_cited_articles(pmid)
      bibliographic_info_ls = extract_bibliographic_info(cited_pmids, max_attempts)
  
      df = pd.DataFrame(bibliographic_info_ls, columns=["pmid", "authors", "title", "journal", "year"])
      df.to_csv("bibliography.tsv", sep="\t", index=False)
      return df
      
  if __name__ == "__main__":
      df = main()
  
  ```
  
  > **Comments:**
  > **username_0**: Really amazing code. Thank you very much. I just had to change to change cited_pmids.append(reference["ArticleIdList"][0]) to cited_pmids.append(reference["ArticleIdList"][-1]) to get the PMIDs instead of the PMCIDs! Thank you!  
  
  ---
  
  