This is a test version of Biostars. For the public version, visit https://www.biostars.org.
Getting Tab-Delimited Pmids And Abstracts From Pubmed

I have a list of 4000+ PMIDs from a meta-analysis query for which I'd like to pull abstracts from Pubmed. I can get title, description, details, nd other items using Batch Entrez http://www.ncbi.nlm.nih.gov/sites/batchentrez? But I can't find a way to get PMIDs and abstracts one per line. Is there a way to do this that doesn't require me to break up my query?

pubmed meta

3 answers

If your list of PMIDs is in a file, pmids.txt with one PMID per line, here's a shell script with TogoWS solution:

for i in `cat pmids.txt`; do echo -n $i;ruby -e 'print "\t"'; curl "http://togows.dbcls.jp/entry/ncbi-pubmed/$i/ab"; done

Good lord, that is an impressive one-liner.

So, in addition to .ab and .pmid, where is there a list of all the suffixes and their corresponding fields which can be pulled from Medline or other NCBI databases in this manner?

Once you get all your articles, click on the button send-to /File/XML and save the articles as XML.

Then apply this XSLT-stylesheet ( xsltproc --novalid stylesheet.xsl pubmed_result.txt )

<xsl:stylesheet version="1.0" xmlns:xsl="&lt;a href=" http:="" www.w3.org="" 1999="" XSL="" Transform"="" rel="nofollow">http://www.w3.org/1999/XSL/Transform" 
    >

<xsl:output method="text"/>
<xsl:template match="/">
    <xsl:for-each select="/PubmedArticleSet/PubmedArticle">
        <xsl:value-of select="MedlineCitation/PMID"/>
        <xsl:text>  </xsl:text>
        <xsl:value-of select="normalize-space(MedlineCitation/Article/Abstract)"/>
        <xsl:text>
</xsl:text>
    </xsl:for-each>
</xsl:template>

</xsl:stylesheet>

Thanks, Pierre. This worked on the file I had. I had pulled an XML file but was unaware of this xsltproc command. I'd not worked with XML files before.

Some parsing is required in cases like this.

If your list of PMIDs is in a file, pmids.txt with one PMID per line, here's a BioRuby solution:

#!/usr/bin/ruby

require "rubygems" # ruby1.8
require "bio"

Bio::NCBI.default_email = "me@me.com"

File.read("pmids.txt").each do |line|
  article = Bio::PubMed.query(line)
  medline = Bio::MEDLINE.new(article)
  puts "#{medline.pmid}\t#{medline.ab}"
end

Neil, this is a quite elegant solution. The more I learn about ruby, the more I am impressed by it.

Log in to answer this question.