Question: problem in code to retrieve articles titles from pubmed
0
gravatar for dreamzz.4you
4.0 years ago by
dreamzz.4you0 wrote:

Hi there,

i am trying to fetch author names and articles' titles from pubmed. The only issue in this code is, it is giving title of articles in this form: ['R', 'o', 'u', 't', 'i', 'n', 'e', ' ', 'A', 'm', 'o', 'x', 'i', 'c', 'i', 'l', 'l', 'i', 'n', ' ', 'f', 'o', 'r', ' ', 'U', 'n', 'c', 'o', 'm', 'p', 'l', 'i', 'c', 'a', 't', 'e', ']

i mean separating each character with ' '. i want to get the names in a proper way. I am learner of python. please anyone help me out.

 

from Bio import Entrez
from Bio import Medline

MAX_COUNT = 15
TERM = 'clinicaltrials.gov+[si]'

#print("getting %d publications containing %s" % (MAX_COUNT,TERM))

print('Getting {0} publications containing {1}...'.format(MAX_COUNT, TERM))
Entrez.email = 'A.N.Other@example.com'
h = Entrez.esearch(db='pubmed', retmax=MAX_COUNT, term=TERM)
result = Entrez.read(h)
print('Total number of publications containing {0}: {1}'.format(TERM, result['Count']))



ids = result['IdList']
h = Entrez.efetch(db='pubmed', id=ids, rettype="Medline", retmode='text')
records = Medline.parse(h)

authors = []
titles=[]
for record in records:
    #print(record)
    au = record.get('AU', '?')
    title=record.get("TI","?")
   # print(au)
    for a in au:
        #if a,b not in authors,t:
        authors.append(a)
    for t in title:
        titles.append(t)
    authors.sort()
print('Authors: {0} '.format(', '.join(authors)))
print(titles)

problem in code • 1.1k views
ADD COMMENTlink modified 3.9 years ago by Biostar ♦♦ 20 • written 4.0 years ago by dreamzz.4you0
1

I am not a Python programmer but assuming that the variable title contains only one title then this code:

    for t in title:
        titles.append(t)

is taking single elements of title (i.e. characters) and adds then to an array named titles so titles ends up being a list of characters contained in title. Just stick to your title variable and if you want to add it to a list of titles then do

titles.append(title)
ADD REPLYlink modified 4.0 years ago • written 4.0 years ago by Jean-Karim Heriche21k
Please log in to add an answer.

Help
Access

Use of this site constitutes acceptance of our User Agreement and Privacy Policy.
Powered by Biostar version 2.3.0
Traffic: 2080 users visited in the last hour