Python and Biotext mining

I've been working with python a lot lately for getting documents and

I've written python utility programs to make some of my daily tasks easier for extracting data from pubmed.

I was using the packages from Biopython to query the pubmed server, but to be honest, it was taking way too long to return results so I created my own and it's fast enough to retrieve




# for each pumbed id get the elemets from the xml

for oid in ls:

    try :

        dom = minidom.parse(urllib.urlopen("http://eutils.ncbi.nlm.nih.gov/entrez/eutils/efetch.fcgi?db=pubmed&id="+oid+"&retmode=xml"))

        pmid = dom.getElementsByTagName("PMID")[0].childNodes[0].data

        journalname = dom.getElementsByTagName("MedlineTA")[0].childNodes[0].data

        authorname = dom.getElementsByTagName("AuthorList")[0].getElementsByTagName("Author")[0].getElementsByTagName("LastName")[0].childNodes[0].data

        initials = dom.getElementsByTagName("AuthorList")[0].getElementsByTagName("Author")[0].getElementsByTagName("Initials")[0].childNodes[0].data

        date = dom.getElementsByTagName("PubDate")[0].getElementsByTagName("Year")[0].childNodes[0].data



        good_docs.append( authorname + " " + initials+ " et al " + journalname + " " +date + ".pdf"  )



        f.write ( oid +"\t"+ authorname + " " + initials+ " et al " + journalname + " " +date +"\n" ) ;

    except:

        #print "failed"

        failed_docs.append( oid )







f.write ( "These documents failed\n" )

for failed in failed_docs:

        f.write ( failed + "\n" )



f.close()





Comments

Popular posts from this blog

Find countries in a file's text using regular expressions and Perl

Make links active in Excel 2007