Example #1
0
def pubmed(gi,ids,query):
    """
    Get the pubmed articles listed by *ids
    """
    _ids=",".join(ids)
    for id in ids:
        handle = efetch(db="pubmed",id=id,retmode='xml',rettype='xml',retmax=MAX_RETURN)
        try:
            #print handle.read()
            results = eread(handle)
            for citation in results:
                #runtime().debug(citation.keys())
                citation = citation['MedlineCitation']
                pmid = citation['PMID']
                article = citation['Article']
                title = article['ArticleTitle']
                journal = article['Journal']['Title']
                try:
                    date = citation['DateCompleted'] if citation.has_key('DateCompleted') else citation['DateCreated']
                    year = date['Year']
                    month = date['Month']
                    day = date['Day']
                    datetime = "%s-%s-%s" % (year,month,day)
                except:
                    datetime = '0000-00-00'
                
                runtime().debug("Parsed pmid:%s" % id)
                yield Citation(gi, pmid, title, journal, datetime, query)
        except:
            runtime().debug("Failure fetching pmid:%s" % id)
            continue
        finally:
            handle.close()
Example #2
0
def publications(gi):
    """
    Grab the list of publications for a given protein
    """
    gi_names = list(names(gi))
    if len(gi_names) == 0:
        return
    #runtime().debug("NAMES",gi_names)
    term = " OR ".join(['"%s"' %n for n in gi_names])
    runtime().debug(term)
    handle = esearch(db="pubmed", 
            term=term,
            retmax=MAX_RETURN,
            mindate="2000")
    try:
        results = eread(handle)
    finally:
        handle.close()
    results[COUNT] = int(results[COUNT])
    runtime().debug("Found",results[COUNT])
    if results[COUNT]>0:
        runtime().debug(gi,term,"\t",results[COUNT], "\n\t",results[IDLIST])
        return list(pubmed(gi,set(results[IDLIST]),term))